From 1ce2a7dce3164fbc72a6cb1628f406e97c51ff62 Mon Sep 17 00:00:00 2001 From: jsm Date: Fri, 17 Sep 1999 20:45:48 +0000 Subject: [PATCH] Make word list for hangman selectable at run time. --- games/hangman/extern.c | 6 ++++-- games/hangman/hangman.6 | 10 +++++++++- games/hangman/hangman.h | 6 ++++-- games/hangman/main.c | 22 +++++++++++++++++++--- games/hangman/setup.c | 8 ++++---- 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/games/hangman/extern.c b/games/hangman/extern.c index a412fe9b1ef3..9a4891beb2a3 100644 --- a/games/hangman/extern.c +++ b/games/hangman/extern.c @@ -1,4 +1,4 @@ -/* $NetBSD: extern.c,v 1.5 1999/09/08 21:17:50 jsm Exp $ */ +/* $NetBSD: extern.c,v 1.6 1999/09/17 20:45:48 jsm Exp $ */ /* * Copyright (c) 1983, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)extern.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: extern.c,v 1.5 1999/09/08 21:17:50 jsm Exp $"); +__RCSID("$NetBSD: extern.c,v 1.6 1999/09/17 20:45:48 jsm Exp $"); #endif #endif /* not lint */ @@ -74,6 +74,8 @@ const ERR_POS Err_pos[MAXERRS] = { {5, 11, '\\'} }; +const char *Dict_name = _PATH_DICT; + FILE *Dict = NULL; off_t Dict_size; diff --git a/games/hangman/hangman.6 b/games/hangman/hangman.6 index 5698c112d581..9e41e27659a7 100644 --- a/games/hangman/hangman.6 +++ b/games/hangman/hangman.6 @@ -1,4 +1,4 @@ -.\" $NetBSD: hangman.6,v 1.6 1997/10/11 01:16:32 lukem Exp $ +.\" $NetBSD: hangman.6,v 1.7 1999/09/17 20:45:49 jsm Exp $ .\" .\" Copyright (c) 1983, 1993 .\" The Regents of the University of California. All rights reserved. @@ -41,6 +41,7 @@ .Nd Computer version of the game hangman .Sh SYNOPSIS .Nm +.Op Fl d Ar wordlist .Sh DESCRIPTION In .Nm "" , @@ -48,6 +49,13 @@ 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 and how many wrong guesses you have made on the screen in a graphic fashion. +.Sh OPTIONS +.Bl -tag -width flag +.It Fl d +Use the specified +.Ar wordlist +instead of the default one named below. +.El .Sh FILES .Bl -tag -width /usr/share/dict/words -compact .It Pa /usr/share/dict/words diff --git a/games/hangman/hangman.h b/games/hangman/hangman.h index 6ab760bf6f35..3ed05db808e2 100644 --- a/games/hangman/hangman.h +++ b/games/hangman/hangman.h @@ -1,4 +1,4 @@ -/* $NetBSD: hangman.h,v 1.9 1999/09/08 21:45:28 jsm Exp $ */ +/* $NetBSD: hangman.h,v 1.10 1999/09/17 20:45:49 jsm Exp $ */ /* * Copyright (c) 1983, 1993 @@ -78,13 +78,15 @@ extern double Average; extern const ERR_POS Err_pos[]; +extern const char *Dict_name; + extern FILE *Dict; extern off_t Dict_size; void die __P((int)) __attribute__((__noreturn__)); void endgame __P((void)); -int main __P((void)); +int main __P((int, char *[])); void getguess __P((void)); void getword __P((void)); void playgame __P((void)); diff --git a/games/hangman/main.c b/games/hangman/main.c index 1cc88e78fd2d..0bab3e90c743 100644 --- a/games/hangman/main.c +++ b/games/hangman/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.7 1999/09/12 09:02:21 jsm Exp $ */ +/* $NetBSD: main.c,v 1.8 1999/09/17 20:45:49 jsm Exp $ */ /* * Copyright (c) 1983, 1993 @@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\ #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: main.c,v 1.7 1999/09/12 09:02:21 jsm Exp $"); +__RCSID("$NetBSD: main.c,v 1.8 1999/09/17 20:45:49 jsm Exp $"); #endif #endif /* not lint */ @@ -53,11 +53,27 @@ __RCSID("$NetBSD: main.c,v 1.7 1999/09/12 09:02:21 jsm Exp $"); * This game written by Ken Arnold. */ int -main(void) +main(argc, argv) + int argc; + char *argv[]; { + int ch; + /* Revoke setgid privileges */ setregid(getgid(), getgid()); + while ((ch = getopt(argc, argv, "d:")) != -1) { + switch (ch) { + case 'd': + Dict_name = optarg; + break; + case '?': + default: + (void)fprintf(stderr, "usage: hangman [-d wordlist]\n"); + exit(1); + } + } + initscr(); signal(SIGINT, die); setup(); diff --git a/games/hangman/setup.c b/games/hangman/setup.c index 81a97339ee19..4c4590da9087 100644 --- a/games/hangman/setup.c +++ b/games/hangman/setup.c @@ -1,4 +1,4 @@ -/* $NetBSD: setup.c,v 1.7 1999/09/09 17:30:20 jsm Exp $ */ +/* $NetBSD: setup.c,v 1.8 1999/09/17 20:45:49 jsm Exp $ */ /*- * Copyright (c) 1983, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)setup.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: setup.c,v 1.7 1999/09/09 17:30:20 jsm Exp $"); +__RCSID("$NetBSD: setup.c,v 1.8 1999/09/17 20:45:49 jsm Exp $"); #endif #endif /* not lint */ @@ -72,9 +72,9 @@ setup() } srand(time(NULL) + getpid()); - if ((Dict = fopen(_PATH_DICT, "r")) == NULL) { + if ((Dict = fopen(Dict_name, "r")) == NULL) { endwin(); - err(1, "fopen %s", _PATH_DICT); + err(1, "fopen %s", Dict_name); } fstat(fileno(Dict), &sbuf); Dict_size = sbuf.st_size;