43 "long", "register", "return", "short", "signed", "sizeof", "static", |
43 "long", "register", "return", "short", "signed", "sizeof", "static", |
44 "struct", "switch", "typedef", "union", "unsigned", "void", "volatile", |
44 "struct", "switch", "typedef", "union", "unsigned", "void", "volatile", |
45 "while", NULL |
45 "while", NULL |
46 }; |
46 }; |
47 |
47 |
48 int istype(char *word, size_t len) { |
48 const char* jkeywords[] = { |
|
49 "abstract", "continue", "for", "new", "switch", "assert", "default", "goto", |
|
50 "package", "synchronized", "boolean", "do", "if", "private", "this", |
|
51 "break", "double", "implements", "protected", "throw", "byte", "else", |
|
52 "import", "public", "throws", "case", "enum", "instanceof", "return", |
|
53 "transient", "catch", "extends", "int", "short", "try", "char", "final", |
|
54 "interface", "static", "void", "class", "finally", "long", "strictfp", |
|
55 "volatile", "const", "float", "native", "super", "while", NULL |
|
56 }; |
|
57 |
|
58 int isctype(char *word, size_t len) { |
49 return (word[len-2] == '_' && word[len-1] == 't'); |
59 return (word[len-2] == '_' && word[len-1] == 't'); |
50 } |
60 } |
51 |
61 |
52 int isdirective(char *word) { |
62 int iscdirective(char *word) { |
53 return (word[0] == '#'); |
63 return (word[0] == '#'); |
54 } |
64 } |
55 |
65 |
56 int notypes(char *word, size_t len) { |
66 int isjtype(char *word, size_t len) { |
57 return 0; |
67 return isupper(word[0]); |
58 } |
68 } |
59 |
69 |
60 int nodirectives(char *word) { |
70 int isjdirective(char *word) { |
61 return 0; |
71 return word[0] == '@'; |
62 } |
72 } |
63 |
73 |
64 typedef struct { |
74 typedef struct { |
65 const char** keywords; |
75 const char** keywords; |
66 int(*istype)(char*,size_t); |
76 int(*istype)(char*,size_t); |
276 dp += 7; |
286 dp += 7; |
277 } |
287 } |
278 } else { |
288 } else { |
279 if (isstring) { |
289 if (isstring) { |
280 dp = writeescapedchar(dest, dp, c); |
290 dp = writeescapedchar(dest, dp, c); |
281 } else if (!isalnum(c) && c != '_' && c != '#' && c != '.') { |
291 } else if (!isalnum(c) && c!='_' && c!='#' && c!='.' && c!='@') { |
282 /* interpret word int_t */ |
292 /* interpret word int_t */ |
283 if (wp > 0 && wp < WORDBUF_SIZE) { |
293 if (wp > 0 && wp < WORDBUF_SIZE) { |
284 int closespan = 1; |
294 int closespan = 1; |
285 if (iskeyword(word, highlighter->keywords)) { |
295 if (iskeyword(word, highlighter->keywords)) { |
286 memcpy(&(dest[dp]), "<span class=\"c2html-keyword\">", 29); |
296 memcpy(&(dest[dp]), "<span class=\"c2html-keyword\">", 29); |
354 settings_t settings; |
365 settings_t settings; |
355 settings.outfilename = NULL; |
366 settings.outfilename = NULL; |
356 settings.highlight = 1; |
367 settings.highlight = 1; |
357 |
368 |
358 highlighter_t highlighter; |
369 highlighter_t highlighter; |
359 highlighter.isdirective = isdirective; |
370 highlighter.isdirective = iscdirective; |
360 highlighter.istype = istype; |
371 highlighter.istype = isctype; |
361 highlighter.keywords = ckeywords; |
372 highlighter.keywords = ckeywords; |
362 |
373 |
363 char optc; |
374 char optc; |
364 while ((optc = getopt(argc, argv, "ho:p")) != -1) { |
375 while ((optc = getopt(argc, argv, "hjo:p")) != -1) { |
365 switch (optc) { |
376 switch (optc) { |
366 case 'o': |
377 case 'o': |
367 if (!(optarg[0] == '-' && optarg[1] == 0)) { |
378 if (!(optarg[0] == '-' && optarg[1] == 0)) { |
368 settings.outfilename = optarg; |
379 settings.outfilename = optarg; |
369 } |
380 } |
|
381 break; |
|
382 case 'j': |
|
383 highlighter.isdirective = isjdirective; |
|
384 highlighter.istype = isjtype; |
|
385 highlighter.keywords = jkeywords; |
370 break; |
386 break; |
371 case 'p': |
387 case 'p': |
372 settings.highlight = 0; |
388 settings.highlight = 0; |
373 break; |
389 break; |
374 case 'h': |
390 case 'h': |