5 # COPYRIGHT: Written by John Cunningham Bowler, 2010.
6 # To the extent possible under law, the author has waived all copyright and
7 # related or neighboring rights to this work. This work is published from:
10 # Check the format of the source files in the current directory - checks for a
11 # line length of 80 characters max and no tab characters.
13 # Optionally arguments are files or directories to check.
15 # -v: output the long lines (makes fixing them easier)
16 # -e: spawn an editor for each file that needs a change ($EDITOR must be
17 # defined). When using -e the script MUST be run from an interactive
32 # Copy the standard streams for the editor
35 echo "chkfmt -e: EDITOR must be defined" >&2
40 # Function to edit a single file - if the file isn't changed ask the user
41 # whether or not to continue. This stuff only works if the script is run from
42 # the command line (otherwise, don't specify -e or you will be sorry).
44 cp "$file" "$file".orig
45 "$EDITOR" "$file" 0>&3 1>&4 2>&5 3>&- 4>&- 5>&- ||
exit 1
46 if cmp -s "$file".orig
"$file"
49 echo -n "$file: file not changed, type anything to continue: " >&5
51 test -n "$ans" ||
return 1
56 # In beta versions the version string which appears in files can be a little
57 # long and cause spuriously overlong lines. To avoid this substitute the version
58 # string with a 'standard' version a.b.cc before checking for long lines.
62 's/^#define PNG_LIBPNG_VER_STRING .\([0-9]\.[0-9]\.[0-9][0-9a-z]*\).$/\1/p' \
64 echo "chkfmt: checking version $vers"
68 echo "chkfmt: png.h not found, ignoring version number" >&2
71 test -n "$1" ||
set -- .
72 find "$@" \
( -type d \
( -name '.git' -o -name '.libs' -o -name 'projects' \
) \
73 -prune \
) -o \
( -type f \
74 ! -name '*.[oa]' ! -name '*.l[oa]' ! -name '*.png' ! -name '*.out' \
75 ! -name '*.jpg' ! -name '*.patch' ! -name '*.obj' ! -name '*.exe' \
76 ! -name '*.com' ! -name '*.tar.*' ! -name '*.zip' ! -name '*.ico' \
77 ! -name '*.res' ! -name '*.rc' ! -name '*.mms' ! -name '*.rej' \
78 ! -name '*.dsp' ! -name '*.orig' ! -name '*.dfn' ! -name '*.swp' \
79 ! -name '~*' ! -name '*.3' \
80 ! -name 'missing' ! -name 'mkinstalldirs' ! -name 'depcomp' \
81 ! -name 'aclocal.m4' ! -name 'install-sh' ! -name 'Makefile.in' \
82 ! -name 'ltmain.sh' ! -name 'config*' -print \
) |
{
87 *.mak|
*[Mm
]akefile.
*|
*[Mm
]akefile
)
88 # Makefiles require tabs, dependency lines can be this long.
92 # Includes literal tabs
94 # The following is arbitrary
104 # Note that vers can only contain 0-9, . and a-z
107 sed -e "s/$vers/a.b.cc/g" "$file" >"$file".$$
109 cp "$file" "$file".$$
111 splt
="`fold -$line_length "$file".$$ | diff -c "$file".$$ -`"
116 echo "$file: lines too long"
118 if test -n "$EDITOR" -a -n "$edit"
120 doed
"$file" ||
exit 1
121 elif test -n "$verbose"
126 if test -n "$check_tabs"
128 tab
="`tr -c -d '\t' <"$file"`"
131 echo "$file: file contains tab characters"
133 if test -n "$EDITOR" -a -n "$edit"
135 doed
"$file" ||
exit 1
136 elif test -n "$verbose"