} hl_group_t;
typedef enum {
+ KEYSYMBOL,
KEYWORD,
MATCH,
REGION
-} token_t;
+} token_type_t;
typedef struct {
hl_group_t * hl;
- token_t t;
+ token_type_t t;
char* syntax;
-} token; // XXX: this will have to be renamed
+} token_t;
/* Temp solution
+ * this should be dynamic
*/
-token * token_table[1000];
+token_t * token_table[1000];
int token_table_top = 0;
-token * new_token(const char * const syntax,
- const token_t t,
+token_t * new_token(const char * const syntax,
+ const token_type_t t,
const hl_group_t * const g) {
- token * mt = (token*)malloc(sizeof(token));
+ token_t * mt = (token_t*)malloc(sizeof(token_t));
mt->hl = g;
mt->t = t;
mt->syntax = syntax;
void new_keyword_tokens(const char * const * words,
hl_group_t * const g) {
+ int i = 0;
while (*words) {
- new_token(*words, KEYWORD, g);
- words = words + 1;
+ if(new_token(*words, KEYWORD, g)){
+ ++i;
+ }
+ ++words;
}
+
+ return i;
}
int token_fits(const char* const pattern,
int i = 0;
for (; i < token_table_top; i++) {
f = token_fits(token_table[i]->syntax, s);
- if(f){ break; };
+ if(f){ break; }
}
//
display_t * display;
- HASH_FIND_STR(display_table, mode, display);
+ HASH_FIND_STR(display_table,
+ mode,
+ display);
//
if (f) {
- display->callback(s, f, token_table[i]->hl->attributes);
+ display->callback(s,
+ f,
+ token_table[i]->hl->attributes);
s += f;
} else {
- display->callback(s, 0, NULL);
+ display->callback(s,
+ 0,
+ NULL);
++s;
}
}
}
+
+void new_display_mode(display_t * mode) {
+ HASH_ADD_STR(display_table,
+ key,
+ mode);
+}
hl_group_t mygroup = (hl_group_t) {
.link = NULL
};
-
- HASH_ADD_STR(display_table,
- key,
- cterm);
+ new_display_mode(cterm);
new_keyword_tokens(c_keywords, &mygroup);
new_keyword_tokens(preprocessor_keywords, &mygroup);