--- a/src/javacodegen.c Tue Aug 23 15:55:02 2016 +0200 +++ b/src/javacodegen.c Tue Aug 23 16:34:02 2016 +0200 @@ -44,17 +44,21 @@ #define memcpy_const(darr,doff,str) memcpy(&(darr[doff]), str, sizeof(str)-1); \ dp += sizeof(str)-1 -void jparseline(char *src, UcxBuffer *destbuf, HighlighterData *hltr) { +void jparseline(char *src, UcxBuffer *destbuf, int *multiline_comment) { /* TODO: workaround for using old code with UcxBuffer */ char *dest = destbuf->space + destbuf->pos; - memset(hltr->word, 0, WORDBUF_SIZE); - size_t wp = 0, sp = (size_t)-1, dp = 0; + /* TODO: try to replace this buffer */ + char wordbuf[WORDBUF_SIZE]; + sstr_t word; + word.ptr = wordbuf; word.length = 0; + + size_t sp = (size_t)-1, dp = 0; int isstring = 0, iscomment = 0, isimport = 0; char quote = '\0'; int isescaping = 0; - if (hltr->iscommentml) { + if (*multiline_comment) { iscomment = 1; memcpy_const(dest, dp, "<span class=\"c2html-comment\">"); } @@ -66,14 +70,14 @@ /* comments */ if (!isstring && c == '/') { - if (hltr->iscommentml && sp > 0 && src[sp-1] == '*') { + if (*multiline_comment && sp > 0 && src[sp-1] == '*') { iscomment = 0; - hltr->iscommentml = 0; + *multiline_comment = 0; memcpy_const(dest, dp, "/</span>"); continue; } else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) { iscomment = 1; - hltr->iscommentml = (src[sp+1] == '*'); + *multiline_comment = (src[sp+1] == '*'); memcpy_const(dest, dp, "<span class=\"c2html-comment\">"); } } @@ -85,7 +89,7 @@ } dp = writeescapedchar(dest, dp, c); } else if (isimport) { - // TODO: local imports + /* TODO: local imports */ } else { /* strings */ if (!isescaping && (c == '\'' || c == '\"')) { @@ -108,43 +112,41 @@ if (isstring) { dp = writeescapedchar(dest, dp, c); } else if (!iswordcharacter(c)) { - /* interpret word int_t */ - if (wp > 0 && wp < WORDBUF_SIZE) { + if (word.length > 0 && word.length < WORDBUF_SIZE) { int closespan = 1; - if (check_keyword(hltr->word, jkeywords)) { + if (check_keyword(word, jkeywords)) { memcpy_const(dest, dp, "<span class=\"c2html-keyword\">"); - } else if (isupper(hltr->word[0])) { + } else if (isupper(word.ptr[0])) { memcpy_const(dest, dp, "<span class=\"c2html-type\">"); - } else if (hltr->word[0] == '@') { + } else if (word.ptr[0] == '@') { memcpy_const(dest, dp, "<span class=\"c2html-directive\">"); - } else if (check_capsonly(hltr->word, wp)) { + } else if (check_capsonly(word)) { memcpy_const(dest, dp, "<span class=\"c2html-macroconst\">"); } else { closespan = 0; } - for (int i = 0 ; i < wp ; i++) { - dp = writeescapedchar(dest, dp, hltr->word[i]); + for (int i = 0 ; i < word.length ; i++) { + dp = writeescapedchar(dest, dp, word.ptr[i]); } if (closespan) { memcpy_const(dest, dp, "</span>"); } } - memset(hltr->word, 0, WORDBUF_SIZE); - wp = 0; + word.length = 0; dp = writeescapedchar(dest, dp, c); } else { /* read word */ - if (wp < WORDBUF_SIZE) { - hltr->word[wp++] = c; - } else if (wp == WORDBUF_SIZE) { + if (word.length < WORDBUF_SIZE) { + word.ptr[word.length++] = c; + } else if (word.length == WORDBUF_SIZE) { for (int i = 0 ; i < WORDBUF_SIZE ; i++) { - dp = writeescapedchar(dest, dp, hltr->word[i]); + dp = writeescapedchar(dest, dp, word.ptr[i]); } - wp++; + word.length++; dp = writeescapedchar(dest, dp, c); } else { dp = writeescapedchar(dest, dp, c);