awk: check presence of parameters

This commit is contained in:
David van Moolenbroek 2009-12-14 20:24:33 +00:00
parent 307ad7b3b0
commit 14367afaf7

View File

@ -70,6 +70,7 @@ main(argc, argv, envp) char **argv, *envp;
else { else {
argc--; s = *++argv; argc--; s = *++argv;
} }
if (s == NULL) usage();
pfp = efopen(s, "r"); pfp = efopen(s, "r");
s += strlen(s) - 1; s += strlen(s) - 1;
break; break;
@ -93,6 +94,8 @@ main(argc, argv, envp) char **argv, *envp;
} }
*/ */
if (pfp == NULL && srcprg == NULL) usage();
while (*xargv != NULL && strchr(*xargv, '=') != NULL) { while (*xargv != NULL && strchr(*xargv, '=') != NULL) {
setvar(*xargv++); setvar(*xargv++);
xargc--; xargc--;
@ -139,3 +142,12 @@ onint(i)
closeall(); closeall();
exit(0x80 | i); exit(0x80 | i);
} }
void
usage()
{
fprintf(stderr,
"usage: %s [options] [-f <rulefile> | <rules>] [inputfiles]\n", cmd);
closeall();
exit(1);
}