Convert mount to use getopt.

This commit is contained in:
Matt Kraai 2001-04-17 04:48:51 +00:00
parent 1240082e37
commit a3045dfd25
2 changed files with 62 additions and 110 deletions

86
mount.c
View File

@ -343,65 +343,44 @@ extern int mount_main(int argc, char **argv)
int all = FALSE; int all = FALSE;
int fakeIt = FALSE; int fakeIt = FALSE;
int useMtab = TRUE; int useMtab = TRUE;
int i;
int rc = EXIT_FAILURE; int rc = EXIT_FAILURE;
int fstabmount = FALSE; int fstabmount = FALSE;
int opt;
/* Parse options */ /* Parse options */
i = --argc; while ((opt = getopt(argc, argv, "o:rt:wafnv")) > 0) {
argv++; switch (opt) {
while (i > 0 && **argv) { case 'o':
if (**argv == '-') { parse_mount_options(optarg, &flags, string_flags);
char *opt = *argv; break;
case 'r':
while (i > 0 && *++opt) flags |= MS_RDONLY;
switch (*opt) { break;
case 'o': case 't':
if (--i == 0) { filesystemType = optarg;
goto goodbye; break;
} case 'w':
parse_mount_options(*(++argv), &flags, string_flags); flags &= ~MS_RDONLY;
break; break;
case 'r': case 'a':
flags |= MS_RDONLY; all = TRUE;
break; break;
case 't': case 'f':
if (--i == 0) { fakeIt = TRUE;
goto goodbye; break;
}
filesystemType = *(++argv);
break;
case 'w':
flags &= ~MS_RDONLY;
break;
case 'a':
all = TRUE;
break;
case 'f':
fakeIt = TRUE;
break;
#ifdef BB_FEATURE_MTAB_SUPPORT #ifdef BB_FEATURE_MTAB_SUPPORT
case 'n': case 'n':
useMtab = FALSE; useMtab = FALSE;
break; break;
#endif #endif
case 'v': case 'v':
break; /* ignore -v */ break; /* ignore -v */
case 'h':
case '-':
goto goodbye;
}
} else {
if (device == NULL)
device = *argv;
else if (directory == NULL)
directory = *argv;
else {
goto goodbye;
}
} }
i--; }
argv++;
if (argv[optind] != NULL) {
device = argv[optind];
directory = argv[optind + 1];
} }
if (device == NULL && !all) if (device == NULL && !all)
@ -469,7 +448,4 @@ singlemount:
} }
goto singlemount; goto singlemount;
goodbye:
show_usage();
} }

View File

@ -343,65 +343,44 @@ extern int mount_main(int argc, char **argv)
int all = FALSE; int all = FALSE;
int fakeIt = FALSE; int fakeIt = FALSE;
int useMtab = TRUE; int useMtab = TRUE;
int i;
int rc = EXIT_FAILURE; int rc = EXIT_FAILURE;
int fstabmount = FALSE; int fstabmount = FALSE;
int opt;
/* Parse options */ /* Parse options */
i = --argc; while ((opt = getopt(argc, argv, "o:rt:wafnv")) > 0) {
argv++; switch (opt) {
while (i > 0 && **argv) { case 'o':
if (**argv == '-') { parse_mount_options(optarg, &flags, string_flags);
char *opt = *argv; break;
case 'r':
while (i > 0 && *++opt) flags |= MS_RDONLY;
switch (*opt) { break;
case 'o': case 't':
if (--i == 0) { filesystemType = optarg;
goto goodbye; break;
} case 'w':
parse_mount_options(*(++argv), &flags, string_flags); flags &= ~MS_RDONLY;
break; break;
case 'r': case 'a':
flags |= MS_RDONLY; all = TRUE;
break; break;
case 't': case 'f':
if (--i == 0) { fakeIt = TRUE;
goto goodbye; break;
}
filesystemType = *(++argv);
break;
case 'w':
flags &= ~MS_RDONLY;
break;
case 'a':
all = TRUE;
break;
case 'f':
fakeIt = TRUE;
break;
#ifdef BB_FEATURE_MTAB_SUPPORT #ifdef BB_FEATURE_MTAB_SUPPORT
case 'n': case 'n':
useMtab = FALSE; useMtab = FALSE;
break; break;
#endif #endif
case 'v': case 'v':
break; /* ignore -v */ break; /* ignore -v */
case 'h':
case '-':
goto goodbye;
}
} else {
if (device == NULL)
device = *argv;
else if (directory == NULL)
directory = *argv;
else {
goto goodbye;
}
} }
i--; }
argv++;
if (argv[optind] != NULL) {
device = argv[optind];
directory = argv[optind + 1];
} }
if (device == NULL && !all) if (device == NULL && !all)
@ -469,7 +448,4 @@ singlemount:
} }
goto singlemount; goto singlemount;
goodbye:
show_usage();
} }