2 * Copyright (C) 2010 Diego Hernan Borghetti.
17 /* our syntax data base. */
18 static E_List syntaxs
= { NULL
, NULL
};
20 static E_Syntax_Word
*e_syntax_word_search(E_Syntax
*sy
, char *word
, int nch
)
24 p
= (E_Syntax_Word
*)sy
->dirs
.first
;
27 if (!strncmp(p
->word
, word
, nch
))
36 static E_Syntax_Char
*e_syntax_char_search(E_Syntax
*sy
, char ch
)
40 p
= (E_Syntax_Char
*)sy
->chars
.first
;
49 E_Syntax
*e_syntax_search(char *ext
)
53 p
= (E_Syntax
*)syntaxs
.first
;
55 if ((*p
->check_type
)(ext
) == 0)
62 void e_syntax_add(E_Syntax
*sy
)
65 E_LIST_ADD(&syntaxs
, sy
);
69 void e_syntax_rem(E_Syntax
*sy
)
72 E_LIST_REM(&syntaxs
, sy
);
76 E_Syntax
*e_syntax_new(void)
80 sy
= (E_Syntax
*)malloc(sizeof(E_Syntax
));
87 sy
->chars
.first
= NULL
;
92 void e_syntax_free(E_Syntax
*sy
)
96 while (sy
->dirs
.first
) {
97 p
= (E_Syntax_Word
*)sy
->dirs
.first
;
98 sy
->dirs
.first
= sy
->dirs
.first
->next
;
99 free((void *)p
->word
);
104 free((void *)sy
->name
);
109 void e_syntax_word_add(E_Syntax
*sy
, char *word
, char fg
, char bg
)
113 wr
= e_syntax_word_search(sy
, word
, strlen(word
));
117 wr
= (E_Syntax_Word
*)malloc(sizeof(E_Syntax_Word
));
120 wr
->word
= strdup(word
);
121 wr
->nch
= strlen(wr
->word
);
124 E_LIST_ADD(&sy
->dirs
, wr
);
127 void e_syntax_char_add(E_Syntax
*sy
, char ch
, char fg
, char bg
)
131 cha
= e_syntax_char_search(sy
, ch
);
135 cha
= (E_Syntax_Char
*)malloc(sizeof(E_Syntax_Char
));
141 E_LIST_ADD(&sy
->chars
, cha
);
144 static int e_syntax_word(char *line
, int *idx
, int nch
)
150 for (i
= *idx
; i
< nch
; i
++) {
151 if (line
[i
] != ' ' && line
[i
] != '\t' && !first
) {
156 if (first
&& (line
[i
] == ' ' || line
[i
] == '\t'))
164 static void e_syntax_color(E_Syntax_Word
*wr
, E_ScreenLine
*ln
, int i
, int nch
)
168 for (e
= i
; e
< (i
+nch
); e
++) {
169 ln
->fcol
[e
]= wr
->fgcol
;
170 ln
->bcol
[e
]= wr
->bgcol
;
174 void e_syntax_apply(E_Syntax
*sy
, E_ScreenLine
*ln
, int ncol
)
182 /* First round, check for words. */
184 nch
= e_syntax_word(ln
->text
, &i
, ncol
);
190 wr
= e_syntax_word_search(sy
, &(ln
->text
[i
]), nch
);
192 e_syntax_color(wr
, ln
, i
, nch
);
199 /* Second round, check for characters. */
201 for (i
= 0; i
< ncol
; i
++) {
202 ch
= e_syntax_char_search(sy
, ln
->text
[i
]);
204 ln
->fcol
[i
]= ch
->fgcol
;
205 ln
->bcol
[i
]= ch
->bgcol
;