highlighter can now handle files which do not end with a blank line

Wed, 31 Aug 2016 12:58:48 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 31 Aug 2016 12:58:48 +0200
changeset 54
b3f24e23bc25
parent 53
5e47a26a16f0
child 55
bf54085ce341

highlighter can now handle files which do not end with a blank line

Makefile file | annotate | diff | comparison | revisions
src/highlighter.c file | annotate | diff | comparison | revisions
     1.1 --- a/Makefile	Fri Aug 26 14:15:29 2016 +0200
     1.2 +++ b/Makefile	Wed Aug 31 12:58:48 2016 +0200
     1.3 @@ -56,7 +56,7 @@
     1.4  build:
     1.5  	$(MKDIR) $@
     1.6  	
     1.7 -test: build/$(BIN)
     1.8 +test: all
     1.9  	./build/$(BIN) test/ctestfile.c -o build/ctest.html \
    1.10  	-H test/header.html -F test/footer.html
    1.11  	./build/$(BIN) -j test/javatestfile.java -o build/javatest.html \
     2.1 --- a/src/highlighter.c	Fri Aug 26 14:15:29 2016 +0200
     2.2 +++ b/src/highlighter.c	Wed Aug 31 12:58:48 2016 +0200
     2.3 @@ -52,7 +52,7 @@
     2.4          ucx_buffer_puts(dest, "&gt;");
     2.5      } else if (c == '<') {
     2.6          ucx_buffer_puts(dest, "&lt;");
     2.7 -    } else {
     2.8 +    } else if (c) {
     2.9          ucx_buffer_putc(dest, c);
    2.10      }
    2.11  }
    2.12 @@ -126,10 +126,6 @@
    2.13      char c;
    2.14      do {
    2.15          c = src[++sp];
    2.16 -        if (!c) {
    2.17 -            /* TODO: might cause problems if code file does not end with NL */
    2.18 -            break;
    2.19 -        }
    2.20          
    2.21          /* comments */
    2.22          if (!isstring && c == '/') {
    2.23 @@ -195,7 +191,10 @@
    2.24              } else {
    2.25                  if (isstring) {
    2.26                      put_htmlescaped(dest, c);
    2.27 -                } else if (!isalnum(c) && c!='_' && c!='#') {
    2.28 +                } else if (isalnum(c) ||  c == '_' || c == '#') {
    2.29 +                    /* buffer the current word */
    2.30 +                    ucx_buffer_putc(wbuf, c);
    2.31 +                } else {
    2.32                      /* write buffered word, if any */
    2.33                      if (wbuf->size > 0) {
    2.34                          sstr_t word = sstrn(wbuf->space, wbuf->size);
    2.35 @@ -226,15 +225,12 @@
    2.36                      
    2.37                      /* write current character */
    2.38                      put_htmlescaped(dest, c);
    2.39 -                } else {
    2.40 -                    /* buffer the current word */
    2.41 -                    ucx_buffer_putc(wbuf, c);
    2.42                  }
    2.43              }
    2.44  
    2.45              isescaping = !isescaping & (c == '\\');
    2.46          }
    2.47 -    } while (c != '\n');
    2.48 +    } while (c && c != '\n');
    2.49  }
    2.50  
    2.51  /* Java Highlighter */
    2.52 @@ -271,10 +267,6 @@
    2.53      char c;
    2.54      do {
    2.55          c = src[++sp];
    2.56 -        if (!c) {
    2.57 -            /* TODO: might cause problems if code file does not end with NL */
    2.58 -            break;
    2.59 -        }
    2.60          
    2.61          /* comments */
    2.62          if (!isstring && c == '/') {
    2.63 @@ -319,7 +311,10 @@
    2.64              } else {
    2.65                  if (isstring) {
    2.66                      put_htmlescaped(dest, c);
    2.67 -                } else if (!isalnum(c) && c!='_' && c!='@') {
    2.68 +                } else if (isalnum(c) || c == '_' || c == '@') {
    2.69 +                    /* buffer the current word */
    2.70 +                    ucx_buffer_putc(wbuf, c);
    2.71 +                } else {
    2.72                      /* write buffered word, if any */
    2.73                      if (wbuf->size > 0) {
    2.74                          sstr_t word = sstrn(wbuf->space, wbuf->size);
    2.75 @@ -349,14 +344,11 @@
    2.76                      
    2.77                      /* write current character */
    2.78                      put_htmlescaped(dest, c);
    2.79 -                } else {
    2.80 -                    /* buffer the current word */
    2.81 -                    ucx_buffer_putc(wbuf, c);
    2.82                  }
    2.83              }
    2.84  
    2.85              isescaping = !isescaping & (c == '\\');
    2.86          }
    2.87 -    } while (c != '\n');
    2.88 +    } while (c && c != '\n');
    2.89  }
    2.90  

mercurial