X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/eb97288b64a4f39e9d0b328aa16a6fd4c657c0e0..3671521369575bb3ac1f1d35852f4f333e0fa288:/arithmetic/arithmetic.c diff --git a/arithmetic/arithmetic.c b/arithmetic/arithmetic.c index 29ffcb99..876153a9 100644 --- a/arithmetic/arithmetic.c +++ b/arithmetic/arithmetic.c @@ -1,4 +1,4 @@ -/* $NetBSD: arithmetic.c,v 1.9 1997/10/15 08:53:24 is Exp $ */ +/* $NetBSD: arithmetic.c,v 1.18 2002/03/31 04:07:22 hubertf Exp $ */ /* * Copyright (c) 1989, 1993 @@ -46,7 +46,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\ #if 0 static char sccsid[] = "@(#)arithmetic.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: arithmetic.c,v 1.9 1997/10/15 08:53:24 is Exp $"); +__RCSID("$NetBSD: arithmetic.c,v 1.18 2002/03/31 04:07:22 hubertf Exp $"); #endif #endif /* not lint */ @@ -86,19 +86,20 @@ __RCSID("$NetBSD: arithmetic.c,v 1.9 1997/10/15 08:53:24 is Exp $"); #include #include #include +#include int getrandom __P((int, int, int)); -void intr __P((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)); +void showstats __P((int)); +void usage __P((void)) __attribute__((__noreturn__)); -char keylist[] = "+-x/"; -char defaultkeys[] = "+-"; -char *keys = defaultkeys; +const char keylist[] = "+-x/"; +const char defaultkeys[] = "+-"; +const char *keys = defaultkeys; int nkeys = sizeof(defaultkeys) - 1; int rangemax = 10; int nright, nwrong; @@ -117,14 +118,15 @@ main(argc, argv) int argc; char **argv; { - extern char *optarg; - extern int optind; int ch, cnt; + /* Revoke setgid privileges */ + setgid(getgid()); + while ((ch = getopt(argc, argv, "r:o:")) != -1) switch(ch) { case 'o': { - char *p; + const char *p; for (p = keys = optarg; *p; ++p) if (!strchr(keylist, *p)) @@ -153,7 +155,7 @@ main(argc, argv) for (cnt = NQUESTS; cnt--;) if (problem() == EOF) exit(0); - showstats(); + showstats(0); } /* NOTREACHED */ } @@ -161,15 +163,16 @@ main(argc, argv) /* Handle interrupt character. Print score and exit. */ void intr(dummy) - int dummy; + int dummy __attribute__((__unused__)); { - showstats(); + showstats(1); exit(0); } /* Print score. Original `arithmetic' had a delay after printing it. */ void -showstats() +showstats(bool_sigint) + int bool_sigint; { if (nright + nwrong > 0) { (void)printf("\n\nRights %d; Wrongs %d; Score %d%%", @@ -178,6 +181,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"); } @@ -384,9 +391,7 @@ opnum(op) void usage() { - extern char *__progname; /* from crt0.o */ - - (void)fprintf(stderr, "usage: %s [-o +-x/] [-r range]\n", - __progname); + (void)fprintf(stderr, "Usage: %s [-o +-x/] [-r range]\n", + getprogname()); exit(1); }