aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorKris Kennaway <kris@FreeBSD.org>1999-06-07 13:53:57 +0000
committerKris Kennaway <kris@FreeBSD.org>1999-06-07 13:53:57 +0000
commit305a253acff09fd2c4102a449e799e0a806f4922 (patch)
tree47940a04f1f836064359bcd8119d906389a6282a /bin
parentb5d512fa689f83b8bf1a4e40784369b7b912f359 (diff)
downloadsrc-305a253acff09fd2c4102a449e799e0a806f4922.tar.gz
src-305a253acff09fd2c4102a449e799e0a806f4922.zip
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
Notes
Notes: svn path=/head/; revision=47816
Diffstat (limited to 'bin')
-rw-r--r--bin/chio/Makefile4
-rw-r--r--bin/chio/chio.14
-rw-r--r--bin/chio/chio.c35
3 files changed, 27 insertions, 16 deletions
diff --git a/bin/chio/Makefile b/bin/chio/Makefile
index 7f56f9ea0093..f5d2d78909b3 100644
--- a/bin/chio/Makefile
+++ b/bin/chio/Makefile
@@ -1,7 +1,7 @@
-# $Id: Makefile,v 1.2 1997/09/12 15:00:06 jkh Exp $
+# $Id: Makefile,v 1.3 1998/09/15 07:48:51 gibbs Exp $
# @(#)Makefile 8.1 (Berkeley) 6/6/93
-CFLAGS+=-I${.CURDIR}/../../sys
+CFLAGS+=-I${.CURDIR}/../../sys -W -Wall
PROG= chio
SRCS= chio.c
diff --git a/bin/chio/chio.1 b/bin/chio/chio.1
index 27fee8d0e3db..344b58747feb 100644
--- a/bin/chio/chio.1
+++ b/bin/chio/chio.1
@@ -30,7 +30,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $Id: chio.1,v 1.7 1998/09/15 07:48:51 gibbs Exp $
+.\" $Id: chio.1,v 1.8 1998/11/30 23:05:38 billf Exp $
.\"
.Dd May 14, 1998
.Dt CHIO 1
@@ -135,7 +135,7 @@ respectively.
.Pp
Note that not all medium changers support the
.Ic exchange
-operation; The changer must have multiple free pickers or emulate
+operation; the changer must have multiple free pickers or emulate
multiple free pickers with transient storage.
.It Xo Nm position
.Ar <to ET> <to EU>
diff --git a/bin/chio/chio.c b/bin/chio/chio.c
index fb82fe63013d..360164920817 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);
}