1.1 --- a/src/ccodegen.c Tue Aug 23 15:55:02 2016 +0200 1.2 +++ b/src/ccodegen.c Tue Aug 23 16:34:02 2016 +0200 1.3 @@ -42,18 +42,27 @@ 1.4 #define memcpy_const(darr,doff,str) memcpy(&(darr[doff]), str, sizeof(str)-1); \ 1.5 dp += sizeof(str)-1 1.6 1.7 -void cparseline(char *src, UcxBuffer *destbuf, HighlighterData *hltr) { 1.8 +void cparseline(char *src, UcxBuffer *destbuf, int *multiline_comment) { 1.9 /* TODO: workaround for using old code with UcxBuffer */ 1.10 char *dest = destbuf->space + destbuf->pos; 1.11 1.12 - memset(hltr->word, 0, WORDBUF_SIZE); 1.13 - size_t wp = 0, ifp = 0, sp = (size_t)-1, dp = 0; 1.14 + /* TODO: try to replace these buffers */ 1.15 + char wordbuf[WORDBUF_SIZE]; 1.16 + sstr_t word; 1.17 + word.ptr = wordbuf; word.length = 0; 1.18 + 1.19 + char includefilebuf[512]; 1.20 + sstr_t includefile; 1.21 + includefile.ptr = includefilebuf; 1.22 + includefile.length = 0; 1.23 + 1.24 + size_t sp = (size_t)-1, dp = 0; 1.25 int isstring = 0, iscomment = 0, isinclude = 0, parseinclude = 0; 1.26 char quote = '\0'; 1.27 int isescaping = 0; 1.28 1.29 /* continue a multi line comment highlighting */ 1.30 - if (hltr->iscommentml) { 1.31 + if (*multiline_comment) { 1.32 iscomment = 1; 1.33 memcpy_const(dest, dp, "<span class=\"c2html-comment\">"); 1.34 } 1.35 @@ -65,14 +74,14 @@ 1.36 1.37 /* comments */ 1.38 if (!isstring && c == '/') { 1.39 - if (hltr->iscommentml && sp > 0 && src[sp-1] == '*') { 1.40 + if (*multiline_comment && sp > 0 && src[sp-1] == '*') { 1.41 iscomment = 0; 1.42 - hltr->iscommentml = 0; 1.43 + *multiline_comment = 0; 1.44 memcpy_const(dest, dp, "/</span>"); 1.45 continue; 1.46 } else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) { 1.47 iscomment = 1; 1.48 - hltr->iscommentml = (src[sp+1] == '*'); 1.49 + *multiline_comment = (src[sp+1] == '*'); 1.50 memcpy_const(dest, dp, "<span class=\"c2html-comment\">"); 1.51 } 1.52 } 1.53 @@ -90,8 +99,8 @@ 1.54 if (parseinclude) { 1.55 dest[dp++] = '\"'; 1.56 dest[dp++] = '>'; 1.57 - memcpy(&(dest[dp]), hltr->includefile, ifp); 1.58 - dp += ifp; 1.59 + memcpy(&(dest[dp]), includefile.ptr, includefile.length); 1.60 + dp += includefile.length; 1.61 1.62 dp = writeescapedchar(dest, dp, c); 1.63 memcpy_const(dest, dp, "</a>"); 1.64 @@ -100,8 +109,8 @@ 1.65 memcpy_const(dest, dp, 1.66 "<a class=\"c2html-userinclude\" href="); 1.67 dp = writeescapedchar(dest, dp, c); 1.68 - ifp = 0; 1.69 - hltr->includefile[ifp++] = '\"'; 1.70 + includefile.length = 0; 1.71 + includefile.ptr[includefile.length++] = '\"'; 1.72 parseinclude = 1; 1.73 } 1.74 } else if (c == '>') { 1.75 @@ -109,7 +118,7 @@ 1.76 memcpy_const(dest, dp, "</span>"); 1.77 } else { 1.78 if (parseinclude) { 1.79 - hltr->includefile[ifp++] = c; 1.80 + includefile.ptr[includefile.length++] = c; 1.81 } 1.82 dp = writeescapedchar(dest, dp, c); 1.83 } 1.84 @@ -135,46 +144,43 @@ 1.85 if (isstring) { 1.86 dp = writeescapedchar(dest, dp, c); 1.87 } else if (!iswordcharacter(c)) { 1.88 - /* interpret word int_t */ 1.89 - if (wp > 0 && wp < WORDBUF_SIZE) { 1.90 + if (word.length > 0 && word.length < WORDBUF_SIZE) { 1.91 int closespan = 1; 1.92 - if (check_keyword(hltr->word, ckeywords)) { 1.93 + sstr_t typesuffix = ST("_t"); 1.94 + if (check_keyword(word, ckeywords)) { 1.95 memcpy_const(dest, dp, 1.96 "<span class=\"c2html-keyword\">"); 1.97 - } else if (hltr->word[wp-2] == '_' 1.98 - && hltr->word[wp-1] == 't') { 1.99 + } else if (sstrsuffix(word, typesuffix)) { 1.100 memcpy_const(dest, dp, 1.101 "<span class=\"c2html-type\">"); 1.102 - } else if (hltr->word[0] == '#') { 1.103 - isinclude = !strncmp( 1.104 - "#include", hltr->word, WORDBUF_SIZE); 1.105 + } else if (word.ptr[0] == '#') { 1.106 + isinclude = !sstrcmp(word, S("#include")); 1.107 memcpy_const(dest, dp, 1.108 "<span class=\"c2html-directive\">"); 1.109 - } else if (check_capsonly(hltr->word, wp)) { 1.110 + } else if (check_capsonly(word)) { 1.111 memcpy_const(dest, dp, 1.112 "<span class=\"c2html-macroconst\">"); 1.113 } else { 1.114 closespan = 0; 1.115 } 1.116 - for (int i = 0 ; i < wp ; i++) { 1.117 - dp = writeescapedchar(dest, dp, hltr->word[i]); 1.118 + for (int i = 0 ; i < word.length ; i++) { 1.119 + dp = writeescapedchar(dest, dp, word.ptr[i]); 1.120 } 1.121 if (closespan) { 1.122 memcpy_const(dest, dp, "</span>"); 1.123 } 1.124 } 1.125 - memset(hltr->word, 0, WORDBUF_SIZE); 1.126 - wp = 0; 1.127 + word.length = 0; 1.128 dp = writeescapedchar(dest, dp, c); 1.129 } else { 1.130 /* read word */ 1.131 - if (wp < WORDBUF_SIZE) { 1.132 - hltr->word[wp++] = c; 1.133 - } else if (wp == WORDBUF_SIZE) { 1.134 + if (word.length < WORDBUF_SIZE) { 1.135 + word.ptr[word.length++] = c; 1.136 + } else if (word.length == WORDBUF_SIZE) { 1.137 for (int i = 0 ; i < WORDBUF_SIZE ; i++) { 1.138 - dp = writeescapedchar(dest, dp, hltr->word[i]); 1.139 + dp = writeescapedchar(dest, dp, word.ptr[i]); 1.140 } 1.141 - wp++; 1.142 + word.length++; 1.143 dp = writeescapedchar(dest, dp, c); 1.144 } else { 1.145 dp = writeescapedchar(dest, dp, c);