includes (with links in user includes)

Fri, 21 Jun 2013 13:32:31 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 21 Jun 2013 13:32:31 +0200
changeset 10
925172e535a9
parent 9
6b1fba10c4cb
child 13
fe74bf2d5f27

includes (with links in user includes)

src/c2html.c file | annotate | diff | comparison | revisions
test/header.html file | annotate | diff | comparison | revisions
--- a/src/c2html.c	Fri Jun 21 12:49:46 2013 +0200
+++ b/src/c2html.c	Fri Jun 21 13:32:31 2013 +0200
@@ -164,10 +164,13 @@
   while (isspace(src[sp])) {
     dest[dp++] = src[sp++];
   }
-  char word[WORDBUF_SIZE];
+  
+  static char word[WORDBUF_SIZE];
+  static char includefile[FILENAME_MAX];
+  
   memset(word, 0, WORDBUF_SIZE);
-  size_t wp = 0;
-  int isstring = 0, iscomment = 0;
+  size_t wp = 0, ifp = 0;
+  int isstring = 0, iscomment = 0, isinclude = 0, parseinclude = 0;
   static int iscommentml;
   int isescaping = 0;
   
@@ -200,6 +203,40 @@
         dp += 7;
       }
       dp = writeescapedchar(dest, dp, c);
+    } else if (isinclude) {
+      if (c == '<') {
+        memcpy(&(dest[dp]), "<span class=\"c2html-stdinclude\">", 32);
+        dp += 32;
+        dp = writeescapedchar(dest, dp, c);
+      } else if (c == '\"') {
+        if (parseinclude) {
+          dest[dp++] = '\"';
+          dest[dp++] = '>';
+          memcpy(&(dest[dp]), includefile, ifp);
+          dp += ifp;
+          
+          dp = writeescapedchar(dest, dp, c);
+          memcpy(&(dest[dp]), "</a>", 4);
+          dp += 4;
+          parseinclude = 0;
+        } else {
+          memcpy(&(dest[dp]), "<a class=\"c2html-userinclude\" href=", 35);
+          dp += 35;
+          dp = writeescapedchar(dest, dp, c);
+          ifp = 0;
+          includefile[ifp++] = '\"';
+          parseinclude = 1;
+        }
+      } else if (c == '>') {
+        dp = writeescapedchar(dest, dp, c);
+        memcpy(&(dest[dp]), "</span>", 7);
+        dp += 7;
+      } else {
+        if (parseinclude) {
+          includefile[ifp++] = c;
+        }
+        dp = writeescapedchar(dest, dp, c);
+      }
     } else {
       /* strings */
       if (!isescaping && (c == '\'' || c == '\"')) {
@@ -216,7 +253,7 @@
       } else {
         if (isstring) {
           dp = writeescapedchar(dest, dp, c);
-        } else if (!isalnum(c) && c != '_' && c != '#') {
+        } else if (!isalnum(c) && c != '_' && c != '#' && c != '.') {
           /* interpret word int_t */
           if (wp > 0 && wp < WORDBUF_SIZE) {
             int closespan = 1;
@@ -227,6 +264,7 @@
               memcpy(&(dest[dp]), "<span class=\"c2html-type\">", 26);
               dp += 26;
             } else if (isdirective(word)) {
+              isinclude = !strncmp("#include", word, WORDBUF_SIZE);
               memcpy(&(dest[dp]), "<span class=\"c2html-directive\">", 31);
               dp += 31;
             } else if (iscapsonly(word, wp)) {
--- a/test/header.html	Fri Jun 21 12:49:46 2013 +0200
+++ b/test/header.html	Fri Jun 21 13:32:31 2013 +0200
@@ -10,18 +10,31 @@
       span.c2html-keyword {
         color: blue;
       }
-      span.c2html-type, span.c2html-macroconst {
+      span.c2html-macroconst {
+        color: cornflowerblue;
+      }
+      span.c2html-type {
         color: cornflowerblue;
       }
       span.c2html-directive {
         color: green;
       }
       span.c2html-string {
-        color: orange;
+        color: darkorange;
       }
       span.c2html-comment {
         color: grey;
       }
+      span.c2html-stdinclude {
+        color: darkorange;
+      }
+      span.c2html-userinclude {
+        color: darkorange;
+      }
+      a.c2html-userinclude {
+        color: darkorange;
+        text-decoration: underline;
+      }
     </style>
   </head>
   <body>

mercurial