chiark / gitweb /
5 minutes -> 30 seconds
[bin.git] / grep-nonposix
1 #! /bin/sh
2
3 LC_ALL=C
4 export LC_ALL
5 IFS='
6 '
7
8 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'
9
10 case $1 in
11 --help)
12   exec echo "$0: usage: $0 [OPTION]... [FILE]...
13 Grep for instances of possible POSIX-conformance problems in the FILEs.
14 Options:
15   -s  Check strictly, even for things that aren't likely to be real problems.
16 The FILEs can be directories, in which case the greps are recursive,
17 though ChangeLogs, backup files, and version-control histories are bypassed.
18 The default FILE is '-', which stands for the standard input.";;
19
20 -s)
21   pattern=$pattern'|[ef]grep\>|(\[|test\>).*[    ]-[ao]\>'
22   shift;;
23 esac
24
25 pattern='\<('$pattern')'
26
27 case $# in
28 0) exec grep -E -n "$pattern";;
29 *) find "${@-.}" -type f \
30          ! -name '*~' ! -name 'ChangeLog*' ! -name '*,v' \
31          -print \
32        | sort | xargs grep -E -n "$pattern";;
33 esac