diff options
author | Philip Guenthe <guenther@cvs.openbsd.org> | 2009-11-14 02:20:44 +0000 |
---|---|---|
committer | Philip Guenthe <guenther@cvs.openbsd.org> | 2009-11-14 02:20:44 +0000 |
commit | 2419480689f49d231c432eeea973d6586b915345 (patch) | |
tree | b20ec8ce4da9c01b24f489c5229c76bddf985781 /games/bs | |
parent | b677e4e1dfa252811f23ceb27126c2140e8c59d4 (diff) |
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.c | 72 |
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) |