X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/94b5353c71e7246077d468afe68d51ce85fc213d..c2997b6e22cfa183e7e73501ecdb2d5020434c9a:/number/number.c?ds=sidebyside diff --git a/number/number.c b/number/number.c index 509f0125..5cf41705 100644 --- a/number/number.c +++ b/number/number.c @@ -1,4 +1,4 @@ -/* $NetBSD: number.c,v 1.3 1995/03/23 08:35:30 cgd Exp $ */ +/* $NetBSD: number.c,v 1.15 2012/06/19 05:46:09 dholland Exp $ */ /* * Copyright (c) 1988, 1993, 1994 @@ -12,11 +12,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. * @@ -33,43 +29,44 @@ * SUCH DAMAGE. */ +#include #ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1988, 1993, 1994\n\ - The Regents of the University of California. All rights reserved.\n"; +__COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\ + The Regents of the University of California. All rights reserved."); #endif /* not lint */ #ifndef lint #if 0 -static char sccsid[] = "@(#)number.c 8.2 (Berkeley) 3/31/94"; +static char sccsid[] = "@(#)number.c 8.3 (Berkeley) 5/4/95"; #else -static char rcsid[] = "$NetBSD: number.c,v 1.3 1995/03/23 08:35:30 cgd Exp $"; +__RCSID("$NetBSD: number.c,v 1.15 2012/06/19 05:46:09 dholland Exp $"); #endif #endif /* not lint */ #include #include +#include #include #include #include -#include +#include #define MAXNUM 65 /* Biggest number we handle. */ -static char *name1[] = { +static const char *const name1[] = { "", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", }, - *name2[] = { + *const name2[] = { "", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety", }, - *name3[] = { + *const name3[] = { "hundred", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion", "septillion", "octillion", "nonillion", "decillion", @@ -79,25 +76,23 @@ static char *name1[] = { "novemdecillion", "vigintillion", }; -void convert __P((char *)); -int number __P((char *, int)); -void pfract __P((int)); -void toobig __P((void)); -int unit __P((int, char *)); -void usage __P((void)); +int main(int, char *[]); +static void convert(char *); +static int number(const char *, int); +static void pfract(int); +static int unit(int, const char *); +static void usage(void) __dead; -int lflag; +static int lflag; int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { int ch, first; char line[256]; lflag = 0; - while ((ch = getopt(argc, argv, "l")) != EOF) + while ((ch = getopt(argc, argv, "l")) != -1) switch (ch) { case 'l': lflag = 1; @@ -128,22 +123,22 @@ main(argc, argv) } void -convert(line) - char *line; +convert(char *line) { - register flen, len, rval; - register char *p, *fraction; + int flen, len, rval; + char *p, *fraction; + flen = 0; fraction = NULL; for (p = line; *p != '\0' && *p != '\n'; ++p) { - if (isblank(*p)) { + if (isblank((unsigned char)*p)) { if (p == line) { ++line; continue; } goto badnum; } - if (isdigit(*p)) + if (isdigit((unsigned char)*p)) continue; switch (*p) { case '.': @@ -164,12 +159,13 @@ badnum: errx(1, "illegal number: %s", line); *p = '\0'; if ((len = strlen(line)) > MAXNUM || - fraction != NULL && (flen = strlen(fraction)) > MAXNUM) + (fraction != NULL && (flen = strlen(fraction)) > MAXNUM)) errx(1, "number too large, max %d digits.", MAXNUM); if (*line == '-') { (void)printf("minus%s", lflag ? " " : "\n"); ++line; + --len; } rval = len > 0 ? unit(len, line) : 0; @@ -195,11 +191,9 @@ badnum: errx(1, "illegal number: %s", line); } int -unit(len, p) - register int len; - register char *p; +unit(int len, const char *p) { - register int off, rval; + int off, rval; rval = 0; if (len > 3) { @@ -231,11 +225,9 @@ unit(len, p) } int -number(p, len) - register char *p; - int len; +number(const char *p, int len) { - register int val, rval; + int val, rval; rval = 0; switch (len) { @@ -271,10 +263,9 @@ number(p, len) } void -pfract(len) - int len; +pfract(int len) { - static char *pref[] = { "", "ten-", "hundred-" }; + static const char *const pref[] = { "", "ten-", "hundred-" }; switch(len) { case 1: @@ -290,7 +281,7 @@ pfract(len) } void -usage() +usage(void) { (void)fprintf(stderr, "usage: number [# ...]\n"); exit(1);