diff options
Diffstat (limited to 'bin/gwp.awk')
-rw-r--r-- | bin/gwp.awk | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/bin/gwp.awk b/bin/gwp.awk index 976b5b84..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,16 +18,18 @@ 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" - exit(1) +function fail(msg) { + stderr = "cat >&2" + printf "%s: %s\n", self, msg | stderr + close(stderr) + exit(2) } # If there's more than one filename, precede the print of the current line with |