diff -r 534a4ef4143d -r c39ecbbca7c0 src/ccodegen.c
--- a/src/ccodegen.c Tue Aug 23 15:55:02 2016 +0200
+++ b/src/ccodegen.c Tue Aug 23 16:34:02 2016 +0200
@@ -42,18 +42,27 @@
#define memcpy_const(darr,doff,str) memcpy(&(darr[doff]), str, sizeof(str)-1); \
dp += sizeof(str)-1
-void cparseline(char *src, UcxBuffer *destbuf, HighlighterData *hltr) {
+void cparseline(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, ifp = 0, sp = (size_t)-1, dp = 0;
+ /* TODO: try to replace these buffers */
+ char wordbuf[WORDBUF_SIZE];
+ sstr_t word;
+ word.ptr = wordbuf; word.length = 0;
+
+ char includefilebuf[512];
+ sstr_t includefile;
+ includefile.ptr = includefilebuf;
+ includefile.length = 0;
+
+ size_t sp = (size_t)-1, dp = 0;
int isstring = 0, iscomment = 0, isinclude = 0, parseinclude = 0;
char quote = '\0';
int isescaping = 0;
/* continue a multi line comment highlighting */
- if (hltr->iscommentml) {
+ if (*multiline_comment) {
iscomment = 1;
memcpy_const(dest, dp, "");
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, "");
} else {
if (parseinclude) {
- hltr->includefile[ifp++] = c;
+ includefile.ptr[includefile.length++] = c;
}
dp = writeescapedchar(dest, dp, c);
}
@@ -135,46 +144,43 @@
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, ckeywords)) {
+ sstr_t typesuffix = ST("_t");
+ if (check_keyword(word, ckeywords)) {
memcpy_const(dest, dp,
"");
- } else if (hltr->word[wp-2] == '_'
- && hltr->word[wp-1] == 't') {
+ } else if (sstrsuffix(word, typesuffix)) {
memcpy_const(dest, dp,
"");
- } else if (hltr->word[0] == '#') {
- isinclude = !strncmp(
- "#include", hltr->word, WORDBUF_SIZE);
+ } else if (word.ptr[0] == '#') {
+ isinclude = !sstrcmp(word, S("#include"));
memcpy_const(dest, dp,
"");
- } else if (check_capsonly(hltr->word, wp)) {
+ } else if (check_capsonly(word)) {
memcpy_const(dest, dp,
"");
} 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, "");
}
}
- 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);