option for plaintext

Wed, 10 Jul 2013 13:45:26 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 10 Jul 2013 13:45:26 +0200
changeset 12
7ce5c4b51959
parent 11
c59fe73459fd
child 13
fe74bf2d5f27

option for plaintext

Makefile file | annotate | diff | comparison | revisions
src/c2html.c file | annotate | diff | comparison | revisions
     1.1 --- a/Makefile	Wed Jul 10 13:38:28 2013 +0200
     1.2 +++ b/Makefile	Wed Jul 10 13:45:26 2013 +0200
     1.3 @@ -37,7 +37,7 @@
     1.4  	$(MKDIR) build
     1.5  	
     1.6  test: compile
     1.7 -	./build/$(BIN) src/c2html.c > build/body.html
     1.8 +	./build/$(BIN) $(ARGS) src/c2html.c > build/body.html
     1.9  	cat test/header.html build/body.html test/footer.html > build/code.html
    1.10  	
    1.11  clean:
     2.1 --- a/src/c2html.c	Wed Jul 10 13:38:28 2013 +0200
     2.2 +++ b/src/c2html.c	Wed Jul 10 13:45:26 2013 +0200
     2.3 @@ -47,6 +47,7 @@
     2.4  typedef struct {
     2.5    char* outfilename;
     2.6    char* infilename;
     2.7 +  int highlight;
     2.8  } settings_t;
     2.9  
    2.10  typedef struct {
    2.11 @@ -227,15 +228,19 @@
    2.12    
    2.13    settings_t settings;
    2.14    settings.outfilename = NULL;
    2.15 +  settings.highlight = 1;
    2.16    
    2.17    char optc;
    2.18 -  while ((optc = getopt(argc, argv, "ho:")) != -1) {
    2.19 +  while ((optc = getopt(argc, argv, "ho:p")) != -1) {
    2.20      switch (optc) {
    2.21        case 'o':
    2.22          if (!(optarg[0] == '-' && optarg[1] == 0)) {
    2.23            settings.outfilename = optarg;
    2.24          }
    2.25          break;
    2.26 +      case 'p':
    2.27 +        settings.highlight = 0;
    2.28 +        break;
    2.29        case 'h':
    2.30          printhelp();
    2.31          return 0;
    2.32 @@ -259,10 +264,15 @@
    2.33          fout = stdout;
    2.34        }
    2.35        fprintf(fout, "<pre>\n");
    2.36 -      char *line = (char*) malloc(inputfile->maxlinewidth*64);
    2.37 +      char *line = (char*) malloc(inputfile->maxlinewidth
    2.38 +          * (settings.highlight?64:0));
    2.39        int lnw = lnint(inputfile->count);
    2.40        for (int i = 0 ; i < inputfile->count ; i++) {
    2.41 -        parseline(inputfile->lines[i], line);
    2.42 +        if (settings.highlight) {
    2.43 +          parseline(inputfile->lines[i], line);
    2.44 +        } else {
    2.45 +          line = inputfile->lines[i];
    2.46 +        }
    2.47          fprintf(fout, "<span class=\"c2html-lineno\">%*d:</span> %s",
    2.48              lnw, i, line);
    2.49        }

mercurial