1
1
#! /usr/bin/env bash
2
2
3
- CPPCHECK_suppresses=" --suppress=missingIncludeSystem"
4
- CPPCHECK_OPTS=" -I. --enable=all --error-exitcode=1 --force $CPPCHECK_suppresses ."
3
+ CPPCHECK_unmatched=
4
+ for f in * .c; do
5
+ CPPCHECK_unmatched=" $CPPCHECK_unmatched --suppress=unmatchedSuppression:$f "
6
+ done
7
+
8
+ CPPCHECK_suppresses=" \
9
+ --suppress=missingIncludeSystem \
10
+ --suppress=noValidConfiguration \
11
+ --suppress=unusedFunction\
12
+ "
13
+ CPPCHECK_OPTS=" -I. --enable=all --error-exitcode=1 --force $CPPCHECK_suppresses $CPPCHECK_unmatched ."
5
14
6
15
RETURN=0
7
16
CLANG_FORMAT=$( which clang-format)
@@ -16,23 +25,45 @@ if [ $? -ne 0 ]; then
16
25
exit 1
17
26
fi
18
27
28
+ # Expected Cppcheck version is 1.90+
29
+ # First, Cppcheck 2.x
30
+ if [ -z " $( $CPPCHECK --version | grep -E ' ^Cppcheck\s2' ) " ]; then
31
+ # Second, Cppcheck 1.x
32
+ CPPCHECK_VER=$( $CPPCHECK --version | sed -Ee ' s/Cppcheck 1.([0-9]+)/\1/;q' )
33
+ if [ $CPPCHECK_VER -lt 90 ]; then
34
+ echo " [!] cppcheck version must be at least 1.90." >&2
35
+ echo -e " Check 'Developer Info' for building Cppcheck from source:\n" \
36
+ " http://cppcheck.sourceforge.net/devinfo/" >&2
37
+ exit 1
38
+ fi
39
+ fi
40
+
19
41
ASPELL=$( which aspell)
20
42
if [ $? -ne 0 ]; then
21
43
echo " [!] aspell not installed. Unable to do spelling check." >&2
22
44
exit 1
23
45
fi
46
+ if [ -z " $( aspell dump dicts | grep -E ' ^en$' ) " ]; then
47
+ echo " [!] aspell-en not installed. Unable to do spelling check." >&2
48
+ exit 1
49
+ fi
24
50
25
51
DIFF=$( which colordiff)
26
52
if [ $? -ne 0 ]; then
27
53
DIFF=diff
28
54
fi
29
55
30
- FILES=` git diff --cached --name-only --diff-filter=ACMR | grep -E " \.(c|cpp|h)$" `
56
+ SHA1SUM=$( which sha1sum)
57
+ if [ $? -ne 0 ]; then
58
+ SHA1SUM=shasum
59
+ fi
60
+
61
+ FILES=$( git diff --cached --name-only --diff-filter=ACMR | grep -E " \.(c|cpp|h)$" )
31
62
for FILE in $FILES ; do
32
- nf=` git checkout-index --temp $FILE | cut -f 1`
33
- tempdir=` mktemp -d` || exit 1
34
- newfile=` mktemp ${tempdir} /${nf} .XXXXXX` || exit 1
35
- basename=` basename $FILE `
63
+ nf=$( git checkout-index --temp $FILE | cut -f 1)
64
+ tempdir=$( mktemp -d) || exit 1
65
+ newfile=$( mktemp ${tempdir} /${nf} .XXXXXX) || exit 1
66
+ basename=$( basename $FILE )
36
67
37
68
source=" ${tempdir} /${basename} "
38
69
mv $nf $source
@@ -54,6 +85,17 @@ for FILE in $FILES; do
54
85
fi
55
86
done
56
87
88
+ if [ ! -z " ${FILES[*]} " ]; then
89
+ echo " Following files need to be cleaned up:"
90
+ echo " ${FILES[*]} "
91
+ fi
92
+
93
+ $SHA1SUM -c scripts/checksums > /dev/null
94
+ if [ $? -ne 0 ]; then
95
+ echo " [!] You are not allowed to change the header file queue.h or list.h" >&2
96
+ exit 1
97
+ fi
98
+
57
99
# Prevent unsafe functions
58
100
root=$( git rev-parse --show-toplevel)
59
101
banned=" ([^f]gets\()|(sprintf\()|(strcpy\()"
@@ -81,4 +123,18 @@ if [ $? -ne 0 ]; then
81
123
echo
82
124
fi
83
125
126
+ # non-ASCII filenames are not allowed.
127
+ # Cross platform projects tend to avoid non-ASCII filenames; prevent
128
+ # them from being added to the repository.
129
+ if test $( git diff --cached --name-only --diff-filter=A -z $against |
130
+ LC_ALL=C tr -d ' [ -~]\0' | wc -c) ! = 0
131
+ then
132
+ cat << \EOF
133
+ ERROR: Attempt to add a non-ASCII file name.
134
+ This can cause problems if you want to work with people on other platforms.
135
+ To be portable it is advisable to rename the file.
136
+ EOF
137
+ RETURN=1
138
+ fi
139
+
84
140
exit $RETURN
0 commit comments