src/c2html.c

changeset 12
7ce5c4b51959
parent 11
c59fe73459fd
child 13
fe74bf2d5f27
     1.1 --- a/src/c2html.c	Wed Jul 10 13:38:28 2013 +0200
     1.2 +++ b/src/c2html.c	Wed Jul 10 13:45:26 2013 +0200
     1.3 @@ -47,6 +47,7 @@
     1.4  typedef struct {
     1.5    char* outfilename;
     1.6    char* infilename;
     1.7 +  int highlight;
     1.8  } settings_t;
     1.9  
    1.10  typedef struct {
    1.11 @@ -227,15 +228,19 @@
    1.12    
    1.13    settings_t settings;
    1.14    settings.outfilename = NULL;
    1.15 +  settings.highlight = 1;
    1.16    
    1.17    char optc;
    1.18 -  while ((optc = getopt(argc, argv, "ho:")) != -1) {
    1.19 +  while ((optc = getopt(argc, argv, "ho:p")) != -1) {
    1.20      switch (optc) {
    1.21        case 'o':
    1.22          if (!(optarg[0] == '-' && optarg[1] == 0)) {
    1.23            settings.outfilename = optarg;
    1.24          }
    1.25          break;
    1.26 +      case 'p':
    1.27 +        settings.highlight = 0;
    1.28 +        break;
    1.29        case 'h':
    1.30          printhelp();
    1.31          return 0;
    1.32 @@ -259,10 +264,15 @@
    1.33          fout = stdout;
    1.34        }
    1.35        fprintf(fout, "<pre>\n");
    1.36 -      char *line = (char*) malloc(inputfile->maxlinewidth*64);
    1.37 +      char *line = (char*) malloc(inputfile->maxlinewidth
    1.38 +          * (settings.highlight?64:0));
    1.39        int lnw = lnint(inputfile->count);
    1.40        for (int i = 0 ; i < inputfile->count ; i++) {
    1.41 -        parseline(inputfile->lines[i], line);
    1.42 +        if (settings.highlight) {
    1.43 +          parseline(inputfile->lines[i], line);
    1.44 +        } else {
    1.45 +          line = inputfile->lines[i];
    1.46 +        }
    1.47          fprintf(fout, "<span class=\"c2html-lineno\">%*d:</span> %s",
    1.48              lnw, i, line);
    1.49        }

mercurial