X-Git-Url: http://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=test%2Fbs.c;h=c7569cf207fd6a9c79de9814b03642f493464c8a;hb=HEAD;hp=0e4076f6110d33dc6ab02939757dc53f760f9bb6;hpb=47d2fb4537d9ad5bb14f4810561a327930ca4280;p=ncurses.git diff --git a/test/bs.c b/test/bs.c index 0e4076f6..c7569cf2 100644 --- a/test/bs.c +++ b/test/bs.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2019,2020 Thomas E. Dickey * + * Copyright 2018-2022,2023 Thomas E. Dickey * * Copyright 1998-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -26,7 +26,7 @@ * sale, use or other dealings in this Software without prior written * * authorization. * ****************************************************************************/ -/* +/* * bs.c - original author: Bruce Holloway * salvo option by: Chuck A DeGaul * with improved user interface, autoconfiguration and code cleanup @@ -35,7 +35,7 @@ * v2.0 featuring strict ANSI/POSIX conformance, November 1993. * v2.1 with ncurses mouse support, September 1995 * - * $Id: bs.c,v 1.75 2020/02/02 23:34:34 tom Exp $ + * $Id: bs.c,v 1.79 2023/05/27 20:13:10 tom Exp $ */ #include @@ -181,7 +181,7 @@ static int salvo, blitz, closepack; #define PR (void)addstr -static void uninitgame(int sig) GCC_NORETURN; +static GCC_NORETURN void uninitgame(int sig); static void uninitgame(int sig GCC_UNUSED) @@ -898,8 +898,9 @@ sgetc(const char *s) ch = toupper(ch); if (is_QUIT(ch)) uninitgame(0); - for (s1 = s; *s1 && ch != *s1; ++s1) - continue; + for (s1 = s; *s1 && ch != *s1; ++s1) { + /* EMPTY */ ; + } if (*s1) { AddCh(ch); (void) refresh(); @@ -1162,55 +1163,6 @@ playagain(void) return (sgetc("YN") == 'Y'); } -static void -do_options(int c, char *op[]) -{ - if (c > 1) { - int i; - - for (i = 1; i < c; i++) { - switch (op[i][0]) { - default: - case '?': - (void) fprintf(stderr, "Usage: bs [-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"); - ExitProgram(EXIT_FAILURE); - 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"); - ExitProgram(EXIT_FAILURE); - } - break; - case 's': - salvo = 1; - if (blitz == 1) { - (void) fprintf(stderr, - "Bad Arg: -s and -b are mutually exclusive\n"); - ExitProgram(EXIT_FAILURE); - } - break; - case 'c': - closepack = 1; - break; - default: - (void) fprintf(stderr, - "Bad arg: type \"%s ?\" for usage message\n", - op[0]); - ExitProgram(EXIT_FAILURE); - } - } - } - } -} - static int scount(int who) { @@ -1231,12 +1183,68 @@ scount(int who) return (shots); } +static void +usage(int ok) +{ + static const char *msg[] = + { + "Usage: bs [options]" + ,"" + ,USAGE_COMMON + ,"Options:" + ," -b play a blitz game" + ," -c ships may be adjacent" + ," -s play a salvo game" + }; + size_t n; + + for (n = 0; n < SIZEOF(msg); n++) + fprintf(stderr, "%s\n", msg[n]); + + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); +} +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ + int main(int argc, char *argv[]) { - setlocale(LC_ALL, ""); + int ch; - do_options(argc, argv); + while ((ch = getopt(argc, argv, OPTS_COMMON "bcs")) != -1) { + switch (ch) { + case 'b': + blitz = 1; + if (salvo == 1) { + (void) fprintf(stderr, + "Bad Arg: -b and -s are mutually exclusive\n"); + ExitProgram(EXIT_FAILURE); + } + break; + case 's': + salvo = 1; + if (blitz == 1) { + (void) fprintf(stderr, + "Bad Arg: -s and -b are mutually exclusive\n"); + ExitProgram(EXIT_FAILURE); + } + break; + case 'c': + closepack = 1; + break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); + default: + usage(ch == OPTS_USAGE); + /* NOTREACHED */ + } + } + if (optind < argc) + usage(FALSE); + + setlocale(LC_ALL, ""); intro(); do { @@ -1263,8 +1271,9 @@ main(int argc, char *argv[]) } } } else - while ((turn ? cputurn() : plyturn()) && awinna() == -1) - continue; + while ((turn ? cputurn() : plyturn()) && awinna() == -1) { + /* EMPTY */ ; + } turn = OTHER; } } while