6 # Written by John Cunningham Bowler, 2010.
7 # Revised by Cosmin Truta, 2022.
8 # To the extent possible under law, the author has waived all copyright and
9 # related or neighboring rights to this work. The author published this work
10 # from the United States.
12 # Check the format of the source files in the current directory:
14 # * The lines should not exceed a predefined maximum length.
15 # * Tab characters should appear only where necessary (e.g. in makefiles).
17 # Optionally arguments are files or directories to check.
19 # -v: output the long lines (makes fixing them easier)
20 # -e: spawn an editor for each file that needs a change ($EDITOR must be
21 # defined). When using -e the script MUST be run from an interactive
24 script_name=`basename "$0"`
39 # Copy the standard streams for the editor
42 echo "$script_name -e: EDITOR must be defined" >&2
47 # Function to edit a single file - if the file isn't changed ask the user
48 # whether or not to continue. This stuff only works if the script is run
49 # from the command line (otherwise, don't specify -e or you will be sorry).
51 cp "$file" "$file".orig
52 "$EDITOR" "$file" 0>&3 1>&4 2>&5 3>&- 4>&- 5>&- || exit 1
53 if cmp -s "$file".orig "$file"
56 echo -n "$file: file not changed, type anything to continue: " >&5
58 test -n "$ans" || return 1
63 # In beta versions, the version string which appears in files can be a little
64 # long and cause spuriously overlong lines. To avoid this, substitute the
65 # version string with a placeholder string "a.b.cc" before checking for long
67 # (Starting from libpng version 1.6.36, we switched to a conventional Git
68 # workflow, and we are no longer publishing beta versions.)
72 's/^#define PNG_LIBPNG_VER_STRING .\([0-9]\.[0-9]\.[0-9][0-9a-z]*\).$/\1/p' \
74 echo "$script_name: checking version $vers"
78 echo "$script_name: png.h not found, ignoring version number" >&2
81 test -n "$1" || set -- .
82 find "$@" \( -type d \( -name '.git' -o -name '.libs' -o -name 'projects' \) \
83 -prune \) -o \( -type f \
84 ! -name '*.[oa]' ! -name '*.l[oa]' ! -name '*.png' ! -name '*.out' \
85 ! -name '*.jpg' ! -name '*.patch' ! -name '*.obj' ! -name '*.exe' \
86 ! -name '*.com' ! -name '*.tar.*' ! -name '*.zip' ! -name '*.ico' \
87 ! -name '*.res' ! -name '*.rc' ! -name '*.mms' ! -name '*.rej' \
88 ! -name '*.dsp' ! -name '*.orig' ! -name '*.dfn' ! -name '*.swp' \
89 ! -name '~*' ! -name '*.3' \
90 ! -name 'missing' ! -name 'mkinstalldirs' ! -name 'depcomp' \
91 ! -name 'aclocal.m4' ! -name 'install-sh' ! -name 'Makefile.in' \
92 ! -name 'ltmain.sh' ! -name 'config*' -print \) | {
97 *.mak|*[Mm]akefile.*|*[Mm]akefile)
98 # Makefiles require tabs, dependency lines can be this long.
102 # Allow literal tabs.
104 # Mainframe line printer, anyone?
117 # Note that vers can only contain 0-9, . and a-z
120 sed -e "s/$vers/a.b.cc/g" "$file" >"$file".$$
122 cp "$file" "$file".$$
124 splt="`fold -$line_length "$file".$$ | diff -c "$file".$$ -`"
129 echo "$file: lines too long"
131 if test -n "$EDITOR" -a -n "$edit"
133 doed "$file" || exit 1
134 elif test -n "$verbose"
139 if test -n "$check_tabs"
141 tab="`tr -c -d '\t' <"$file"`"
144 echo "$file: file contains tab characters"
146 if test -n "$EDITOR" -a -n "$edit"
148 doed "$file" || exit 1
149 elif test -n "$verbose"