Codebase list libisal / 74d5d36
build: Add format checking script Signed-off-by: Greg Tucker <greg.b.tucker@intel.com> Greg Tucker 6 years ago
3 changed file(s) with 65 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
2929
3030 ./tools/iindent your_files.c
3131
32 And use check format script before submitting.
33
34 ./tools/check_format.sh
35
3236 [mailing list]:https://lists.01.org/mailman/listinfo/isal
3337 [license]:LICENSE
3438 [signed-off-by language]:https://01.org/community/signed-process
0 #!/usr/bin/env bash
1
2 set -e
3 rc=0
4 verbose=0
5 indent_args='-npro -kr -i8 -ts8 -sob -l95 -ss -ncs -cp1 -lps'
6
7 while [ -n "$*" ]; do
8 case "$1" in
9 -v )
10 verbose=1
11 shift
12 ;;
13 -h )
14 echo check_format.sh [-h -v]
15 exit 0
16 ;;
17 esac
18 done
19
20 echo "Checking format of files in the git index at $PWD"
21 if ! git rev-parse --is-inside-work-tree >& /dev/null; then
22 echo "Not in a git repo: Fail"
23 exit 1
24 fi
25
26 if hash indent && indent --version | grep -q GNU; then
27 echo "Checking C files for coding style..."
28 for f in `git ls-files '*.c'`; do
29 [ "$verbose" -gt 0 ] 2> /dev/null && echo "checking $f"
30 if ! indent $indent_args -st $f | diff -q $f - >& /dev/null; then
31 echo " File found with formatting issues: $f"
32 [ "$verbose" -gt 0 ] 2> /dev/null && indent $indent_args -st $f | diff -u $f -
33 rc=1
34 fi
35 done
36 [ "$rc" -gt 0 ] && echo " Run ./tools/iindent on files"
37 else
38 echo "You do not have indent installed so your code style is not being checked!"
39 fi
40
41 if hash grep; then
42 echo "Checking for dos and whitespace violations..."
43 for f in `git ls-files '*.c' '*.h' '*.asm' '*.inc' '*.am' '*.txt' '*.md' `; do
44 [ "$verbose" -gt 0 ] 2> /dev/null && echo "checking $f"
45 if grep -q '[[:space:]]$' $f ; then
46 echo " File found with trailing whitespace: $f"
47 rc=1
48 fi
49 if grep -q $'\r' $f ; then
50 echo " File found with dos formatting: $f"
51 rc=1
52 fi
53 done
54 fi
55
56 [ "$rc" -gt 0 ] && echo Format Fail || echo Format Pass
57
58 exit $rc
0 #!/bin/sh
1 sed -i -i.bak 's/[[:blank:]]*$//' "$@"