summaryrefslogtreecommitdiffstats
path: root/quiz
diff options
context:
space:
mode:
authorlukem <lukem@NetBSD.org>1997-09-20 14:28:16 +0000
committerlukem <lukem@NetBSD.org>1997-09-20 14:28:16 +0000
commit7284e71c584d91c40ff4b6e19cd75aef8aae7010 (patch)
tree3eb5fd1560b00635386814d8f5bfa5048fd73e6a /quiz
parentdd3111969330fee8b8de8f3602e5658c3fd0e2db (diff)
downloadbsdgames-darwin-7284e71c584d91c40ff4b6e19cd75aef8aae7010.tar.gz
bsdgames-darwin-7284e71c584d91c40ff4b6e19cd75aef8aae7010.tar.zst
bsdgames-darwin-7284e71c584d91c40ff4b6e19cd75aef8aae7010.zip
- WARNSify
- deprecate register - getopts returns -1 not EOF - last character returned by fgetln() isn't always \n - cleanup .Nm use
Diffstat (limited to 'quiz')
-rw-r--r--quiz/quiz.616
-rw-r--r--quiz/quiz.c67
-rw-r--r--quiz/rxp.c15
3 files changed, 53 insertions, 45 deletions
diff --git a/quiz/quiz.6 b/quiz/quiz.6
index 8d9d9f19..67009a96 100644
--- a/quiz/quiz.6
+++ b/quiz/quiz.6
@@ -1,4 +1,4 @@
-.\" $NetBSD: quiz.6,v 1.5 1997/03/08 13:32:12 mouse Exp $
+.\" $NetBSD: quiz.6,v 1.6 1997/09/20 14:28:16 lukem Exp $
.\"
.\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -43,17 +43,17 @@
.Nm quiz
.Nd random knowledge tests
.Sh SYNOPSIS
-.Nm quiz
+.Nm
.Op Fl t
.Op Fl i Ar file
.Op Ar question answer
.Sh DESCRIPTION
The
-.Nm quiz
+.Nm
utility tests your knowledge of random facts.
It has a database of subjects from which you can choose.
With no arguments,
-.Nm quiz
+.Nm
displays the list of available subjects.
.Pp
The options are as follows:
@@ -68,7 +68,7 @@ Specify an alternative index file.
.Pp
Subjects are divided into categories.
You can pick any two categories from the same subject.
-.Nm Quiz
+.Nm
will ask questions from the first category and it expects answers from
the second category.
For example, the command ``quiz victim killer'' asks questions which are
@@ -77,7 +77,7 @@ untimely demise, whereas the command ``quiz killer victim'' works the
other way around.
.Pp
If you get the answer wrong,
-.Nm quiz
+.Nm
lets you try again.
To see the right answer, enter a blank line.
.Sh "Index and Data File Syntax"
@@ -109,7 +109,7 @@ characters, or at the end of a line to signify that a continuation line
follows.
.Pp
If either a question or its answer is empty,
-.Nm quiz
+.Nm
will refrain from asking it.
.Sh FILES
.Bl -tag -width /usr/share/games/quiz.db -compact
@@ -117,5 +117,5 @@ will refrain from asking it.
The default index and data files.
.El
.Sh BUGS
-.Nm Quiz
+.Nm
is pretty cynical about certain subjects.
diff --git a/quiz/quiz.c b/quiz/quiz.c
index 5aca0ac3..a2463b12 100644
--- a/quiz/quiz.c
+++ b/quiz/quiz.c
@@ -1,4 +1,4 @@
-/* $NetBSD: quiz.c,v 1.11 1997/07/06 11:19:16 mycroft Exp $ */
+/* $NetBSD: quiz.c,v 1.12 1997/09/20 14:28:18 lukem Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,17 +37,17 @@
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-static char copyright[] =
-"@(#) Copyright (c) 1991, 1993\n\
- The Regents of the University of California. All rights reserved.\n";
+__COPYRIGHT("@(#) Copyright (c) 1991, 1993\n\
+ The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)quiz.c 8.3 (Berkeley) 5/4/95";
#else
-static char rcsid[] = "$NetBSD: quiz.c,v 1.11 1997/07/06 11:19:16 mycroft Exp $";
+__RCSID("$NetBSD: quiz.c,v 1.12 1997/09/20 14:28:18 lukem Exp $");
#endif
#endif /* not lint */
@@ -73,6 +73,7 @@ char *appdstr __P((char *, char *, size_t));
void downcase __P((char *));
void get_cats __P((char *, char *));
void get_file __P((char *));
+int main __P((int, char *[]));
char *next_cat __P((char *));
void quiz __P((void));
void score __P((u_int, u_int, u_int));
@@ -84,11 +85,11 @@ main(argc, argv)
int argc;
char *argv[];
{
- register int ch;
+ int ch;
char *indexfile;
indexfile = _PATH_QUIZIDX;
- while ((ch = getopt(argc, argv, "i:t")) != EOF)
+ while ((ch = getopt(argc, argv, "i:t")) != -1)
switch(ch) {
case 'i':
indexfile = optarg;
@@ -123,8 +124,8 @@ void
get_file(file)
char *file;
{
- register FILE *fp;
- register QE *qp;
+ FILE *fp;
+ QE *qp;
size_t len;
char *lp;
@@ -139,15 +140,18 @@ get_file(file)
qp = &qlist;
qsize = 0;
while ((lp = fgetln(fp, &len)) != NULL) {
- lp[--len] = '\0';
+ if (lp[len - 1] == '\n')
+ lp[--len] = '\0';
if (qp->q_text && qp->q_text[strlen(qp->q_text) - 1] == '\\')
qp->q_text = appdstr(qp->q_text, lp, len);
else {
if ((qp->q_next = malloc(sizeof(QE))) == NULL)
- err(1, NULL);
+ errx(1, "malloc");
qp = qp->q_next;
- if ((qp->q_text = strdup(lp)) == NULL)
- err(1, NULL);
+ if ((qp->q_text = malloc(len + 1)) == NULL)
+ errx(1, "malloc");
+ strncpy(qp->q_text, lp, len);
+ qp->q_text[len] = '\0';
qp->q_asked = qp->q_answered = FALSE;
qp->q_next = NULL;
++qsize;
@@ -159,8 +163,8 @@ get_file(file)
void
show_index()
{
- register QE *qp;
- register char *p, *s;
+ QE *qp;
+ char *p, *s;
FILE *pf;
if ((pf = popen(_PATH_PAGER, "w")) == NULL)
@@ -170,7 +174,7 @@ show_index()
for (s = next_cat(qp->q_text); s; s = next_cat(s)) {
if (!rxp_compile(s))
errx(1, "%s", rxperr);
- if (p = rxp_expand())
+ if ((p = rxp_expand()) != NULL)
(void)fprintf(pf, "%s ", p);
}
(void)fprintf(pf, "\n");
@@ -186,7 +190,7 @@ void
get_cats(cat1, cat2)
char *cat1, *cat2;
{
- register QE *qp;
+ QE *qp;
int i;
char *s;
@@ -218,8 +222,8 @@ get_cats(cat1, cat2)
void
quiz()
{
- register QE *qp;
- register int i;
+ QE *qp;
+ int i;
size_t len;
u_int guesses, rights, wrongs;
int next;
@@ -271,7 +275,8 @@ quiz()
qp->q_asked = TRUE;
(void)printf("%s?\n", question);
for (;; ++guesses) {
- if ((answer = fgetln(stdin, &len)) == NULL) {
+ if ((answer = fgetln(stdin, &len)) == NULL ||
+ answer[len - 1] != '\n') {
score(rights, wrongs, guesses);
exit(0);
}
@@ -298,7 +303,7 @@ quiz()
char *
next_cat(s)
- register char * s;
+ char * s;
{
int esc;
@@ -323,21 +328,23 @@ next_cat(s)
char *
appdstr(s, tp, len)
char *s;
- register char *tp;
+ char *tp;
size_t len;
{
- register char *mp, *sp;
- register int ch;
+ char *mp, *sp;
+ int ch;
char *m;
if ((m = malloc(strlen(s) + len + 1)) == NULL)
- err(1, NULL);
- for (mp = m, sp = s; *mp++ = *sp++;);
+ errx(1, "malloc");
+ for (mp = m, sp = s; (*mp++ = *sp++) != NULL; )
+ ;
--mp;
if (*(mp - 1) == '\\')
--mp;
- while ((ch = *mp++ = *tp++) && ch != '\n');
+ while ((ch = *mp++ = *tp++) && ch != '\n')
+ ;
*mp = '\0';
free(s);
@@ -356,11 +363,11 @@ score(r, w, g)
void
downcase(p)
- register char *p;
+ char *p;
{
- register int ch;
+ int ch;
- for (; ch = *p; ++p)
+ for (; (ch = *p) != '\0'; ++p)
if (isascii(ch) && isupper(ch))
*p = tolower(ch);
}
diff --git a/quiz/rxp.c b/quiz/rxp.c
index f835913e..19a31bf6 100644
--- a/quiz/rxp.c
+++ b/quiz/rxp.c
@@ -1,4 +1,4 @@
-/* $NetBSD: rxp.c,v 1.5 1995/04/22 10:17:00 cgd Exp $ */
+/* $NetBSD: rxp.c,v 1.6 1997/09/20 14:28:19 lukem Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,11 +37,12 @@
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)rxp.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$NetBSD: rxp.c,v 1.5 1995/04/22 10:17:00 cgd Exp $";
+__RCSID("$NetBSD: rxp.c,v 1.6 1997/09/20 14:28:19 lukem Exp $");
#endif
#endif /* not lint */
@@ -90,14 +91,14 @@ static int rxp__match __P((char *, int, Rxp_t *, Rxp_t *, char *));
int
rxp_compile(s)
- register char * s;
+ char * s;
{
return (rxp__compile(s, TRUE));
}
static int
rxp__compile(s, first)
- register char *s;
+ char *s;
int first;
{
static Rxp_t *rp;
@@ -195,7 +196,7 @@ rxp__compile(s, first)
*/
int
rxp_match(s)
- register char * s;
+ char * s;
{
return (rxp__match(s, TRUE, NULL, NULL, NULL));
}
@@ -210,8 +211,8 @@ rxp__match(s, first, j_succ, j_fail, sp_fail)
{
static Rxp_t *rp;
static char *sp;
- register int ch;
- Rxp_t *grp_end;
+ int ch;
+ Rxp_t *grp_end = NULL;
int err;
if (first) {