Date: Wed, 20 Jun 2001 10:24:00 +1000 (EST) From: <andrew@ugh.net.au> To: Dima Dorfman <dima@unixfreak.org> Cc: <freebsd-gnats-submit@freebsd.org>, <freebsd-bugs@FreeBSD.org> Subject: Re: bin/25278: bs accepts -s -c but not -sc Message-ID: <20010620102232.K84226-100000@starbug.ugh.net.au> In-Reply-To: <20010620001739.EC32D3E2F@bazooka.unixfreak.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 19 Jun 2001, Dima Dorfman wrote:
> > OK here's a patch to just add a usage function and convert bs to using
> > getopt.
>
> Did you forget to attach something? :-)
Ooops. Lets try again...
--- bs/bs.c Tue Jun 19 20:09:29 2001
+++ bs.usage/bs.c Tue Jun 19 20:38:38 2001
@@ -17,6 +17,7 @@
#include <unistd.h>
#include <time.h>
#include <string.h>
+#include <sysexits.h>
#ifndef A_UNDERLINE /* BSD curses */
#define beep() write(1,"\007",1);
@@ -1110,59 +1111,53 @@
return(sgetc("YN") == 'Y');
}
-static void do_options(c,op)
-int c;
-char *op[];
+static void usage()
{
- int i;
- if (c > 1)
- {
- for (i=1; i<c; i++)
- {
- switch(op[i][0])
- {
- default:
- case '?':
- (void) fprintf(stderr, "Usage: battle [-s | -b] [-c]\n");
- (void) fprintf(stderr, "\tWhere the options are:\n");
- (void) fprintf(stderr, "\t-s : play a salvo game\n");
- (void) fprintf(stderr, "\t-b : play a blitz game\n");
- (void) fprintf(stderr, "\t-c : ships may be adjacent\n");
- exit(1);
- break;
- case '-':
- switch(op[i][1])
- {
+ (void) fprintf(stderr, "Usage: bs [-s | -b] [-c]\n"
+ "\tWhere the options are:\n"
+ "\t-s : play a salvo game\n"
+ "\t-b : play a blitz game\n"
+ "\t-c : ships may be adjacent\n");
+ exit(EX_USAGE);
+}
+
+static void do_options(argc,argv)
+int argc;
+char *argv[];
+{
+ int c;
+
+ while ((c = getopt(argc, argv, "bcs")) != -1) {
+ switch (c) {
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;
+ if (salvo == 1)
+ {
+ (void) fprintf(stderr,
+ "Bad arg: -b and -s are mutually exclusive\n");
+ exit(EX_USAGE);
+ } else {
+ blitz = 1;
+ }
+ break;
case 'c':
- closepack = 1;
- break;
+ closepack = 1;
+ break;
+ case 's':
+ if (blitz == 1)
+ {
+ (void) fprintf(stderr,
+ "Bad arg: -s and -b are mutually exclusive\n");
+ exit(EX_USAGE);
+ } else {
+ salvo = 1;
+ }
+ break;
+ case '?':
default:
- (void) fprintf(stderr,
- "Bad arg: type \"%s ?\" for usage message\n", op[0]);
- exit(1);
+ usage();
}
- }
}
- }
}
static int scount(who)
Thanks,
Andrew
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010620102232.K84226-100000>
