Allow fsdb the ability to work with entries named with whitespace embedded.
This works by retokenizing a line with a split limit so that if the argument count for a command is greater than the number of arguments formed by splitting apart the line of user input, the last argument is instead all of the remainder of the input line. Yes, I needed this capability at one point to fix a filesystem manually, which happened to break with a problematic space-containing directory entry.
This commit is contained in:
parent
cdd27ea438
commit
8660ce229c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=89791
@ -259,7 +259,11 @@ cmdloop()
|
|||||||
else if (cmd_argc >= cmdp->minargc &&
|
else if (cmd_argc >= cmdp->minargc &&
|
||||||
cmd_argc <= cmdp->maxargc)
|
cmd_argc <= cmdp->maxargc)
|
||||||
rval = (*cmdp->handler)(cmd_argc, cmd_argv);
|
rval = (*cmdp->handler)(cmd_argc, cmd_argv);
|
||||||
else
|
else if (cmd_argc >= cmdp->minargc) {
|
||||||
|
strcpy(line, elline);
|
||||||
|
cmd_argv = recrack(line, &cmd_argc, cmdp->maxargc);
|
||||||
|
rval = (*cmdp->handler)(cmd_argc, cmd_argv);
|
||||||
|
} else
|
||||||
rval = argcount(cmdp, cmd_argc, cmd_argv);
|
rval = argcount(cmdp, cmd_argc, cmd_argv);
|
||||||
known = 1;
|
known = 1;
|
||||||
break;
|
break;
|
||||||
@ -494,7 +498,7 @@ CMDFUNCSTART(rm)
|
|||||||
printf("Name `%s' removed\n", argv[1]);
|
printf("Name `%s' removed\n", argv[1]);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
printf("could not remove name? weird.\n");
|
printf("could not remove name ('%s')? weird.\n", argv[1]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,7 @@ extern ino_t curinum;
|
|||||||
|
|
||||||
int argcount __P((struct cmdtable *cmdp, int argc, char *argv[]));
|
int argcount __P((struct cmdtable *cmdp, int argc, char *argv[]));
|
||||||
char **crack __P((char *line, int *argc));
|
char **crack __P((char *line, int *argc));
|
||||||
|
char **recrack __P((char *line, int *argc, int argc_max));
|
||||||
void printstat __P((const char *cp, ino_t inum, struct dinode *dp));
|
void printstat __P((const char *cp, ino_t inum, struct dinode *dp));
|
||||||
int printactive __P((void));
|
int printactive __P((void));
|
||||||
int checkactive __P((void));
|
int checkactive __P((void));
|
||||||
|
@ -67,6 +67,30 @@ crack(line, argc)
|
|||||||
return argv;
|
return argv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char **
|
||||||
|
recrack(line, argc, argc_max)
|
||||||
|
char *line;
|
||||||
|
int *argc;
|
||||||
|
int argc_max;
|
||||||
|
{
|
||||||
|
static char *argv[8];
|
||||||
|
int i;
|
||||||
|
char *p, *val;
|
||||||
|
for (p = line, i = 0; p != NULL && i < 8 && i < argc_max - 1; i++) {
|
||||||
|
while ((val = strsep(&p, " \t\n")) != NULL && *val == '\0')
|
||||||
|
/**/;
|
||||||
|
if (val)
|
||||||
|
argv[i] = val;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
argv[i] = argv[i - 1] + strlen(argv[i - 1]) + 1;
|
||||||
|
argv[i][strcspn(argv[i], "\n")] = '\0';
|
||||||
|
*argc = i + 1;
|
||||||
|
printf("returning with argc %u\n", *argc);
|
||||||
|
return argv;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
argcount(cmdp, argc, argv)
|
argcount(cmdp, argc, argv)
|
||||||
struct cmdtable *cmdp;
|
struct cmdtable *cmdp;
|
||||||
@ -74,7 +98,8 @@ argcount(cmdp, argc, argv)
|
|||||||
char *argv[];
|
char *argv[];
|
||||||
{
|
{
|
||||||
if (cmdp->minargc == cmdp->maxargc)
|
if (cmdp->minargc == cmdp->maxargc)
|
||||||
warnx("command `%s' takes %u arguments", cmdp->cmd, cmdp->minargc-1);
|
warnx("command `%s' takes %u arguments, got %u", cmdp->cmd,
|
||||||
|
cmdp->minargc-1, argc);
|
||||||
else
|
else
|
||||||
warnx("command `%s' takes from %u to %u arguments",
|
warnx("command `%s' takes from %u to %u arguments",
|
||||||
cmdp->cmd, cmdp->minargc-1, cmdp->maxargc-1);
|
cmdp->cmd, cmdp->minargc-1, cmdp->maxargc-1);
|
||||||
|
Loading…
Reference in New Issue
Block a user