]> Zhao Yanbai Git Server - minix.git/commitdiff
awk: check presence of parameters
authorDavid van Moolenbroek <david@minix3.org>
Mon, 14 Dec 2009 20:24:33 +0000 (20:24 +0000)
committerDavid van Moolenbroek <david@minix3.org>
Mon, 14 Dec 2009 20:24:33 +0000 (20:24 +0000)
commands/awk/m.c

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