--- a/src/javacodegen.c Sat Apr 25 19:01:16 2015 +0200 +++ b/src/javacodegen.c Sat Apr 25 19:14:57 2015 +0200 @@ -49,6 +49,9 @@ return word[0] == '@'; } +#define memcpy_const(darr,doff,str) memcpy(&(darr[doff]), str, sizeof(str)-1); \ + dp += sizeof(str)-1 + void jparseline(char *src, char *dest, highlighter_t *hltr) { size_t sp = 0, dp = 0; /* indent */ @@ -64,8 +67,7 @@ if (hltr->iscommentml) { iscomment = 1; - memcpy(&(dest[dp]), "<span class=\"c2html-comment\">", 29); - dp += 29; + memcpy_const(dest, dp, "<span class=\"c2html-comment\">"); } for (char c = src[sp] ; c ; c=src[++sp]) { @@ -74,14 +76,12 @@ if (hltr->iscommentml && sp > 0 && src[sp-1] == '*') { iscomment = 0; hltr->iscommentml = 0; - memcpy(&(dest[dp]), "/</span>", 8); - dp += 8; + memcpy_const(dest, dp, "/</span>"); continue; } else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) { iscomment = 1; hltr->iscommentml = (src[sp+1] == '*'); - memcpy(&(dest[dp]), "<span class=\"c2html-comment\">", 29); - dp += 29; + memcpy_const(dest, dp, "<span class=\"c2html-comment\">"); } } @@ -97,20 +97,19 @@ /* strings */ if (!isescaping && (c == '\'' || c == '\"')) { if (isstring) { + dp = writeescapedchar(dest, dp, c); if (c == quote) { isstring = 0; - memcpy(&(dest[dp]), "<span class=\"c2html-string\">", 28); - dp += 28; - dp = writeescapedchar(dest, dp, c); + memcpy_const(dest, dp, "</span>"); } else { dp = writeescapedchar(dest, dp, c); } } else { isstring = 1; quote = c; + memcpy_const(dest, dp, + "<span class=\"c2html-string\">"); dp = writeescapedchar(dest, dp, c); - memcpy(&(dest[dp]), "</span>", 7); - dp += 7; } } else { if (isstring) { @@ -120,21 +119,17 @@ if (wp > 0 && wp < WORDBUF_SIZE) { int closespan = 1; if (iskeyword(hltr->word, hltr->keywords)) { - memcpy(&(dest[dp]), - "<span class=\"c2html-keyword\">", 29); - dp += 29; + memcpy_const(dest, dp, + "<span class=\"c2html-keyword\">"); } else if (hltr->istype(hltr->word, wp)) { - memcpy(&(dest[dp]), - "<span class=\"c2html-type\">", 26); - dp += 26; + memcpy_const(dest, dp, + "<span class=\"c2html-type\">"); } else if (hltr->isdirective(hltr->word)) { - memcpy(&(dest[dp]), - "<span class=\"c2html-directive\">", 31); - dp += 31; + memcpy_const(dest, dp, + "<span class=\"c2html-directive\">"); } else if (iscapsonly(hltr->word, wp)) { - memcpy(&(dest[dp]), - "<span class=\"c2html-macroconst\">", 32); - dp += 32; + memcpy_const(dest, dp, + "<span class=\"c2html-macroconst\">"); } else { closespan = 0; } @@ -142,8 +137,7 @@ dp = writeescapedchar(dest, dp, hltr->word[i]); } if (closespan) { - memcpy(&(dest[dp]), "</span>", 7); - dp += 7; + memcpy_const(dest, dp, "</span>"); } } memset(hltr->word, 0, WORDBUF_SIZE);