src/c2html.c

changeset 18
5085b57e3fd6
parent 17
7ea86024aef0
child 19
2e812df2b231
equal deleted inserted replaced
17:7ea86024aef0 18:5085b57e3fd6
33 #include <fcntl.h> 33 #include <fcntl.h>
34 #include <unistd.h> 34 #include <unistd.h>
35 #include <ctype.h> 35 #include <ctype.h>
36 36
37 #define INPUTBUF_SIZE 2048 37 #define INPUTBUF_SIZE 2048
38 #define WORDBUF_SIZE 16 38 #define WORDBUF_SIZE 64
39 39
40 const char* ckeywords[] = { 40 const char* ckeywords[] = {
41 "auto", "break", "case", "char", "const", "continue", "default", "do", 41 "auto", "break", "case", "char", "const", "continue", "default", "do",
42 "double", "else", "enum", "extern", "float", "for", "goto", "if", "int", 42 "double", "else", "enum", "extern", "float", "for", "goto", "if", "int",
43 "long", "register", "return", "short", "signed", "sizeof", "static", 43 "long", "register", "return", "short", "signed", "sizeof", "static",
52 "import", "public", "throws", "case", "enum", "instanceof", "return", 52 "import", "public", "throws", "case", "enum", "instanceof", "return",
53 "transient", "catch", "extends", "int", "short", "try", "char", "final", 53 "transient", "catch", "extends", "int", "short", "try", "char", "final",
54 "interface", "static", "void", "class", "finally", "long", "strictfp", 54 "interface", "static", "void", "class", "finally", "long", "strictfp",
55 "volatile", "const", "float", "native", "super", "while", NULL 55 "volatile", "const", "float", "native", "super", "while", NULL
56 }; 56 };
57
58 #define iswordcharacter(c) (isalnum(c) || c=='_' || c=='#' || c=='@')
57 59
58 int isctype(char *word, size_t len) { 60 int isctype(char *word, size_t len) {
59 return (word[len-2] == '_' && word[len-1] == 't'); 61 return (word[len-2] == '_' && word[len-1] == 't');
60 } 62 }
61 63
286 dp += 7; 288 dp += 7;
287 } 289 }
288 } else { 290 } else {
289 if (isstring) { 291 if (isstring) {
290 dp = writeescapedchar(dest, dp, c); 292 dp = writeescapedchar(dest, dp, c);
291 } else if (!isalnum(c) && c!='_' && c!='#' && c!='.' && c!='@') { 293 } else if (!iswordcharacter(c)) {
292 /* interpret word int_t */ 294 /* interpret word int_t */
293 if (wp > 0 && wp < WORDBUF_SIZE) { 295 if (wp > 0 && wp < WORDBUF_SIZE) {
294 int closespan = 1; 296 int closespan = 1;
295 if (iskeyword(word, highlighter->keywords)) { 297 if (iskeyword(word, highlighter->keywords)) {
296 memcpy(&(dest[dp]), "<span class=\"c2html-keyword\">", 29); 298 memcpy(&(dest[dp]), "<span class=\"c2html-keyword\">", 29);

mercurial