diff -r c39ecbbca7c0 -r b2724c711203 src/javacodegen.c
--- a/src/javacodegen.c Tue Aug 23 16:34:02 2016 +0200
+++ b/src/javacodegen.c Tue Aug 23 17:24:58 2016 +0200
@@ -41,26 +41,21 @@
"volatile", "const", "float", "native", "super", "while", NULL
};
-#define memcpy_const(darr,doff,str) memcpy(&(darr[doff]), str, sizeof(str)-1); \
- dp += sizeof(str)-1
+void java_highlighter(char *src, UcxBuffer *dest, int *multiline_comment) {
-void jparseline(char *src, UcxBuffer *destbuf, int *multiline_comment) {
- /* TODO: workaround for using old code with UcxBuffer */
- char *dest = destbuf->space + destbuf->pos;
-
/* 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;
+ size_t sp = (size_t)-1;
int isstring = 0, iscomment = 0, isimport = 0;
char quote = '\0';
int isescaping = 0;
if (*multiline_comment) {
iscomment = 1;
- memcpy_const(dest, dp, "");
continue;
} else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) {
iscomment = 1;
*multiline_comment = (src[sp+1] == '*');
- memcpy_const(dest, dp, "\n");
+ } else {
+ put_htmlescaped(dest, c);
}
- dp = writeescapedchar(dest, dp, c);
} else if (isimport) {
/* TODO: local imports */
} else {
/* strings */
if (!isescaping && (c == '\'' || c == '\"')) {
if (isstring) {
- dp = writeescapedchar(dest, dp, c);
+ put_htmlescaped(dest, c);
if (c == quote) {
isstring = 0;
- memcpy_const(dest, dp, "");
+ ucx_buffer_puts(dest, "");
} else {
- dp = writeescapedchar(dest, dp, c);
+ put_htmlescaped(dest, c);
}
} else {
isstring = 1;
quote = c;
- memcpy_const(dest, dp,
+ ucx_buffer_puts(dest,
"");
- dp = writeescapedchar(dest, dp, c);
+ put_htmlescaped(dest, c);
}
} else {
if (isstring) {
- dp = writeescapedchar(dest, dp, c);
- } else if (!iswordcharacter(c)) {
+ put_htmlescaped(dest, c);
+ } else if (!check_alnumex(c)) {
if (word.length > 0 && word.length < WORDBUF_SIZE) {
int closespan = 1;
if (check_keyword(word, jkeywords)) {
- memcpy_const(dest, dp,
+ ucx_buffer_puts(dest,
"");
} else if (isupper(word.ptr[0])) {
- memcpy_const(dest, dp,
+ ucx_buffer_puts(dest,
"");
} else if (word.ptr[0] == '@') {
- memcpy_const(dest, dp,
+ ucx_buffer_puts(dest,
"");
} else if (check_capsonly(word)) {
- memcpy_const(dest, dp,
+ ucx_buffer_puts(dest,
"");
} else {
closespan = 0;
}
- for (int i = 0 ; i < word.length ; i++) {
- dp = writeescapedchar(dest, dp, word.ptr[i]);
- }
+ put_htmlescapedstr(dest, word);
+
if (closespan) {
- memcpy_const(dest, dp, "");
+ ucx_buffer_puts(dest, "");
}
}
word.length = 0;
- dp = writeescapedchar(dest, dp, c);
+ put_htmlescaped(dest, c);
} else {
/* read word */
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, word.ptr[i]);
- }
- word.length++;
- dp = writeescapedchar(dest, dp, c);
+ /* TODO: this will be removed */
+ ucx_buffer_puts(dest,
+ "!!! WARNING - WORD TOO LONG TO PARSE !!!");
+ word.length = 0;
} else {
- dp = writeescapedchar(dest, dp, c);
+ put_htmlescaped(dest, c);
}
}
}
@@ -157,9 +150,4 @@
isescaping = !isescaping & (c == '\\');
}
} while (c != '\n');
- dest[dp] = 0;
-
- /* TODO: workaround */
- destbuf->pos += dp;
- destbuf->size += dp;
}