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 /*----- Revision history --------------------------------------------------*
32 * Revision 1.1 2002/02/02 19:16:28 mdw
33 * New audio subsystem.
37 /*----- Header files ------------------------------------------------------*/
49 #include <mLib/dstr.h>
53 /*----- Main code ---------------------------------------------------------*/
57 * Arguments: @char x@ = single digit to read
61 * Use: Reads a single digit.
64 static void digit(int x
)
66 static char tagbuf
[4] = "n-?";
73 * Arguments: @const char *p@ = pointer to digits
74 * @size_t n@ = number of digits
78 * Use: Reads a sequence of digits.
81 static void digits(const char *p
, size_t n
)
89 /* --- @lasttwo@ --- *
91 * Arguments: @const char *p@ = pointer to digits
92 * @size_t n@ = number of digits
93 * @unsigned f@ = flags
95 * Returns: Nonzero if the number was nonzero.
97 * Use: Reads out a number of no more than two digits.
102 static int lasttwo(const char *p
, size_t n
, unsigned f
)
104 static char tagbuf
[5] = "n-??";
106 while (n
&& *p
== '0') {
117 else if (*p
== '1') {
131 /* --- @bignum@ --- *
133 * Arguments: @const char *p@ = pointer to digits
134 * @size_t n@ = number of digits
136 * Returns: Nonzero if the number was nonzero.
138 * Use: Reads out a (large) integer in English.
141 static int bignum(const char *p
, size_t n
)
151 rc
= bignum(p
, n
- 3);
169 return (lasttwo(p
, n
, nz ? f_and
: 0) || nz
);
174 * Arguments: @const char *p@ = pointer to number's textual representation
178 * Use: Reads the given number aloud.
181 void aunum(const char *p
)
186 /* --- Pick off a leading sign --- */
191 else if (*p
== '-') {
196 /* --- Work out how many digits we have --- */
199 pl
= strspn(p
, "0123456789");
203 /* --- If the value was zero, and there's no `point', say `zero' --- */
205 if (*p
!= '.' && !nz
)
210 pl
= strspn(p
, "0123456789");
214 if (*p
== 'e' || *p
== 'E') {
220 /* --- Run out of things to do --- */
225 /* --- @aunum_ulong@ --- *
227 * Arguments: @unsigned long n@ = number to be read
231 * Use: Reads a number expressed as an @unsigned long@.
234 void aunum_ulong(unsigned long n
)
238 dstr_putf(&d
, "%lu", n
);
243 /*----- That's all, folks -------------------------------------------------*/