diff options
author | kris <kris@FreeBSD.org> | 1999-06-07 13:53:57 +0000 |
---|---|---|
committer | kris <kris@FreeBSD.org> | 1999-06-07 13:53:57 +0000 |
commit | bb3080b84d578420d338dce2d7c475e540858ed9 (patch) | |
tree | c61156dad9b51b07110115ac6797e01eae11dfd6 /bin/chio/chio.c | |
parent | f6c90a57fe5ea1a3a06e155145cdaa3ee547c9ae (diff) | |
download | FreeBSD-src-bb3080b84d578420d338dce2d7c475e540858ed9.zip FreeBSD-src-bb3080b84d578420d338dce2d7c475e540858ed9.tar.gz |
Changes from OpenBSD:
* Better usage() - correct syntax, display available commands
instead of examples
* Accept command abbreviations
* sprintf -> snprintf (for paranoia)
* manpage capitalisation tweak
Obtained from: OpenBSD
Diffstat (limited to 'bin/chio/chio.c')
-rw-r--r-- | bin/chio/chio.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/bin/chio/chio.c b/bin/chio/chio.c index fb82fe6..3601649 100644 --- a/bin/chio/chio.c +++ b/bin/chio/chio.c @@ -77,23 +77,23 @@ static int do_voltag(char *, int, char **); /* Valid changer element types. */ const struct element_type elements[] = { + { "drive", CHET_DT }, { "picker", CHET_MT }, - { "slot", CHET_ST }, { "portal", CHET_IE }, - { "drive", CHET_DT }, + { "slot", CHET_ST }, { NULL, 0 }, }; /* Valid commands. */ const struct changer_command commands[] = { - { "move", do_move }, { "exchange", do_exchange }, - { "position", do_position }, - { "params", do_params }, { "getpicker", do_getpicker }, + { "ielem", do_ielem }, + { "move", do_move }, + { "params", do_params }, + { "position", do_position }, { "setpicker", do_setpicker }, { "status", do_status }, - { "ielem", do_ielem }, { "voltag", do_voltag }, { NULL, 0 }, }; @@ -147,6 +147,14 @@ main(int argc, char *argv[]) for (i = 0; commands[i].cc_name != NULL; ++i) if (strcmp(*argv, commands[i].cc_name) == 0) break; + if (commands[i].cc_name == NULL) { + /* look for abbreviation */ + for (i = 0; commands[i].cc_name != NULL; ++i) + if (strncmp(*argv, commands[i].cc_name, + strlen(*argv)) == 0) + break; + } + if (commands[i].cc_name == NULL) errx(1, "unknown command: %s", *argv); @@ -881,7 +889,9 @@ bits_to_string(int v, const char *cp) np++; if ((v & (1 << (f - 1))) == 0) continue; - bp += sprintf(bp, "%c%.*s", sep, (int)(long)(np - cp), cp); + (void) snprintf(bp, sizeof(buf) - (bp - &buf[0]), + "%c%.*s", sep, (int)(long)(np - cp), cp); + bp += strlen(bp); sep = ','; } if (sep != '<') @@ -900,11 +910,12 @@ cleanup() static void usage() { + int i; - (void) fprintf(stderr, "usage: %s command arg1 arg2 ...\n", __progname); - (void) fprintf(stderr, "Examples:\n"); - (void) fprintf(stderr, "\tchio -f /dev/ch0 move slot 1 drive 0\n"); - (void) fprintf(stderr, "\tchio ielem\n"); - (void) fprintf(stderr, "\tchio -f /dev/ch1 status\n"); + (void) fprintf(stderr, "usage: %s [-f device] command [-<flags>] [args ...]\n", __progname); + (void) fprintf(stderr, "commands:"); + for (i = 0; commands[i].cc_name; i++) + (void) fprintf(stderr, " %s", commands[i].cc_name); + (void) fprintf(stderr, "\n"); exit(1); } |