42 }; |
42 }; |
43 |
43 |
44 #define memcpy_const(darr,doff,str) memcpy(&(darr[doff]), str, sizeof(str)-1); \ |
44 #define memcpy_const(darr,doff,str) memcpy(&(darr[doff]), str, sizeof(str)-1); \ |
45 dp += sizeof(str)-1 |
45 dp += sizeof(str)-1 |
46 |
46 |
47 void jparseline(char *src, UcxBuffer *destbuf, HighlighterData *hltr) { |
47 void jparseline(char *src, UcxBuffer *destbuf, int *multiline_comment) { |
48 /* TODO: workaround for using old code with UcxBuffer */ |
48 /* TODO: workaround for using old code with UcxBuffer */ |
49 char *dest = destbuf->space + destbuf->pos; |
49 char *dest = destbuf->space + destbuf->pos; |
50 |
50 |
51 memset(hltr->word, 0, WORDBUF_SIZE); |
51 /* TODO: try to replace this buffer */ |
52 size_t wp = 0, sp = (size_t)-1, dp = 0; |
52 char wordbuf[WORDBUF_SIZE]; |
|
53 sstr_t word; |
|
54 word.ptr = wordbuf; word.length = 0; |
|
55 |
|
56 size_t sp = (size_t)-1, dp = 0; |
53 int isstring = 0, iscomment = 0, isimport = 0; |
57 int isstring = 0, iscomment = 0, isimport = 0; |
54 char quote = '\0'; |
58 char quote = '\0'; |
55 int isescaping = 0; |
59 int isescaping = 0; |
56 |
60 |
57 if (hltr->iscommentml) { |
61 if (*multiline_comment) { |
58 iscomment = 1; |
62 iscomment = 1; |
59 memcpy_const(dest, dp, "<span class=\"c2html-comment\">"); |
63 memcpy_const(dest, dp, "<span class=\"c2html-comment\">"); |
60 } |
64 } |
61 |
65 |
62 char c; |
66 char c; |
64 c = src[++sp]; |
68 c = src[++sp]; |
65 if (!c) break; |
69 if (!c) break; |
66 |
70 |
67 /* comments */ |
71 /* comments */ |
68 if (!isstring && c == '/') { |
72 if (!isstring && c == '/') { |
69 if (hltr->iscommentml && sp > 0 && src[sp-1] == '*') { |
73 if (*multiline_comment && sp > 0 && src[sp-1] == '*') { |
70 iscomment = 0; |
74 iscomment = 0; |
71 hltr->iscommentml = 0; |
75 *multiline_comment = 0; |
72 memcpy_const(dest, dp, "/</span>"); |
76 memcpy_const(dest, dp, "/</span>"); |
73 continue; |
77 continue; |
74 } else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) { |
78 } else if (!iscomment && (src[sp+1] == '/' || src[sp+1] == '*')) { |
75 iscomment = 1; |
79 iscomment = 1; |
76 hltr->iscommentml = (src[sp+1] == '*'); |
80 *multiline_comment = (src[sp+1] == '*'); |
77 memcpy_const(dest, dp, "<span class=\"c2html-comment\">"); |
81 memcpy_const(dest, dp, "<span class=\"c2html-comment\">"); |
78 } |
82 } |
79 } |
83 } |
80 |
84 |
81 if (iscomment) { |
85 if (iscomment) { |
83 memcpy(&(dest[dp]), "</span>", 7); |
87 memcpy(&(dest[dp]), "</span>", 7); |
84 dp += 7; |
88 dp += 7; |
85 } |
89 } |
86 dp = writeescapedchar(dest, dp, c); |
90 dp = writeescapedchar(dest, dp, c); |
87 } else if (isimport) { |
91 } else if (isimport) { |
88 // TODO: local imports |
92 /* TODO: local imports */ |
89 } else { |
93 } else { |
90 /* strings */ |
94 /* strings */ |
91 if (!isescaping && (c == '\'' || c == '\"')) { |
95 if (!isescaping && (c == '\'' || c == '\"')) { |
92 if (isstring) { |
96 if (isstring) { |
93 dp = writeescapedchar(dest, dp, c); |
97 dp = writeescapedchar(dest, dp, c); |
106 } |
110 } |
107 } else { |
111 } else { |
108 if (isstring) { |
112 if (isstring) { |
109 dp = writeescapedchar(dest, dp, c); |
113 dp = writeescapedchar(dest, dp, c); |
110 } else if (!iswordcharacter(c)) { |
114 } else if (!iswordcharacter(c)) { |
111 /* interpret word int_t */ |
115 if (word.length > 0 && word.length < WORDBUF_SIZE) { |
112 if (wp > 0 && wp < WORDBUF_SIZE) { |
|
113 int closespan = 1; |
116 int closespan = 1; |
114 if (check_keyword(hltr->word, jkeywords)) { |
117 if (check_keyword(word, jkeywords)) { |
115 memcpy_const(dest, dp, |
118 memcpy_const(dest, dp, |
116 "<span class=\"c2html-keyword\">"); |
119 "<span class=\"c2html-keyword\">"); |
117 } else if (isupper(hltr->word[0])) { |
120 } else if (isupper(word.ptr[0])) { |
118 memcpy_const(dest, dp, |
121 memcpy_const(dest, dp, |
119 "<span class=\"c2html-type\">"); |
122 "<span class=\"c2html-type\">"); |
120 } else if (hltr->word[0] == '@') { |
123 } else if (word.ptr[0] == '@') { |
121 memcpy_const(dest, dp, |
124 memcpy_const(dest, dp, |
122 "<span class=\"c2html-directive\">"); |
125 "<span class=\"c2html-directive\">"); |
123 } else if (check_capsonly(hltr->word, wp)) { |
126 } else if (check_capsonly(word)) { |
124 memcpy_const(dest, dp, |
127 memcpy_const(dest, dp, |
125 "<span class=\"c2html-macroconst\">"); |
128 "<span class=\"c2html-macroconst\">"); |
126 } else { |
129 } else { |
127 closespan = 0; |
130 closespan = 0; |
128 } |
131 } |
129 for (int i = 0 ; i < wp ; i++) { |
132 for (int i = 0 ; i < word.length ; i++) { |
130 dp = writeescapedchar(dest, dp, hltr->word[i]); |
133 dp = writeescapedchar(dest, dp, word.ptr[i]); |
131 } |
134 } |
132 if (closespan) { |
135 if (closespan) { |
133 memcpy_const(dest, dp, "</span>"); |
136 memcpy_const(dest, dp, "</span>"); |
134 } |
137 } |
135 } |
138 } |
136 memset(hltr->word, 0, WORDBUF_SIZE); |
139 word.length = 0; |
137 wp = 0; |
|
138 dp = writeescapedchar(dest, dp, c); |
140 dp = writeescapedchar(dest, dp, c); |
139 } else { |
141 } else { |
140 /* read word */ |
142 /* read word */ |
141 if (wp < WORDBUF_SIZE) { |
143 if (word.length < WORDBUF_SIZE) { |
142 hltr->word[wp++] = c; |
144 word.ptr[word.length++] = c; |
143 } else if (wp == WORDBUF_SIZE) { |
145 } else if (word.length == WORDBUF_SIZE) { |
144 for (int i = 0 ; i < WORDBUF_SIZE ; i++) { |
146 for (int i = 0 ; i < WORDBUF_SIZE ; i++) { |
145 dp = writeescapedchar(dest, dp, hltr->word[i]); |
147 dp = writeescapedchar(dest, dp, word.ptr[i]); |
146 } |
148 } |
147 wp++; |
149 word.length++; |
148 dp = writeescapedchar(dest, dp, c); |
150 dp = writeescapedchar(dest, dp, c); |
149 } else { |
151 } else { |
150 dp = writeescapedchar(dest, dp, c); |
152 dp = writeescapedchar(dest, dp, c); |
151 } |
153 } |
152 } |
154 } |