39 "transient", "catch", "extends", "int", "short", "try", "char", "final", |
39 "transient", "catch", "extends", "int", "short", "try", "char", "final", |
40 "interface", "static", "void", "class", "finally", "long", "strictfp", |
40 "interface", "static", "void", "class", "finally", "long", "strictfp", |
41 "volatile", "const", "float", "native", "super", "while", NULL |
41 "volatile", "const", "float", "native", "super", "while", NULL |
42 }; |
42 }; |
43 |
43 |
44 #define memcpy_const(darr,doff,str) memcpy(&(darr[doff]), str, sizeof(str)-1); \ |
44 void java_highlighter(char *src, UcxBuffer *dest, int *multiline_comment) { |
45 dp += sizeof(str)-1 |
|
46 |
45 |
47 void jparseline(char *src, UcxBuffer *destbuf, int *multiline_comment) { |
|
48 /* TODO: workaround for using old code with UcxBuffer */ |
|
49 char *dest = destbuf->space + destbuf->pos; |
|
50 |
|
51 /* TODO: try to replace this buffer */ |
46 /* TODO: try to replace this buffer */ |
52 char wordbuf[WORDBUF_SIZE]; |
47 char wordbuf[WORDBUF_SIZE]; |
53 sstr_t word; |
48 sstr_t word; |
54 word.ptr = wordbuf; word.length = 0; |
49 word.ptr = wordbuf; word.length = 0; |
55 |
50 |
56 size_t sp = (size_t)-1, dp = 0; |
51 size_t sp = (size_t)-1; |
57 int isstring = 0, iscomment = 0, isimport = 0; |
52 int isstring = 0, iscomment = 0, isimport = 0; |
58 char quote = '\0'; |
53 char quote = '\0'; |
59 int isescaping = 0; |
54 int isescaping = 0; |
60 |
55 |
61 if (*multiline_comment) { |
56 if (*multiline_comment) { |
62 iscomment = 1; |
57 iscomment = 1; |
63 memcpy_const(dest, dp, "<span class=\"c2html-comment\">"); |
58 ucx_buffer_puts(dest, "<span class=\"c2html-comment\">"); |
64 } |
59 } |
65 |
60 |
66 char c; |
61 char c; |
67 do { |
62 do { |
68 c = src[++sp]; |
63 c = src[++sp]; |
71 /* comments */ |
66 /* comments */ |
72 if (!isstring && c == '/') { |
67 if (!isstring && c == '/') { |
73 if (*multiline_comment && sp > 0 && src[sp-1] == '*') { |
68 if (*multiline_comment && sp > 0 && src[sp-1] == '*') { |
74 iscomment = 0; |
69 iscomment = 0; |
75 *multiline_comment = 0; |
70 *multiline_comment = 0; |
76 memcpy_const(dest, dp, "/</span>"); |
71 ucx_buffer_puts(dest, "/</span>"); |
77 continue; |
72 continue; |
78 } else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) { |
73 } else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) { |
79 iscomment = 1; |
74 iscomment = 1; |
80 *multiline_comment = (src[sp+1] == '*'); |
75 *multiline_comment = (src[sp+1] == '*'); |
81 memcpy_const(dest, dp, "<span class=\"c2html-comment\">"); |
76 ucx_buffer_puts(dest, "<span class=\"c2html-comment\">"); |
82 } |
77 } |
83 } |
78 } |
84 |
79 |
85 if (iscomment) { |
80 if (iscomment) { |
86 if (c == '\n') { |
81 if (c == '\n') { |
87 memcpy(&(dest[dp]), "</span>", 7); |
82 ucx_buffer_puts(dest, "</span>\n"); |
88 dp += 7; |
83 } else { |
|
84 put_htmlescaped(dest, c); |
89 } |
85 } |
90 dp = writeescapedchar(dest, dp, c); |
|
91 } else if (isimport) { |
86 } else if (isimport) { |
92 /* TODO: local imports */ |
87 /* TODO: local imports */ |
93 } else { |
88 } else { |
94 /* strings */ |
89 /* strings */ |
95 if (!isescaping && (c == '\'' || c == '\"')) { |
90 if (!isescaping && (c == '\'' || c == '\"')) { |
96 if (isstring) { |
91 if (isstring) { |
97 dp = writeescapedchar(dest, dp, c); |
92 put_htmlescaped(dest, c); |
98 if (c == quote) { |
93 if (c == quote) { |
99 isstring = 0; |
94 isstring = 0; |
100 memcpy_const(dest, dp, "</span>"); |
95 ucx_buffer_puts(dest, "</span>"); |
101 } else { |
96 } else { |
102 dp = writeescapedchar(dest, dp, c); |
97 put_htmlescaped(dest, c); |
103 } |
98 } |
104 } else { |
99 } else { |
105 isstring = 1; |
100 isstring = 1; |
106 quote = c; |
101 quote = c; |
107 memcpy_const(dest, dp, |
102 ucx_buffer_puts(dest, |
108 "<span class=\"c2html-string\">"); |
103 "<span class=\"c2html-string\">"); |
109 dp = writeescapedchar(dest, dp, c); |
104 put_htmlescaped(dest, c); |
110 } |
105 } |
111 } else { |
106 } else { |
112 if (isstring) { |
107 if (isstring) { |
113 dp = writeescapedchar(dest, dp, c); |
108 put_htmlescaped(dest, c); |
114 } else if (!iswordcharacter(c)) { |
109 } else if (!check_alnumex(c)) { |
115 if (word.length > 0 && word.length < WORDBUF_SIZE) { |
110 if (word.length > 0 && word.length < WORDBUF_SIZE) { |
116 int closespan = 1; |
111 int closespan = 1; |
117 if (check_keyword(word, jkeywords)) { |
112 if (check_keyword(word, jkeywords)) { |
118 memcpy_const(dest, dp, |
113 ucx_buffer_puts(dest, |
119 "<span class=\"c2html-keyword\">"); |
114 "<span class=\"c2html-keyword\">"); |
120 } else if (isupper(word.ptr[0])) { |
115 } else if (isupper(word.ptr[0])) { |
121 memcpy_const(dest, dp, |
116 ucx_buffer_puts(dest, |
122 "<span class=\"c2html-type\">"); |
117 "<span class=\"c2html-type\">"); |
123 } else if (word.ptr[0] == '@') { |
118 } else if (word.ptr[0] == '@') { |
124 memcpy_const(dest, dp, |
119 ucx_buffer_puts(dest, |
125 "<span class=\"c2html-directive\">"); |
120 "<span class=\"c2html-directive\">"); |
126 } else if (check_capsonly(word)) { |
121 } else if (check_capsonly(word)) { |
127 memcpy_const(dest, dp, |
122 ucx_buffer_puts(dest, |
128 "<span class=\"c2html-macroconst\">"); |
123 "<span class=\"c2html-macroconst\">"); |
129 } else { |
124 } else { |
130 closespan = 0; |
125 closespan = 0; |
131 } |
126 } |
132 for (int i = 0 ; i < word.length ; i++) { |
127 put_htmlescapedstr(dest, word); |
133 dp = writeescapedchar(dest, dp, word.ptr[i]); |
128 |
134 } |
|
135 if (closespan) { |
129 if (closespan) { |
136 memcpy_const(dest, dp, "</span>"); |
130 ucx_buffer_puts(dest, "</span>"); |
137 } |
131 } |
138 } |
132 } |
139 word.length = 0; |
133 word.length = 0; |
140 dp = writeescapedchar(dest, dp, c); |
134 put_htmlescaped(dest, c); |
141 } else { |
135 } else { |
142 /* read word */ |
136 /* read word */ |
143 if (word.length < WORDBUF_SIZE) { |
137 if (word.length < WORDBUF_SIZE) { |
144 word.ptr[word.length++] = c; |
138 word.ptr[word.length++] = c; |
145 } else if (word.length == WORDBUF_SIZE) { |
139 } else if (word.length == WORDBUF_SIZE) { |
146 for (int i = 0 ; i < WORDBUF_SIZE ; i++) { |
140 /* TODO: this will be removed */ |
147 dp = writeescapedchar(dest, dp, word.ptr[i]); |
141 ucx_buffer_puts(dest, |
148 } |
142 "!!! WARNING - WORD TOO LONG TO PARSE !!!"); |
149 word.length++; |
143 word.length = 0; |
150 dp = writeescapedchar(dest, dp, c); |
|
151 } else { |
144 } else { |
152 dp = writeescapedchar(dest, dp, c); |
145 put_htmlescaped(dest, c); |
153 } |
146 } |
154 } |
147 } |
155 } |
148 } |
156 |
149 |
157 isescaping = !isescaping & (c == '\\'); |
150 isescaping = !isescaping & (c == '\\'); |
158 } |
151 } |
159 } while (c != '\n'); |
152 } while (c != '\n'); |
160 dest[dp] = 0; |
|
161 |
|
162 /* TODO: workaround */ |
|
163 destbuf->pos += dp; |
|
164 destbuf->size += dp; |
|
165 } |
153 } |