-/* $NetBSD: quiz.c,v 1.13 1998/09/13 15:27:29 hubertf Exp $ */
+/* $NetBSD: quiz.c,v 1.23 2008/07/20 01:03:22 lukem Exp $ */
/*-
* Copyright (c) 1991, 1993
* 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.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
#include <sys/cdefs.h>
#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1991, 1993\n\
- The Regents of the University of California. All rights reserved.\n");
+__COPYRIGHT("@(#) Copyright (c) 1991, 1993\
+ The Regents of the University of California. All rights reserved.");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)quiz.c 8.3 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: quiz.c,v 1.13 1998/09/13 15:27:29 hubertf Exp $");
+__RCSID("$NetBSD: quiz.c,v 1.23 2008/07/20 01:03:22 lukem Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
#include <err.h>
#include <time.h>
#include <unistd.h>
static int catone, cattwo, tflag;
static u_int qsize;
-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));
-void show_index __P((void));
-void usage __P((void)) __attribute__((__noreturn__));
+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) __dead;
int
main(argc, argv)
char *argv[];
{
int ch;
- char *indexfile;
+ const char *indexfile;
+
+ /* Revoke setgid privileges */
+ setgid(getgid());
indexfile = _PATH_QUIZIDX;
while ((ch = getopt(argc, argv, "i:t")) != -1)
void
get_file(file)
- char *file;
+ const char *file;
{
FILE *fp;
QE *qp;
show_index()
{
QE *qp;
- char *p, *s;
+ const char *p, *s;
FILE *pf;
+ const char *pager;
- if ((pf = popen(_PATH_PAGER, "w")) == NULL)
- err(1, "%s", _PATH_PAGER);
+ 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);
(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)) {
{
QE *qp;
int i;
- char *s;
+ const char *s;
downcase(cat1);
downcase(cat2);
size_t len;
u_int guesses, rights, wrongs;
int next;
- char *answer, *s, *t, question[LINE_SZ];
+ char *answer, *t, question[LINE_SZ];
+ const char *s;
srandom(time(NULL));
guesses = rights = wrongs = 0;
score(rights, wrongs, guesses);
}
-char *
+const char *
next_cat(s)
- char * s;
+ const char * s;
{
int esc;
char *
appdstr(s, tp, len)
char *s;
- char *tp;
+ const char *tp;
size_t len;
{
- char *mp, *sp;
+ char *mp;
+ const char *sp;
int ch;
char *m;
if ((m = malloc(strlen(s) + len + 1)) == NULL)
errx(1, "malloc");
- for (mp = m, sp = s; (*mp++ = *sp++) != NULL; )
+ for (mp = m, sp = s; (*mp++ = *sp++) != '\0'; )
;
--mp;
if (*(mp - 1) == '\\')