Fri, 21 Jun 2013 12:49:46 +0200
long words are correctly separated by non alpha numeric chars, underscore or hash + support for macro constants
src/c2html.c | file | annotate | diff | comparison | revisions | |
test/header.html | file | annotate | diff | comparison | revisions |
--- a/src/c2html.c Fri Jun 21 12:27:45 2013 +0200 +++ b/src/c2html.c Fri Jun 21 12:49:46 2013 +0200 @@ -149,6 +149,15 @@ return 0; } +int iscapsonly(char *word, size_t wp) { + for (size_t i = 0 ; i < wp ; i++) { + if (!isupper(word[i]) && word[i] != '_') { + return 0; + } + } + return 1; +} + void parseline(char *src, char *dest) { size_t sp = 0, dp = 0; /* indent */ @@ -167,8 +176,7 @@ memcpy(&(dest[dp]), "<span class=\"c2html-comment\">", 29); dp += 29; } - // a fucking /* comment */ - /* again // / */ + for (char c = src[sp] ; c ; c=src[++sp]) { /* comments */ if (c == '/') { @@ -221,6 +229,9 @@ } else if (isdirective(word)) { memcpy(&(dest[dp]), "<span class=\"c2html-directive\">", 31); dp += 31; + } else if (iscapsonly(word, wp)) { + memcpy(&(dest[dp]), "<span class=\"c2html-macroconst\">", 32); + dp += 32; } else { closespan = 0; } @@ -231,9 +242,9 @@ memcpy(&(dest[dp]), "</span>", 7); dp += 7; } - memset(word, 0, WORDBUF_SIZE); - wp = 0; } + memset(word, 0, WORDBUF_SIZE); + wp = 0; dp = writeescapedchar(dest, dp, c); } else { /* read word */ @@ -286,7 +297,7 @@ for (int i = 0 ; i < inputfile->count ; i++) { parseline(inputfile->lines[i], line); printf("<span class=\"c2html-lineno\">%*d:</span> %s", - lnw, i, line); + lnw, i+1, line); } free(line); printf("</pre>\n");