src/c2html.c

changeset 10
925172e535a9
parent 9
6b1fba10c4cb
child 13
fe74bf2d5f27
--- 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)) {

mercurial