aboutsummaryrefslogtreecommitdiff
path: root/bin/gwp.awk
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-07-02 17:36:37 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-07-02 22:57:07 +1200
commit95276f25769a0607cda50041169197d0522b98ff (patch)
tree3a4738901390c94f76de6ee7b6394d39b4c1ed00 /bin/gwp.awk
parentCoerce seed to number (diff)
downloaddotfiles-95276f25769a0607cda50041169197d0522b98ff.tar.gz
dotfiles-95276f25769a0607cda50041169197d0522b98ff.zip
Lots of cleanup of awk scripts
Mostly inspired by suggestions from gawk --lint
Diffstat (limited to 'bin/gwp.awk')
-rw-r--r--bin/gwp.awk11
1 files changed, 8 insertions, 3 deletions
diff --git a/bin/gwp.awk b/bin/gwp.awk
index f1e3b3bd..6b558388 100644
--- a/bin/gwp.awk
+++ b/bin/gwp.awk
@@ -7,6 +7,9 @@ BEGIN {
# Words are separated by any non-alphanumeric characters
FS = "[^a-zA-Z0-9]+"
+ # Nothing found yet
+ found = 0
+
# First argument is the word required; push its case downward so we can
# match case-insensitively
word = tolower(ARGV[1])
@@ -15,15 +18,17 @@ BEGIN {
ARGV[1] = ""
# Bail out if we don't have a suitable word
- if (!word)
+ if (!length(word))
fail("Need a single non-null alphanumeric string as a search word")
if (word ~ FS)
fail("Word contains non-alphanumeric characters; use grep(1)")
}
# Bailout function
-function fail(str) {
- printf "%s: %s\n", self, str | "cat >&2"
+function fail(msg) {
+ stderr = "cat >&2"
+ printf "%s: %s\n", self, msg | stderr
+ close(stderr)
exit(2)
}