tests: add regression tests for Follow TCP Stream
[metze/wireshark/wip.git] / tools / cppcheck / cppcheck.sh
1 #!/bin/bash
2
3 #
4 # cppcheck.sh
5 # Script to run CppCheck Static Analyzer.
6 # http://cppcheck.sourceforge.net/
7 #
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)
14 #       -v      quiet mode
15 # If argument file is omitted then checking all files in the current directory.
16 #
17 # Wireshark - Network traffic analyzer
18 # By Gerald Combs <gerald@wireshark.org>
19 # Copyright 2012 Gerald Combs
20 #
21 # SPDX-License-Identifier: GPL-2.0-or-later
22 #
23
24 CPPCHECK=`which cppcheck`
25 CPPCHECK_DIR=`dirname $0`
26
27 THREADS=4
28 QUIET="--quiet"
29 SUPPRESSIONS="--suppressions-list=$CPPCHECK_DIR/suppressions"
30 INCLUDES="--includes-file=$CPPCHECK_DIR/includes"
31 MODE="gcc"
32 COLORIZE_HTML_MODE="no"
33
34 colorize_worker()
35 {
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">/' \
40         || sed ''
41 }
42
43 # switcher
44 colorize()
45 {
46     [ -z "$1" ] && colorize_worker || colorize_worker <<< "$1"
47 }
48
49 while getopts "achj:v" OPTCHAR ; do
50     case $OPTCHAR in
51         a) SUPPRESSIONS=" " ;;
52         c) COLORIZE_HTML_MODE="yes" ;;
53         h) MODE="html" ;;
54         j) THREADS="$OPTARG" ;;
55         v) QUIET=" " ;;
56     esac
57 done
58 shift $(($OPTIND-1))
59
60 if [ "$MODE" = "gcc" ]; then
61     TEMPLATE="gcc"
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>"
67 fi
68
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"
71
72 if [ $# -eq 0 ]; then
73     TARGET="."
74 else
75     TARGET=$@
76 fi
77
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.
81 trap : INT
82
83 $CPPCHECK --force --enable=style $QUIET    \
84           $SUPPRESSIONS $INCLUDES -i asn1/ \
85           --std=c99 --template=$TEMPLATE   \
86           -j $THREADS $TARGET 2>&1 | colorize
87
88 if [ "$MODE" = "html" ]; then
89     echo "</table></body></html>"
90 fi
91
92 #
93 # Editor modelines  -  http://www.wireshark.org/tools/modelines.html
94 #
95 # Local variables:
96 # c-basic-offset: 4
97 # tab-width: 8
98 # indent-tabs-mode: nil
99 # End:
100 #
101 # vi: set shiftwidth=4 tabstop=8 expandtab:
102 # :indentSize=4:tabSize=8:noTabs=true:
103 #