Subject: [malcolm.parsons@virgin.net: bsdgames: number claims English output, but outputs in American]
To: None <tech-userlevel@netbsd.org>
From: Malcolm Parsons <malcolm.parsons@virgin.net>
List: tech-userlevel
Date: 11/08/2003 12:31:09
--pWyiEgJYm5f9v55/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline


I've attached debian bug report #219666, and an email from Joseph Myers
asking questions about the correct way too fix it.

What does NetBSD think is the correct fix for this bug?

Thanks,

Malcolm Parsons

--pWyiEgJYm5f9v55/
Content-Type: message/rfc822
Content-Disposition: inline

Return-path: <malcolm.parsons@virgin.net>
Envelope-to: malcolm@localhost
Delivery-date: Fri, 07 Nov 2003 23:16:46 +0000
	by localhost with esmtp (Exim 3.36 #1 (Debian))
	id 1AIFqQ-0001Wi-00
	for <malcolm@localhost>; Fri, 07 Nov 2003 23:16:46 +0000
	by localhost with POP3 (fetchmail-6.2.4)
	for malcolm@localhost (single-drop); Fri, 07 Nov 2003 23:16:46 +0000 (GMT)
          by mta2-svc.business.ntl.com
          (InterMail vM.4.01.03.37 201-229-121-137-20020806) with ESMTP
          id <20031107231518.HVH28456.mta2-svc.business.ntl.com@smtp-out5.blueyonder.co.uk>
          for <malcolm.parsons@virgin.net>; Fri, 7 Nov 2003 23:15:18 +0000
	 Fri, 7 Nov 2003 23:15:19 +0000
	id 1AIFov-0001UG-00; Fri, 07 Nov 2003 23:15:13 +0000
Date: Fri, 7 Nov 2003 23:15:13 +0000
From: Malcolm Parsons <malcolm.parsons@virgin.net>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: bsdgames: number claims English output, but outputs in American
Message-ID: <20031107231513.GA5445@ivywell.screaming.net>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="fdj2RfSjLxBAspz7"
Content-Disposition: inline
User-Agent: Mutt/1.5.4i


--fdj2RfSjLxBAspz7
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Package: bsdgames
Version: 2.14-8
Severity: normal

The manpage for number states:

      number - convert Arabic numerals to English

Well it doesn't:

malcolm@arthur:~$ number 1000000000
one billion.

The attached patch adds a -e option to number that changes the output
into English:

malcolm@arthur:~$ number -e 1000000000
one thousand.
million.

Also added support for googol:

malcolm@arthur:~$ number -le 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
one googol 

I've updated the manpage and testsuite.

-- System Information:
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux arthur 2.4.22eth #1 Thu Oct 23 16:31:44 BST 2003 i686
Locale: LANG=C, LC_CTYPE=C

Versions of packages bsdgames depends on:
ii  libc6                     2.3.2.ds1-10   GNU C Library: Shared libraries an
ii  libncurses5               5.3.20030719-3 Shared libraries for terminal hand
ii  wamerican [wordlist]      5-3            American English dictionary words 
ii  wbritish-large [wordlist] 5-3            British English dictionary words f

-- no debconf information


--fdj2RfSjLxBAspz7
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="english_number.patch"

diff -ruN orig/bsdgames-2.14/number/number.6 bsdgames-2.14/number/number.6
--- orig/bsdgames-2.14/number/number.6	2002-01-19 23:53:10.000000000 +0000
+++ bsdgames-2.14/number/number.6	2003-11-07 22:54:35.000000000 +0000
@@ -38,7 +38,7 @@
 .Os
 .Sh NAME
 .Nm number
-.Nd convert Arabic numerals to English
+.Nd convert Arabic numerals to American or English
 .Sh SYNOPSIS
 .Nm
 .Op Fl l
@@ -46,7 +46,7 @@
 .Sh DESCRIPTION
 The
 .Nm
-utility prints the English equivalent of the number to the standard
+utility prints the American or English equivalent of the number to the standard
 output, with each 10^3 magnitude displayed on a separate line.
 If no argument is specified,
 .Nm
@@ -54,6 +54,8 @@
 .Pp
 The options are as follows:
 .Bl -tag -width Ds
+.It Fl e
+Display the number in English.
 .It Fl l
 Display the number on a single line.
 .El
diff -ruN orig/bsdgames-2.14/number/number.c bsdgames-2.14/number/number.c
--- orig/bsdgames-2.14/number/number.c	1999-09-15 11:34:31.000000000 +0100
+++ bsdgames-2.14/number/number.c	2003-11-07 23:07:16.000000000 +0000
@@ -56,7 +56,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#define	MAXNUM		65		/* Biggest number we handle. */
+#define	MAXNUM		(eflag ? 126 : 65 )		/* Biggest number we handle. */
 
 static const char	*const name1[] = {
 	"",		"one",		"two",		"three",
@@ -78,16 +78,28 @@
 	"quindecillion",		"sexdecillion",	
 	"septendecillion",		"octodecillion",
 	"novemdecillion",		"vigintillion",
+},
+		*const name4[] = {
+	"hundred",	"thousand",	"million",	"thousand",
+	"billion",	"thousand",	"trillion",	"thousand",
+        "quadrillion",	"thousand",	"quintillion",	"thousand",
+        "sextillion",	"thousand",	"septillion",	"thousand",
+        "octillion",	"thousand",	"nonillion",	"thousand",
+        "decillion",	"thousand",	"undecillion",	"thousand",
+        "duodecillion",	"thousand",	"tredecillion",	"thousand",
+        "quattuordecillion",	"thousand",	"quindecillion",	
+        "thousand",        "sexdecillion",	"thousand"
 };
 
 void	convert __P((char *));
 int	main __P((int, char *[]));
-int	number __P((const char *, int));
+int	number __P((const char *, int, int));
 void	pfract __P((int));
 int	unit __P((int, const char *));
 void	usage __P((void)) __attribute__((__noreturn__));
 
 int lflag;
+int eflag;
 
 int
 main(argc, argv)
@@ -101,8 +113,12 @@
 	setregid(getgid(), getgid());
 
 	lflag = 0;
-	while ((ch = getopt(argc, argv, "l")) != -1)
+	eflag = 0;
+	while ((ch = getopt(argc, argv, "el")) != -1)
 		switch (ch) {
+		case 'e':
+			eflag = 1;
+			break;
 		case 'l':
 			lflag = 1;
 			break;
@@ -178,7 +194,18 @@
 		--len;
 	}
 
-	rval = len > 0 ? unit(len, line) : 0;
+	if (len > 100)
+	{
+		rval = unit(len-100, line);
+		printf("%sgoogol%s", lflag ? " " : "", lflag ? " " : ".\n");
+		line += len - 100 ;
+		len = 100 ;
+		unit(len, line);
+	}
+	else
+	{
+		rval = len > 0 ? unit(len, line) : 0;
+	}
 	if (fraction != NULL && flen != 0)
 		for (p = fraction; *p != '\0'; ++p)
 			if (*p != '0') {
@@ -205,30 +232,42 @@
 	int len;
 	const char *p;
 {
-	int off, rval;
+	int off, rval, cval;
 
 	rval = 0;
+	cval = 0;
 	if (len > 3) {
 		if (len % 3) {
 			off = len % 3;
 			len -= off;
-			if (number(p, off)) {
+			if (number(p, off, cval)) {
 				rval = 1;
+				cval = (len / 3) % 2;
 				(void)printf(" %s%s",
-				    name3[len / 3], lflag ? " " : ".\n");
+					     (eflag ? name4 : name3)[len / 3],
+					     lflag ? " " : ".\n");
 			}
 			p += off;
 		}
 		for (; len > 3; p += 3) {
 			len -= 3;
-			if (number(p, 3)) {
+			if (number(p, 3, cval)) {
 				rval = 1;
+				cval = (len / 3) % 2;
 				(void)printf(" %s%s",
-				    name3[len / 3], lflag ? " " : ".\n");
+					     (eflag ? name4 : name3)[len / 3],
+					     lflag ? " " : ".\n");
+			}
+			else 
+			{
+				if (cval && eflag) 
+					(void)printf("%s%s",
+						     name4[len / 3], lflag ? " " : ".\n");
+				cval = 0;
 			}
 		}
 	}
-	if (number(p, len)) {
+	if (number(p, len, rval)) {
 		if (!lflag)
 			(void)printf(".\n");
 		rval = 1;
@@ -237,9 +276,10 @@
 }
 
 int
-number(p, len)
+number(p, len, cval)
 	const char *p;
 	int len;
+    int cval;
 {
 	int val, rval;
 
@@ -256,13 +296,27 @@
 		val = (p[1] - '0') + (p[0] - '0') * 10;
 		if (val) {
 			if (rval)
-				(void)printf(" ");
+            {
+                if (eflag)
+                    (void)printf(" and ");
+                else
+                    (void)printf(" ");
+            }
+            else if ( cval && eflag)
+            {
+                (void)printf("and ");
+            }
 			if (val < 20)
 				(void)printf("%s", name1[val]);
 			else {
 				(void)printf("%s", name2[val / 10]);
 				if (val % 10)
-					(void)printf("-%s", name1[val % 10]);
+                {
+                    if (eflag)
+                        (void)printf(" %s", name1[val % 10]);
+                    else
+                        (void)printf("-%s", name1[val % 10]);
+                }
 			}
 			rval = 1;
 		}
@@ -290,7 +344,7 @@
 		(void)printf("hundredths.\n");
 		break;
 	default:
-		(void)printf("%s%sths.\n", pref[len % 3], name3[len / 3]);
+		(void)printf("%s%sths.\n", pref[len % 3], (eflag ? name4 : name3)[len / 3]);
 		break;
 	}
 }
diff -ruN orig/bsdgames-2.14/tests/number.e.1000000000 bsdgames-2.14/tests/number.e.1000000000
--- orig/bsdgames-2.14/tests/number.e.1000000000	1970-01-01 01:00:00.000000000 +0100
+++ bsdgames-2.14/tests/number.e.1000000000	2003-11-07 22:02:10.000000000 +0000
@@ -0,0 +1,2 @@
+one thousand.
+million.
diff -ruN orig/bsdgames-2.14/tests/number.e.1000000001 bsdgames-2.14/tests/number.e.1000000001
--- orig/bsdgames-2.14/tests/number.e.1000000001	1970-01-01 01:00:00.000000000 +0100
+++ bsdgames-2.14/tests/number.e.1000000001	2003-11-07 22:03:08.000000000 +0000
@@ -0,0 +1,3 @@
+one thousand.
+million.
+and one.
diff -ruN orig/bsdgames-2.14/tests/number.e.1015023 bsdgames-2.14/tests/number.e.1015023
--- orig/bsdgames-2.14/tests/number.e.1015023	1970-01-01 01:00:00.000000000 +0100
+++ bsdgames-2.14/tests/number.e.1015023	2003-11-07 22:15:38.000000000 +0000
@@ -0,0 +1,3 @@
+one million.
+fifteen thousand.
+and twenty three.
diff -ruN orig/bsdgames-2.14/tests/number.e.7015023045078034006 bsdgames-2.14/tests/number.e.7015023045078034006
--- orig/bsdgames-2.14/tests/number.e.7015023045078034006	1970-01-01 01:00:00.000000000 +0100
+++ bsdgames-2.14/tests/number.e.7015023045078034006	2003-11-07 22:24:28.000000000 +0000
@@ -0,0 +1 @@
+seven trillion fifteen thousand and twenty three billion forty five thousand and seventy eight million thirty four thousand and six
diff -ruN orig/bsdgames-2.14/tests/number.e.987654321 bsdgames-2.14/tests/number.e.987654321
--- orig/bsdgames-2.14/tests/number.e.987654321	1970-01-01 01:00:00.000000000 +0100
+++ bsdgames-2.14/tests/number.e.987654321	2003-11-07 22:14:10.000000000 +0000
@@ -0,0 +1,4 @@
+nine thousand.
+eight hundred and seventy six million.
+five hundred and forty three thousand.
+three hundred and twenty one.
diff -ruN orig/bsdgames-2.14/tests/number.e.googol bsdgames-2.14/tests/number.e.googol
--- orig/bsdgames-2.14/tests/number.e.googol	1970-01-01 01:00:00.000000000 +0100
+++ bsdgames-2.14/tests/number.e.googol	2003-11-07 23:11:00.000000000 +0000
@@ -0,0 +1 @@
+one googol 
diff -ruN orig/bsdgames-2.14/tests/number.e.more_googol bsdgames-2.14/tests/number.e.more_googol
--- orig/bsdgames-2.14/tests/number.e.more_googol	1970-01-01 01:00:00.000000000 +0100
+++ bsdgames-2.14/tests/number.e.more_googol	2003-11-07 23:08:52.000000000 +0000
@@ -0,0 +1,38 @@
+twelve million.
+three hundred and forty five thousand.
+six hundred and seventy eight.
+googol.
+nine thousand.
+and twelve sexdecillion.
+three hundred and forty five thousand.
+six hundred and seventy eight quindecillion.
+nine hundred and one thousand.
+two hundred and thirty four quattuordecillion.
+five hundred and sixty seven thousand.
+eight hundred and ninety tredecillion.
+one hundred and twenty three thousand.
+four hundred and fifty six duodecillion.
+seven hundred and eighty nine thousand.
+and twelve undecillion.
+three hundred and forty five thousand.
+six hundred and seventy eight decillion.
+nine hundred and one thousand.
+two hundred and thirty four nonillion.
+five hundred and sixty seven thousand.
+eight hundred and ninety octillion.
+one hundred and twenty three thousand.
+four hundred and fifty six septillion.
+seven hundred and eighty nine thousand.
+and twelve sextillion.
+three hundred and forty five thousand.
+six hundred and seventy eight quintillion.
+nine hundred and one thousand.
+two hundred and thirty four quadrillion.
+five hundred and sixty seven thousand.
+eight hundred and ninety trillion.
+one hundred and twenty three thousand.
+four hundred and fifty six billion.
+seven hundred and eighty nine thousand.
+and twelve million.
+three hundred and forty five thousand.
+six hundred and seventy eight.
diff -ruN orig/bsdgames-2.14/tests/number.test bsdgames-2.14/tests/number.test
--- orig/bsdgames-2.14/tests/number.test	1999-09-15 11:34:31.000000000 +0100
+++ bsdgames-2.14/tests/number.test	2003-11-07 23:09:20.000000000 +0000
@@ -47,3 +47,39 @@
 number/number -- 987654321 >test.out 2>&1 || failtest
 compare test.out tests/number.987654321
 rm -f test.out
+
+testno 4
+number/number -e -- 1000000000 >test.out 2>&1 || failtest
+compare test.out tests/number.e.1000000000
+rm -f test.out
+
+testno 5
+number/number -e -- 1000000001 >test.out 2>&1 || failtest
+compare test.out tests/number.e.1000000001
+rm -f test.out
+
+testno 6
+number/number -e -- 9876543321 >test.out 2>&1 || failtest
+compare test.out tests/number.e.987654321
+rm -f test.out
+
+testno 7
+number/number -e -- 1015023 >test.out 2>&1 || failtest
+compare test.out tests/number.e.1015023
+rm -f test.out
+
+testno 8
+number/number -el -- 7015023045078034006 >test.out 2>&1 || failtest
+compare test.out tests/number.e.7015023045078034006 
+rm -f test.out
+
+testno 9
+number/number -le -- 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 >test.out 2>&1 || failtest
+compare test.out tests/number.e.googol 
+rm -f test.out
+
+testno 10
+number/number -e -- 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678 >test.out 2>&1 || failtest
+compare test.out tests/number.e.more_googol 
+rm -f test.out
+

--fdj2RfSjLxBAspz7--

--pWyiEgJYm5f9v55/
Content-Type: message/rfc822
Content-Disposition: inline

Return-path: <jsm@polyomino.org.uk>
Envelope-to: malcolm@localhost
Delivery-date: Sat, 08 Nov 2003 10:58:53 +0000
	by localhost with esmtp (Exim 3.36 #1 (Debian))
	id 1AIQnt-0001on-00
	for <malcolm@localhost>; Sat, 08 Nov 2003 10:58:53 +0000
	by localhost with POP3 (fetchmail-6.2.4)
	for malcolm@localhost (single-drop); Sat, 08 Nov 2003 10:58:53 +0000 (GMT)
          by mta5-svc.business.ntl.com
          (InterMail vM.4.01.03.37 201-229-121-137-20020806) with SMTP
          id <20031108105702.JBNX285.mta5-svc.business.ntl.com@lon-mail-1.gradwell.net>
          for <malcolm.parsons@virgin.net>; Sat, 8 Nov 2003 10:57:02 +0000
  by lon-mail-1.gradwell.net with SMTP; 8 Nov 2003 10:57:02 -0000
	by digraph.polyomino.org.uk with local-esmtp (Exim 4.24)
	id 1AIQm6-000325-1F
	for malcolm.parsons@virgin.net; Sat, 08 Nov 2003 10:57:02 +0000
Date: Sat, 8 Nov 2003 10:57:01 +0000 (UTC)
From: "Joseph S. Myers" <jsm@polyomino.org.uk>
To: Malcolm Parsons <malcolm.parsons@virgin.net>
Subject: Re: [malcolm.parsons@virgin.net: bsdgames: number claims English
 output, but outputs in American]
In-Reply-To: <20031108092246.GA28909@ivywell.screaming.net>
Message-ID: <Pine.LNX.4.58.0311081045390.11599@digraph.polyomino.org.uk>
References: <20031108092246.GA28909@ivywell.screaming.net>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Sender: "Joseph S. Myers" <jsm@polyomino.org.uk>

On Sat, 8 Nov 2003, Malcolm Parsons wrote:

> Joey Hess said I should "Feel free to pester upstream about this".
> 
> So I am.

So I'll say the same :-).  Pester tech-userlevel@netbsd.org, upstream of
me.  The right approach clearly is to use the locale (I think LC_MESSAGES
rather than LC_NUMERIC) to determine the language output, i.e. this would
depend on en_US vs. en_GB, rather than adding ad hoc command-line options
for particular language output.  But though I wouldn't see any need for
you to implement further languages beyond those two to get this feature
in, some sort of general design would need to be agreed for generally
implementing multiple languages.  How would you avoid problems with
multiple character sets in the source file?  How would you deal with the
same language being usable in multiple character sets (e.g.
fr_FR.ISO-8859-15 or fr_FR.UTF-8)?  What variant do you choose when only
the language (en) but no location is specified, or where a location
without specific implementation is specified (en_AU)?  (Discuss these
questions with tech-userlevel, not with me.  In this sort of case it's
NetBSD that needs to agree on what is the Right Way to do things; I
wouldn't try to maintain this sort of thing as a large unmerged patch or
operate as an intermediary in rehashing the design.)

> Also, my email address has changed, could you update the THANKS
> file please.

Done.

-- 
Joseph S. Myers
jsm@polyomino.org.uk

--pWyiEgJYm5f9v55/--