1 /*
2   FXiTe - The Free eXtensIble Text Editor
3   Copyright (c) 2009-2012 Jeffrey Pohlmeyer <yetanothergeek@gmail.com>
4 
5   This program is free software; you can redistribute it and/or modify it
6   under the terms of the GNU General Public License version 3 as
7   published by the Free Software Foundation.
8 
9   This software is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   GNU General Public License for more details.
13 
14   You should have received a copy of the GNU General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18 
19 
20 
21 #include <fx.h>
22 #include <SciLexer.h>
23 
24 #include "compat.h"
25 
26 #include "lang.h"
27 
28 #define COMMNT_FG "#a04040"
29 #define PREPRC_FG "#4040e0"
30 #define NUMBER_FG "#0000ff"
31 #define OPERTR_FG "#000000"
32 #define STRING_FG "#00c000"
33 #define STREOL_FG "#ff0000"
34 #define _WORD1_FG "#b06000"
35 #define _WORD2_FG "#6000b0"
36 #define _WORD3_FG "#cc00cc"
37 #define SCALAR_FG "#00bbbb"
38 #define __ORANGE_ "#ff8000"
39 #define __PURPLE_ "#cc00cc"
40 #define ___BLUE__ "#0000ee"
41 #define __GREEN__ "#00cc00"
42 #define __DKRED__ "#cc6060"
43 #define _HERE_BG_ "#ffffee"
44 
45 #define _DEFLT_BG "\0\0\0\0\0\0\0"
46 #define _DEFLT_FG "\0\0\0\0\0\0\0"
47 
48 static LangStyle LangNULL = {
49   NULL,
50   SCLEX_NULL,
51   NULL,
52   NULL,
53   NULL,
54   NULL,
55   0,
56   TABS_DEFAULT
57 };
58 
59 
60 
61 #include "langlist.h"
62 
63 
64 
KeywordListsCount(LangStyle * lang)65 static int KeywordListsCount(LangStyle*lang)
66 {
67   int i=0;
68   while (lang->words[i]) { i++; }
69   return i;
70 }
71 
72 
73 
SetKeywordList(LangStyle * lang,int index,const FXString & keywords)74 void SetKeywordList(LangStyle*lang, int index, const FXString &keywords)
75 {
76   FXuint flag=1<<index;
77   if (!lang) { return; }
78   if ((index<0)||(index>=KeywordListsCount(lang))) { return; }
79   if (strcmp(keywords.text(),lang->words[index])==0) { return; }
80   if ( lang->mallocs & flag ) {
81     free(lang->words[index]);
82     lang->words[index]=NULL;
83   }
84   lang->words[index]=strdup(keywords.text());
85   lang->mallocs |= flag;
86 }
87 
88 
89 
GetLangByName(const char * name)90 LangStyle*GetLangByName(const char*name)
91 {
92   if (name) {
93     LangStyle*lang;
94     for (lang=languages; lang->name; lang++) {
95       if (strcmp(name, lang->name)==0) { return lang; }
96     }
97   }
98   return NULL;
99 }
100 
101 
102 
FreeAllKeywordLists()103 void FreeAllKeywordLists()
104 {
105   LangStyle*lang;
106   for (lang=languages; lang->name; lang++) {
107     int i;
108     for (i=0; lang->words[i]; i++) {
109       if (lang->mallocs & (1<<i)) {
110         free(lang->words[i]);
111       }
112     }
113     if (lang->mallocs & LANGSTYLE_MASK_ALLOCD) {
114       free(lang->mask);
115     }
116     if (lang->mallocs & LANGSTYLE_APPS_ALLOCD) {
117       free(lang->apps);
118     }
119   }
120 }
121 
122 
GetLangFromDocName(const char * filename)123 LangStyle*GetLangFromDocName(const char*filename)
124 {
125   LangStyle*lang;
126   for (lang=languages; lang->name; lang++) {
127     if (PathMatch(lang->mask,filename,FILEMATCH_FILE_NAME|FILEMATCH_CASEFOLD)) { return lang; }
128   }
129   return NULL;
130 }
131 
132 
GetLangFromAppName(const char * app)133 LangStyle*GetLangFromAppName(const char*app)
134 {
135    LangStyle*lang;
136   int len=app?strlen(app):0;
137   if (!len) {return NULL;}
138   for (lang=languages; lang->name; lang++) {
139     char*p=lang->apps;
140     while (p) {
141       while (*p=='|') {p++;}
142       if ((strncmp(p,app,len)==0) && ((p[len]=='|')||(p[len]=='\0')))  {
143         return lang;
144       }
145       p=strchr(p, '|');
146     };
147   }
148   return NULL;
149 }
150 
151 
GetStyleFromId(StyleDef * styles,int id)152 StyleDef* GetStyleFromId(StyleDef*styles, int id)
153 {
154   StyleDef*sd;
155   for (sd=styles; sd->key; sd++) {
156     if (sd->id==id) { return sd; }
157   }
158   return NULL;
159 }
160 
161