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
     1.1 --- a/src/c2html.c	Fri Jun 21 12:49:46 2013 +0200
     1.2 +++ b/src/c2html.c	Fri Jun 21 13:32:31 2013 +0200
     1.3 @@ -164,10 +164,13 @@
     1.4    while (isspace(src[sp])) {
     1.5      dest[dp++] = src[sp++];
     1.6    }
     1.7 -  char word[WORDBUF_SIZE];
     1.8 +  
     1.9 +  static char word[WORDBUF_SIZE];
    1.10 +  static char includefile[FILENAME_MAX];
    1.11 +  
    1.12    memset(word, 0, WORDBUF_SIZE);
    1.13 -  size_t wp = 0;
    1.14 -  int isstring = 0, iscomment = 0;
    1.15 +  size_t wp = 0, ifp = 0;
    1.16 +  int isstring = 0, iscomment = 0, isinclude = 0, parseinclude = 0;
    1.17    static int iscommentml;
    1.18    int isescaping = 0;
    1.19    
    1.20 @@ -200,6 +203,40 @@
    1.21          dp += 7;
    1.22        }
    1.23        dp = writeescapedchar(dest, dp, c);
    1.24 +    } else if (isinclude) {
    1.25 +      if (c == '<') {
    1.26 +        memcpy(&(dest[dp]), "<span class=\"c2html-stdinclude\">", 32);
    1.27 +        dp += 32;
    1.28 +        dp = writeescapedchar(dest, dp, c);
    1.29 +      } else if (c == '\"') {
    1.30 +        if (parseinclude) {
    1.31 +          dest[dp++] = '\"';
    1.32 +          dest[dp++] = '>';
    1.33 +          memcpy(&(dest[dp]), includefile, ifp);
    1.34 +          dp += ifp;
    1.35 +          
    1.36 +          dp = writeescapedchar(dest, dp, c);
    1.37 +          memcpy(&(dest[dp]), "</a>", 4);
    1.38 +          dp += 4;
    1.39 +          parseinclude = 0;
    1.40 +        } else {
    1.41 +          memcpy(&(dest[dp]), "<a class=\"c2html-userinclude\" href=", 35);
    1.42 +          dp += 35;
    1.43 +          dp = writeescapedchar(dest, dp, c);
    1.44 +          ifp = 0;
    1.45 +          includefile[ifp++] = '\"';
    1.46 +          parseinclude = 1;
    1.47 +        }
    1.48 +      } else if (c == '>') {
    1.49 +        dp = writeescapedchar(dest, dp, c);
    1.50 +        memcpy(&(dest[dp]), "</span>", 7);
    1.51 +        dp += 7;
    1.52 +      } else {
    1.53 +        if (parseinclude) {
    1.54 +          includefile[ifp++] = c;
    1.55 +        }
    1.56 +        dp = writeescapedchar(dest, dp, c);
    1.57 +      }
    1.58      } else {
    1.59        /* strings */
    1.60        if (!isescaping && (c == '\'' || c == '\"')) {
    1.61 @@ -216,7 +253,7 @@
    1.62        } else {
    1.63          if (isstring) {
    1.64            dp = writeescapedchar(dest, dp, c);
    1.65 -        } else if (!isalnum(c) && c != '_' && c != '#') {
    1.66 +        } else if (!isalnum(c) && c != '_' && c != '#' && c != '.') {
    1.67            /* interpret word int_t */
    1.68            if (wp > 0 && wp < WORDBUF_SIZE) {
    1.69              int closespan = 1;
    1.70 @@ -227,6 +264,7 @@
    1.71                memcpy(&(dest[dp]), "<span class=\"c2html-type\">", 26);
    1.72                dp += 26;
    1.73              } else if (isdirective(word)) {
    1.74 +              isinclude = !strncmp("#include", word, WORDBUF_SIZE);
    1.75                memcpy(&(dest[dp]), "<span class=\"c2html-directive\">", 31);
    1.76                dp += 31;
    1.77              } else if (iscapsonly(word, wp)) {
     2.1 --- a/test/header.html	Fri Jun 21 12:49:46 2013 +0200
     2.2 +++ b/test/header.html	Fri Jun 21 13:32:31 2013 +0200
     2.3 @@ -10,18 +10,31 @@
     2.4        span.c2html-keyword {
     2.5          color: blue;
     2.6        }
     2.7 -      span.c2html-type, span.c2html-macroconst {
     2.8 +      span.c2html-macroconst {
     2.9 +        color: cornflowerblue;
    2.10 +      }
    2.11 +      span.c2html-type {
    2.12          color: cornflowerblue;
    2.13        }
    2.14        span.c2html-directive {
    2.15          color: green;
    2.16        }
    2.17        span.c2html-string {
    2.18 -        color: orange;
    2.19 +        color: darkorange;
    2.20        }
    2.21        span.c2html-comment {
    2.22          color: grey;
    2.23        }
    2.24 +      span.c2html-stdinclude {
    2.25 +        color: darkorange;
    2.26 +      }
    2.27 +      span.c2html-userinclude {
    2.28 +        color: darkorange;
    2.29 +      }
    2.30 +      a.c2html-userinclude {
    2.31 +        color: darkorange;
    2.32 +        text-decoration: underline;
    2.33 +      }
    2.34      </style>
    2.35    </head>
    2.36    <body>

mercurial