Date: Thu, 22 Feb 2001 23:34:44 +1100 (EST) From: andrew@ugh.net.au To: FreeBSD-gnats-submit@freebsd.org Subject: bin/25278: bs accepts -s -c but not -sc Message-ID: <20010222123444.91DF5A86C@starbug.ugh.net.au>
next in thread | raw e-mail | index | archive | help
>Number: 25278
>Category: bin
>Synopsis: bs accepts -s -c but not -sc
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Thu Feb 22 04:40:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Andrew
>Release: FreeBSD 4.2-STABLE i386
>Organization:
UgH!
>Environment:
4.2-STABLE as of a week ago.
>Description:
The bs program accepts -s and -c as arguments but not -sc. bs was using its own
argument passing routines so I changed it over to getopt. While I was at it I
added a usage function, changed the program name in the usage message from
battle to bs (as that is what it is installed as nowdays), changed the exit
value from 1 to EX_USAGE when exiting because of invalid arguments, sorted the
included header files as per style(9) and added -Wall to the makefile.
I've tried to keep the same programming style as the existing code.
>How-To-Repeat:
bs -sc (it runs but the c is ignored)
>Fix:
--- /usr/src/games/bs/Makefile Sat Aug 28 09:28:57 1999
+++ Makefile Thu Feb 22 22:17:20 2001
@@ -2,6 +2,7 @@
PROG= bs
MAN6= bs.6
+CFLAGS+=-Wall
DPADD= ${LIBNCURSES} ${LIBMYTINFO}
LDADD= -lncurses -lmytinfo
HIDEGAME=hidegame
--- /usr/src/games/bs/bs.c Mon Feb 21 13:07:31 2000
+++ bs.c Thu Feb 22 22:25:08 2001
@@ -9,14 +9,15 @@
* $FreeBSD: src/games/bs/bs.c,v 1.9 2000/02/21 03:07:31 billf Exp $
*/
+#include <assert.h>
+#include <ctype.h>
#include <ncurses.h>
#include <signal.h>
-#include <ctype.h>
-#include <assert.h>
#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
#include <string.h>
+#include <sysexits.h>
+#include <time.h>
+#include <unistd.h>
#ifndef A_UNDERLINE /* BSD curses */
#define beep() write(1,"\007",1);
@@ -1110,58 +1111,50 @@
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])
- {
- case 'b':
+ (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':
+ if (salvo == 1) {
+ (void) fprintf(stderr,
+ "Bad Arg: -b and -s are mutually exclusive\n");
+ exit(EX_USAGE);
+ } else {
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;
- default:
+ }
+ break;
+ case 'c':
+ closepack = 1;
+ break;
+ case 's':
+ if (blitz == 1) {
(void) fprintf(stderr,
- "Bad arg: type \"%s ?\" for usage message\n", op[0]);
- exit(1);
+ "Bad Arg: -s and -b are mutually exclusive\n");
+ exit(EX_USAGE);
+ } else {
+ salvo = 1;
}
- }
- }
+ break;
+ case '?':
+ default:
+ usage();
+ }
}
}
>Release-Note:
>Audit-Trail:
>Unformatted:
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?20010222123444.91DF5A86C>
