From 0cc9b20c15460213e488bf5e70963b941482f628 Mon Sep 17 00:00:00 2001 From: William Harrington Date: Tue, 14 Jan 2025 16:06:02 -0600 Subject: Add source. --- spo256/number.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 spo256/number.c (limited to 'spo256/number.c') diff --git a/spo256/number.c b/spo256/number.c new file mode 100644 index 0000000..16c662a --- /dev/null +++ b/spo256/number.c @@ -0,0 +1,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 +#include +#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); +} -- cgit v1.2.3-54-g00ecf