added HTML escaping for plain text files

Fri, 29 May 2015 14:32:02 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 29 May 2015 14:32:02 +0200
changeset 30
0bfd4d6f086a
parent 29
ec6e97454e64
child 31
50ae611a785c

added HTML escaping for plain text files

Makefile file | annotate | diff | comparison | revisions
src/c2html.c file | annotate | diff | comparison | revisions
test/plain.csp file | annotate | diff | comparison | revisions
--- a/Makefile	Sat Apr 25 19:14:57 2015 +0200
+++ b/Makefile	Fri May 29 14:32:02 2015 +0200
@@ -37,12 +37,13 @@
 	$(MKDIR) build
 	
 test: compile
-	./build/$(BIN) $(ARGS) test/ctestfile.c -o build/ctest.html \
-	-H test/header.html -F test/footer.html
-	./build/$(BIN) $(ARGS) -j test/javatestfile.java -o build/javatest.html \
+	./build/$(BIN) test/ctestfile.c -o build/ctest.html \
 	-H test/header.html -F test/footer.html
-	./build/$(BIN) $(ARGS) test/bigtestfile.c -o build/bigtest.html \
+	./build/$(BIN) -j test/javatestfile.java -o build/javatest.html \
+	-H test/jheader.html -F test/footer.html
+	./build/$(BIN) test/bigtestfile.c -o build/bigtest.html \
 	-H test/header.html -F test/footer.html
-
+	./build/$(BIN) -p test/plain.csp -o build/plain.html \
+	-H test/header.html -F test/footer.html
 clean:
 	$(RM) -f -R build
--- a/src/c2html.c	Sat Apr 25 19:14:57 2015 +0200
+++ b/src/c2html.c	Fri May 29 14:32:02 2015 +0200
@@ -158,13 +158,18 @@
     
     int lnw = lnint(in->count);
     for (int i = 0 ; i < in->count ; i++) {
-        char *ln = line;
         if (highlighter) {
             highlighter->parser(in->lines[i], line, highlighter);
         } else {
-            ln = in->lines[i];
+            char *c = in->lines[i];
+            size_t dp = 0;
+            while (*c) {
+                dp = writeescapedchar(line, dp, *c);
+                c++;
+            }
+            line[dp] = '\0';
         }
-        
+
         // write line number
         if (showln) {
             WRITECONST(stream, out, "<span class=\"c2html-lineno\">");
@@ -181,7 +186,7 @@
         }
         
         // write formated (or plain) code line
-        out(ln, 1, strlen(ln), stream);
+        out(line, 1, strlen(line), stream);
     }
     
     WRITECONST(stream, out, "</pre>\n");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/plain.csp	Fri May 29 14:32:02 2015 +0200
@@ -0,0 +1,6 @@
+</body>
+</html>
+<!c
+pblock_free(q);
+!>
+

mercurial