src/c2html.c

changeset 12
7ce5c4b51959
parent 11
c59fe73459fd
child 13
fe74bf2d5f27
equal deleted inserted replaced
11:c59fe73459fd 12:7ce5c4b51959
45 }; 45 };
46 46
47 typedef struct { 47 typedef struct {
48 char* outfilename; 48 char* outfilename;
49 char* infilename; 49 char* infilename;
50 int highlight;
50 } settings_t; 51 } settings_t;
51 52
52 typedef struct { 53 typedef struct {
53 size_t count; 54 size_t count;
54 size_t capacity; 55 size_t capacity;
225 226
226 int main(int argc, char** argv) { 227 int main(int argc, char** argv) {
227 228
228 settings_t settings; 229 settings_t settings;
229 settings.outfilename = NULL; 230 settings.outfilename = NULL;
231 settings.highlight = 1;
230 232
231 char optc; 233 char optc;
232 while ((optc = getopt(argc, argv, "ho:")) != -1) { 234 while ((optc = getopt(argc, argv, "ho:p")) != -1) {
233 switch (optc) { 235 switch (optc) {
234 case 'o': 236 case 'o':
235 if (!(optarg[0] == '-' && optarg[1] == 0)) { 237 if (!(optarg[0] == '-' && optarg[1] == 0)) {
236 settings.outfilename = optarg; 238 settings.outfilename = optarg;
237 } 239 }
240 break;
241 case 'p':
242 settings.highlight = 0;
238 break; 243 break;
239 case 'h': 244 case 'h':
240 printhelp(); 245 printhelp();
241 return 0; 246 return 0;
242 default: 247 default:
257 fout = fopen(settings.outfilename, "w"); 262 fout = fopen(settings.outfilename, "w");
258 } else { 263 } else {
259 fout = stdout; 264 fout = stdout;
260 } 265 }
261 fprintf(fout, "<pre>\n"); 266 fprintf(fout, "<pre>\n");
262 char *line = (char*) malloc(inputfile->maxlinewidth*64); 267 char *line = (char*) malloc(inputfile->maxlinewidth
268 * (settings.highlight?64:0));
263 int lnw = lnint(inputfile->count); 269 int lnw = lnint(inputfile->count);
264 for (int i = 0 ; i < inputfile->count ; i++) { 270 for (int i = 0 ; i < inputfile->count ; i++) {
265 parseline(inputfile->lines[i], line); 271 if (settings.highlight) {
272 parseline(inputfile->lines[i], line);
273 } else {
274 line = inputfile->lines[i];
275 }
266 fprintf(fout, "<span class=\"c2html-lineno\">%*d:</span> %s", 276 fprintf(fout, "<span class=\"c2html-lineno\">%*d:</span> %s",
267 lnw, i, line); 277 lnw, i, line);
268 } 278 }
269 free(line); 279 free(line);
270 fprintf(fout, "</pre>\n"); 280 fprintf(fout, "</pre>\n");

mercurial