From: Martin Mares Date: Sun, 17 Apr 2005 15:24:10 +0000 (+0000) Subject: Added pedantic check of file syntax. X-Git-Tag: python-dummy-working~430 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=6f969e65e2bee7745a28f9f8cf54540257895f7e;p=eval.git Added pedantic check of file syntax. --- diff --git a/Makefile b/Makefile index 70d6c0a..db12c3f 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ VERSION=1.0 #DEBUG=-ggdb CFLAGS=-O2 -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Winline $(DEBUG) -all: bin/box bin/iwrapper bin/md5crypt +all: bin/box bin/iwrapper bin/md5crypt bin/pedant bin/%: src/%.o $(CC) $(LDFLAGS) -o $@ $^ @@ -10,6 +10,7 @@ bin/%: src/%.o bin/box: src/box.o bin/iwrapper: src/iwrapper.o bin/md5crypt: src/md5crypt.o src/md5.o +bin/pedant: src/pedant.o clean: rm -f `find . -name "*~" -or -name "*.[oa]" -or -name "\#*\#" -or -name TAGS -or -name core` diff --git a/src/pedant.c b/src/pedant.c new file mode 100644 index 0000000..cefd317 --- /dev/null +++ b/src/pedant.c @@ -0,0 +1,58 @@ +/* + * A Pedantic Check of Text Input/Output File Syntax + * + * (c) 2005 Martin Mares + */ + +#include + +int main(void) +{ + int line = 1; + int pos = 0; + int maxlen = 0; + int lastlen = -1; + int space = 0; + int c; + while ((c = getchar()) >= 0) + { + if (c == '\n') + { + if (space) + printf("Line %d: Trailing spaces\n", line); + if (line == 1 && !pos) + printf("Line %d: Leading empty line\n", line); + if (maxlen < pos) + maxlen = pos; + if (!lastlen && !pos) + printf("Line %d: Consecutive empty lines\n", line); + lastlen = pos; + line++; + pos = space = 0; + } + else + { + if (c == ' ') + { + if (!pos) + printf("Line %d: Leading spaces\n", line); + if (space) + printf("Line %d: Consecutive spaces\n", line); + space = 1; + } + else + { + space = 0; + if (c < ' ' || c >= 0x7f) + printf("Line %d: Invalid character 0x%02x\n", line, c); + } + pos++; + } + } + if (pos) + printf("Line %d: Incomplete line at the end of file\n", line); + else if (!lastlen) + printf("Line %d: Trailing empty line\n", line-1); + printf("Found %d lines, the longest has %d chars\n", line-1, maxlen); + return 0; +}