src/c2html.c

changeset 10
925172e535a9
parent 9
6b1fba10c4cb
child 13
fe74bf2d5f27
equal deleted inserted replaced
9:6b1fba10c4cb 10:925172e535a9
162 size_t sp = 0, dp = 0; 162 size_t sp = 0, dp = 0;
163 /* indent */ 163 /* indent */
164 while (isspace(src[sp])) { 164 while (isspace(src[sp])) {
165 dest[dp++] = src[sp++]; 165 dest[dp++] = src[sp++];
166 } 166 }
167 char word[WORDBUF_SIZE]; 167
168 static char word[WORDBUF_SIZE];
169 static char includefile[FILENAME_MAX];
170
168 memset(word, 0, WORDBUF_SIZE); 171 memset(word, 0, WORDBUF_SIZE);
169 size_t wp = 0; 172 size_t wp = 0, ifp = 0;
170 int isstring = 0, iscomment = 0; 173 int isstring = 0, iscomment = 0, isinclude = 0, parseinclude = 0;
171 static int iscommentml; 174 static int iscommentml;
172 int isescaping = 0; 175 int isescaping = 0;
173 176
174 if (iscommentml) { 177 if (iscommentml) {
175 iscomment = 1; 178 iscomment = 1;
198 if (c == '\n') { 201 if (c == '\n') {
199 memcpy(&(dest[dp]), "</span>", 7); 202 memcpy(&(dest[dp]), "</span>", 7);
200 dp += 7; 203 dp += 7;
201 } 204 }
202 dp = writeescapedchar(dest, dp, c); 205 dp = writeescapedchar(dest, dp, c);
206 } else if (isinclude) {
207 if (c == '<') {
208 memcpy(&(dest[dp]), "<span class=\"c2html-stdinclude\">", 32);
209 dp += 32;
210 dp = writeescapedchar(dest, dp, c);
211 } else if (c == '\"') {
212 if (parseinclude) {
213 dest[dp++] = '\"';
214 dest[dp++] = '>';
215 memcpy(&(dest[dp]), includefile, ifp);
216 dp += ifp;
217
218 dp = writeescapedchar(dest, dp, c);
219 memcpy(&(dest[dp]), "</a>", 4);
220 dp += 4;
221 parseinclude = 0;
222 } else {
223 memcpy(&(dest[dp]), "<a class=\"c2html-userinclude\" href=", 35);
224 dp += 35;
225 dp = writeescapedchar(dest, dp, c);
226 ifp = 0;
227 includefile[ifp++] = '\"';
228 parseinclude = 1;
229 }
230 } else if (c == '>') {
231 dp = writeescapedchar(dest, dp, c);
232 memcpy(&(dest[dp]), "</span>", 7);
233 dp += 7;
234 } else {
235 if (parseinclude) {
236 includefile[ifp++] = c;
237 }
238 dp = writeescapedchar(dest, dp, c);
239 }
203 } else { 240 } else {
204 /* strings */ 241 /* strings */
205 if (!isescaping && (c == '\'' || c == '\"')) { 242 if (!isescaping && (c == '\'' || c == '\"')) {
206 isstring ^= 1; 243 isstring ^= 1;
207 if (isstring) { 244 if (isstring) {
214 dp += 7; 251 dp += 7;
215 } 252 }
216 } else { 253 } else {
217 if (isstring) { 254 if (isstring) {
218 dp = writeescapedchar(dest, dp, c); 255 dp = writeescapedchar(dest, dp, c);
219 } else if (!isalnum(c) && c != '_' && c != '#') { 256 } else if (!isalnum(c) && c != '_' && c != '#' && c != '.') {
220 /* interpret word int_t */ 257 /* interpret word int_t */
221 if (wp > 0 && wp < WORDBUF_SIZE) { 258 if (wp > 0 && wp < WORDBUF_SIZE) {
222 int closespan = 1; 259 int closespan = 1;
223 if (iskeyword(word)) { 260 if (iskeyword(word)) {
224 memcpy(&(dest[dp]), "<span class=\"c2html-keyword\">", 29); 261 memcpy(&(dest[dp]), "<span class=\"c2html-keyword\">", 29);
225 dp += 29; 262 dp += 29;
226 } else if (istype(word, wp)) { 263 } else if (istype(word, wp)) {
227 memcpy(&(dest[dp]), "<span class=\"c2html-type\">", 26); 264 memcpy(&(dest[dp]), "<span class=\"c2html-type\">", 26);
228 dp += 26; 265 dp += 26;
229 } else if (isdirective(word)) { 266 } else if (isdirective(word)) {
267 isinclude = !strncmp("#include", word, WORDBUF_SIZE);
230 memcpy(&(dest[dp]), "<span class=\"c2html-directive\">", 31); 268 memcpy(&(dest[dp]), "<span class=\"c2html-directive\">", 31);
231 dp += 31; 269 dp += 31;
232 } else if (iscapsonly(word, wp)) { 270 } else if (iscapsonly(word, wp)) {
233 memcpy(&(dest[dp]), "<span class=\"c2html-macroconst\">", 32); 271 memcpy(&(dest[dp]), "<span class=\"c2html-macroconst\">", 32);
234 dp += 32; 272 dp += 32;

mercurial