]> git.draconx.ca Git - dxcommon.git/commitdiff
Explicitly test for empty strings in awk scripts.
authorNick Bowler <nbowler@draconx.ca>
Sun, 3 Dec 2023 05:36:52 +0000 (00:36 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sun, 3 Dec 2023 06:07:52 +0000 (01:07 -0500)
ULTRIX 4.5 nawk does not treat arbitrary nonempty strings as "true"
in boolean contexts; they appear to be converted to integers and
compared against zero, which means most nonempty strings are false.
Easy enough to work around.

scripts/gen-options.awk
scripts/gen-strtab.awk
scripts/gen-tree.awk

index f2cdfe7825ab6f600334a7bb76fbe32408b6f1a4..98b7c17119988438797bddfc3ae5963357abf174 100755 (executable)
@@ -213,11 +213,10 @@ $0 ~ /^-/ {
 }
 
 # Ignore any line beginning with a #
-$0 ~ /^#/ { next }
+$0 ~ /^#/ { next; }
 
-lopt {
-  sub(/^[ \t]*/, "")
-  if (!$0) { next }
+NF && lopt != "" {
+  sub(/^[ \t]*/, "");
 
   if (lopt in optionhelp)
     $0 = "\n" $0;
index 6ec06be8b526c469c2f094babf6fb0bee2867b3c..beacad6b7c64a1b97ec68e27a6a730602e6cd2ee 100755 (executable)
@@ -111,9 +111,9 @@ sub(/^@/, "", $0) {
 }
 
 sub(/^[&]/, "") {
-  if (ident) {
-    finish_string_input(strings, ident, collected)
-    vars[num_vars++] = ident
+  if (ident != "") {
+    finish_string_input(strings, ident, collected);
+    vars[num_vars++] = ident;
   }
 
   current_l10n = !sub(/^[&]/, "", $1);
@@ -124,7 +124,7 @@ sub(/^[&]/, "") {
   collected = ""
 }
 
-ident {
+ident != "" {
   sub(/^[ \t]*/, "")
   if (collected) {
     collected = collected "\n" $0
@@ -136,7 +136,7 @@ ident {
 }
 
 END {
-  if (ident) {
+  if (ident != "") {
     finish_string_input(strings, ident, collected)
     vars[num_vars++] = ident
   }
index 413f156707c96b1f3578aca519ba40b105eb9335..1334bf8dfe9611ad83bdfce79fcb99020af25f32 100755 (executable)
@@ -165,12 +165,12 @@ indent > 0 {
   level_count[depth]++;
 }
 
-indent == 0 && tree_identifier {
+indent == 0 && tree_identifier != "" {
   trees[tree_identifier] = format_items();
   tree_identifier = "";
 }
 END {
-  if (tree_identifier)
+  if (tree_identifier != "")
     trees[tree_identifier] = format_items()
 }
 indent == 0 { tree_identifier = $1 }
@@ -225,7 +225,7 @@ function format_items(s, i)
     depth--;
   }
 
-  for (i = 2; tree_items[i]; i++) {
+  for (i = 2; tree_items[i] != ""; i++) {
     level_count[i] += level_count[i-1];
   }
 
@@ -234,7 +234,7 @@ function format_items(s, i)
     delete subtree_depth[i];
   }
 
-  for (i = 1; tree_items[i]; i++) {
+  for (i = 1; tree_items[i] != ""; i++) {
     s = s tree_items[i];
     delete tree_items[i];
     delete level_count[i];