X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/5291c642e33577c5d349d5104aa04bec925c15bc..0aa54da72125ab6eec1f8dd721546f109aa6df70:/arithmetic/arithmetic.c

diff --git a/arithmetic/arithmetic.c b/arithmetic/arithmetic.c
index 03e00106..696208c6 100644
--- a/arithmetic/arithmetic.c
+++ b/arithmetic/arithmetic.c
@@ -1,4 +1,4 @@
-/*	$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
@@ -15,11 +15,7 @@
  * 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.
  *
@@ -38,15 +34,15 @@
 
 #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 */
 
@@ -88,26 +84,23 @@ __RCSID("$NetBSD: arithmetic.c,v 1.16 2001/02/05 00:20:58 christos Exp $");
 #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
@@ -116,9 +109,7 @@ extern char *__progname;	/* from crt0.o */
  * so far are printed.
  */
 int
-main(argc, argv)
-	int argc;
-	char **argv;
+main(int argc, char **argv)
 {
 	int ch, cnt;
 
@@ -157,23 +148,24 @@ main(argc, argv)
 		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%%",
@@ -182,6 +174,10 @@ showstats()
 	(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");
 }
 
@@ -193,7 +189,7 @@ showstats()
  * 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;
@@ -247,8 +243,8 @@ retry:
 			(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;
 		}
@@ -293,8 +289,8 @@ retry:
  * 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];
@@ -306,14 +302,14 @@ struct penalty {
  * 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;
@@ -327,7 +323,7 @@ penalise(value, op, operand)
  * 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;
 {
@@ -372,7 +368,7 @@ getrandom(maxval, op, operand)
 }
 
 /* Return an index for the character op, which is one of [+-x/]. */
-int
+static int
 opnum(op)
 	int op;
 {
@@ -385,10 +381,10 @@ opnum(op)
 }
 
 /* Print usage message and quit. */
-void
+static void
 usage()
 {
 	(void)fprintf(stderr, "Usage: %s [-o +-x/] [-r range]\n",
-		__progname);
+		getprogname());
 	exit(1);
 }