long words are correctly separated by non alpha numeric chars, underscore or hash + support for macro constants

Fri, 21 Jun 2013 12:49:46 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 21 Jun 2013 12:49:46 +0200
changeset 9
6b1fba10c4cb
parent 8
417cd3b29f97
child 10
925172e535a9

long words are correctly separated by non alpha numeric chars, underscore or hash + support for macro constants

src/c2html.c file | annotate | diff | comparison | revisions
test/header.html file | annotate | diff | comparison | revisions
--- a/src/c2html.c	Fri Jun 21 12:27:45 2013 +0200
+++ b/src/c2html.c	Fri Jun 21 12:49:46 2013 +0200
@@ -149,6 +149,15 @@
   return 0;
 }
 
+int iscapsonly(char *word, size_t wp) {
+  for (size_t i = 0 ; i < wp ; i++) {
+    if (!isupper(word[i]) && word[i] != '_') {
+      return 0;
+    }
+  }
+  return 1;
+}
+
 void parseline(char *src, char *dest) {
   size_t sp = 0, dp = 0;
   /* indent */
@@ -167,8 +176,7 @@
     memcpy(&(dest[dp]), "<span class=\"c2html-comment\">", 29);
     dp += 29;
   }
-  // a fucking /* comment */
-  /* again // / */
+
   for (char c = src[sp] ; c ; c=src[++sp]) {
     /* comments */
     if (c == '/') {
@@ -221,6 +229,9 @@
             } else if (isdirective(word)) {
               memcpy(&(dest[dp]), "<span class=\"c2html-directive\">", 31);
               dp += 31;
+            } else if (iscapsonly(word, wp)) {
+              memcpy(&(dest[dp]), "<span class=\"c2html-macroconst\">", 32);
+              dp += 32;
             } else {
               closespan = 0;
             }
@@ -231,9 +242,9 @@
               memcpy(&(dest[dp]), "</span>", 7);
               dp += 7;
             }
-            memset(word, 0, WORDBUF_SIZE);
-            wp = 0;
           }
+          memset(word, 0, WORDBUF_SIZE);
+          wp = 0;
           dp = writeescapedchar(dest, dp, c);
         } else {
           /* read word */
@@ -286,7 +297,7 @@
       for (int i = 0 ; i < inputfile->count ; i++) {
         parseline(inputfile->lines[i], line);
         printf("<span class=\"c2html-lineno\">%*d:</span> %s",
-            lnw, i, line);
+            lnw, i+1, line);
       }
       free(line);
       printf("</pre>\n");
--- a/test/header.html	Fri Jun 21 12:27:45 2013 +0200
+++ b/test/header.html	Fri Jun 21 12:49:46 2013 +0200
@@ -10,7 +10,7 @@
       span.c2html-keyword {
         color: blue;
       }
-      span.c2html-type {
+      span.c2html-type, span.c2html-macroconst {
         color: cornflowerblue;
       }
       span.c2html-directive {

mercurial