summaryrefslogtreecommitdiffstats
path: root/games/bs
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2009-11-14 02:20:43 +0000
committerguenther <guenther@openbsd.org>2009-11-14 02:20:43 +0000
commit95bd487303a3a54317ff0e05fad7a9bb349d8f7d (patch)
tree99c3ada6517de01eeadedcef9efe25e5105c01c0 /games/bs
parentRemove an unnecessary assignment. From NetBSD via Brad. (diff)
downloadwireguard-openbsd-95bd487303a3a54317ff0e05fad7a9bb349d8f7d.tar.xz
wireguard-openbsd-95bd487303a3a54317ff0e05fad7a9bb349d8f7d.zip
Use getopt() to parse the argument list, shrinking the code and
permitting options to be grouped ok deraadt@
Diffstat (limited to 'games/bs')
-rw-r--r--games/bs/bs.c72
1 files changed, 29 insertions, 43 deletions
diff --git a/games/bs/bs.c b/games/bs/bs.c
index abf2708c28d..dc7a83b50b0 100644
--- a/games/bs/bs.c
+++ b/games/bs/bs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bs.c,v 1.22 2009/10/27 23:59:24 deraadt Exp $ */
+/* $OpenBSD: bs.c,v 1.23 2009/11/14 02:20:43 guenther Exp $ */
/*
* Copyright (c) 1986, Bruce Holloway
* All rights reserved.
@@ -1290,53 +1290,39 @@ void usage()
static void do_options(int c, char *op[])
{
- int i;
+ int ch;
- if (c > 1)
- {
- for (i=1; i<c; i++)
- {
- switch(op[i][0])
+ while ((ch = getopt(c, op, "bchs")) != -1) {
+ switch (ch) {
+ case 'b':
+ blitz = 1;
+ if (salvo == 1)
{
- default:
- case '?':
- (void) usage();
- break;
- case '-':
- switch(op[i][1])
- {
- case 'b':
- blitz = 1;
- if (salvo == 1)
- {
- (void) fprintf(stderr,
- "Bad Arg: -b and -s are mutually exclusive\n");
- exit(1);
- }
- break;
- case 's':
- salvo = 1;
- if (blitz == 1)
- {
- (void) fprintf(stderr,
- "Bad Arg: -s and -b are mutually exclusive\n");
- exit(1);
- }
- break;
- case 'c':
- closepack = 1;
- break;
- case 'h':
- (void) usage();
- break;
- default:
- (void) fprintf(stderr,
- "Bad arg: type \"%s -h\" for usage message\n", op[0]);
- exit(1);
- }
+ (void) fprintf(stderr,
+ "Bad Arg: -b and -s are mutually exclusive\n");
+ exit(1);
}
+ break;
+ case 's':
+ salvo = 1;
+ if (blitz == 1)
+ {
+ (void) fprintf(stderr,
+ "Bad Arg: -s and -b are mutually exclusive\n");
+ exit(1);
+ }
+ break;
+ case 'c':
+ closepack = 1;
+ break;
+ case 'h':
+ default:
+ (void) usage();
+ exit(1);
}
}
+ if (op[optind] != NULL)
+ (void) usage();
}
static int scount(int who)