-/* $NetBSD: number.c,v 1.5 1997/10/10 16:41:43 lukem Exp $ */
+/* $NetBSD: number.c,v 1.16 2014/03/23 00:03:04 dholland Exp $ */
/*
* Copyright (c) 1988, 1993, 1994
* 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) 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.3 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: number.c,v 1.5 1997/10/10 16:41:43 lukem Exp $");
+__RCSID("$NetBSD: number.c,v 1.16 2014/03/23 00:03:04 dholland Exp $");
#endif
#endif /* not lint */
#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",
"novemdecillion", "vigintillion",
};
-void convert __P((char *));
-int main __P((int, 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 *, size_t);
+static void pfract(size_t);
+static int unit(size_t, 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];
}
void
-convert(line)
- char *line;
+convert(char *line)
{
- int flen, len, rval;
+ size_t flen, len;
+ int 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 '.':
if (*line == '-') {
(void)printf("minus%s", lflag ? " " : "\n");
++line;
+ --len;
}
rval = len > 0 ? unit(len, line) : 0;
}
int
-unit(len, p)
- int len;
- char *p;
+unit(size_t len, const char *p)
{
- int off, rval;
+ size_t off;
+ int rval;
rval = 0;
if (len > 3) {
}
int
-number(p, len)
- char *p;
- int len;
+number(const char *p, size_t len)
{
int val, rval;
}
void
-pfract(len)
- int len;
+pfract(size_t len)
{
- static char *pref[] = { "", "ten-", "hundred-" };
+ static const char *const pref[] = { "", "ten-", "hundred-" };
switch(len) {
case 1:
}
void
-usage()
+usage(void)
{
(void)fprintf(stderr, "usage: number [# ...]\n");
exit(1);