summaryrefslogtreecommitdiffstats
path: root/hangman
diff options
context:
space:
mode:
authorjsm <jsm@NetBSD.org>1999-09-17 20:45:48 +0000
committerjsm <jsm@NetBSD.org>1999-09-17 20:45:48 +0000
commit77f0652e937d91406765636e43f56c09a46f2f80 (patch)
treec69919778511f58c286dedb3ffbc43ec828f3dac /hangman
parent1f4431b09beb5f94c47e37d8d209a0c9cc0479f9 (diff)
downloadbsdgames-darwin-77f0652e937d91406765636e43f56c09a46f2f80.tar.gz
bsdgames-darwin-77f0652e937d91406765636e43f56c09a46f2f80.tar.zst
bsdgames-darwin-77f0652e937d91406765636e43f56c09a46f2f80.zip
Make word list for hangman selectable at run time.
Diffstat (limited to 'hangman')
-rw-r--r--hangman/extern.c6
-rw-r--r--hangman/hangman.610
-rw-r--r--hangman/hangman.h6
-rw-r--r--hangman/main.c22
-rw-r--r--hangman/setup.c8
5 files changed, 40 insertions, 12 deletions
diff --git a/hangman/extern.c b/hangman/extern.c
index a412fe9b..9a4891be 100644
--- a/hangman/extern.c
+++ b/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/hangman/hangman.6 b/hangman/hangman.6
index 5698c112..9e41e276 100644
--- a/hangman/hangman.6
+++ b/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/hangman/hangman.h b/hangman/hangman.h
index 6ab760bf..3ed05db8 100644
--- a/hangman/hangman.h
+++ b/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/hangman/main.c b/hangman/main.c
index 1cc88e78..0bab3e90 100644
--- a/hangman/main.c
+++ b/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/hangman/setup.c b/hangman/setup.c
index 81a97339..4c4590da 100644
--- a/hangman/setup.c
+++ b/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;