Wed, 31 Aug 2016 12:58:48 +0200
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 |
--- a/Makefile Fri Aug 26 14:15:29 2016 +0200 +++ b/Makefile Wed Aug 31 12:58:48 2016 +0200 @@ -56,7 +56,7 @@ build: $(MKDIR) $@ -test: build/$(BIN) +test: all ./build/$(BIN) test/ctestfile.c -o build/ctest.html \ -H test/header.html -F test/footer.html ./build/$(BIN) -j test/javatestfile.java -o build/javatest.html \
--- a/src/highlighter.c Fri Aug 26 14:15:29 2016 +0200 +++ b/src/highlighter.c Wed Aug 31 12:58:48 2016 +0200 @@ -52,7 +52,7 @@ ucx_buffer_puts(dest, ">"); } else if (c == '<') { ucx_buffer_puts(dest, "<"); - } else { + } else if (c) { ucx_buffer_putc(dest, c); } } @@ -126,10 +126,6 @@ char c; do { c = src[++sp]; - if (!c) { - /* TODO: might cause problems if code file does not end with NL */ - break; - } /* comments */ if (!isstring && c == '/') { @@ -195,7 +191,10 @@ } else { if (isstring) { put_htmlescaped(dest, c); - } else if (!isalnum(c) && c!='_' && c!='#') { + } else if (isalnum(c) || c == '_' || c == '#') { + /* buffer the current word */ + ucx_buffer_putc(wbuf, c); + } else { /* write buffered word, if any */ if (wbuf->size > 0) { sstr_t word = sstrn(wbuf->space, wbuf->size); @@ -226,15 +225,12 @@ /* write current character */ put_htmlescaped(dest, c); - } else { - /* buffer the current word */ - ucx_buffer_putc(wbuf, c); } } isescaping = !isescaping & (c == '\\'); } - } while (c != '\n'); + } while (c && c != '\n'); } /* Java Highlighter */ @@ -271,10 +267,6 @@ char c; do { c = src[++sp]; - if (!c) { - /* TODO: might cause problems if code file does not end with NL */ - break; - } /* comments */ if (!isstring && c == '/') { @@ -319,7 +311,10 @@ } else { if (isstring) { put_htmlescaped(dest, c); - } else if (!isalnum(c) && c!='_' && c!='@') { + } else if (isalnum(c) || c == '_' || c == '@') { + /* buffer the current word */ + ucx_buffer_putc(wbuf, c); + } else { /* write buffered word, if any */ if (wbuf->size > 0) { sstr_t word = sstrn(wbuf->space, wbuf->size); @@ -349,14 +344,11 @@ /* write current character */ put_htmlescaped(dest, c); - } else { - /* buffer the current word */ - ucx_buffer_putc(wbuf, c); } } isescaping = !isescaping & (c == '\\'); } - } while (c != '\n'); + } while (c && c != '\n'); }