2004-01-27 23:30:28 +03:00
|
|
|
/* $NetBSD: quiz.c,v 1.20 2004/01/27 20:30:30 jsm Exp $ */
|
1995-04-22 14:16:53 +04:00
|
|
|
|
1993-04-04 14:49:24 +04:00
|
|
|
/*-
|
1995-04-22 13:06:33 +04:00
|
|
|
* Copyright (c) 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-04-04 14:49:24 +04:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
1995-04-22 13:06:33 +04:00
|
|
|
* Jim R. Oldroyd at The Instruction Set and Keith Gabryelski at
|
|
|
|
* Commodore Business Machines.
|
1993-04-04 14:49:24 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 13:36:50 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-04-04 14:49:24 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-09-20 18:28:16 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-04-04 14:49:24 +04:00
|
|
|
#ifndef lint
|
1997-09-20 18:28:16 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1991, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n");
|
1993-04-04 14:49:24 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1995-04-22 14:16:53 +04:00
|
|
|
#if 0
|
1997-01-07 15:24:57 +03:00
|
|
|
static char sccsid[] = "@(#)quiz.c 8.3 (Berkeley) 5/4/95";
|
1995-04-22 14:16:53 +04:00
|
|
|
#else
|
2004-01-27 23:30:28 +03:00
|
|
|
__RCSID("$NetBSD: quiz.c,v 1.20 2004/01/27 20:30:30 jsm Exp $");
|
1995-04-22 14:16:53 +04:00
|
|
|
#endif
|
1993-04-04 14:49:24 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
1997-01-07 15:24:57 +03:00
|
|
|
|
|
|
|
#include <ctype.h>
|
1993-04-04 14:49:24 +04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
1994-04-08 12:33:13 +04:00
|
|
|
#include <err.h>
|
1997-01-07 15:24:57 +03:00
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
1993-04-04 14:49:24 +04:00
|
|
|
#include "quiz.h"
|
|
|
|
#include "pathnames.h"
|
|
|
|
|
|
|
|
static QE qlist;
|
|
|
|
static int catone, cattwo, tflag;
|
|
|
|
static u_int qsize;
|
|
|
|
|
2004-01-27 23:30:28 +03:00
|
|
|
char *appdstr(char *, const char *, size_t);
|
|
|
|
void downcase(char *);
|
|
|
|
void get_cats(char *, char *);
|
|
|
|
void get_file(const char *);
|
|
|
|
int main(int, char *[]);
|
|
|
|
const char *next_cat(const char *);
|
|
|
|
void quiz(void);
|
|
|
|
void score(u_int, u_int, u_int);
|
|
|
|
void show_index(void);
|
|
|
|
void usage(void) __attribute__((__noreturn__));
|
1993-04-04 14:49:24 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
1997-09-20 18:28:16 +04:00
|
|
|
int ch;
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
const char *indexfile;
|
1993-04-04 14:49:24 +04:00
|
|
|
|
1999-09-12 13:02:20 +04:00
|
|
|
/* Revoke setgid privileges */
|
2000-05-08 11:55:59 +04:00
|
|
|
setgid(getgid());
|
1999-09-12 13:02:20 +04:00
|
|
|
|
1993-04-04 14:49:24 +04:00
|
|
|
indexfile = _PATH_QUIZIDX;
|
1997-09-20 18:28:16 +04:00
|
|
|
while ((ch = getopt(argc, argv, "i:t")) != -1)
|
1993-04-04 14:49:24 +04:00
|
|
|
switch(ch) {
|
|
|
|
case 'i':
|
|
|
|
indexfile = optarg;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
tflag = 1;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
switch(argc) {
|
|
|
|
case 0:
|
|
|
|
get_file(indexfile);
|
|
|
|
show_index();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
get_file(indexfile);
|
|
|
|
get_cats(argv[0], argv[1]);
|
|
|
|
quiz();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
get_file(file)
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
const char *file;
|
1993-04-04 14:49:24 +04:00
|
|
|
{
|
1997-09-20 18:28:16 +04:00
|
|
|
FILE *fp;
|
|
|
|
QE *qp;
|
1993-04-04 14:49:24 +04:00
|
|
|
size_t len;
|
|
|
|
char *lp;
|
|
|
|
|
|
|
|
if ((fp = fopen(file, "r")) == NULL)
|
1994-04-08 12:33:13 +04:00
|
|
|
err(1, "%s", file);
|
1993-04-04 14:49:24 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* Should really free up space from any earlier read list
|
|
|
|
* but there are no reverse pointers to do so with.
|
|
|
|
*/
|
|
|
|
qp = &qlist;
|
|
|
|
qsize = 0;
|
1994-01-04 08:16:44 +03:00
|
|
|
while ((lp = fgetln(fp, &len)) != NULL) {
|
1997-09-20 18:28:16 +04:00
|
|
|
if (lp[len - 1] == '\n')
|
|
|
|
lp[--len] = '\0';
|
1995-04-22 13:06:33 +04:00
|
|
|
if (qp->q_text && qp->q_text[strlen(qp->q_text) - 1] == '\\')
|
|
|
|
qp->q_text = appdstr(qp->q_text, lp, len);
|
|
|
|
else {
|
1993-04-04 14:49:24 +04:00
|
|
|
if ((qp->q_next = malloc(sizeof(QE))) == NULL)
|
1997-09-20 18:28:16 +04:00
|
|
|
errx(1, "malloc");
|
1993-04-04 14:49:24 +04:00
|
|
|
qp = qp->q_next;
|
1997-09-20 18:28:16 +04:00
|
|
|
if ((qp->q_text = malloc(len + 1)) == NULL)
|
|
|
|
errx(1, "malloc");
|
|
|
|
strncpy(qp->q_text, lp, len);
|
|
|
|
qp->q_text[len] = '\0';
|
1993-04-04 14:49:24 +04:00
|
|
|
qp->q_asked = qp->q_answered = FALSE;
|
|
|
|
qp->q_next = NULL;
|
|
|
|
++qsize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(void)fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
show_index()
|
|
|
|
{
|
1997-09-20 18:28:16 +04:00
|
|
|
QE *qp;
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
const char *p, *s;
|
1993-04-04 14:49:24 +04:00
|
|
|
FILE *pf;
|
1999-12-16 16:45:48 +03:00
|
|
|
const char *pager;
|
1993-04-04 14:49:24 +04:00
|
|
|
|
1999-12-16 16:45:48 +03:00
|
|
|
if (!isatty(1))
|
|
|
|
pager = "cat";
|
|
|
|
else {
|
|
|
|
if (!(pager = getenv("PAGER")) || (*pager == 0))
|
|
|
|
pager = _PATH_PAGER;
|
|
|
|
}
|
|
|
|
if ((pf = popen(pager, "w")) == NULL)
|
|
|
|
err(1, "%s", pager);
|
1993-04-04 14:49:24 +04:00
|
|
|
(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))
|
1994-04-08 12:33:13 +04:00
|
|
|
errx(1, "%s", rxperr);
|
1997-09-20 18:28:16 +04:00
|
|
|
if ((p = rxp_expand()) != NULL)
|
1993-04-04 14:49:24 +04:00
|
|
|
(void)fprintf(pf, "%s ", p);
|
|
|
|
}
|
|
|
|
(void)fprintf(pf, "\n");
|
|
|
|
}
|
|
|
|
(void)fprintf(pf, "\n%s\n%s\n%s\n",
|
|
|
|
"For example, \"quiz victim killer\" prints a victim's name and you reply",
|
|
|
|
"with the killer, and \"quiz killer victim\" works the other way around.",
|
|
|
|
"Type an empty line to get the correct answer.");
|
|
|
|
(void)pclose(pf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
get_cats(cat1, cat2)
|
|
|
|
char *cat1, *cat2;
|
|
|
|
{
|
1997-09-20 18:28:16 +04:00
|
|
|
QE *qp;
|
1993-04-04 14:49:24 +04:00
|
|
|
int i;
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
const char *s;
|
1993-04-04 14:49:24 +04:00
|
|
|
|
|
|
|
downcase(cat1);
|
|
|
|
downcase(cat2);
|
|
|
|
for (qp = qlist.q_next; qp; qp = qp->q_next) {
|
|
|
|
s = next_cat(qp->q_text);
|
|
|
|
catone = cattwo = i = 0;
|
|
|
|
while (s) {
|
|
|
|
if (!rxp_compile(s))
|
1994-04-08 12:33:13 +04:00
|
|
|
errx(1, "%s", rxperr);
|
1993-04-04 14:49:24 +04:00
|
|
|
i++;
|
|
|
|
if (rxp_match(cat1))
|
|
|
|
catone = i;
|
|
|
|
if (rxp_match(cat2))
|
|
|
|
cattwo = i;
|
|
|
|
s = next_cat(s);
|
|
|
|
}
|
|
|
|
if (catone && cattwo && catone != cattwo) {
|
|
|
|
if (!rxp_compile(qp->q_text))
|
1994-04-08 12:33:13 +04:00
|
|
|
errx(1, "%s", rxperr);
|
1993-04-04 14:49:24 +04:00
|
|
|
get_file(rxp_expand());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1994-04-08 12:33:13 +04:00
|
|
|
errx(1, "invalid categories");
|
1993-04-04 14:49:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
quiz()
|
|
|
|
{
|
1997-09-20 18:28:16 +04:00
|
|
|
QE *qp;
|
|
|
|
int i;
|
1995-04-22 13:06:33 +04:00
|
|
|
size_t len;
|
1993-04-04 14:49:24 +04:00
|
|
|
u_int guesses, rights, wrongs;
|
1995-04-22 13:06:33 +04:00
|
|
|
int next;
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
char *answer, *t, question[LINE_SZ];
|
|
|
|
const char *s;
|
1993-04-04 14:49:24 +04:00
|
|
|
|
|
|
|
srandom(time(NULL));
|
|
|
|
guesses = rights = wrongs = 0;
|
|
|
|
for (;;) {
|
|
|
|
if (qsize == 0)
|
|
|
|
break;
|
|
|
|
next = random() % qsize;
|
|
|
|
qp = qlist.q_next;
|
|
|
|
for (i = 0; i < next; i++)
|
|
|
|
qp = qp->q_next;
|
|
|
|
while (qp && qp->q_answered)
|
|
|
|
qp = qp->q_next;
|
|
|
|
if (!qp) {
|
|
|
|
qsize = next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (tflag && random() % 100 > 20) {
|
|
|
|
/* repeat questions in tutorial mode */
|
|
|
|
while (qp && (!qp->q_asked || qp->q_answered))
|
|
|
|
qp = qp->q_next;
|
|
|
|
if (!qp)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
s = qp->q_text;
|
|
|
|
for (i = 0; i < catone - 1; i++)
|
|
|
|
s = next_cat(s);
|
|
|
|
if (!rxp_compile(s))
|
1994-04-08 12:33:13 +04:00
|
|
|
errx(1, "%s", rxperr);
|
1993-04-04 14:49:24 +04:00
|
|
|
t = rxp_expand();
|
|
|
|
if (!t || *t == '\0') {
|
|
|
|
qp->q_answered = TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
(void)strcpy(question, t);
|
|
|
|
s = qp->q_text;
|
|
|
|
for (i = 0; i < cattwo - 1; i++)
|
|
|
|
s = next_cat(s);
|
|
|
|
if (!rxp_compile(s))
|
1994-04-08 12:33:13 +04:00
|
|
|
errx(1, "%s", rxperr);
|
1993-04-04 14:49:24 +04:00
|
|
|
t = rxp_expand();
|
|
|
|
if (!t || *t == '\0') {
|
|
|
|
qp->q_answered = TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
qp->q_asked = TRUE;
|
|
|
|
(void)printf("%s?\n", question);
|
|
|
|
for (;; ++guesses) {
|
1997-09-20 18:28:16 +04:00
|
|
|
if ((answer = fgetln(stdin, &len)) == NULL ||
|
|
|
|
answer[len - 1] != '\n') {
|
1993-04-04 14:49:24 +04:00
|
|
|
score(rights, wrongs, guesses);
|
|
|
|
exit(0);
|
|
|
|
}
|
1993-12-22 10:23:27 +03:00
|
|
|
answer[len - 1] = '\0';
|
1993-04-04 14:49:24 +04:00
|
|
|
downcase(answer);
|
|
|
|
if (rxp_match(answer)) {
|
|
|
|
(void)printf("Right!\n");
|
|
|
|
++rights;
|
|
|
|
qp->q_answered = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*answer == '\0') {
|
|
|
|
(void)printf("%s\n", t);
|
|
|
|
++wrongs;
|
|
|
|
if (!tflag)
|
|
|
|
qp->q_answered = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
(void)printf("What?\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
score(rights, wrongs, guesses);
|
|
|
|
}
|
|
|
|
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
const char *
|
1993-04-04 14:49:24 +04:00
|
|
|
next_cat(s)
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
const char * s;
|
1993-04-04 14:49:24 +04:00
|
|
|
{
|
1997-07-06 15:19:16 +04:00
|
|
|
int esc;
|
|
|
|
|
|
|
|
esc = 0;
|
1993-04-04 14:49:24 +04:00
|
|
|
for (;;)
|
|
|
|
switch (*s++) {
|
|
|
|
case '\0':
|
|
|
|
return (NULL);
|
|
|
|
case '\\':
|
1997-07-06 15:19:16 +04:00
|
|
|
esc = 1;
|
1993-04-04 14:49:24 +04:00
|
|
|
break;
|
|
|
|
case ':':
|
1997-07-06 15:19:16 +04:00
|
|
|
if (!esc)
|
|
|
|
return (s);
|
|
|
|
default:
|
|
|
|
esc = 0;
|
|
|
|
break;
|
1993-04-04 14:49:24 +04:00
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
1995-04-22 13:06:33 +04:00
|
|
|
appdstr(s, tp, len)
|
1993-04-04 14:49:24 +04:00
|
|
|
char *s;
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
const char *tp;
|
1995-04-22 13:06:33 +04:00
|
|
|
size_t len;
|
1993-04-04 14:49:24 +04:00
|
|
|
{
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
char *mp;
|
|
|
|
const char *sp;
|
1997-09-20 18:28:16 +04:00
|
|
|
int ch;
|
1993-04-04 14:49:24 +04:00
|
|
|
char *m;
|
|
|
|
|
1995-04-22 13:06:33 +04:00
|
|
|
if ((m = malloc(strlen(s) + len + 1)) == NULL)
|
1997-09-20 18:28:16 +04:00
|
|
|
errx(1, "malloc");
|
1999-09-17 21:07:11 +04:00
|
|
|
for (mp = m, sp = s; (*mp++ = *sp++) != '\0'; )
|
1997-09-20 18:28:16 +04:00
|
|
|
;
|
1995-04-22 13:59:01 +04:00
|
|
|
--mp;
|
1993-04-04 14:49:24 +04:00
|
|
|
if (*(mp - 1) == '\\')
|
|
|
|
--mp;
|
1995-04-22 13:59:01 +04:00
|
|
|
|
1997-09-20 18:28:16 +04:00
|
|
|
while ((ch = *mp++ = *tp++) && ch != '\n')
|
|
|
|
;
|
1993-04-04 14:49:24 +04:00
|
|
|
*mp = '\0';
|
|
|
|
|
|
|
|
free(s);
|
|
|
|
return (m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
score(r, w, g)
|
|
|
|
u_int r, w, g;
|
|
|
|
{
|
|
|
|
(void)printf("Rights %d, wrongs %d,", r, w);
|
|
|
|
if (g)
|
|
|
|
(void)printf(" extra guesses %d,", g);
|
|
|
|
(void)printf(" score %d%%\n", (r + w + g) ? r * 100 / (r + w + g) : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
downcase(p)
|
1997-09-20 18:28:16 +04:00
|
|
|
char *p;
|
1993-04-04 14:49:24 +04:00
|
|
|
{
|
1997-09-20 18:28:16 +04:00
|
|
|
int ch;
|
1993-04-04 14:49:24 +04:00
|
|
|
|
1997-09-20 18:28:16 +04:00
|
|
|
for (; (ch = *p) != '\0'; ++p)
|
1993-04-04 14:49:24 +04:00
|
|
|
if (isascii(ch) && isupper(ch))
|
|
|
|
*p = tolower(ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
(void)fprintf(stderr, "quiz [-t] [-i file] category1 category2\n");
|
|
|
|
exit(1);
|
|
|
|
}
|