Debian Codegraph @

tools/check-syntax

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 #
4 # libseccomp code syntax checking tool
5 #
6 # Copyright (c) 2013,2015 Red Hat <[email protected]>
7 # Author: Paul Moore <[email protected]>
8 #
9
10 #
11 # This library is free software; you can redistribute it and/or modify it
12 # under the terms of version 2.1 of the GNU Lesser General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This library is distributed in the hope that it will be useful, but WITHOUT
16 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
18 # for more details.
19 #
20 # You should have received a copy of the GNU Lesser General Public License
21 # along with this library; if not, see <http://www.gnu.org/licenses>.
22 #
23
24 CHK_C_LIST="include/seccomp.h.in \
25 include/seccomp-syscalls.h \
26 src/*.c src/*.h \
27 tests/*.c tests/*.h \
28 tools/*.c tools/*.h"
29 CHK_C_EXCLUDE="src/syscalls.perf.c"
30
31 CHK_SPELL_EXCLUDE_WORDS=""
32
33 ####
34 # functions
35
36 #
37 # Dependency verification
38 #
39 # Arguments:
40 # 1 Dependency to check for
41 #
42 function verify_depsscip-shell shell libseccomp 2.6.0-2 verify_deps().() {
43 [[ -z "$1" ]] && return
44 if ! whichscip-shell system . . which. "$1" >& /dev/null; then
45 echoscip-shell system . . echo. "error: install \"$1\" and include it in your \$PATH"
46 exit 1
47 fi
48 }
49
50 #
51 # Print out script usage details
52 #
53 function usagescip-shell shell libseccomp 2.6.0-2 usage().() {
54 catscip-shell system . . cat. << EOF
55 usage: check-syntax [-h]
56
57 libseccomp code syntax checking tool
58 optional arguments:
59 -h show this help message and exit
60 -f fix the file formatting
61 EOF
62 }
63
64 #
65 # Spellcheck source code
66 #
67 function tool_spell_checkscip-shell shell libseccomp 2.6.0-2 tool_spell_check().() {
68 local tfile
69
70 tfile=$(mktempscip-shell system . . mktemp. -t check-syntax-XXXXXX)
71 catscip-shell system . . cat. - > $tfile
72 codespell -q 16 -d -w -L "$CHK_SPELL_EXCLUDE_WORDS" $tfile
73 catscip-shell system . . cat. $tfile
74 rmscip-shell system . . rm. -f $tfile
75 }
76
77 #
78 # Generate a properly formatted C source/header file
79 #
80 function tool_c_stylescip-shell shell libseccomp 2.6.0-2 tool_c_style().() {
81 catscip-shell system . . cat. - | astyle --options=none --lineend=linux --mode=c \
82 --style=linux \
83 --indent=force-tab=8 \
84 --indent-col1-comments \
85 --min-conditional-indent=0 \
86 --max-continuation-indent=80 \
87 --pad-oper \
88 --align-pointer=name \
89 --align-reference=name \
90 --max-code-length=80 \
91 --break-after-logical
92 }
93
94 #
95 # Generate a properly formatted and spellchecked C source/header file
96 #
97 # Arguments:
98 # 1 Source file
99 #
100 function tool_c_idealscip-shell shell libseccomp 2.6.0-2 tool_c_ideal().() {
101 catscip-shell system . . cat. "$1" | tool_spell_checkscip-shell shell libseccomp 2.6.0-2 tool_spell_check(). | tool_c_stylescip-shell shell libseccomp 2.6.0-2 tool_c_style().
102 }
103
104 #
105 # Check the formatting on a C source/header file
106 #
107 # Arguments:
108 # 1 File to check
109 #
110 function tool_c_style_checkscip-shell shell libseccomp 2.6.0-2 tool_c_style_check().() {
111 [[ -z "$1" || ! -r "$1" ]] && return
112
113 tool_c_idealscip-shell shell libseccomp 2.6.0-2 tool_c_ideal(). "$1" | diffscip-shell system . . diff. -pu --label="$1.orig" "$1" --label="$1" -
114 }
115
116 #
117 # Fix the formatting on a C source/header file
118 #
119 # Arguments:
120 # 1 File to fix
121 #
122 function tool_c_style_fixscip-shell shell libseccomp 2.6.0-2 tool_c_style_fix().() {
123 [[ -z "$1" || ! -r "$1" ]] && return
124
125 tmp="$(mktempscip-shell system . . mktemp. --tmpdir=$(dirnamescip-shell system . . dirname. "$1"))"
126 tool_c_idealscip-shell shell libseccomp 2.6.0-2 tool_c_ideal(). "$1" > "$tmp"
127 mvscip-shell system . . mv. "$tmp" "$1"
128 }
129
130 #
131 # Perform all known syntax checks for the configured C sources/headers
132 #
133 function check_cscip-shell shell libseccomp 2.6.0-2 check_c().() {
134 for i in $CHK_C_LIST; do
135 echoscip-shell system . . echo. "$CHK_C_EXCLUDE" | grepscip-shell system . . grep. -q "$i" && continue
136 echoscip-shell system . . echo. "Differences for $i"
137 tool_c_style_checkscip-shell shell libseccomp 2.6.0-2 tool_c_style_check(). "$i"
138 done
139 }
140
141 #
142 # Perform all known syntax fixess for the configured C sources/headers
143 #
144 function fix_cscip-shell shell libseccomp 2.6.0-2 fix_c().() {
145 for i in $CHK_C_LIST; do
146 echoscip-shell system . . echo. "$CHK_C_EXCLUDE" | grepscip-shell system . . grep. -q "$i" && continue
147 echoscip-shell system . . echo. "Fixing $i"
148 tool_c_style_fixscip-shell shell libseccomp 2.6.0-2 tool_c_style_fix(). "$i"
149 done
150 }
151
152 ####
153 # main
154
155 verify_depsscip-shell shell libseccomp 2.6.0-2 verify_deps(). astyle
156 verify_depsscip-shell shell libseccomp 2.6.0-2 verify_deps(). codespell
157
158 opt_fix=0
159
160 while getopts "fh" opt; do
161 case $opt in
162 f)
163 opt_fix=1
164 ;;
165 h|*)
166 usagescip-shell shell libseccomp 2.6.0-2 usage().
167 exit 1
168 ;;
169 esac
170 done
171
172 # display the results
173 echoscip-shell system . . echo. "=============== $(datescip-shell system . . date.) ==============="
174 echoscip-shell system . . echo. "Code Syntax Check Results (\"check-syntax $*\")"
175 if [[ $opt_fix -eq 1 ]]; then
176 fix_cscip-shell shell libseccomp 2.6.0-2 fix_c().
177 else
178 check_cscip-shell shell libseccomp 2.6.0-2 check_c().
179 fi
180 echoscip-shell system . . echo. "============================================================"
181
182 # exit
183 exit 0