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
--- a/Makefile	Wed Jul 10 13:38:28 2013 +0200
+++ b/Makefile	Wed Jul 10 13:45:26 2013 +0200
@@ -37,7 +37,7 @@
 	$(MKDIR) build
 	
 test: compile
-	./build/$(BIN) src/c2html.c > build/body.html
+	./build/$(BIN) $(ARGS) src/c2html.c > build/body.html
 	cat test/header.html build/body.html test/footer.html > build/code.html
 	
 clean:
--- a/src/c2html.c	Wed Jul 10 13:38:28 2013 +0200
+++ b/src/c2html.c	Wed Jul 10 13:45:26 2013 +0200
@@ -47,6 +47,7 @@
 typedef struct {
   char* outfilename;
   char* infilename;
+  int highlight;
 } settings_t;
 
 typedef struct {
@@ -227,15 +228,19 @@
   
   settings_t settings;
   settings.outfilename = NULL;
+  settings.highlight = 1;
   
   char optc;
-  while ((optc = getopt(argc, argv, "ho:")) != -1) {
+  while ((optc = getopt(argc, argv, "ho:p")) != -1) {
     switch (optc) {
       case 'o':
         if (!(optarg[0] == '-' && optarg[1] == 0)) {
           settings.outfilename = optarg;
         }
         break;
+      case 'p':
+        settings.highlight = 0;
+        break;
       case 'h':
         printhelp();
         return 0;
@@ -259,10 +264,15 @@
         fout = stdout;
       }
       fprintf(fout, "<pre>\n");
-      char *line = (char*) malloc(inputfile->maxlinewidth*64);
+      char *line = (char*) malloc(inputfile->maxlinewidth
+          * (settings.highlight?64:0));
       int lnw = lnint(inputfile->count);
       for (int i = 0 ; i < inputfile->count ; i++) {
-        parseline(inputfile->lines[i], line);
+        if (settings.highlight) {
+          parseline(inputfile->lines[i], line);
+        } else {
+          line = inputfile->lines[i];
+        }
         fprintf(fout, "<span class=\"c2html-lineno\">%*d:</span> %s",
             lnw, i, line);
       }

mercurial