1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*
* Number base pronounciation rules and special cases.
* $Id: number.c 1.2 Mon, 24 Mar 1997 12:25:37 -0500 dyfet $
* Copyright (c) 1997 by Tycho Softworks.
* For conditions of distribution and reuse see product license.
*/
#include <other/string.h>
#include <other/config.h>
#include "speak.h"
static char *nteen[] = {
"ten", "eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
static char *n10[] = {
"zero", "ten", "twenty", "thirty", "fourty",
"fifty", "sixty", "seventy", "eighty", "ninety"};
static void digits(long value)
{
bool hundred = FALSE;
char buf[2];
if(value >= 100)
{
digits(value / 100);
spo_word("hundred");
value %= 100;
hundred = TRUE;
}
if(!value && hundred)
return;
if(value >= 20)
{
spo_word(n10[value / 10]);
value %= 10;
if(!value)
return;
}
if(value < 10)
{
buf[0] = value + '0';
buf[1] = 0;
spo_word(buf);
return;
}
spo_word(nteen[value - 10]);
}
void number(char *str)
{
char *p;
long value = atol(str);
if(lit || spell)
{
spo_word(str);
return;
}
/* Check for w.x.y.z as "w dot x dot y dot z" */
if(ccount(str, ".") > 1)
{
while(NULL != (p = strchr(str, '.')))
{
*(p++) = 0;
number(str);
str = p;
}
number(str);
return;
}
if(NULL != (p = strchr(str, '.')))
{
*(p++) = 0;
number(str);
spo_word("point");
spo_word(p);
return;
}
if(NULL != (p = strchr(str, ':')))
{
digits(atol(str));
++p;
if(atol(p) < 10)
if(atol(p))
write(spo, " O ", 2);
if(atol(p))
digits(atol(p));
if(NULL != (p = strchr(p, ':')))
{
spo_word("and");
digits(atol(++p));
spo_word("seconds");
}
else
{
p = str;
if(strchr(p, 'a') || strchr(p, 'A'))
write(spo, "A M ", 5);
if(strchr(p, 'p') || strchr(p, 'P'))
write(spo, "P M ", 5);
}
return;
}
if(value >= 1000000l)
{
digits(value / 1000000l);
spo_word("million");
value %= 1000000l;
}
if(value >= 1000)
{
digits(value / 1000);
spo_word("thousand");
value %= 1000;
}
digits(value);
}
|