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
     1.1 --- a/src/c2html.c	Fri Jun 21 12:27:45 2013 +0200
     1.2 +++ b/src/c2html.c	Fri Jun 21 12:49:46 2013 +0200
     1.3 @@ -149,6 +149,15 @@
     1.4    return 0;
     1.5  }
     1.6  
     1.7 +int iscapsonly(char *word, size_t wp) {
     1.8 +  for (size_t i = 0 ; i < wp ; i++) {
     1.9 +    if (!isupper(word[i]) && word[i] != '_') {
    1.10 +      return 0;
    1.11 +    }
    1.12 +  }
    1.13 +  return 1;
    1.14 +}
    1.15 +
    1.16  void parseline(char *src, char *dest) {
    1.17    size_t sp = 0, dp = 0;
    1.18    /* indent */
    1.19 @@ -167,8 +176,7 @@
    1.20      memcpy(&(dest[dp]), "<span class=\"c2html-comment\">", 29);
    1.21      dp += 29;
    1.22    }
    1.23 -  // a fucking /* comment */
    1.24 -  /* again // / */
    1.25 +
    1.26    for (char c = src[sp] ; c ; c=src[++sp]) {
    1.27      /* comments */
    1.28      if (c == '/') {
    1.29 @@ -221,6 +229,9 @@
    1.30              } else if (isdirective(word)) {
    1.31                memcpy(&(dest[dp]), "<span class=\"c2html-directive\">", 31);
    1.32                dp += 31;
    1.33 +            } else if (iscapsonly(word, wp)) {
    1.34 +              memcpy(&(dest[dp]), "<span class=\"c2html-macroconst\">", 32);
    1.35 +              dp += 32;
    1.36              } else {
    1.37                closespan = 0;
    1.38              }
    1.39 @@ -231,9 +242,9 @@
    1.40                memcpy(&(dest[dp]), "</span>", 7);
    1.41                dp += 7;
    1.42              }
    1.43 -            memset(word, 0, WORDBUF_SIZE);
    1.44 -            wp = 0;
    1.45            }
    1.46 +          memset(word, 0, WORDBUF_SIZE);
    1.47 +          wp = 0;
    1.48            dp = writeescapedchar(dest, dp, c);
    1.49          } else {
    1.50            /* read word */
    1.51 @@ -286,7 +297,7 @@
    1.52        for (int i = 0 ; i < inputfile->count ; i++) {
    1.53          parseline(inputfile->lines[i], line);
    1.54          printf("<span class=\"c2html-lineno\">%*d:</span> %s",
    1.55 -            lnw, i, line);
    1.56 +            lnw, i+1, line);
    1.57        }
    1.58        free(line);
    1.59        printf("</pre>\n");
     2.1 --- a/test/header.html	Fri Jun 21 12:27:45 2013 +0200
     2.2 +++ b/test/header.html	Fri Jun 21 12:49:46 2013 +0200
     2.3 @@ -10,7 +10,7 @@
     2.4        span.c2html-keyword {
     2.5          color: blue;
     2.6        }
     2.7 -      span.c2html-type {
     2.8 +      span.c2html-type, span.c2html-macroconst {
     2.9          color: cornflowerblue;
    2.10        }
    2.11        span.c2html-directive {

mercurial