-/* $NetBSD: arithmetic.c,v 1.16 2001/02/05 00:20:58 christos Exp $ */
+/* $NetBSD: arithmetic.c,v 1.25 2009/08/27 00:21:45 dholland Exp $ */
/*
* Copyright (c) 1989, 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) 1989, 1993\n\
- The Regents of the University of California. All rights reserved.\n");
+__COPYRIGHT("@(#) Copyright (c) 1989, 1993\
+ The Regents of the University of California. All rights reserved.");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)arithmetic.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: arithmetic.c,v 1.16 2001/02/05 00:20:58 christos Exp $");
+__RCSID("$NetBSD: arithmetic.c,v 1.25 2009/08/27 00:21:45 dholland Exp $");
#endif
#endif /* not lint */
#include <time.h>
#include <unistd.h>
-int getrandom __P((int, int, int));
-void intr __P((int)) __attribute__((__noreturn__));
-int main __P((int, char *[]));
-int opnum __P((int));
-void penalise __P((int, int, int));
-int problem __P((void));
-void showstats __P((void));
-void usage __P((void)) __attribute__((__noreturn__));
-
-const char keylist[] = "+-x/";
-const char defaultkeys[] = "+-";
-const char *keys = defaultkeys;
-int nkeys = sizeof(defaultkeys) - 1;
-int rangemax = 10;
-int nright, nwrong;
-time_t qtime;
+static int getrandom(int, int, int);
+static void intr(int) __dead;
+static int opnum(int);
+static void penalise(int, int, int);
+static int problem(void);
+static void showstats(int);
+static void usage(void) __dead;
+
+static const char keylist[] = "+-x/";
+static const char defaultkeys[] = "+-";
+static const char *keys = defaultkeys;
+static int nkeys = sizeof(defaultkeys) - 1;
+static int rangemax = 10;
+static int nright, nwrong;
+static time_t qtime;
#define NQUESTS 20
-extern char *__progname; /* from crt0.o */
-
/*
* Select keys from +-x/ to be asked addition, subtraction, multiplication,
* and division problems. More than one key may be given. The default is
* so far are printed.
*/
int
-main(argc, argv)
- int argc;
- char **argv;
+main(int argc, char **argv)
{
int ch, cnt;
for (cnt = NQUESTS; cnt--;)
if (problem() == EOF)
exit(0);
- showstats();
+ showstats(0);
}
/* NOTREACHED */
}
/* Handle interrupt character. Print score and exit. */
-void
+static void
intr(dummy)
- int dummy __attribute__((__unused__));
+ int dummy __unused;
{
- showstats();
+ showstats(1);
exit(0);
}
/* Print score. Original `arithmetic' had a delay after printing it. */
-void
-showstats()
+static void
+showstats(bool_sigint)
+ int bool_sigint;
{
if (nright + nwrong > 0) {
(void)printf("\n\nRights %d; Wrongs %d; Score %d%%",
(void)printf("\nTotal time %ld seconds; %.1f seconds per problem\n\n",
(long)qtime, (float)qtime / nright);
}
+ if(!bool_sigint) {
+ (void)printf("Press RETURN to continue...\n");
+ while(!getchar()) ;
+ }
(void)printf("\n");
}
* answer causes the numbers in the problem to be penalised, so that they are
* more likely to appear in subsequent problems.
*/
-int
+static int
problem()
{
char *p;
(void)printf("\n");
return(EOF);
}
- for (p = line; *p && isspace(*p); ++p);
- if (!isdigit(*p)) {
+ for (p = line; *p && isspace((unsigned char)*p); ++p);
+ if (!isdigit((unsigned char)*p)) {
(void)printf("Please type a number.\n");
continue;
}
* penalties themselves.
*/
-int penalty[sizeof(keylist) - 1][2];
-struct penalty {
+static int penalty[sizeof(keylist) - 1][2];
+static struct penalty {
int value, penalty; /* Penalised value and its penalty. */
struct penalty *next;
} *penlist[sizeof(keylist) - 1][2];
* operand number `operand' (0 or 1). If we run out of memory, we just
* forget about the penalty (how likely is this, anyway?).
*/
-void
+static void
penalise(value, op, operand)
int value, op, operand;
{
struct penalty *p;
op = opnum(op);
- if ((p = (struct penalty *)malloc((u_int)sizeof(*p))) == NULL)
+ if ((p = malloc(sizeof(*p))) == NULL)
return;
p->next = penlist[op][operand];
penlist[op][operand] = p;
* as a value, or represents a position in the penalty list. If the latter,
* we find the corresponding value and return that, decreasing its penalty.
*/
-int
+static int
getrandom(maxval, op, operand)
int maxval, op, operand;
{
}
/* Return an index for the character op, which is one of [+-x/]. */
-int
+static int
opnum(op)
int op;
{
}
/* Print usage message and quit. */
-void
+static void
usage()
{
(void)fprintf(stderr, "Usage: %s [-o +-x/] [-r range]\n",
- __progname);
+ getprogname());
exit(1);
}