aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Cholewiński <harry666t@gmail.com>2015-10-10 13:00:47 +0200
committerKamil Cholewiński <harry666t@gmail.com>2015-10-10 13:10:49 +0200
commit83d6197d6f82b5b2e0e6df1c5fa429b3bde9a6d9 (patch)
treef560c8c9cf052a7c17d33aa7c7de10a2497d0ccf
parent69bd4c618971caacb8b621ad6f9ff5ec49047019 (diff)
downloadtinyscheme-83d6197d6f82b5b2e0e6df1c5fa429b3bde9a6d9.zip
tinyscheme-83d6197d6f82b5b2e0e6df1c5fa429b3bde9a6d9.tar.gz
tinyscheme-83d6197d6f82b5b2e0e6df1c5fa429b3bde9a6d9.tar.bz2
Simple style linter
-rw-r--r--Makefile16
-rwxr-xr-xtest-style35
2 files changed, 48 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 62539cd..29c48a6 100644
--- a/Makefile
+++ b/Makefile
@@ -21,11 +21,21 @@ SCM = ${shell find . -name "*.scm"}
SRC = dynload.c scheme.c
HDR = dynload.h opdefines.h scheme-private.h scheme.h
OBJ = ${SRC:.c=.o}
+SO = libtinyscheme.so
+A = libtinyscheme.a
+EXE = scheme
-all: options libtinyscheme.so libtinyscheme.a scheme
+all: options ${SO} ${A} ${EXE}
-test: scheme
- ./scheme -1 test.scm
+test: test.style test.scheme
+
+test.style: ${SRC} ${HDR} ${SCM}
+ @echo test.style
+ @./test-style ${SRC} ${HDR} ${SCM}
+
+test.scheme: ${EXE} test.scm
+ @echo test.scheme
+ @./scheme -1 test.scm
autofmt:
astyle \
diff --git a/test-style b/test-style
new file mode 100755
index 0000000..f1079b8
--- /dev/null
+++ b/test-style
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+from __future__ import print_function
+import re
+import sys
+
+
+def ferror(fname, line, msg):
+ return print("%s:%s:" % (fname, line), msg, file=sys.stderr)
+
+
+def parse_style(fname):
+ status = 0
+ with open(fname, "rU") as f:
+ for i, line in enumerate(f, 1):
+ if len(line) >= 80:
+ ferror(fname, i, "line over 80 colums")
+ status |= 1
+ if " " in line and "\t" in line:
+ ferror(fname, i, "mixed tabs and spaces")
+ status |= 1
+ if re.match("[ \t\r]+$", line):
+ ferror(fname, i, "trailing whitespace")
+ status |= 1
+ return status
+
+
+def main():
+ status = 0
+ for fname in sys.argv[1:]:
+ status |= parse_style(fname)
+ sys.exit(status)
+
+
+if __name__ == "__main__":
+ main()