add more argument checking

This commit is contained in:
lukem 2002-02-07 11:35:56 +00:00
parent 4b8350b194
commit 2d60e83706
1 changed files with 12 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: makedev2spec.awk,v 1.1 2002/02/06 16:08:16 lukem Exp $ # $NetBSD: makedev2spec.awk,v 1.2 2002/02/07 11:35:56 lukem Exp $
# #
# Copyright (c) 2002 The NetBSD Foundation, Inc. # Copyright (c) 2002 The NetBSD Foundation, Inc.
# All rights reserved. # All rights reserved.
@ -61,6 +61,8 @@ $1 == "ln" \
$1 == "mkdir" \ $1 == "mkdir" \
{ {
if (NF != 2)
err("Usage: mkdir dir");
type[$2] = "type=dir"; type[$2] = "type=dir";
next; next;
} }
@ -79,6 +81,8 @@ $1 == "mknod" \
$1 == "rm" \ $1 == "rm" \
{ {
if (NF < 2)
err("Usage: rm [-f] file [...]");
for (i = 2; i <= NF; i++) { for (i = 2; i <= NF; i++) {
if ($i == "-f") if ($i == "-f")
continue; continue;
@ -98,6 +102,8 @@ $1 == "rm" \
# XXX: doesn't change symlinks - need to fix # XXX: doesn't change symlinks - need to fix
$1 == "chgrp" \ $1 == "chgrp" \
{ {
if (NF < 3)
err("Usage: chgrp group file [...]");
for (i = 3; i <= NF; i++) { for (i = 3; i <= NF; i++) {
n = split(glob($i), globs, " "); n = split(glob($i), globs, " ");
for (j = 1; j <= n; j++) { for (j = 1; j <= n; j++) {
@ -110,6 +116,8 @@ $1 == "chgrp" \
# XXX: doesn't change symlinks - need to fix # XXX: doesn't change symlinks - need to fix
$1 == "chmod" \ $1 == "chmod" \
{ {
if (NF < 3)
err("Usage: chmod mode file [...]");
for (i = 3; i <= NF; i++) { for (i = 3; i <= NF; i++) {
n = split(glob($i), globs, " "); n = split(glob($i), globs, " ");
for (j = 1; j <= n; j++) { for (j = 1; j <= n; j++) {
@ -122,6 +130,8 @@ $1 == "chmod" \
# XXX: doesn't change symlinks - need to fix # XXX: doesn't change symlinks - need to fix
$1 == "chown" \ $1 == "chown" \
{ {
if (NF < 3)
err("Usage: chown user[:group] file [...]");
user = $2; user = $2;
if ((n = match(user, /[\.:]/)) > 0) { if ((n = match(user, /[\.:]/)) > 0) {
group = substr(user, n + 1); group = substr(user, n + 1);
@ -141,7 +151,7 @@ $1 == "chown" \
} }
{ {
err("Unknown keyword " $1); err("Unknown keyword '" $1 "'");
} }