aboutsummaryrefslogtreecommitdiff
path: root/sbin/fsdb/fsdbutil.c
diff options
context:
space:
mode:
authorBrian Feldman <green@FreeBSD.org>2002-01-25 18:31:57 +0000
committerBrian Feldman <green@FreeBSD.org>2002-01-25 18:31:57 +0000
commit8660ce229c04f3553fbeaa4ea10dfe9bf384ad93 (patch)
tree61ddf6b7f196d256a0f261988215c65286cb9238 /sbin/fsdb/fsdbutil.c
parentcdd27ea438327769dfe61931b45b8bc2c4ccad54 (diff)
downloadsrc-8660ce229c04f3553fbeaa4ea10dfe9bf384ad93.tar.gz
src-8660ce229c04f3553fbeaa4ea10dfe9bf384ad93.zip
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.
Notes
Notes: svn path=/head/; revision=89791
Diffstat (limited to 'sbin/fsdb/fsdbutil.c')
-rw-r--r--sbin/fsdb/fsdbutil.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/sbin/fsdb/fsdbutil.c b/sbin/fsdb/fsdbutil.c
index 3fbc8aa17f5d..ee85a3fe01bb 100644
--- a/sbin/fsdb/fsdbutil.c
+++ b/sbin/fsdb/fsdbutil.c
@@ -67,6 +67,30 @@ crack(line, argc)
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
argcount(cmdp, argc, argv)
struct cmdtable *cmdp;
@@ -74,7 +98,8 @@ argcount(cmdp, argc, argv)
char *argv[];
{
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
warnx("command `%s' takes from %u to %u arguments",
cmdp->cmd, cmdp->minargc-1, cmdp->maxargc-1);