]> mj.ucw.cz Git - eval.git/commitdiff
Added pedantic check of file syntax.
authorMartin Mares <mj@ucw.cz>
Sun, 17 Apr 2005 15:24:10 +0000 (15:24 +0000)
committerMartin Mares <mj@ucw.cz>
Sun, 17 Apr 2005 15:24:10 +0000 (15:24 +0000)
Makefile
src/pedant.c [new file with mode: 0644]

index 70d6c0aeb9daa095bf1f5dcef20c01028865dd96..db12c3fb7a4c4d963d504663bce22a5d5f4d17f2 100644 (file)
--- 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 (file)
index 0000000..cefd317
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ *     A Pedantic Check of Text Input/Output File Syntax
+ *
+ *     (c) 2005 Martin Mares <mj@ucw.cz>
+ */
+
+#include <stdio.h>
+
+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;
+}