From 5fc35dc076078b9710d86b47c53f4315edd3cd82 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 6 Dec 2023 21:12:04 -0500 Subject: [PATCH] cdecl99: Fix "help" command on ULTRIX. ULTRIX 4.5 nawk does not always interpret a nonempty string as "true", so install a workaround to the gen-cmdlist.awk script for this issue. And fix the test suite which purports to test this command but failed to notice that no useful help was printed. --- src/gen-cmdlist.awk | 17 +++++++++-------- tests/general.at | 28 ++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/gen-cmdlist.awk b/src/gen-cmdlist.awk index ea096eb..42cd593 100755 --- a/src/gen-cmdlist.awk +++ b/src/gen-cmdlist.awk @@ -1,6 +1,6 @@ #!/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 @@ -28,10 +28,10 @@ END { 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/ { @@ -41,9 +41,9 @@ $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 { @@ -64,8 +64,9 @@ END { function get_stringpool_id(s) { if (sub(/.*stringpool_str/, "stringpool_str", s) && sub(/[,[].*/, "", s)) { - return s + ID = s; + return 1 } - return "" + return 0 } diff --git a/tests/general.at b/tests/general.at index fb4ee68..7b34b9d 100644 --- a/tests/general.at +++ b/tests/general.at @@ -63,13 +63,33 @@ AT_CLEANUP 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 -- 2.43.2