/* * 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); }