diff options
author | lukem <lukem@NetBSD.org> | 1997-10-11 01:16:26 +0000 |
---|---|---|
committer | lukem <lukem@NetBSD.org> | 1997-10-11 01:16:26 +0000 |
commit | a020fc98d8da9cac6990006871414e8654ac5c1d (patch) | |
tree | 541f25c2addb96a6859c8a6cb86709830680fa34 /hangman | |
parent | b4a56b0ad7d1689e935db1f0f29f6cdfb65961fd (diff) | |
download | bsdgames-darwin-a020fc98d8da9cac6990006871414e8654ac5c1d.tar.gz bsdgames-darwin-a020fc98d8da9cac6990006871414e8654ac5c1d.tar.zst bsdgames-darwin-a020fc98d8da9cac6990006871414e8654ac5c1d.zip |
WARNSify, KNFify
Diffstat (limited to 'hangman')
-rw-r--r-- | hangman/endgame.c | 27 | ||||
-rw-r--r-- | hangman/extern.c | 60 | ||||
-rw-r--r-- | hangman/getguess.c | 49 | ||||
-rw-r--r-- | hangman/getword.c | 15 | ||||
-rw-r--r-- | hangman/hangman.6 | 6 | ||||
-rw-r--r-- | hangman/hangman.h | 78 | ||||
-rw-r--r-- | hangman/main.c | 23 | ||||
-rw-r--r-- | hangman/playgame.c | 12 | ||||
-rw-r--r-- | hangman/prdata.c | 16 | ||||
-rw-r--r-- | hangman/prman.c | 10 | ||||
-rw-r--r-- | hangman/prword.c | 8 | ||||
-rw-r--r-- | hangman/setup.c | 14 |
12 files changed, 167 insertions, 151 deletions
diff --git a/hangman/endgame.c b/hangman/endgame.c index 300c0efb..56066b0c 100644 --- a/hangman/endgame.c +++ b/hangman/endgame.c @@ -1,4 +1,4 @@ -/* $NetBSD: endgame.c,v 1.3 1995/03/23 08:32:40 cgd Exp $ */ +/* $NetBSD: endgame.c,v 1.4 1997/10/11 01:16:26 lukem Exp $ */ /* * Copyright (c) 1983, 1993 @@ -33,23 +33,25 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)endgame.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: endgame.c,v 1.3 1995/03/23 08:32:40 cgd Exp $"; +__RCSID("$NetBSD: endgame.c,v 1.4 1997/10/11 01:16:26 lukem Exp $"); #endif #endif /* not lint */ -# include "hangman.h" +#include "hangman.h" /* * endgame: * Do what's necessary at the end of the game */ +void endgame() { - register char ch; + char ch; prman(); if (Errors >= MAXERRS) @@ -67,9 +69,10 @@ endgame() leaveok(stdscr, FALSE); refresh(); if ((ch = readch()) == 'n') - die(); - else if (ch == 'y') - break; + die(0); + else + if (ch == 'y') + break; mvaddstr(MESGY + 2, MESGX, "Please type 'y' or 'n'"); } @@ -79,13 +82,3 @@ endgame() deleteln(); deleteln(); } - - - - - - - - - - diff --git a/hangman/extern.c b/hangman/extern.c index 2d5f0082..59a310fa 100644 --- a/hangman/extern.c +++ b/hangman/extern.c @@ -1,4 +1,4 @@ -/* $NetBSD: extern.c,v 1.3 1995/03/23 08:32:41 cgd Exp $ */ +/* $NetBSD: extern.c,v 1.4 1997/10/11 01:16:27 lukem Exp $ */ /* * Copyright (c) 1983, 1993 @@ -33,48 +33,46 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)extern.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: extern.c,v 1.3 1995/03/23 08:32:41 cgd Exp $"; +__RCSID("$NetBSD: extern.c,v 1.4 1997/10/11 01:16:27 lukem Exp $"); #endif #endif /* not lint */ -# include "hangman.h" +#include "hangman.h" -bool Guessed[26]; +bool Guessed[26]; -char Word[BUFSIZ], - Known[BUFSIZ], - *Noose_pict[] = { - " ______", - " | |", - " |", - " |", - " |", - " |", - " __|_____", - " | |___", - " |_________|", - NULL - }; +char Word[BUFSIZ], Known[BUFSIZ], *Noose_pict[] = { + " ______", + " | |", + " |", + " |", + " |", + " |", + " __|_____", + " | |___", + " |_________|", + NULL +}; -int Errors, - Wordnum = 0; +int Errors, Wordnum = 0; -double Average = 0.0; +double Average = 0.0; -ERR_POS Err_pos[MAXERRS] = { - { 2, 10, 'O' }, - { 3, 10, '|' }, - { 4, 10, '|' }, - { 5, 9, '/' }, - { 3, 9, '/' }, - { 3, 11, '\\' }, - { 5, 11, '\\' } +ERR_POS Err_pos[MAXERRS] = { + {2, 10, 'O'}, + {3, 10, '|'}, + {4, 10, '|'}, + {5, 9, '/'}, + {3, 9, '/'}, + {3, 11, '\\'}, + {5, 11, '\\'} }; -FILE *Dict = NULL; +FILE *Dict = NULL; -off_t Dict_size; +off_t Dict_size; diff --git a/hangman/getguess.c b/hangman/getguess.c index ce08f882..4f248bda 100644 --- a/hangman/getguess.c +++ b/hangman/getguess.c @@ -1,4 +1,4 @@ -/* $NetBSD: getguess.c,v 1.6 1997/05/23 23:27:40 jtc Exp $ */ +/* $NetBSD: getguess.c,v 1.7 1997/10/11 01:16:29 lukem Exp $ */ /* * Copyright (c) 1983, 1993 @@ -33,11 +33,12 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)getguess.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: getguess.c,v 1.6 1997/05/23 23:27:40 jtc Exp $"; +__RCSID("$NetBSD: getguess.c,v 1.7 1997/10/11 01:16:29 lukem Exp $"); #endif #endif /* not lint */ @@ -48,11 +49,12 @@ static char rcsid[] = "$NetBSD: getguess.c,v 1.6 1997/05/23 23:27:40 jtc Exp $"; * getguess: * Get another guess */ +void getguess() { - register int i; - register int ch; - register bool correct; + int i; + int ch; + bool correct; leaveok(stdscr, FALSE); for (;;) { @@ -63,15 +65,16 @@ getguess() if (isupper(ch)) ch = tolower(ch); if (Guessed[ch - 'a']) - mvprintw(MESGY, MESGX, "Already guessed '%c'", ch); + mvprintw(MESGY, MESGX, "Already guessed '%c'", + ch); else break; - } - else if (ch == CTRL('D')) - die(); - else - mvprintw(MESGY, MESGX, "Not a valid guess: '%s'", - unctrl(ch)); + } else + if (ch == CTRL('D')) + die(0); + else + mvprintw(MESGY, MESGX, + "Not a valid guess: '%s'", unctrl(ch)); } leaveok(stdscr, TRUE); move(MESGY, MESGX); @@ -87,27 +90,25 @@ getguess() if (!correct) Errors++; } - /* * readch; * Read a character from the input */ +int readch() { - register int cnt, r; - auto char ch; + int cnt; + char ch; cnt = 0; for (;;) { - if (read(0, &ch, sizeof ch) <= 0) - { + if (read(0, &ch, sizeof ch) <= 0) { if (++cnt > 100) - die(); - } - else if (ch == CTRL('L')) { - wrefresh(curscr); - } - else - return ch; + die(0); + } else + if (ch == CTRL('L')) { + wrefresh(curscr); + } else + return ch; } } diff --git a/hangman/getword.c b/hangman/getword.c index e858fabe..3539c140 100644 --- a/hangman/getword.c +++ b/hangman/getword.c @@ -1,4 +1,4 @@ -/* $NetBSD: getword.c,v 1.4 1995/03/23 08:32:45 cgd Exp $ */ +/* $NetBSD: getword.c,v 1.5 1997/10/11 01:16:30 lukem Exp $ */ /* * Copyright (c) 1983, 1993 @@ -33,30 +33,31 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)getword.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: getword.c,v 1.4 1995/03/23 08:32:45 cgd Exp $"; +__RCSID("$NetBSD: getword.c,v 1.5 1997/10/11 01:16:30 lukem Exp $"); #endif #endif /* not lint */ #include "hangman.h" -#include <stdlib.h> /* * getword: * Get a valid word out of the dictionary file */ +void getword() { - register FILE *inf; - register char *wp, *gp; - register long pos; + FILE *inf; + char *wp, *gp; + long pos; inf = Dict; for (;;) { - pos = (double)rand() / (RAND_MAX + 1.0) * (double)Dict_size; + pos = (double) rand() / (RAND_MAX + 1.0) * (double) Dict_size; fseek(inf, pos, 0); if (fgets(Word, BUFSIZ, inf) == NULL) continue; diff --git a/hangman/hangman.6 b/hangman/hangman.6 index 42040574..5698c112 100644 --- a/hangman/hangman.6 +++ b/hangman/hangman.6 @@ -1,4 +1,4 @@ -.\" $NetBSD: hangman.6,v 1.5 1995/03/23 08:32:46 cgd Exp $ +.\" $NetBSD: hangman.6,v 1.6 1997/10/11 01:16:32 lukem Exp $ .\" .\" Copyright (c) 1983, 1993 .\" The Regents of the University of California. All rights reserved. @@ -40,10 +40,10 @@ .Nm hangman .Nd Computer version of the game hangman .Sh SYNOPSIS -.Nm /usr/games/hangman +.Nm .Sh DESCRIPTION In -.Nm hangman, +.Nm "" , the computer picks a word from the on-line word list and you must try to guess it. The computer keeps track of which letters have been guessed diff --git a/hangman/hangman.h b/hangman/hangman.h index 7452b3ec..4709c001 100644 --- a/hangman/hangman.h +++ b/hangman/hangman.h @@ -1,4 +1,4 @@ -/* $NetBSD: hangman.h,v 1.5 1995/04/24 12:23:44 cgd Exp $ */ +/* $NetBSD: hangman.h,v 1.6 1997/10/11 01:16:34 lukem Exp $ */ /* * Copyright (c) 1983, 1993 @@ -35,48 +35,60 @@ * @(#)hangman.h 8.1 (Berkeley) 5/31/93 */ -# include <curses.h> -# include <sys/types.h> -# include <sys/stat.h> -# include <ctype.h> -# include <signal.h> -# include <string.h> -# include "pathnames.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <ctype.h> +#include <curses.h> +#include <signal.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include "pathnames.h" -# define MINLEN 6 -# define MAXERRS 7 +#define MINLEN 6 +#define MAXERRS 7 -# define MESGY 12 -# define MESGX 0 -# define PROMPTY 11 -# define PROMPTX 0 -# define KNOWNY 10 -# define KNOWNX 1 -# define NUMBERY 4 -# define NUMBERX (COLS - 1 - 26) -# define AVGY 5 -# define AVGX (COLS - 1 - 26) -# define GUESSY 2 -# define GUESSX (COLS - 1 - 26) +#define MESGY 12 +#define MESGX 0 +#define PROMPTY 11 +#define PROMPTX 0 +#define KNOWNY 10 +#define KNOWNX 1 +#define NUMBERY 4 +#define NUMBERX (COLS - 1 - 26) +#define AVGY 5 +#define AVGX (COLS - 1 - 26) +#define GUESSY 2 +#define GUESSX (COLS - 1 - 26) typedef struct { - short y, x; - char ch; -} ERR_POS; + short y, x; + char ch; +} ERR_POS; -extern bool Guessed[]; +extern bool Guessed[]; -extern char Word[], Known[], *Noose_pict[]; +extern char Word[], Known[], *Noose_pict[]; -extern int Errors, Wordnum; +extern int Errors, Wordnum; -extern double Average; +extern double Average; -extern ERR_POS Err_pos[]; +extern ERR_POS Err_pos[]; -extern FILE *Dict; +extern FILE *Dict; -extern off_t Dict_size; +extern off_t Dict_size; -void die(); +void die __P((int)); +void endgame __P((void)); +int main __P((int, char **)); +void getguess __P((void)); +void getword __P((void)); +void playgame __P((void)); +void prdata __P((void)); +void prman __P((void)); +void prword __P((void)); +int readch __P((void)); +void setup __P((void)); diff --git a/hangman/main.c b/hangman/main.c index 3da3bac1..4919cdb2 100644 --- a/hangman/main.c +++ b/hangman/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.3 1995/03/23 08:32:50 cgd Exp $ */ +/* $NetBSD: main.c,v 1.4 1997/10/11 01:16:35 lukem Exp $ */ /* * Copyright (c) 1983, 1993 @@ -33,29 +33,30 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1983, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; +__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: main.c,v 1.3 1995/03/23 08:32:50 cgd Exp $"; +__RCSID("$NetBSD: main.c,v 1.4 1997/10/11 01:16:35 lukem Exp $"); #endif #endif /* not lint */ -# include "hangman.h" +#include "hangman.h" /* * This game written by Ken Arnold. */ -main() +int +main(argc, argv) + int argc; + char *argv[]; { - void die(); - initscr(); signal(SIGINT, die); setup(); @@ -66,13 +67,13 @@ main() } /* NOTREACHED */ } - /* * die: * Die properly. */ void -die() +die(dummy) + int dummy; { mvcur(0, COLS - 1, LINES - 1, 0); endwin(); diff --git a/hangman/playgame.c b/hangman/playgame.c index 5a591520..f8f15232 100644 --- a/hangman/playgame.c +++ b/hangman/playgame.c @@ -1,4 +1,4 @@ -/* $NetBSD: playgame.c,v 1.3 1995/03/23 08:32:53 cgd Exp $ */ +/* $NetBSD: playgame.c,v 1.4 1997/10/11 01:16:36 lukem Exp $ */ /*- * Copyright (c) 1983, 1993 @@ -33,30 +33,32 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)playgame.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: playgame.c,v 1.3 1995/03/23 08:32:53 cgd Exp $"; +__RCSID("$NetBSD: playgame.c,v 1.4 1997/10/11 01:16:36 lukem Exp $"); #endif #endif /* not lint */ -# include "hangman.h" +#include "hangman.h" /* * playgame: * play a game */ +void playgame() { - register bool *bp; + bool *bp; getword(); Errors = 0; bp = Guessed; while (bp < &Guessed[26]) *bp++ = FALSE; - while (Errors < MAXERRS && index(Known, '-') != NULL) { + while (Errors < MAXERRS && strchr(Known, '-') != NULL) { prword(); prdata(); prman(); diff --git a/hangman/prdata.c b/hangman/prdata.c index adfff8f3..5ee00228 100644 --- a/hangman/prdata.c +++ b/hangman/prdata.c @@ -1,4 +1,4 @@ -/* $NetBSD: prdata.c,v 1.3 1995/03/23 08:32:54 cgd Exp $ */ +/* $NetBSD: prdata.c,v 1.4 1997/10/11 01:16:37 lukem Exp $ */ /*- * Copyright (c) 1983, 1993 @@ -33,23 +33,25 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)prdata.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: prdata.c,v 1.3 1995/03/23 08:32:54 cgd Exp $"; +__RCSID("$NetBSD: prdata.c,v 1.4 1997/10/11 01:16:37 lukem Exp $"); #endif #endif /* not lint */ -# include "hangman.h" +#include "hangman.h" /* * prdata: * Print out the current guesses */ +void prdata() { - register bool *bp; + bool *bp; move(GUESSY, GUESSX + sizeof "Guessed: "); bp = Guessed; @@ -58,7 +60,7 @@ prdata() addch((bp - Guessed) + 'a' - 1); clrtoeol(); mvprintw(NUMBERY, NUMBERX + sizeof "Word #: ", "%d", Wordnum); - mvprintw(AVGY, AVGX + sizeof "Current Average: ", "%.3f", - (Average * (Wordnum - 1) + Errors) / Wordnum); - mvprintw(AVGY + 1, AVGX + sizeof "Overall Average: ", "%.3f", Average); + mvprintw(AVGY, AVGX + sizeof "Current Average: ", "%.3f", + (Average * (Wordnum - 1) + Errors) / Wordnum); + mvprintw(AVGY + 1, AVGX + sizeof "Overall Average: ", "%.3f", Average); } diff --git a/hangman/prman.c b/hangman/prman.c index 2337b639..fc16408f 100644 --- a/hangman/prman.c +++ b/hangman/prman.c @@ -1,4 +1,4 @@ -/* $NetBSD: prman.c,v 1.3 1995/03/23 08:32:56 cgd Exp $ */ +/* $NetBSD: prman.c,v 1.4 1997/10/11 01:16:39 lukem Exp $ */ /*- * Copyright (c) 1983, 1993 @@ -33,24 +33,26 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)prman.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: prman.c,v 1.3 1995/03/23 08:32:56 cgd Exp $"; +__RCSID("$NetBSD: prman.c,v 1.4 1997/10/11 01:16:39 lukem Exp $"); #endif #endif /* not lint */ -# include "hangman.h" +#include "hangman.h" /* * prman: * Print out the man appropriately for the give number * of incorrect guesses. */ +void prman() { - register int i; + int i; for (i = 0; i < Errors; i++) mvaddch(Err_pos[i].y, Err_pos[i].x, Err_pos[i].ch); diff --git a/hangman/prword.c b/hangman/prword.c index ba2ab634..b1da612f 100644 --- a/hangman/prword.c +++ b/hangman/prword.c @@ -1,4 +1,4 @@ -/* $NetBSD: prword.c,v 1.3 1995/03/23 08:32:58 cgd Exp $ */ +/* $NetBSD: prword.c,v 1.4 1997/10/11 01:16:40 lukem Exp $ */ /*- * Copyright (c) 1983, 1993 @@ -33,20 +33,22 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)prword.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: prword.c,v 1.3 1995/03/23 08:32:58 cgd Exp $"; +__RCSID("$NetBSD: prword.c,v 1.4 1997/10/11 01:16:40 lukem Exp $"); #endif #endif /* not lint */ -# include "hangman.h" +#include "hangman.h" /* * prword: * Print out the current state of the word */ +void prword() { move(KNOWNY, KNOWNX + sizeof "Word: "); diff --git a/hangman/setup.c b/hangman/setup.c index 73c835f9..0ddb2602 100644 --- a/hangman/setup.c +++ b/hangman/setup.c @@ -1,4 +1,4 @@ -/* $NetBSD: setup.c,v 1.3 1995/03/23 08:32:59 cgd Exp $ */ +/* $NetBSD: setup.c,v 1.4 1997/10/11 01:16:42 lukem Exp $ */ /*- * Copyright (c) 1983, 1993 @@ -33,24 +33,26 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)setup.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: setup.c,v 1.3 1995/03/23 08:32:59 cgd Exp $"; +__RCSID("$NetBSD: setup.c,v 1.4 1997/10/11 01:16:42 lukem Exp $"); #endif -#endif /* not lint */ +#endif /* not lint */ -# include "hangman.h" +#include "hangman.h" /* * setup: * Set up the strings on the screen. */ +void setup() { - register char **sp; - static struct stat sbuf; + char **sp; + static struct stat sbuf; noecho(); crmode(); |