Allow short command names as long as they are not ambiguous.
This commit is contained in:
parent
ecb75428c0
commit
cff5b51c44
26
bin/mt/mt.c
26
bin/mt/mt.c
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: mt.c,v 1.38 2005/02/03 00:03:02 christos Exp $ */
|
/* $NetBSD: mt.c,v 1.39 2005/02/03 15:15:48 christos Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1980, 1993
|
* Copyright (c) 1980, 1993
|
||||||
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)mt.c 8.2 (Berkeley) 6/6/93";
|
static char sccsid[] = "@(#)mt.c 8.2 (Berkeley) 6/6/93";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: mt.c,v 1.38 2005/02/03 00:03:02 christos Exp $");
|
__RCSID("$NetBSD: mt.c,v 1.39 2005/02/03 15:15:48 christos Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@ -48,6 +48,7 @@ __RCSID("$NetBSD: mt.c,v 1.38 2005/02/03 00:03:02 christos Exp $");
|
|||||||
* magnetic tape manipulation program
|
* magnetic tape manipulation program
|
||||||
*/
|
*/
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/mtio.h>
|
#include <sys/mtio.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -111,13 +112,14 @@ int main(int, char *[]);
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const struct commands *comp = (const struct commands *) NULL;
|
const struct commands *cp, *comp;
|
||||||
struct mtget mt_status;
|
struct mtget mt_status;
|
||||||
struct mtop mt_com;
|
struct mtop mt_com;
|
||||||
int ch, mtfd, flags;
|
int ch, mtfd, flags;
|
||||||
char *p;
|
char *p;
|
||||||
const char *tape;
|
const char *tape;
|
||||||
int count;
|
int count;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
setprogname(argv[0]);
|
setprogname(argv[0]);
|
||||||
if ((tape = getenv("TAPE")) == NULL)
|
if ((tape = getenv("TAPE")) == NULL)
|
||||||
@ -139,13 +141,19 @@ main(int argc, char *argv[])
|
|||||||
if (argc < 1 || argc > 2)
|
if (argc < 1 || argc > 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
p = *argv++;
|
len = strlen(p = *argv++);
|
||||||
for (comp = com;; comp++) {
|
for (comp = NULL, cp = com; cp->c_name != NULL; cp++) {
|
||||||
if (comp->c_name == NULL)
|
size_t clen = MIN(len, cp->c_namelen);
|
||||||
errx(1, "%s: unknown command", p);
|
if (strncmp(p, cp->c_name, clen) == 0) {
|
||||||
if (strncmp(p, comp->c_name, comp->c_namelen) == 0)
|
if (comp != NULL)
|
||||||
break;
|
errx(1, "%s: Ambiguous command `%s' or `%s'?",
|
||||||
|
p, cp->c_name, comp->c_name);
|
||||||
|
else
|
||||||
|
comp = cp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (comp == NULL)
|
||||||
|
errx(1, "%s: unknown command", p);
|
||||||
|
|
||||||
if (*argv) {
|
if (*argv) {
|
||||||
count = strtol(*argv, &p, 10);
|
count = strtol(*argv, &p, 10);
|
||||||
|
Loading…
Reference in New Issue
Block a user