summaryrefslogtreecommitdiff
path: root/games/quiz/quiz.c
diff options
context:
space:
mode:
authorPaul Janzen <pjanzen@cvs.openbsd.org>1998-08-19 07:42:28 +0000
committerPaul Janzen <pjanzen@cvs.openbsd.org>1998-08-19 07:42:28 +0000
commited884b9fa4509c09f0f7ab71efe57a4e83a2e055 (patch)
treeef9d859a0754785b42ea5cacb27aff54b5000315 /games/quiz/quiz.c
parentf4fc9566a4d35c0cc2bf8c7f1136287d8eec8c44 (diff)
tags, formatting, ANSI-fication, prototypes, de-typos, and the occasional
initialization, removal of unused variable, or other minor fix. Most changes are from or inspired by NetBSD.
Diffstat (limited to 'games/quiz/quiz.c')
-rw-r--r--games/quiz/quiz.c65
1 files changed, 37 insertions, 28 deletions
diff --git a/games/quiz/quiz.c b/games/quiz/quiz.c
index 28eb3904aac..56208d79fbb 100644
--- a/games/quiz/quiz.c
+++ b/games/quiz/quiz.c
@@ -1,3 +1,4 @@
+/* $OpenBSD: quiz.c,v 1.6 1998/08/19 07:40:57 pjanzen Exp $ */
/* $NetBSD: quiz.c,v 1.9 1995/04/22 10:16:58 cgd Exp $ */
/*-
@@ -45,20 +46,21 @@ static char copyright[] =
#ifndef lint
#if 0
-static char sccsid[] = "@(#)quiz.c 8.2 (Berkeley) 1/3/94";
+static char sccsid[] = "@(#)quiz.c 8.3 (Berkeley) 5/4/95";
#else
-static char rcsid[] = "$NetBSD: quiz.c,v 1.9 1995/04/22 10:16:58 cgd Exp $";
+static char rcsid[] = "$OpenBSD: quiz.c,v 1.6 1998/08/19 07:40:57 pjanzen Exp $";
#endif
#endif /* not lint */
#include <sys/types.h>
#include <errno.h>
-#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <err.h>
+#include <time.h>
+#include <unistd.h>
#include "quiz.h"
#include "pathnames.h"
@@ -81,7 +83,7 @@ main(argc, argv)
int argc;
char *argv[];
{
- register int ch;
+ int ch;
char *indexfile;
/* revoke */
@@ -124,8 +126,8 @@ void
get_file(file)
char *file;
{
- register FILE *fp;
- register QE *qp;
+ FILE *fp;
+ QE *qp;
size_t len;
char *lp;
@@ -140,15 +142,18 @@ get_file(file)
qp = &qlist;
qsize = 0;
while ((lp = fgetln(fp, &len)) != NULL) {
- lp[--len] = '\0';
+ if (lp[len - 1] == '\n')
+ --len;
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;
@@ -160,8 +165,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)
@@ -171,7 +176,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()))
(void)fprintf(pf, "%s ", p);
}
(void)fprintf(pf, "\n");
@@ -187,7 +192,7 @@ void
get_cats(cat1, cat2)
char *cat1, *cat2;
{
- register QE *qp;
+ QE *qp;
int i;
char *s;
@@ -219,8 +224,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;
@@ -272,7 +277,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);
}
@@ -299,10 +305,11 @@ quiz()
char *
next_cat(s)
- register char * s;
+ char * s;
{
- int esc = 0;
+ int esc;
+ esc = 0;
for (;;)
switch (*s++) {
case '\0':
@@ -323,21 +330,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 +365,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);
}