# HG changeset patch # User Mike Becker # Date 1472641128 -7200 # Node ID b3f24e23bc2519ae0b79756f4e69a36e6941415c # Parent 5e47a26a16f0492ddf3fefd027f974ea27d49641 highlighter can now handle files which do not end with a blank line diff -r 5e47a26a16f0 -r b3f24e23bc25 Makefile --- 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 \ diff -r 5e47a26a16f0 -r b3f24e23bc25 src/highlighter.c --- 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'); }