chiark / gitweb /
grep-nonposix: New script to check for obvious POSIX 1003.1-2001
authorColin Watson <cjwatson@chiark.greenend.org.uk>
Thu, 23 Oct 2003 16:36:01 +0000 (16:36 +0000)
committerColin Watson <cjwatson@chiark.greenend.org.uk>
Thu, 23 Oct 2003 16:36:01 +0000 (16:36 +0000)
non-conformance, modified from a version by Paul Eggert. See:
http://lists.debian.org/debian-glibc/2003/debian-glibc-200308/msg00120.html

grep-nonposix [new file with mode: 0755]

diff --git a/grep-nonposix b/grep-nonposix
new file mode 100755 (executable)
index 0000000..a964cb0
--- /dev/null
@@ -0,0 +1,33 @@
+#! /bin/sh
+
+LC_ALL=C
+export LC_ALL
+IFS='
+'
+
+pattern='(expand|head|fold|split|tail|uniq|unexpand|nice|diff)\>.*[     ]-[a-zA-Z]*[0-9]|(sort|tail|uniq)\>.*[  ]\+[0-9]+[a-zA-Z_]*|sort\>.*[   ]-o'
+
+case $1 in
+--help)
+  exec echo "$0: usage: $0 [OPTION]... [FILE]...
+Grep for instances of possible POSIX-conformance problems in the FILEs.
+Options:
+  -s  Check strictly, even for things that aren't likely to be real problems.
+The FILEs can be directories, in which case the greps are recursive,
+though ChangeLogs, backup files, and version-control histories are bypassed.
+The default FILE is '-', which stands for the standard input.";;
+
+-s)
+  pattern=$pattern'|[ef]grep\>|(\[|test\>).*[   ]-[ao]\>'
+  shift;;
+esac
+
+pattern='\<('$pattern')'
+
+case $# in
+0) exec grep -E -n "$pattern";;
+*) find "${@-.}" -type f \
+         ! -name '*~' ! -name 'ChangeLog*' ! -name '*,v' \
+         -print \
+       | sort | xargs grep -E -n "$pattern";;
+esac