drivers/mge-hid.c: restore white-space (TAB indentation and between decl type and...
[networkupstools.git] / indent.sh
blob67cfd723524c9bd9e8829f1ced4f2a1c063281ae
1 #!/usr/bin/env bash
3 # Filter NUT C source file style to conform to recommendations of
4 # https://www.networkupstools.org/docs/developer-guide.chunked/ar01s03.html#_coding_style
5 # Note that the sed filter "command does a reasonable job of converting
6 # most C++ style comments (but not URLs and DOCTYPE strings)" so a manual
7 # pass may be needed to revise the changes.
9 # Since that the result is not always immediately acceptable, so this script
10 # is not part of e.g. automated testing - but it helps clean up much of the
11 # codebase to be up to a common spec.
13 # Script wrapping (C) 2017 by Jim Klimov
14 # Rules (C) long ago by NUT project team
16 set -o pipefail
18 TMPFILE=".style-tmp.$$"
19 trap 'EXITCODE=$? ; rm -f "$TMPFILE" ; exit $EXITCODE' 0 1 2 3 15
21 convertFile() {
22 SRCFILE="$1"
24 # TODO: The indent below does a poor job for C++
25 cat "$SRCFILE" \
26 | indent -kr -i8 -T FILE -l1000 -nhnl \
27 | sed 's#\(^\|[ \t]\)//[ \t]*\(.*\)[ \t]*#/* \2 */#' \
28 > "$TMPFILE"
29 STEPCODE=$?
30 if [ "$STEPCODE" != 0 ]; then
31 TOTALCODE="$STEPCODE"
32 echo "FAILED to process file: $SRCFILE" >&2
33 continue
36 if diff -q "$SRCFILE" "$TMPFILE" ; then
37 echo "File was not changed: $SRCFILE" >&2
38 else
39 echo "File was changed: $SRCFILE - please revise the differences" >&2
40 meld "$SRCFILE" "$TMPFILE"
44 TOTALCODE=0
45 if [ $# = 0 ] ; then
46 git ls-files | grep -E '\.(c|h)$' | while read F ; do
47 convertFile "$F"
48 done
49 else
50 case "$1" in
51 -h|--help)
52 echo "Usage: $0 [file.c] [header.h] - process listed file(s)"
53 echo "Usage: $0 - process all .c and .h files currently tracked in Git repo"
56 for F in "$@" ; do
57 convertFile "$F"
58 done
60 esac
63 exit $TOTALCODE