1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#!/bin/sh
set -eu
assert_sequential_ids() {
awk '
BEGIN {
n = 0
}
/^#define MSG_/ {
if (++n != $3) {
print "Bad sequential ID:"
printf "%s:%s:%s\n", FILENAME, NR, $0
printf "expected: %s\ngot: %s\n", n, $3
exit 1
}
}
' "$1"
}
assert_consistent_msg_definitions() {
awk '
BEGIN {
i = 0
j = 0
}
/^#define MSG_/ {
defines[i++] = $2
}
/^\t\[MSG_/ {
msgs[j++] = substr($0, 3, index($0, "]") - 3)
}
END {
for (n in defines) {
if (defines[n] != msgs[n]) {
printf "Order mismatch between #define"
printf " and usage in MSGS[]:\n"
printf "#define: %s\nMSGS[]: %s\n",
defines[n], msgs[n]
exit 1
}
}
}
' "$1"
}
assert_no_unused_msgs() {
DEFINES="$(mktemp)"
USAGES="$(mktemp)"
awk '/^#define MSG_/ { print $2 }' "$f" | sort > "$DEFINES"
awk -F'_\\(' '
/_\(MSG_/ { print substr($2, 0, index($2, ")") - 1) }
' "$f" | sort | uniq > "$USAGES"
if ! diff "$DEFINES" "$USAGES"; then
echo 'Some defined MSG_ items not being used' >&2
exit 1
fi
}
for f in "$@"; do
assert_sequential_ids "$f"
assert_consistent_msg_definitions "$f"
assert_no_unused_msgs "$f"
done
|