Allow minimum word length to be set on command line. Patch based on

one by Joey Hess <joeyh@debian.org>.
This commit is contained in:
jsm 2002-01-20 00:42:51 +00:00
parent 71a4ca8acd
commit 26891a9fd2
5 changed files with 22 additions and 11 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.c,v 1.6 1999/09/17 20:45:48 jsm Exp $ */ /* $NetBSD: extern.c,v 1.7 2002/01/20 00:42:51 jsm Exp $ */
/* /*
* Copyright (c) 1983, 1993 * Copyright (c) 1983, 1993
@ -38,7 +38,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)extern.c 8.1 (Berkeley) 5/31/93"; static char sccsid[] = "@(#)extern.c 8.1 (Berkeley) 5/31/93";
#else #else
__RCSID("$NetBSD: extern.c,v 1.6 1999/09/17 20:45:48 jsm Exp $"); __RCSID("$NetBSD: extern.c,v 1.7 2002/01/20 00:42:51 jsm Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -61,6 +61,7 @@ const char *const Noose_pict[] = {
}; };
int Errors, Wordnum = 0; int Errors, Wordnum = 0;
unsigned int Minlen = MINLEN;
double Average = 0.0; double Average = 0.0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: getword.c,v 1.6 1999/09/08 21:57:17 jsm Exp $ */ /* $NetBSD: getword.c,v 1.7 2002/01/20 00:42:51 jsm Exp $ */
/* /*
* Copyright (c) 1983, 1993 * Copyright (c) 1983, 1993
@ -38,7 +38,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)getword.c 8.1 (Berkeley) 5/31/93"; static char sccsid[] = "@(#)getword.c 8.1 (Berkeley) 5/31/93";
#else #else
__RCSID("$NetBSD: getword.c,v 1.6 1999/09/08 21:57:17 jsm Exp $"); __RCSID("$NetBSD: getword.c,v 1.7 2002/01/20 00:42:51 jsm Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -64,7 +64,7 @@ getword()
if (fgets(Word, BUFSIZ, inf) == NULL) if (fgets(Word, BUFSIZ, inf) == NULL)
continue; continue;
Word[strlen(Word) - 1] = '\0'; Word[strlen(Word) - 1] = '\0';
if (strlen(Word) < MINLEN) if (strlen(Word) < Minlen)
continue; continue;
for (wp = Word; *wp; wp++) for (wp = Word; *wp; wp++)
if (!islower(*wp)) if (!islower(*wp))

View File

@ -1,4 +1,4 @@
.\" $NetBSD: hangman.6,v 1.7 1999/09/17 20:45:49 jsm Exp $ .\" $NetBSD: hangman.6,v 1.8 2002/01/20 00:42:51 jsm Exp $
.\" .\"
.\" Copyright (c) 1983, 1993 .\" Copyright (c) 1983, 1993
.\" The Regents of the University of California. All rights reserved. .\" The Regents of the University of California. All rights reserved.
@ -42,6 +42,7 @@
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl d Ar wordlist .Op Fl d Ar wordlist
.Op Fl m Ar minlen
.Sh DESCRIPTION .Sh DESCRIPTION
In In
.Nm "" , .Nm "" ,
@ -55,6 +56,8 @@ and how many wrong guesses you have made on the screen in a graphic fashion.
Use the specified Use the specified
.Ar wordlist .Ar wordlist
instead of the default one named below. instead of the default one named below.
.It Fl m
Set the minimum word length to use. The default is 6 letters.
.El .El
.Sh FILES .Sh FILES
.Bl -tag -width /usr/share/dict/words -compact .Bl -tag -width /usr/share/dict/words -compact

View File

@ -1,4 +1,4 @@
/* $NetBSD: hangman.h,v 1.10 1999/09/17 20:45:49 jsm Exp $ */ /* $NetBSD: hangman.h,v 1.11 2002/01/20 00:42:51 jsm Exp $ */
/* /*
* Copyright (c) 1983, 1993 * Copyright (c) 1983, 1993
@ -73,6 +73,7 @@ extern char Word[], Known[];
extern const char *const Noose_pict[]; extern const char *const Noose_pict[];
extern int Errors, Wordnum; extern int Errors, Wordnum;
extern unsigned int Minlen;
extern double Average; extern double Average;

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.9 2000/05/08 07:56:04 mycroft Exp $ */ /* $NetBSD: main.c,v 1.10 2002/01/20 00:42:51 jsm Exp $ */
/* /*
* Copyright (c) 1983, 1993 * Copyright (c) 1983, 1993
@ -43,10 +43,11 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
#if 0 #if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
#else #else
__RCSID("$NetBSD: main.c,v 1.9 2000/05/08 07:56:04 mycroft Exp $"); __RCSID("$NetBSD: main.c,v 1.10 2002/01/20 00:42:51 jsm Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
#include <err.h>
#include "hangman.h" #include "hangman.h"
/* /*
@ -62,14 +63,19 @@ main(argc, argv)
/* Revoke setgid privileges */ /* Revoke setgid privileges */
setgid(getgid()); setgid(getgid());
while ((ch = getopt(argc, argv, "d:")) != -1) { while ((ch = getopt(argc, argv, "d:m:")) != -1) {
switch (ch) { switch (ch) {
case 'd': case 'd':
Dict_name = optarg; Dict_name = optarg;
break; break;
case 'm':
Minlen = atoi(optarg);
if (Minlen < 2)
errx(1, "minimum word length too short");
break;
case '?': case '?':
default: default:
(void)fprintf(stderr, "usage: hangman [-d wordlist]\n"); (void)fprintf(stderr, "usage: hangman [-d wordlist] [-m minlen]\n");
exit(1); exit(1);
} }
} }