o Do recrack(arguments) for commands which actually take NAME as
arguments so we do not coredump at "help foo", "back bar" and such. o Be consistent and print argc - 1 as a command arguments number in all cases. PR: bin/37096 Submitted by: Joshua Goodall MFC after: 1 month
This commit is contained in:
parent
1def0ca64d
commit
1bc508492a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=157950
@ -151,8 +151,8 @@ struct cmdtable cmds[] = {
|
||||
{ "?", "Print out help", 1, 1, FL_RO, helpfn },
|
||||
{ "inode", "Set active inode to INUM", 2, 2, FL_RO, focus },
|
||||
{ "clri", "Clear inode INUM", 2, 2, FL_WR, zapi },
|
||||
{ "lookup", "Set active inode by looking up NAME", 2, 2, FL_RO, focusname },
|
||||
{ "cd", "Set active inode by looking up NAME", 2, 2, FL_RO, focusname },
|
||||
{ "lookup", "Set active inode by looking up NAME", 2, 2, FL_RO | FL_ST, focusname },
|
||||
{ "cd", "Set active inode by looking up NAME", 2, 2, FL_RO | FL_ST, focusname },
|
||||
{ "back", "Go to previous active inode", 1, 1, FL_RO, back },
|
||||
{ "active", "Print active inode", 1, 1, FL_RO, active },
|
||||
{ "print", "Print active inode", 1, 1, FL_RO, active },
|
||||
@ -161,11 +161,11 @@ struct cmdtable cmds[] = {
|
||||
{ "downlink", "Decrement link count", 1, 1, FL_WR, downlink },
|
||||
{ "linkcount", "Set link count to COUNT", 2, 2, FL_WR, linkcount },
|
||||
{ "ls", "List current inode as directory", 1, 1, FL_RO, ls },
|
||||
{ "rm", "Remove NAME from current inode directory", 2, 2, FL_WR, rm },
|
||||
{ "del", "Remove NAME from current inode directory", 2, 2, FL_WR, rm },
|
||||
{ "ln", "Hardlink INO into current inode directory as NAME", 3, 3, FL_WR, ln },
|
||||
{ "rm", "Remove NAME from current inode directory", 2, 2, FL_WR | FL_ST, rm },
|
||||
{ "del", "Remove NAME from current inode directory", 2, 2, FL_WR | FL_ST, rm },
|
||||
{ "ln", "Hardlink INO into current inode directory as NAME", 3, 3, FL_WR | FL_ST, ln },
|
||||
{ "chinum", "Change dir entry number INDEX to INUM", 3, 3, FL_WR, chinum },
|
||||
{ "chname", "Change dir entry number INDEX to NAME", 3, 3, FL_WR, chname },
|
||||
{ "chname", "Change dir entry number INDEX to NAME", 3, 3, FL_WR | FL_ST, chname },
|
||||
{ "chtype", "Change type of current inode to TYPE", 2, 2, FL_WR, newtype },
|
||||
{ "chmod", "Change mode of current inode to MODE", 2, 2, FL_WR, chmode },
|
||||
{ "chlen", "Change length of current inode to LENGTH", 2, 2, FL_WR, chlen },
|
||||
@ -188,11 +188,11 @@ helpfn(int argc, char *argv[])
|
||||
struct cmdtable *cmdtp;
|
||||
|
||||
printf("Commands are:\n%-10s %5s %5s %s\n",
|
||||
"command", "min argc", "max argc", "what");
|
||||
"command", "min args", "max args", "what");
|
||||
|
||||
for (cmdtp = cmds; cmdtp->cmd; cmdtp++)
|
||||
printf("%-10s %5u %5u %s\n",
|
||||
cmdtp->cmd, cmdtp->minargc, cmdtp->maxargc, cmdtp->helptxt);
|
||||
cmdtp->cmd, cmdtp->minargc-1, cmdtp->maxargc-1, cmdtp->helptxt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -255,7 +255,8 @@ cmdloop(void)
|
||||
else if (cmd_argc >= cmdp->minargc &&
|
||||
cmd_argc <= cmdp->maxargc)
|
||||
rval = (*cmdp->handler)(cmd_argc, cmd_argv);
|
||||
else if (cmd_argc >= cmdp->minargc) {
|
||||
else if (cmd_argc >= cmdp->minargc &&
|
||||
(cmdp->flags & FL_ST) == FL_ST) {
|
||||
strcpy(line, elline);
|
||||
cmd_argv = recrack(line, &cmd_argc, cmdp->maxargc);
|
||||
rval = (*cmdp->handler)(cmd_argc, cmd_argv);
|
||||
|
@ -48,6 +48,7 @@ struct cmdtable {
|
||||
unsigned int flags;
|
||||
#define FL_RO 0x0000 /* for symmetry */
|
||||
#define FL_WR 0x0001 /* wants to write */
|
||||
#define FL_ST 0x0002 /* resplit final string if argc > maxargc */
|
||||
int (*handler)(int argc, char *argv[]);
|
||||
};
|
||||
extern union dinode *curinode;
|
||||
|
@ -98,7 +98,7 @@ argcount(struct cmdtable *cmdp, int argc, char *argv[])
|
||||
{
|
||||
if (cmdp->minargc == cmdp->maxargc)
|
||||
warnx("command `%s' takes %u arguments, got %u", cmdp->cmd,
|
||||
cmdp->minargc-1, argc);
|
||||
cmdp->minargc-1, argc-1);
|
||||
else
|
||||
warnx("command `%s' takes from %u to %u arguments",
|
||||
cmdp->cmd, cmdp->minargc-1, cmdp->maxargc-1);
|
||||
|
Loading…
Reference in New Issue
Block a user