commit 4e48a95792ffb45a10031ee50dea68cc5a71c148
parent 2f9c80e32d2a499dcadd8d58c9e3d615fd3af0a6
Author: Jacob R. Edwards <n/a>
Date: Wed, 30 Nov 2022 21:12:51 -0600
Try and prevent future bugs in netname script
The gen function now makes sure that 'found' and 'notfound' are set
and the '?' function was renamed to setifnot, because it seems wrong
to have a byte of punctuation as a function name (and I wouldn't
be surprised if rc(1) isn't suppost to support it).
Diffstat:
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/local/bin/bin/netname b/local/bin/bin/netname
@@ -18,16 +18,19 @@ if (! ~ $#* 0) {
tlds = $*
}
-# Perhaps not a name portable to other rcs
-fn '?' {
- ?name = $1
+fn setifnot {
+ _name = $1
shift
- if (~ $#$?name 0)
- $?name = $*
+ if (~ $#$_name 0)
+ $_name = $*
}
# General function; called once $found and $notfound are set
fn gen {
+ if (~ $#found 0 || ~ $#notfound 0) {
+ echo 'BUG: found or notfound not set' >[1=2]
+ exit 1
+ }
awk '{
printf "%s.%s: ", ENVIRON["name"], ENVIRON["tld"]
}
@@ -46,8 +49,8 @@ fn gen {
}
fn def {
- ? notfound '.*NOT FOUND\)?$'
- ? found ' *(Server|Domain) Name:'
+ setifnot notfound '.*NOT FOUND\)?$'
+ setifnot found ' *(Server|Domain) Name:'
gen
}
@@ -60,8 +63,8 @@ fn org {
}
fn net {
- ? notfound '^No match for '
- def
+ setifnot notfound '^No match for '
+ def
}
fn com {
@@ -69,7 +72,7 @@ fn com {
}
fn us {
- ? notfound '^No Data Found$'
+ setifnot notfound '^No Data Found$'
def
}