Make word list for hangman selectable at run time.

This commit is contained in:
jsm 1999-09-17 20:45:48 +00:00
parent 010f0ab865
commit 1ce2a7dce3
5 changed files with 40 additions and 12 deletions

View File

@ -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;

View File

@ -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

View File

@ -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));

View File

@ -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();

View File

@ -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;