#!/bin/awk -f
#
-# Copyright © 2021 Nick Bowler
+# Copyright © 2021, 2023 Nick Bowler
#
# Hackjob to try and find all the relevant wordlist items from the gperf
# output, in order to produce (at runtime) a list of those commands, in
BEGIN { maxline = 0 }
-$1 == "char" && (id = get_stringpool_id($2)) {
+$1 == "char" && get_stringpool_id($2) {
sub(/[^"]*"/, "", $2)
sub(/".*/, "", $2)
- pool[id] = $2
+ pool[ID] = $2
}
$1 ~ /^#line/ {
}
}
-(id = get_stringpool_id($0)) && $0 ~ "cmd_" pool[id] {
- sub(/^stringpool_str/, "", id)
- indices[line] = id
+get_stringpool_id($0) && $0 ~ "cmd_" pool[ID] {
+ sub(/^stringpool_str/, "", ID)
+ indices[line] = ID
}
END {
function get_stringpool_id(s)
{
if (sub(/.*stringpool_str/, "stringpool_str", s) && sub(/[,[].*/, "", s)) {
- return s
+ ID = s;
+ return 1
}
- return ""
+ return 0
}
AT_SETUP([cdecl99 help command])
-AT_DATA([input], [[help
+AT_DATA([input],
+[[help
explain int
]])
-AT_CHECK([cdecl99 -f input], [0], [stdout])
-AT_CHECK([sed -n '$p' stdout], [0], [type int
-])
+# Program to generate expected output based on src/execute.gperf
+AT_DATA([expout.sed],
+[[#n
+/^%%$/,/^%%$/ {
+ s/^exit.*//
+ s/,.*//p
+}
+$a\
+type int
+]])
+sed -f expout.sed "$srcdir/src/execute.gperf" >expout
+
+# Program to filter the help output to extract the command list from "help"
+# without any descriptions.
+AT_DATA([filter.sed],
+[[/^ /,$ !d
+/^ /d
+s/^ *\([^ ]*\).*/\1/
+]])
+
+AT_CHECK([LC_ALL=C cdecl99 -f input >stdout && sed -f filter.sed stdout],
+ [0], [expout])
AT_CLEANUP