]> git.draconx.ca Git - cdecl99.git/commitdiff
cdecl99: Fix "help" command on ULTRIX.
authorNick Bowler <nbowler@draconx.ca>
Thu, 7 Dec 2023 02:12:04 +0000 (21:12 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 7 Dec 2023 02:12:04 +0000 (21:12 -0500)
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
tests/general.at

index ea096eb195f2b533340e84a07cda60d9795ab050..42cd593dc7c4652faa8eb1662563b0c660c8aaa8 100755 (executable)
@@ -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
 }
index fb4ee68fdad436c33e6fac9c573f855d93ae1e4c..7b34b9d45912ee360e88d8e57b82070df4fdf93a 100644 (file)
@@ -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