3 * $Id: aunum.c,v 1.1 2002/02/02 19:16:28 mdw Exp $
5 * Reading numbers to audio output
7 * (c) 2002 Mark Wooding
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Jog: Programming for a jogging machine.
14 * Jog is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * Jog is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Jog; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Header files ------------------------------------------------------*/
41 #include <mLib/dstr.h>
45 /*----- Main code ---------------------------------------------------------*/
49 * Arguments: @char x@ = single digit to read
53 * Use: Reads a single digit.
56 static void digit(int x)
58 static char tagbuf[4] = "n-?";
65 * Arguments: @const char *p@ = pointer to digits
66 * @size_t n@ = number of digits
70 * Use: Reads a sequence of digits.
73 static void digits(const char *p, size_t n)
81 /* --- @lasttwo@ --- *
83 * Arguments: @const char *p@ = pointer to digits
84 * @size_t n@ = number of digits
85 * @unsigned f@ = flags
87 * Returns: Nonzero if the number was nonzero.
89 * Use: Reads out a number of no more than two digits.
94 static int lasttwo(const char *p, size_t n, unsigned f)
96 static char tagbuf[5] = "n-??";
98 while (n && *p == '0') {
109 else if (*p == '1') {
123 /* --- @bignum@ --- *
125 * Arguments: @const char *p@ = pointer to digits
126 * @size_t n@ = number of digits
128 * Returns: Nonzero if the number was nonzero.
130 * Use: Reads out a (large) integer in English.
133 static int bignum(const char *p, size_t n)
143 rc = bignum(p, n - 3);
161 return (lasttwo(p, n, nz ? f_and : 0) || nz);
166 * Arguments: @const char *p@ = pointer to number's textual representation
170 * Use: Reads the given number aloud.
173 void aunum(const char *p)
178 /* --- Pick off a leading sign --- */
183 else if (*p == '-') {
188 /* --- Work out how many digits we have --- */
191 pl = strspn(p, "0123456789");
195 /* --- If the value was zero, and there's no `point', say `zero' --- */
197 if (*p != '.' && !nz)
202 pl = strspn(p, "0123456789");
206 if (*p == 'e' || *p == 'E') {
212 /* --- Run out of things to do --- */
217 /* --- @aunum_ulong@ --- *
219 * Arguments: @unsigned long n@ = number to be read
223 * Use: Reads a number expressed as an @unsigned long@.
226 void aunum_ulong(unsigned long n)
230 dstr_putf(&d, "%lu", n);
235 /*----- That's all, folks -------------------------------------------------*/