1.1 --- a/src/javacodegen.c Thu Aug 25 11:30:30 2016 +0200 1.2 +++ b/src/javacodegen.c Thu Aug 25 12:16:57 2016 +0200 1.3 @@ -39,19 +39,21 @@ 1.4 "volatile", "const", "float", "native", "super", "while", NULL 1.5 }; 1.6 1.7 -void java_highlighter(char *src, UcxBuffer *dest, int *multiline_comment) { 1.8 +void java_highlighter(char *src, UcxBuffer *dest, HighlighterData *hd) { 1.9 + /* reset buffers without clearing them */ 1.10 + hd->primary_buffer->size = hd->primary_buffer->pos = 0; 1.11 + hd->secondary_buffer->size = hd->secondary_buffer->pos = 0; 1.12 1.13 - /* TODO: try to replace this buffer */ 1.14 - char wordbuf[WORDBUF_SIZE]; 1.15 - sstr_t word; 1.16 - word.ptr = wordbuf; word.length = 0; 1.17 + /* alias the buffers for better handling */ 1.18 + UcxBuffer *wbuf = hd->primary_buffer; 1.19 1.20 + /* local information */ 1.21 size_t sp = (size_t)-1; 1.22 int isstring = 0, iscomment = 0, isimport = 0; 1.23 char quote = '\0'; 1.24 int isescaping = 0; 1.25 1.26 - if (*multiline_comment) { 1.27 + if (hd->multiline_comment) { 1.28 iscomment = 1; 1.29 ucx_buffer_puts(dest, "<span class=\"c2html-comment\">"); 1.30 } 1.31 @@ -63,14 +65,14 @@ 1.32 1.33 /* comments */ 1.34 if (!isstring && c == '/') { 1.35 - if (*multiline_comment && sp > 0 && src[sp-1] == '*') { 1.36 + if (hd->multiline_comment && sp > 0 && src[sp-1] == '*') { 1.37 iscomment = 0; 1.38 - *multiline_comment = 0; 1.39 + hd->multiline_comment = 0; 1.40 ucx_buffer_puts(dest, "/</span>"); 1.41 continue; 1.42 } else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) { 1.43 iscomment = 1; 1.44 - *multiline_comment = (src[sp+1] == '*'); 1.45 + hd->multiline_comment = (src[sp+1] == '*'); 1.46 ucx_buffer_puts(dest, "<span class=\"c2html-comment\">"); 1.47 } 1.48 } 1.49 @@ -104,8 +106,10 @@ 1.50 } else { 1.51 if (isstring) { 1.52 put_htmlescaped(dest, c); 1.53 - } else if (!isalnum(c) && c!='_' && c!='#' && c!='@') { 1.54 - if (word.length > 0 && word.length < WORDBUF_SIZE) { 1.55 + } else if (!isalnum(c) && c!='_' && c!='@') { 1.56 + /* write buffered word, if any */ 1.57 + if (wbuf->size > 0) { 1.58 + sstr_t word = sstrn(wbuf->space, wbuf->size); 1.59 int closespan = 1; 1.60 if (check_keyword(word, jkeywords)) { 1.61 ucx_buffer_puts(dest, 1.62 @@ -128,20 +132,13 @@ 1.63 ucx_buffer_puts(dest, "</span>"); 1.64 } 1.65 } 1.66 - word.length = 0; 1.67 + wbuf->pos = wbuf->size = 0; /* reset buffer */ 1.68 + 1.69 + /* write current character */ 1.70 put_htmlescaped(dest, c); 1.71 } else { 1.72 - /* read word */ 1.73 - if (word.length < WORDBUF_SIZE) { 1.74 - word.ptr[word.length++] = c; 1.75 - } else if (word.length == WORDBUF_SIZE) { 1.76 - /* TODO: this will be removed */ 1.77 - ucx_buffer_puts(dest, 1.78 - "!!! WARNING - WORD TOO LONG TO PARSE !!!"); 1.79 - word.length = 0; 1.80 - } else { 1.81 - put_htmlescaped(dest, c); 1.82 - } 1.83 + /* buffer the current word */ 1.84 + ucx_buffer_putc(wbuf, c); 1.85 } 1.86 } 1.87