From e0eee379d3bce3e3629175d4a214439da630c1ed Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 3 Dec 2023 00:36:52 -0500 Subject: [PATCH] Explicitly test for empty strings in awk scripts. 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 | 7 +++---- scripts/gen-strtab.awk | 10 +++++----- scripts/gen-tree.awk | 8 ++++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/scripts/gen-options.awk b/scripts/gen-options.awk index f2cdfe7..98b7c17 100755 --- a/scripts/gen-options.awk +++ b/scripts/gen-options.awk @@ -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; diff --git a/scripts/gen-strtab.awk b/scripts/gen-strtab.awk index 6ec06be..beacad6 100755 --- a/scripts/gen-strtab.awk +++ b/scripts/gen-strtab.awk @@ -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 } diff --git a/scripts/gen-tree.awk b/scripts/gen-tree.awk index 413f156..1334bf8 100755 --- a/scripts/gen-tree.awk +++ b/scripts/gen-tree.awk @@ -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]; -- 2.43.2