diff options
| author | Anders Betts <anders.betts@gmail.com> | 2026-09-20 20:11:19 +0200 |
|---|---|---|
| committer | Anders Betts <anders.betts@gmail.com> | 2026-09-20 20:11:19 +0200 |
| commit | 8351fa7752bb8341ef405a37ff7c73142715e981 (patch) | |
| tree | dde603d313f4f26934f2ce20a22dfd9b69324cf0 /scripts/check-consistency.sh | |
| parent | beafdbe0d64340387d619c38554976410129f05b (diff) | |
| download | bokf-8351fa7752bb8341ef405a37ff7c73142715e981.tar.gz bokf-8351fa7752bb8341ef405a37ff7c73142715e981.zip | |
commands: split the command table by domain
Diffstat (limited to 'scripts/check-consistency.sh')
| -rwxr-xr-x | scripts/check-consistency.sh | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/scripts/check-consistency.sh b/scripts/check-consistency.sh index f67695f..600db25 100755 --- a/scripts/check-consistency.sh +++ b/scripts/check-consistency.sh @@ -1,8 +1,9 @@ #!/bin/sh # Check that the daemon source and docs/PROTOCOL.md have not drifted apart: # -# 1. every command in g_commands[] (src/commands.c) is listed in a -# PROTOCOL.md table whose first column is "Command", and vice versa; +# 1. every command in the `g_cmd_<domain>[]` tables (src/commands.c and +# src/cmd_*.c) is listed in a PROTOCOL.md table whose first column is +# "Command", and vice versa; # 2. every error code passed to fail()/failf()/add_error() in src/*.c is # documented in PROTOCOL.md section 5.3, and vice versa (documented but # unused codes are warnings only, some are reserved). @@ -12,7 +13,9 @@ # # Environment overrides (used by the self-tests): # REPO_ROOT repository root, default "." (run from the repo root) -# COMMANDS_C command table source, default $REPO_ROOT/src/commands.c +# COMMANDS_C primary command table source, default $REPO_ROOT/src/commands.c +# CMDS_GLOB shell glob of command table sources, +# default "$COMMANDS_C $REPO_ROOT/src/cmd_*.c" # PROTOCOL_MD protocol document, default $REPO_ROOT/docs/PROTOCOL.md # SRC_GLOB shell glob of sources scanned for error codes, # default $REPO_ROOT/src/*.c @@ -26,6 +29,7 @@ export LC_ALL=C REPO_ROOT=${REPO_ROOT:-.} COMMANDS_C=${COMMANDS_C:-$REPO_ROOT/src/commands.c} +CMDS_GLOB=${CMDS_GLOB:-$COMMANDS_C $REPO_ROOT/src/cmd_*.c} PROTOCOL_MD=${PROTOCOL_MD:-$REPO_ROOT/docs/PROTOCOL.md} SRC_GLOB=${SRC_GLOB:-$REPO_ROOT/src/*.c} @@ -43,20 +47,23 @@ trap 'rm -rf "$tmp"' EXIT HUP INT TERM # --- extract what the code implements -------------------------------------- -awk ' - /g_commands[[:space:]]*\[[[:space:]]*\][[:space:]]*=/ { in_table = 1; next } - in_table && /^[[:space:]]*\};/ { in_table = 0 } - in_table && /^[[:space:]]*\{[[:space:]]*"/ { - line = $0 - sub(/^[^{]*\{[[:space:]]*"/, "", line) - sub(/".*/, "", line) - if (line != "") - print line - } -' "$COMMANDS_C" | sort -u > "$tmp/impl_commands" +for f in $CMDS_GLOB; do + [ -f "$f" ] || continue + awk ' + /const struct command g_cmd_[a-z_]+\[\][[:space:]]*=/ { in_table = 1; next } + in_table && /^[[:space:]]*\};/ { in_table = 0 } + in_table && /^[[:space:]]*\{[[:space:]]*"/ { + line = $0 + sub(/^[^{]*\{[[:space:]]*"/, "", line) + sub(/".*/, "", line) + if (line != "") + print line + } + ' "$f" +done | sort -u > "$tmp/impl_commands" if [ ! -s "$tmp/impl_commands" ]; then - echo "check-consistency: no commands parsed from $COMMANDS_C" >&2 + echo "check-consistency: no commands parsed from $CMDS_GLOB" >&2 exit 2 fi @@ -143,7 +150,7 @@ section() { echo "== $1 ==" } -section "commands: implemented in $COMMANDS_C but not documented in $PROTOCOL_MD" +section "commands: implemented in $CMDS_GLOB but not documented in $PROTOCOL_MD" if [ -s "$tmp/cmd_undocumented" ]; then while IFS= read -r name; do echo "command: undocumented: $name" |
