45 " -l Disable line numbers\n" |
45 " -l Disable line numbers\n" |
46 " -V, -v Prints version and exits\n" |
46 " -V, -v Prints version and exits\n" |
47 "\n"); |
47 "\n"); |
48 } |
48 } |
49 |
49 |
50 /* TODO: remove this workaround after refactoring highlighter structure */ |
50 static void plain_highlighter(char *src, UcxBuffer *dest, int* x) { |
51 static void plainparseline(char *src, UcxBuffer *dest, int* x) { |
|
52 size_t dp = 0; |
|
53 char *buf = dest->space + dest->pos; |
|
54 while (*src && *src != '\n') { |
51 while (*src && *src != '\n') { |
55 dp = writeescapedchar(buf, dp, *src); |
52 put_htmlescaped(dest, *src); |
56 src++; |
53 src++; |
57 } |
54 } |
58 buf[dp++] = '\n'; |
55 ucx_buffer_putc(dest, '\n'); |
59 buf[dp] = '\0'; |
|
60 dest->pos += dp; |
|
61 dest->size += dp; |
|
62 } |
56 } |
63 |
57 |
64 int formatlines(highlighter_func highlighter, |
58 int formatlines(highlighter_func highlighter, |
65 UcxList *in, write_func out, void *stream, int showlineno) { |
59 UcxList *in, write_func out, void *stream, int showlineno) { |
66 |
60 |
99 } |
93 } |
100 |
94 |
101 /* process code line */ |
95 /* process code line */ |
102 highlighter(sourceline->data, line, &multiline_comment); |
96 highlighter(sourceline->data, line, &multiline_comment); |
103 |
97 |
104 /* write code line */ |
98 /* write code line and reset buffer */ |
105 out(line->space, 1, line->size, stream); |
99 out(line->space, 1, line->size, stream); |
106 } |
100 } |
107 |
101 |
108 /* end monospace formatting */ |
102 /* end monospace formatting */ |
109 out("</pre>\n", 1, 7, stream); |
103 out("</pre>\n", 1, 7, stream); |
175 } else { |
169 } else { |
176 /* Choose highlighter */ |
170 /* Choose highlighter */ |
177 highlighter_func hltr = NULL; |
171 highlighter_func hltr = NULL; |
178 switch (sourcetype) { |
172 switch (sourcetype) { |
179 case SOURCE_C: |
173 case SOURCE_C: |
180 hltr = cparseline; |
174 hltr = c_highlighter; |
181 break; |
175 break; |
182 case SOURCE_JAVA: |
176 case SOURCE_JAVA: |
183 hltr = jparseline; |
177 hltr = java_highlighter; |
184 break; |
178 break; |
185 case SOURCE_PLAIN: |
179 case SOURCE_PLAIN: |
186 hltr = plainparseline; |
180 hltr = plain_highlighter; |
187 break; |
181 break; |
188 default: /* should be unreachable */ |
182 default: /* should be unreachable */ |
189 fprintf(stderr, "error in enum source_type\n"); |
183 fprintf(stderr, "error in enum source_type\n"); |
190 return EXIT_FAILURE; |
184 return EXIT_FAILURE; |
191 } |
185 } |