5 # Script to run CppCheck Static Analyzer.
6 # http://cppcheck.sourceforge.net/
8 # Usage: tools/cppcheck/cppcheck.sh [options] [file]
9 # Where options can be:
10 # -a disable suppression list (see $CPPCHECK_DIR/suppressions)
11 # -c colorize html output
12 # -h html output (default is gcc)
13 # -t threads (default: 4)
15 # If argument file is omitted then checking all files in the current directory.
17 # Wireshark - Network traffic analyzer
18 # By Gerald Combs <gerald@wireshark.org>
19 # Copyright 2012 Gerald Combs
21 # SPDX-License-Identifier: GPL-2.0-or-later
24 CPPCHECK=`which cppcheck`
25 CPPCHECK_DIR=`dirname $0`
29 SUPPRESSIONS="--suppressions-list=$CPPCHECK_DIR/suppressions"
30 INCLUDES="--includes-file=$CPPCHECK_DIR/includes"
32 COLORIZE_HTML_MODE="no"
36 # always uses stdin/stdout
37 [ "$COLORIZE_HTML_MODE" = "yes" ] && \
38 sed -e '/<td>warning<\/td>/s/^<tr>/<tr bgcolor="#ff3">/' \
39 -e '/<td>error<\/td>/s/^<tr>/<tr bgcolor="#faa">/' \
46 [ -z "$1" ] && colorize_worker || colorize_worker <<< "$1"
49 while getopts "achj:v" OPTCHAR ; do
51 a) SUPPRESSIONS=" " ;;
52 c) COLORIZE_HTML_MODE="yes" ;;
54 j) THREADS="$OPTARG" ;;
60 if [ "$MODE" = "gcc" ]; then
62 elif [ "$MODE" = "html" ]; then
63 echo "<html><body><table border=1>"
64 echo "<tr><th>File</th><th>Line</th><th>Severity</th>"
65 echo "<th>Message</th><th>ID</th></tr>"
66 TEMPLATE="<tr><td>{file}</td><td>{line}</td><td>{severity}</td><td>{message}</td><td>{id}</td></tr>"
69 # Ensure that the COLORIZE_HTML_MODE option is used only with HTML-mode and not with GCC-mode.
70 [ "$MODE" = "html" ] && [ "$COLORIZE_HTML_MODE" = "yes" ] || COLORIZE_HTML_MODE="no"
78 # Use a little-documented feature of the shell to pass SIGINTs only to the
79 # child process (cppcheck in this case). That way the final 'echo' still
80 # runs and we aren't left with broken HTML.
83 $CPPCHECK --force --enable=style $QUIET \
84 $SUPPRESSIONS $INCLUDES -i asn1/ \
85 --std=c99 --template=$TEMPLATE \
86 -j $THREADS $TARGET 2>&1 | colorize
88 if [ "$MODE" = "html" ]; then
89 echo "</table></body></html>"
93 # Editor modelines - http://www.wireshark.org/tools/modelines.html
98 # indent-tabs-mode: nil
101 # vi: set shiftwidth=4 tabstop=8 expandtab:
102 # :indentSize=4:tabSize=8:noTabs=true: