summaryrefslogtreecommitdiffstats
path: root/quiz
diff options
context:
space:
mode:
authorpk <pk@NetBSD.org>1994-04-08 08:33:13 +0000
committerpk <pk@NetBSD.org>1994-04-08 08:33:13 +0000
commitd7c75ff32a979078381d12f2121e1b1097d42a55 (patch)
tree4af4bc24c9b9fcc523e2e4ec58925f2d83da9e58 /quiz
parente2fbb6593242e98fd7feb75fc220c3b913058f1f (diff)
downloadbsdgames-darwin-d7c75ff32a979078381d12f2121e1b1097d42a55.tar.gz
bsdgames-darwin-d7c75ff32a979078381d12f2121e1b1097d42a55.tar.zst
bsdgames-darwin-d7c75ff32a979078381d12f2121e1b1097d42a55.zip
Theorem:
Computer scientists don't care much for poetry. Prove: They haven't run `quiz poem next-line' for ages. get_file(), appdstr() and quiz() we made one more correctly catenate. On top of that, repeat after me: "Thou shallst not err, except in libc!"
Diffstat (limited to 'quiz')
-rw-r--r--quiz/quiz.c60
1 files changed, 17 insertions, 43 deletions
diff --git a/quiz/quiz.c b/quiz/quiz.c
index 06b82409..00e2e2a4 100644
--- a/quiz/quiz.c
+++ b/quiz/quiz.c
@@ -42,7 +42,7 @@ char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)quiz.c 5.1 (Berkeley) 11/10/91";*/
-static char rcsid[] = "$Id: quiz.c,v 1.5 1994/01/04 05:23:56 cgd Exp $";
+static char rcsid[] = "$Id: quiz.c,v 1.6 1994/04/08 08:33:13 pk Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -52,6 +52,7 @@ static char rcsid[] = "$Id: quiz.c,v 1.5 1994/01/04 05:23:56 cgd Exp $";
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <err.h>
#include "quiz.h"
#include "pathnames.h"
@@ -61,7 +62,6 @@ static u_int qsize;
char *appdstr __P((char *, char *));
void downcase __P((char *));
-void err __P((const char *, ...));
void get_cats __P((char *, char *));
void get_file __P((char *));
char *next_cat __P((char *));
@@ -120,7 +120,7 @@ get_file(file)
char *lp;
if ((fp = fopen(file, "r")) == NULL)
- err("%s: %s", file, strerror(errno));
+ err(1, "%s", file);
/*
* XXX
@@ -130,15 +130,16 @@ get_file(file)
qp = &qlist;
qsize = 0;
while ((lp = fgetln(fp, &len)) != NULL) {
- if (qp->q_text && qp->q_text[strlen(qp->q_text) - 1] == '\\')
+ if (qp->q_text && qp->q_text[strlen(qp->q_text) - 1] == '\\') {
+ lp[len - 1] = '\0';
qp->q_text = appdstr(qp->q_text, lp);
- else {
+ } else {
if ((qp->q_next = malloc(sizeof(QE))) == NULL)
- err("%s", strerror(errno));
+ err(1, NULL);
qp = qp->q_next;
lp[len - 1] = '\0';
if ((qp->q_text = strdup(lp)) == NULL)
- err("%s", strerror(errno));
+ err(1, NULL);
qp->q_asked = qp->q_answered = FALSE;
qp->q_next = NULL;
++qsize;
@@ -155,12 +156,12 @@ show_index()
FILE *pf;
if ((pf = popen(_PATH_PAGER, "w")) == NULL)
- err("%s: %s", _PATH_PAGER, strerror(errno));
+ err(1, "%s", _PATH_PAGER);
(void)fprintf(pf, "Subjects:\n\n");
for (qp = qlist.q_next; qp; qp = qp->q_next) {
for (s = next_cat(qp->q_text); s; s = next_cat(s)) {
if (!rxp_compile(s))
- err("%s", rxperr);
+ errx(1, "%s", rxperr);
if (p = rxp_expand())
(void)fprintf(pf, "%s ", p);
}
@@ -188,7 +189,7 @@ get_cats(cat1, cat2)
catone = cattwo = i = 0;
while (s) {
if (!rxp_compile(s))
- err("%s", rxperr);
+ errx(1, "%s", rxperr);
i++;
if (rxp_match(cat1))
catone = i;
@@ -198,12 +199,12 @@ get_cats(cat1, cat2)
}
if (catone && cattwo && catone != cattwo) {
if (!rxp_compile(qp->q_text))
- err("%s", rxperr);
+ errx(1, "%s", rxperr);
get_file(rxp_expand());
return;
}
}
- err("invalid categories");
+ errx(1, "invalid categories");
}
void
@@ -242,7 +243,7 @@ quiz()
for (i = 0; i < catone - 1; i++)
s = next_cat(s);
if (!rxp_compile(s))
- err("%s", rxperr);
+ errx(1, "%s", rxperr);
t = rxp_expand();
if (!t || *t == '\0') {
qp->q_answered = TRUE;
@@ -253,7 +254,7 @@ quiz()
for (i = 0; i < cattwo - 1; i++)
s = next_cat(s);
if (!rxp_compile(s))
- err("%s", rxperr);
+ errx(1, "%s", rxperr);
t = rxp_expand();
if (!t || *t == '\0') {
qp->q_answered = TRUE;
@@ -313,8 +314,9 @@ appdstr(s, tp)
char *m;
if ((m = malloc(strlen(s) + strlen(tp) + 1)) == NULL)
- err("%s", strerror(errno));
+ err(1, NULL);
for (mp = m, sp = s; *mp++ = *sp++;);
+ --mp;
if (*(mp - 1) == '\\')
--mp;
@@ -352,31 +354,3 @@ usage()
(void)fprintf(stderr, "quiz [-t] [-i file] category1 category2\n");
exit(1);
}
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-void
-#if __STDC__
-err(const char *fmt, ...)
-#else
-err(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- (void)fprintf(stderr, "quiz: ");
- (void)vfprintf(stderr, fmt, ap);
- va_end(ap);
- (void)fprintf(stderr, "\n");
- exit(1);
-}