* Added -m option to hangman to set MINLEN. Closes: #129998

git-svn-id: file:///srv/svn/joey/bsdgames-trunk@5180 a4a2c43b-8ac3-0310-8836-e0e880c912e2
This commit is contained in:
joey
2002-01-20 00:26:56 +00:00
parent 0a887df528
commit 259231e07c
6 changed files with 60 additions and 14 deletions

6
debian/changelog vendored
View File

@@ -1,3 +1,9 @@
bsdgames (2.13-3) unstable; urgency=low
* Added -m option to hangman to set MINLEN. Closes: #129998
-- Joey Hess <joeyh@debian.org> Sat, 19 Jan 2002 18:04:06 -0500
bsdgames (2.13-2) unstable; urgency=low
* Fixed bad merge (that's why sail was broken).

View File

@@ -1,4 +1,4 @@
/* $NetBSD: extern.c,v 1.4 1997/10/11 01:16:27 lukem 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.4 1997/10/11 01:16:27 lukem Exp $");
__RCSID("$NetBSD: extern.c,v 1.6 1999/09/17 20:45:48 jsm Exp $");
#endif
#endif /* not lint */
@@ -61,6 +61,7 @@ const char *const Noose_pict[] = {
};
int Errors, Wordnum = 0;
unsigned int Minlen = MINLEN;
double Average = 0.0;
@@ -74,6 +75,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: getword.c,v 1.5 1997/10/11 01:16:30 lukem Exp $ */
/* $NetBSD: getword.c,v 1.6 1999/09/08 21:57:17 jsm Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)getword.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: getword.c,v 1.5 1997/10/11 01:16:30 lukem Exp $");
__RCSID("$NetBSD: getword.c,v 1.6 1999/09/08 21:57:17 jsm Exp $");
#endif
#endif /* not lint */
@@ -58,13 +58,13 @@ getword()
inf = Dict;
for (;;) {
pos = (double) rand() / (RAND_MAX + 1.0) * (double) Dict_size;
fseek(inf, pos, 0);
fseek(inf, pos, SEEK_SET);
if (fgets(Word, BUFSIZ, inf) == NULL)
continue;
if (fgets(Word, BUFSIZ, inf) == NULL)
continue;
Word[strlen(Word) - 1] = '\0';
if (strlen(Word) < MINLEN)
if (strlen(Word) < Minlen)
continue;
for (wp = Word; *wp; wp++)
if (!islower(*wp))

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,8 @@
.Nd Computer version of the game hangman
.Sh SYNOPSIS
.Nm
.Op Fl d Ar wordlist
.Op Fl m Ar minlen
.Sh DESCRIPTION
In
.Nm "" ,
@@ -48,6 +50,15 @@ 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.
.It Fl m
Set the minimum word length to use. The default is 6 letters.
.El
.Sh FILES
.Bl -tag -width @hangman_wordsfile@ -compact
.It Pa @hangman_wordsfile@

View File

@@ -1,4 +1,4 @@
/* $NetBSD: hangman.h,v 1.7 1998/09/11 13:42:03 hubertf Exp $ */
/* $NetBSD: hangman.h,v 1.10 1999/09/17 20:45:49 jsm Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -73,18 +73,21 @@ extern char Word[], Known[];
extern const char *const Noose_pict[];
extern int Errors, Wordnum;
extern unsigned int Minlen;
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));
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.5 1998/09/11 13:42:03 hubertf Exp $ */
/* $NetBSD: main.c,v 1.9 2000/05/08 07:56:04 mycroft 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.5 1998/09/11 13:42:03 hubertf Exp $");
__RCSID("$NetBSD: main.c,v 1.9 2000/05/08 07:56:04 mycroft Exp $");
#endif
#endif /* not lint */
@@ -53,11 +53,34 @@ __RCSID("$NetBSD: main.c,v 1.5 1998/09/11 13:42:03 hubertf 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, "m:d:")) != -1) {
switch (ch) {
case 'd':
Dict_name = optarg;
break;
case 'm':
Minlen = atoi(optarg);
if (Minlen < 2) {
fprintf(stderr, "minlen too short\n");
exit(1);
}
break;
case '?':
default:
(void)fprintf(stderr, "usage: hangman [-d wordlist] [-m minlen]\n");
exit(1);
}
}
initscr();
signal(SIGINT, die);
setup();
@@ -74,7 +97,7 @@ main(void)
*/
void
die(dummy)
int dummy __attribute__((unused));
int dummy __attribute__((__unused__));
{
mvcur(0, COLS - 1, LINES - 1, 0);
endwin();