eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

numbers.cpp 47KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2011 by Jonathan Duddington *
  3. * email: [email protected] *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 3 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, see: *
  17. * <http://www.gnu.org/licenses/>. *
  18. ***************************************************************************/
  19. #include "StdAfx.h"
  20. #include <stdio.h>
  21. #include <ctype.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <wctype.h>
  25. #include <wchar.h>
  26. #include "speak_lib.h"
  27. #include "speech.h"
  28. #include "phoneme.h"
  29. #include "synthesize.h"
  30. #include "voice.h"
  31. #include "translate.h"
  32. #define M_NAME 0
  33. #define M_SMALLCAP 1
  34. #define M_TURNED 2
  35. #define M_REVERSED 3
  36. #define M_CURL 4
  37. #define M_ACUTE 5
  38. #define M_BREVE 6
  39. #define M_CARON 7
  40. #define M_CEDILLA 8
  41. #define M_CIRCUMFLEX 9
  42. #define M_DIAERESIS 10
  43. #define M_DOUBLE_ACUTE 11
  44. #define M_DOT_ABOVE 12
  45. #define M_GRAVE 13
  46. #define M_MACRON 14
  47. #define M_OGONEK 15
  48. #define M_RING 16
  49. #define M_STROKE 17
  50. #define M_TILDE 18
  51. #define M_BAR 19
  52. #define M_RETROFLEX 20
  53. #define M_HOOK 21
  54. #define M_MIDDLE_DOT M_DOT_ABOVE // duplicate of M_DOT_ABOVE
  55. #define M_IMPLOSIVE M_HOOK
  56. static int n_digit_lookup;
  57. static char *digit_lookup;
  58. static int speak_missing_thousands;
  59. static int number_control;
  60. typedef struct {
  61. const char *name;
  62. int flags;
  63. } ACCENTS;
  64. // these are tokens to look up in the *_list file.
  65. static ACCENTS accents_tab[] = {
  66. {"_lig", 1},
  67. {"_smc", 1}, // smallcap
  68. {"_tur", 1}, // turned
  69. {"_rev", 1}, // reversed
  70. {"_crl", 0}, // curl
  71. {"_acu", 0}, // acute
  72. {"_brv", 0}, // breve
  73. {"_hac", 0}, // caron/hacek
  74. {"_ced", 0}, // cedilla
  75. {"_cir", 0}, // circumflex
  76. {"_dia", 0}, // diaeresis
  77. {"_ac2", 0}, // double acute
  78. {"_dot", 0}, // dot
  79. {"_grv", 0}, // grave
  80. {"_mcn", 0}, // macron
  81. {"_ogo", 0}, // ogonek
  82. {"_rng", 0}, // ring
  83. {"_stk", 0}, // stroke
  84. {"_tld", 0}, // tilde
  85. {"_bar", 0}, // bar
  86. {"_rfx", 0}, // retroflex
  87. {"_hok", 0}, // hook
  88. };
  89. #define CAPITAL 0
  90. #define LETTER(ch,mod1,mod2) (ch-59)+(mod1 << 6)+(mod2 << 11)
  91. #define LIGATURE(ch1,ch2,mod1) (ch1-59)+((ch2-59) << 6)+(mod1 << 12)+0x8000
  92. #define L_ALPHA 60 // U+3B1
  93. #define L_SCHWA 61 // U+259
  94. #define L_OPEN_E 62 // U+25B
  95. #define L_GAMMA 63 // U+3B3
  96. #define L_IOTA 64 // U+3B9
  97. #define L_OE 65 // U+153
  98. #define L_OMEGA 66 // U+3C9
  99. #define L_PHI 67 // U+3C6
  100. #define L_ESH 68 // U+283
  101. #define L_UPSILON 69 // U+3C5
  102. #define L_EZH 70 // U+292
  103. #define L_GLOTTAL 71 // U+294
  104. #define L_RTAP 72 // U+27E
  105. static const short non_ascii_tab[] = {
  106. 0, 0x3b1, 0x259, 0x25b, 0x3b3, 0x3b9, 0x153, 0x3c9,
  107. 0x3c6, 0x283, 0x3c5, 0x292, 0x294, 0x27e };
  108. // characters U+00e0 to U+017f
  109. static const unsigned short letter_accents_0e0[] = {
  110. LETTER('a',M_GRAVE,0), // U+00e0
  111. LETTER('a',M_ACUTE,0),
  112. LETTER('a',M_CIRCUMFLEX,0),
  113. LETTER('a',M_TILDE,0),
  114. LETTER('a',M_DIAERESIS,0),
  115. LETTER('a',M_RING,0),
  116. LIGATURE('a','e',0),
  117. LETTER('c',M_CEDILLA,0),
  118. LETTER('e',M_GRAVE,0),
  119. LETTER('e',M_ACUTE,0),
  120. LETTER('e',M_CIRCUMFLEX,0),
  121. LETTER('e',M_DIAERESIS,0),
  122. LETTER('i',M_GRAVE,0),
  123. LETTER('i',M_ACUTE,0),
  124. LETTER('i',M_CIRCUMFLEX,0),
  125. LETTER('i',M_DIAERESIS,0),
  126. LETTER('d',M_NAME,0), // eth // U+00f0
  127. LETTER('n',M_TILDE,0),
  128. LETTER('o',M_GRAVE,0),
  129. LETTER('o',M_ACUTE,0),
  130. LETTER('o',M_CIRCUMFLEX,0),
  131. LETTER('o',M_TILDE,0),
  132. LETTER('o',M_DIAERESIS,0),
  133. 0, // division sign
  134. LETTER('o',M_STROKE,0),
  135. LETTER('u',M_GRAVE,0),
  136. LETTER('u',M_ACUTE,0),
  137. LETTER('u',M_CIRCUMFLEX,0),
  138. LETTER('u',M_DIAERESIS,0),
  139. LETTER('y',M_ACUTE,0),
  140. LETTER('t',M_NAME,0), // thorn
  141. LETTER('y',M_DIAERESIS,0),
  142. CAPITAL, // U+0100
  143. LETTER('a',M_MACRON,0),
  144. CAPITAL,
  145. LETTER('a',M_BREVE,0),
  146. CAPITAL,
  147. LETTER('a',M_OGONEK,0),
  148. CAPITAL,
  149. LETTER('c',M_ACUTE,0),
  150. CAPITAL,
  151. LETTER('c',M_CIRCUMFLEX,0),
  152. CAPITAL,
  153. LETTER('c',M_DOT_ABOVE,0),
  154. CAPITAL,
  155. LETTER('c',M_CARON,0),
  156. CAPITAL,
  157. LETTER('d',M_CARON,0),
  158. CAPITAL, // U+0110
  159. LETTER('d',M_STROKE,0),
  160. CAPITAL,
  161. LETTER('e',M_MACRON,0),
  162. CAPITAL,
  163. LETTER('e',M_BREVE,0),
  164. CAPITAL,
  165. LETTER('e',M_DOT_ABOVE,0),
  166. CAPITAL,
  167. LETTER('e',M_OGONEK,0),
  168. CAPITAL,
  169. LETTER('e',M_CARON,0),
  170. CAPITAL,
  171. LETTER('g',M_CIRCUMFLEX,0),
  172. CAPITAL,
  173. LETTER('g',M_BREVE,0),
  174. CAPITAL, // U+0120
  175. LETTER('g',M_DOT_ABOVE,0),
  176. CAPITAL,
  177. LETTER('g',M_CEDILLA,0),
  178. CAPITAL,
  179. LETTER('h',M_CIRCUMFLEX,0),
  180. CAPITAL,
  181. LETTER('h',M_STROKE,0),
  182. CAPITAL,
  183. LETTER('i',M_TILDE,0),
  184. CAPITAL,
  185. LETTER('i',M_MACRON,0),
  186. CAPITAL,
  187. LETTER('i',M_BREVE,0),
  188. CAPITAL,
  189. LETTER('i',M_OGONEK,0),
  190. CAPITAL, // U+0130
  191. LETTER('i',M_NAME,0), // dotless i
  192. CAPITAL,
  193. LIGATURE('i','j',0),
  194. CAPITAL,
  195. LETTER('j',M_CIRCUMFLEX,0),
  196. CAPITAL,
  197. LETTER('k',M_CEDILLA,0),
  198. LETTER('k',M_NAME,0), // kra
  199. CAPITAL,
  200. LETTER('l',M_ACUTE,0),
  201. CAPITAL,
  202. LETTER('l',M_CEDILLA,0),
  203. CAPITAL,
  204. LETTER('l',M_CARON,0),
  205. CAPITAL,
  206. LETTER('l',M_MIDDLE_DOT,0), // U+0140
  207. CAPITAL,
  208. LETTER('l',M_STROKE,0),
  209. CAPITAL,
  210. LETTER('n',M_ACUTE,0),
  211. CAPITAL,
  212. LETTER('n',M_CEDILLA,0),
  213. CAPITAL,
  214. LETTER('n',M_CARON,0),
  215. LETTER('n',M_NAME,0), // apostrophe n
  216. CAPITAL,
  217. LETTER('n',M_NAME,0), // eng
  218. CAPITAL,
  219. LETTER('o',M_MACRON,0),
  220. CAPITAL,
  221. LETTER('o',M_BREVE,0),
  222. CAPITAL, // U+0150
  223. LETTER('o',M_DOUBLE_ACUTE,0),
  224. CAPITAL,
  225. LIGATURE('o','e',0),
  226. CAPITAL,
  227. LETTER('r',M_ACUTE,0),
  228. CAPITAL,
  229. LETTER('r',M_CEDILLA,0),
  230. CAPITAL,
  231. LETTER('r',M_CARON,0),
  232. CAPITAL,
  233. LETTER('s',M_ACUTE,0),
  234. CAPITAL,
  235. LETTER('s',M_CIRCUMFLEX,0),
  236. CAPITAL,
  237. LETTER('s',M_CEDILLA,0),
  238. CAPITAL, // U+0160
  239. LETTER('s',M_CARON,0),
  240. CAPITAL,
  241. LETTER('t',M_CEDILLA,0),
  242. CAPITAL,
  243. LETTER('t',M_CARON,0),
  244. CAPITAL,
  245. LETTER('t',M_STROKE,0),
  246. CAPITAL,
  247. LETTER('u',M_TILDE,0),
  248. CAPITAL,
  249. LETTER('u',M_MACRON,0),
  250. CAPITAL,
  251. LETTER('u',M_BREVE,0),
  252. CAPITAL,
  253. LETTER('u',M_RING,0),
  254. CAPITAL, // U+0170
  255. LETTER('u',M_DOUBLE_ACUTE,0),
  256. CAPITAL,
  257. LETTER('u',M_OGONEK,0),
  258. CAPITAL,
  259. LETTER('w',M_CIRCUMFLEX,0),
  260. CAPITAL,
  261. LETTER('y',M_CIRCUMFLEX,0),
  262. CAPITAL, // Y-DIAERESIS
  263. CAPITAL,
  264. LETTER('z',M_ACUTE,0),
  265. CAPITAL,
  266. LETTER('z',M_DOT_ABOVE,0),
  267. CAPITAL,
  268. LETTER('z',M_CARON,0),
  269. LETTER('s',M_NAME,0), // long-s // U+17f
  270. };
  271. // characters U+0250 to U+029F
  272. static const unsigned short letter_accents_250[] = {
  273. LETTER('a',M_TURNED,0), // U+250
  274. LETTER(L_ALPHA,0,0),
  275. LETTER(L_ALPHA,M_TURNED,0),
  276. LETTER('b',M_IMPLOSIVE,0),
  277. 0, // open-o
  278. LETTER('c',M_CURL,0),
  279. LETTER('d',M_RETROFLEX,0),
  280. LETTER('d',M_IMPLOSIVE,0),
  281. LETTER('e',M_REVERSED,0), // U+258
  282. 0, // schwa
  283. LETTER(L_SCHWA,M_HOOK,0),
  284. 0, // open-e
  285. LETTER(L_OPEN_E,M_REVERSED,0),
  286. LETTER(L_OPEN_E,M_HOOK,M_REVERSED),
  287. 0,//LETTER(L_OPEN_E,M_CLOSED,M_REVERSED),
  288. LETTER('j',M_BAR,0),
  289. LETTER('g',M_IMPLOSIVE,0), // U+260
  290. LETTER('g',0,0),
  291. LETTER('g',M_SMALLCAP,0),
  292. LETTER(L_GAMMA,0,0),
  293. 0, // ramshorn
  294. LETTER('h',M_TURNED,0),
  295. LETTER('h',M_HOOK,0),
  296. 0,//LETTER(L_HENG,M_HOOK,0),
  297. LETTER('i',M_BAR,0), // U+268
  298. LETTER(L_IOTA,0,0),
  299. LETTER('i',M_SMALLCAP,0),
  300. LETTER('l',M_TILDE,0),
  301. LETTER('l',M_BAR,0),
  302. LETTER('l',M_RETROFLEX,0),
  303. LIGATURE('l','z',0),
  304. LETTER('m',M_TURNED,0),
  305. 0,//LETTER('m',M_TURNED,M_LEG), // U+270
  306. LETTER('m',M_HOOK,0),
  307. 0,//LETTER('n',M_LEFTHOOK,0),
  308. LETTER('n',M_RETROFLEX,0),
  309. LETTER('n',M_SMALLCAP,0),
  310. LETTER('o',M_BAR,0),
  311. LIGATURE('o','e',M_SMALLCAP),
  312. 0,//LETTER(L_OMEGA,M_CLOSED,0),
  313. LETTER(L_PHI,0,0), // U+278
  314. LETTER('r',M_TURNED,0),
  315. 0,//LETTER('r',M_TURNED,M_LEG),
  316. LETTER('r',M_RETROFLEX,M_TURNED),
  317. 0,//LETTER('r',M_LEG,0),
  318. LETTER('r',M_RETROFLEX,0),
  319. 0, // r-tap
  320. LETTER(L_RTAP,M_REVERSED,0),
  321. LETTER('r',M_SMALLCAP,0), // U+280
  322. LETTER('r',M_TURNED,M_SMALLCAP),
  323. LETTER('s',M_RETROFLEX,0),
  324. 0, // esh
  325. 0,//LETTER('j',M_BAR,L_IMPLOSIVE),
  326. LETTER(L_ESH,M_REVERSED,0),
  327. LETTER(L_ESH,M_CURL,0),
  328. LETTER('t',M_TURNED,0),
  329. LETTER('t',M_RETROFLEX,0), // U+288
  330. LETTER('u',M_BAR,0),
  331. LETTER(L_UPSILON,0,0),
  332. LETTER('v',M_HOOK,0),
  333. LETTER('v',M_TURNED,0),
  334. LETTER('w',M_TURNED,0),
  335. LETTER('y',M_TURNED,0),
  336. LETTER('y',M_SMALLCAP,0),
  337. LETTER('z',M_RETROFLEX,0), // U+290
  338. LETTER('z',M_CURL,0),
  339. 0, // ezh
  340. LETTER(L_EZH,M_CURL,0),
  341. 0, // glottal stop
  342. LETTER(L_GLOTTAL,M_REVERSED,0),
  343. LETTER(L_GLOTTAL,M_TURNED,0),
  344. 0,//LETTER('c',M_LONG,0),
  345. 0, // bilabial click // U+298
  346. LETTER('b',M_SMALLCAP,0),
  347. 0,//LETTER(L_OPEN_E,M_CLOSED,0),
  348. LETTER('g',M_IMPLOSIVE,M_SMALLCAP),
  349. LETTER('h',M_SMALLCAP,0),
  350. LETTER('j',M_CURL,0),
  351. LETTER('k',M_TURNED,0),
  352. LETTER('l',M_SMALLCAP,0),
  353. LETTER('q',M_HOOK,0), // U+2a0
  354. LETTER(L_GLOTTAL,M_STROKE,0),
  355. LETTER(L_GLOTTAL,M_STROKE,M_REVERSED),
  356. LIGATURE('d','z',0),
  357. 0, // dezh
  358. LIGATURE('d','z',M_CURL),
  359. LIGATURE('t','s',0),
  360. 0, // tesh
  361. LIGATURE('t','s',M_CURL),
  362. };
  363. static int LookupLetter2(Translator *tr, unsigned int letter, char *ph_buf)
  364. {//========================================================================
  365. int len;
  366. char single_letter[10];
  367. single_letter[0] = 0;
  368. single_letter[1] = '_';
  369. len = utf8_out(letter, &single_letter[2]);
  370. single_letter[len+2] = ' ';
  371. single_letter[len+3] = 0;
  372. if(Lookup(tr, &single_letter[1], ph_buf) == 0)
  373. {
  374. single_letter[1] = ' ';
  375. if(Lookup(tr, &single_letter[2], ph_buf) == 0)
  376. {
  377. TranslateRules(tr, &single_letter[2], ph_buf, 20, NULL,0,NULL);
  378. }
  379. }
  380. return(ph_buf[0]);
  381. }
  382. void LookupAccentedLetter(Translator *tr, unsigned int letter, char *ph_buf)
  383. {//=========================================================================
  384. // lookup the character in the accents table
  385. int accent_data = 0;
  386. int accent1 = 0;
  387. int accent2 = 0;
  388. int basic_letter;
  389. int letter2=0;
  390. char ph_letter1[30];
  391. char ph_letter2[30];
  392. char ph_accent1[30];
  393. char ph_accent2[30];
  394. ph_accent2[0] = 0;
  395. if((letter >= 0xe0) && (letter < 0x17f))
  396. {
  397. accent_data = letter_accents_0e0[letter - 0xe0];
  398. }
  399. else
  400. if((letter >= 0x250) && (letter <= 0x2a8))
  401. {
  402. accent_data = letter_accents_250[letter - 0x250];
  403. }
  404. if(accent_data != 0)
  405. {
  406. basic_letter = (accent_data & 0x3f) + 59;
  407. if(basic_letter < 'a')
  408. basic_letter = non_ascii_tab[basic_letter-59];
  409. if(accent_data & 0x8000)
  410. {
  411. letter2 = (accent_data >> 6) & 0x3f;
  412. letter2 += 59;
  413. accent2 = (accent_data >> 12) & 0x7;
  414. }
  415. else
  416. {
  417. accent1 = (accent_data >> 6) & 0x1f;
  418. accent2 = (accent_data >> 11) & 0xf;
  419. }
  420. if(Lookup(tr, accents_tab[accent1].name, ph_accent1) != 0)
  421. {
  422. if(LookupLetter2(tr, basic_letter, ph_letter1) != 0)
  423. {
  424. if(accent2 != 0)
  425. {
  426. if(Lookup(tr, accents_tab[accent2].name, ph_accent2) == 0)
  427. {
  428. // break;
  429. }
  430. if(accents_tab[accent2].flags & 1)
  431. {
  432. strcpy(ph_buf,ph_accent2);
  433. ph_buf += strlen(ph_buf);
  434. ph_accent2[0] = 0;
  435. }
  436. }
  437. if(letter2 != 0)
  438. {
  439. //ligature
  440. LookupLetter2(tr, letter2, ph_letter2);
  441. sprintf(ph_buf,"%s%c%s%c%s%s",ph_accent1, phonPAUSE_VSHORT, ph_letter1, phonSTRESS_P, ph_letter2, ph_accent2);
  442. }
  443. else
  444. {
  445. if(accent1 == 0)
  446. strcpy(ph_buf, ph_letter1);
  447. else
  448. if((tr->langopts.accents & 1) || (accents_tab[accent1].flags & 1))
  449. sprintf(ph_buf,"%s%c%c%s", ph_accent1, phonPAUSE_VSHORT, phonSTRESS_P, ph_letter1);
  450. else
  451. sprintf(ph_buf,"%c%s%c%s%c", phonSTRESS_2, ph_letter1, phonPAUSE_VSHORT, ph_accent1, phonPAUSE_VSHORT);
  452. }
  453. }
  454. }
  455. }
  456. } // end of LookupAccentedLetter
  457. void LookupLetter(Translator *tr, unsigned int letter, int next_byte, char *ph_buf1, int control)
  458. {//==============================================================================================
  459. // control, bit 0: not the first letter of a word
  460. int len;
  461. static char single_letter[10] = {0,0};
  462. unsigned int dict_flags[2];
  463. char ph_buf3[40];
  464. ph_buf1[0] = 0;
  465. len = utf8_out(letter,&single_letter[2]);
  466. single_letter[len+2] = ' ';
  467. if(next_byte == -1)
  468. {
  469. // speaking normal text, not individual characters
  470. if(Lookup(tr, &single_letter[2], ph_buf1) != 0)
  471. return;
  472. single_letter[1] = '_';
  473. if(Lookup(tr, &single_letter[1], ph_buf3) != 0)
  474. return; // the character is specified as _* so ignore it when speaking normal text
  475. // check whether this character is specified for English
  476. if(tr->translator_name == L('e','n'))
  477. return; // we are already using English
  478. SetTranslator2("en");
  479. if(Lookup(translator2, &single_letter[2], ph_buf3) != 0)
  480. {
  481. // yes, switch to English and re-translate the word
  482. sprintf(ph_buf1,"%c",phonSWITCH);
  483. }
  484. SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
  485. return;
  486. }
  487. if((letter <= 32) || iswspace(letter))
  488. {
  489. // lookup space as _&32 etc.
  490. sprintf(&single_letter[1],"_#%d ",letter);
  491. Lookup(tr, &single_letter[1], ph_buf1);
  492. return;
  493. }
  494. if(next_byte != ' ')
  495. next_byte = RULE_SPELLING;
  496. single_letter[3+len] = next_byte; // follow by space-space if the end of the word, or space-31
  497. single_letter[1] = '_';
  498. // if the $accent flag is set for this letter, use the accents table (below)
  499. dict_flags[1] = 0;
  500. if(Lookup(tr, &single_letter[1], ph_buf3) == 0)
  501. {
  502. single_letter[1] = ' ';
  503. if(Lookup(tr, &single_letter[2], ph_buf3) == 0)
  504. {
  505. TranslateRules(tr, &single_letter[2], ph_buf3, sizeof(ph_buf3), NULL,FLAG_NO_TRACE,NULL);
  506. }
  507. }
  508. if(ph_buf3[0] == 0)
  509. {
  510. LookupAccentedLetter(tr, letter, ph_buf3);
  511. }
  512. strcpy(ph_buf1, ph_buf3);
  513. if((ph_buf1[0] == 0) || (ph_buf1[0] == phonSWITCH))
  514. {
  515. return;
  516. }
  517. dict_flags[0] = 0;
  518. dict_flags[1] = 0;
  519. SetWordStress(tr, ph_buf1, dict_flags, -1, control & 1);
  520. } // end of LookupLetter
  521. int TranslateLetter(Translator *tr, char *word, char *phonemes, int control)
  522. {//=========================================================================
  523. // get pronunciation for an isolated letter
  524. // return number of bytes used by the letter
  525. // control bit 0: a non-initial letter in a word
  526. // bit 1: say 'capital'
  527. int n_bytes;
  528. int letter;
  529. int len;
  530. int save_option_phonemes;
  531. char *p2;
  532. char *pbuf;
  533. char capital[20];
  534. char ph_buf[60];
  535. char ph_buf2[60];
  536. char hexbuf[6];
  537. ph_buf[0] = 0;
  538. capital[0] = 0;
  539. n_bytes = utf8_in(&letter,word);
  540. if((letter & 0xfff00) == 0x0e000)
  541. {
  542. letter &= 0xff; // uncode private usage area
  543. }
  544. if(control & 2)
  545. {
  546. // include CAPITAL information
  547. if(iswupper(letter))
  548. {
  549. Lookup(tr, "_cap", capital);
  550. }
  551. }
  552. letter = towlower2(letter);
  553. LookupLetter(tr, letter, word[n_bytes], ph_buf, control & 1);
  554. if(ph_buf[0] == phonSWITCH)
  555. {
  556. strcpy(phonemes,ph_buf);
  557. return(0);
  558. }
  559. if((ph_buf[0] == 0) && (tr->translator_name != L('e','n')))
  560. {
  561. // speak as English, check whether there is a translation for this character
  562. SetTranslator2("en");
  563. save_option_phonemes = option_phonemes;
  564. option_phonemes = 0;
  565. LookupLetter(translator2, letter, word[n_bytes], ph_buf, control & 1);
  566. SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
  567. option_phonemes = save_option_phonemes;
  568. if(ph_buf[0] != 0)
  569. {
  570. sprintf(phonemes,"%cen",phonSWITCH);
  571. return(0);
  572. }
  573. }
  574. if(ph_buf[0] == 0)
  575. {
  576. // character name not found
  577. if(iswalpha(letter))
  578. Lookup(tr, "_?A", ph_buf);
  579. if((ph_buf[0]==0) && !iswspace(letter))
  580. Lookup(tr, "_??", ph_buf);
  581. if(ph_buf[0] != 0)
  582. {
  583. // speak the hexadecimal number of the character code
  584. sprintf(hexbuf,"%x",letter);
  585. pbuf = ph_buf;
  586. for(p2 = hexbuf; *p2 != 0; p2++)
  587. {
  588. pbuf += strlen(pbuf);
  589. *pbuf++ = phonPAUSE_VSHORT;
  590. LookupLetter(tr, *p2, 0, pbuf, 1);
  591. }
  592. }
  593. }
  594. len = strlen(phonemes);
  595. if(tr->langopts.accents & 2)
  596. sprintf(ph_buf2,"%c%s%s",0xff,ph_buf,capital);
  597. else
  598. sprintf(ph_buf2,"%c%s%s",0xff,capital,ph_buf); // the 0xff marker will be removed or replaced in SetSpellingStress()
  599. if((len + strlen(ph_buf2)) < N_WORD_PHONEMES)
  600. {
  601. strcpy(&phonemes[len],ph_buf2);
  602. }
  603. return(n_bytes);
  604. } // end of TranslateLetter
  605. void SetSpellingStress(Translator *tr, char *phonemes, int control, int n_chars)
  606. {//=============================================================================
  607. // Individual letter names, reduce the stress of some.
  608. int ix;
  609. unsigned int c;
  610. int n_stress=0;
  611. int count;
  612. unsigned char buf[N_WORD_PHONEMES];
  613. for(ix=0; (c = phonemes[ix]) != 0; ix++)
  614. {
  615. if(c == phonSTRESS_P)
  616. {
  617. n_stress++;
  618. }
  619. buf[ix] = c;
  620. }
  621. buf[ix] = 0;
  622. count = 0;
  623. for(ix=0; (c = buf[ix]) != 0; ix++)
  624. {
  625. if((c == phonSTRESS_P) && (n_chars > 1))
  626. {
  627. count++;
  628. if(tr->langopts.spelling_stress == 1)
  629. {
  630. // stress on initial letter when spelling
  631. if(count > 1)
  632. c = phonSTRESS_3;
  633. }
  634. else
  635. {
  636. if(count != n_stress)
  637. {
  638. if(((count % 3) != 0) || (count == n_stress-1))
  639. c = phonSTRESS_3; // reduce to secondary stress
  640. }
  641. }
  642. }
  643. else
  644. if(c == 0xff)
  645. {
  646. if((control < 2) || (ix==0))
  647. continue; // don't insert pauses
  648. if(control == 4)
  649. c = phonPAUSE; // pause after each character
  650. if(((count % 3) == 0) || (control > 2))
  651. c = phonPAUSE_NOLINK; // pause following a primary stress
  652. else
  653. c = phonPAUSE_VSHORT;
  654. // else
  655. // continue; // remove marker
  656. }
  657. *phonemes++ = c;
  658. }
  659. if(control >= 2)
  660. *phonemes++ = phonPAUSE_NOLINK;
  661. *phonemes = 0;
  662. } // end of SetSpellingStress
  663. // Numbers
  664. static char ph_ordinal2[12];
  665. static int CheckDotOrdinal(Translator *tr, char *word, char *word_end, WORD_TAB *wtab, int roman)
  666. {//==============================================================================================
  667. int ordinal = 0;
  668. int c2;
  669. int nextflags;
  670. if((tr->langopts.numbers & NUM_ORDINAL_DOT) && ((word_end[0] == '.') || (wtab[0].flags & FLAG_HAS_DOT)) && !(wtab[1].flags & FLAG_NOSPACE))
  671. {
  672. if(roman || !(wtab[1].flags & FLAG_FIRST_UPPER))
  673. {
  674. if(word_end[0] == '.')
  675. utf8_in(&c2, &word_end[2]);
  676. else
  677. utf8_in(&c2, &word_end[0]);
  678. if((word_end[0] != 0) && (word_end[1] != 0) && ((c2 == 0) || (wtab[0].flags & FLAG_COMMA_AFTER) || IsAlpha(c2)))
  679. {
  680. // ordinal number is indicated by dot after the number
  681. // but not if the next word starts with an upper-case letter
  682. // (c2 == 0) is for cases such as, "2.,"
  683. ordinal = 2;
  684. if(word_end[0] == '.')
  685. word_end[0] = ' ';
  686. if((roman==0) && (tr->translator_name == L('h','u')))
  687. {
  688. // lang=hu don't treat dot as ordinal indicator if the next word is a month name ($alt). It may have a suffix.
  689. nextflags = 0;
  690. if(IsAlpha(c2))
  691. {
  692. nextflags = TranslateWord(tr, &word_end[2], 0, NULL);
  693. }
  694. if((tr->prev_dict_flags & FLAG_ALT_TRANS) && ((c2 == 0) || (wtab[0].flags & FLAG_COMMA_AFTER) || iswdigit(c2)))
  695. ordinal = 0; // TEST 09.02.10
  696. if(nextflags & FLAG_ALT_TRANS)
  697. ordinal = 0;
  698. if(nextflags & FLAG_ALT3_TRANS)
  699. {
  700. if(word[-2] == '-')
  701. ordinal = 0; // eg. december 2-5. között
  702. if(tr->prev_dict_flags & (FLAG_ALT_TRANS | FLAG_ALT3_TRANS))
  703. ordinal = 0x22;
  704. }
  705. }
  706. }
  707. }
  708. }
  709. return(ordinal);
  710. } // end of CheckDotOrdinal
  711. static int hu_number_e(const char *word, int thousandplex, int value)
  712. {//==================================================================
  713. // lang-hu: variant form of numbers when followed by hyphen and a suffix starting with 'a' or 'e' (but not a, e, az, ez, azt, ezt, att. ett
  714. if((word[0] == 'a') || (word[0] == 'e'))
  715. {
  716. if((word[1] == ' ') || (word[1] == 'z') || ((word[1] == 't') && (word[2] == 't')))
  717. return(0);
  718. if(((thousandplex==1) || ((value % 1000) == 0)) && (word[1] == 'l'))
  719. return(0); // 1000-el
  720. return(1);
  721. }
  722. return(0);
  723. } // end of hu_numnber_e
  724. int TranslateRoman(Translator *tr, char *word, char *ph_out, WORD_TAB *wtab)
  725. {//=========================================================================
  726. int c;
  727. char *p;
  728. const char *p2;
  729. int acc;
  730. int prev;
  731. int value;
  732. int subtract;
  733. int repeat = 0;
  734. int n_digits = 0;
  735. char *word_start;
  736. int num_control = 0;
  737. unsigned int flags[2];
  738. char ph_roman[30];
  739. char number_chars[N_WORD_BYTES];
  740. static const char *roman_numbers = "ixcmvld";
  741. static int roman_values[] = {1,10,100,1000,5,50,500};
  742. acc = 0;
  743. prev = 0;
  744. subtract = 0x7fff;
  745. ph_out[0] = 0;
  746. flags[0] = 0;
  747. flags[1] = 0;
  748. if(((tr->langopts.numbers & NUM_ROMAN_CAPITALS) && !(wtab[0].flags & FLAG_ALL_UPPER)) || isdigit(word[-2]))
  749. return(0); // not '2xx'
  750. word_start = word;
  751. while((c = *word++) != ' ')
  752. {
  753. if((p2 = strchr(roman_numbers,c)) == NULL)
  754. return(0);
  755. value = roman_values[p2 - roman_numbers];
  756. if(value == prev)
  757. {
  758. repeat++;
  759. if(repeat >= 3)
  760. return(0);
  761. }
  762. else
  763. repeat = 0;
  764. if((prev > 1) && (prev != 10) && (prev != 100))
  765. {
  766. if(value >= prev)
  767. return(0);
  768. }
  769. if((prev != 0) && (prev < value))
  770. {
  771. if(((acc % 10) != 0) || ((prev*10) < value))
  772. return(0);
  773. subtract = prev;
  774. value -= subtract;
  775. }
  776. else
  777. if(value >= subtract)
  778. return(0);
  779. else
  780. acc += prev;
  781. prev = value;
  782. n_digits++;
  783. }
  784. if(isdigit(word[0]))
  785. return(0); // eg. 'xx2'
  786. acc += prev;
  787. if(acc < tr->langopts.min_roman)
  788. return(0);
  789. if(acc > tr->langopts.max_roman)
  790. return(0);
  791. Lookup(tr, "_roman",ph_roman); // precede by "roman" if _rom is defined in *_list
  792. p = &ph_out[0];
  793. if((tr->langopts.numbers & NUM_ROMAN_AFTER) == 0)
  794. {
  795. strcpy(ph_out,ph_roman);
  796. p = &ph_out[strlen(ph_roman)];
  797. }
  798. sprintf(number_chars," %d ",acc);
  799. if(word[0] == '.')
  800. {
  801. // dot has not been removed. This implies that there was no space after it
  802. return(0);
  803. }
  804. if(CheckDotOrdinal(tr, word_start, word, wtab, 1))
  805. wtab[0].flags |= FLAG_ORDINAL;
  806. if(tr->langopts.numbers & NUM_ROMAN_ORDINAL)
  807. {
  808. if(tr->translator_name == L('h','u'))
  809. {
  810. if(!(wtab[0].flags & FLAG_ORDINAL))
  811. {
  812. if((wtab[0].flags & FLAG_HYPHEN_AFTER) && hu_number_e(word, 0, acc))
  813. {
  814. // should use the 'e' form of the number
  815. num_control |= 1;
  816. }
  817. else
  818. return(0);
  819. }
  820. }
  821. else
  822. {
  823. wtab[0].flags |= FLAG_ORDINAL;
  824. }
  825. }
  826. tr->prev_dict_flags = 0;
  827. TranslateNumber(tr, &number_chars[2], p, flags, wtab, num_control);
  828. if(tr->langopts.numbers & NUM_ROMAN_AFTER)
  829. strcat(ph_out,ph_roman);
  830. return(1);
  831. } // end of TranslateRoman
  832. static const char *M_Variant(int value)
  833. {//====================================
  834. // returns M, or perhaps MA for some cases
  835. if((translator->langopts.numbers2 & 0x100) && (value >= 2) && (value <= 4))
  836. return("0MA"); // Czech, Slovak
  837. else
  838. if(((value % 100) < 10) || ((value % 100) > 20)) // but not teens, 10 to 19
  839. {
  840. if ((translator->langopts.numbers2 & 0x40) &&
  841. ((value % 10)>=2) &&
  842. ((value % 10)<=4))
  843. {
  844. // for Polish language - two forms of plural!
  845. return("0MA");
  846. }
  847. if((translator->langopts.numbers2 & 0x80) &&
  848. ((value % 10)==1))
  849. {
  850. return("1MA");
  851. }
  852. }
  853. return("0M");
  854. }
  855. static int LookupThousands(Translator *tr, int value, int thousandplex, int thousands_exact, char *ph_out)
  856. {//=======================================================================================================
  857. // thousands_exact: bit 0 no hundreds,tens,or units, bit 1 ordinal numberr
  858. int found;
  859. int found_value=0;
  860. char string[12];
  861. char ph_of[12];
  862. char ph_thousands[40];
  863. char ph_buf[40];
  864. ph_of[0] = 0;
  865. // first look for a match with the exact value of thousands
  866. if(value > 0)
  867. {
  868. if(thousands_exact & 1)
  869. {
  870. if(thousands_exact & 2)
  871. {
  872. // ordinal number
  873. sprintf(string,"_%dM%do",value,thousandplex);
  874. found_value = Lookup(tr, string, ph_thousands);
  875. }
  876. if(!found_value & (number_control & 1))
  877. {
  878. // look for the 'e' variant
  879. sprintf(string,"_%dM%de",value,thousandplex);
  880. found_value = Lookup(tr, string, ph_thousands);
  881. }
  882. if(!found_value)
  883. {
  884. // is there a different pronunciation if there are no hundreds,tens,or units ? (LANG=ta)
  885. sprintf(string,"_%dM%dx",value,thousandplex);
  886. found_value = Lookup(tr, string, ph_thousands);
  887. }
  888. }
  889. if(found_value == 0)
  890. {
  891. sprintf(string,"_%dM%d",value,thousandplex);
  892. found_value = Lookup(tr, string, ph_thousands);
  893. }
  894. }
  895. if(found_value == 0)
  896. {
  897. if((value % 100) >= 20)
  898. {
  899. Lookup(tr, "_0of", ph_of);
  900. }
  901. found = 0;
  902. if(thousands_exact & 1)
  903. {
  904. if(thousands_exact & 2)
  905. {
  906. // ordinal number
  907. sprintf(string,"_%s%do",M_Variant(value), thousandplex);
  908. found = Lookup(tr, string, ph_thousands);
  909. }
  910. if(!found && (number_control & 1))
  911. {
  912. // look for the 'e' variant
  913. sprintf(string,"_%s%de",M_Variant(value), thousandplex);
  914. found = Lookup(tr, string, ph_thousands);
  915. }
  916. if(!found)
  917. {
  918. // is there a different pronunciation if there are no hundreds,tens,or units ?
  919. sprintf(string,"_%s%dx",M_Variant(value), thousandplex);
  920. found = Lookup(tr, string, ph_thousands);
  921. }
  922. }
  923. if(found == 0)
  924. {
  925. sprintf(string,"_%s%d",M_Variant(value), thousandplex);
  926. if(Lookup(tr, string, ph_thousands) == 0)
  927. {
  928. if(thousandplex > 3)
  929. {
  930. sprintf(string,"_0M%d", thousandplex-1);
  931. if(Lookup(tr, string, ph_buf) == 0)
  932. {
  933. // say "millions" if this name is not available and neither is the next lower
  934. Lookup(tr, "_0M2", ph_thousands);
  935. speak_missing_thousands = 3;
  936. }
  937. }
  938. if(ph_thousands[0] == 0)
  939. {
  940. // repeat "thousand" if higher order names are not available
  941. sprintf(string,"_%dM1",value);
  942. if((found_value = Lookup(tr, string, ph_thousands)) == 0)
  943. Lookup(tr, "_0M1", ph_thousands);
  944. speak_missing_thousands = 2;
  945. }
  946. }
  947. }
  948. }
  949. sprintf(ph_out,"%s%s",ph_of,ph_thousands);
  950. if((value == 1) && (thousandplex == 1) && (tr->langopts.numbers & NUM_OMIT_1_THOUSAND))
  951. return(1);
  952. return(found_value);
  953. } // end f LookupThousands
  954. static int LookupNum2(Translator *tr, int value, int control, char *ph_out)
  955. {//========================================================================
  956. // Lookup a 2 digit number
  957. // control bit 0: ordinal number
  958. // control bit 1: final tens and units (not number of thousands) (use special form of '1', LANG=de "eins")
  959. // control bit 2: tens and units only, no higher digits
  960. // control bit 3: use feminine form of '2' (for thousands
  961. // control bit 4: speak zero tens
  962. // control bit 5: variant of ordinal number (lang=hu)
  963. int found;
  964. int ix;
  965. int units;
  966. int tens;
  967. int used_and=0;
  968. int found_ordinal = 0;
  969. int next_phtype;
  970. int ord_type = 'o';
  971. char string[12]; // for looking up entries in *_list
  972. char ph_ordinal[20];
  973. char ph_tens[50];
  974. char ph_digits[50];
  975. char ph_and[12];
  976. units = value % 10;
  977. tens = value / 10;
  978. found = 0;
  979. ph_ordinal[0] = 0;
  980. ph_tens[0] = 0;
  981. ph_digits[0] = 0;
  982. ph_and[0] = 0;
  983. if(control & 0x20)
  984. {
  985. ord_type = 'q';
  986. }
  987. if((control & 2) && (n_digit_lookup == 2))
  988. {
  989. // pronunciation of the final 2 digits has already been found
  990. strcpy(ph_out, digit_lookup);
  991. }
  992. else
  993. {
  994. if(digit_lookup[0] == 0)
  995. {
  996. // is there a special pronunciation for this 2-digit number
  997. if(control & 8)
  998. {
  999. sprintf(string,"_%df",value);
  1000. found = Lookup(tr, string, ph_digits);
  1001. }
  1002. else
  1003. if(control & 1)
  1004. {
  1005. strcpy(ph_ordinal, ph_ordinal2);
  1006. if(control & 4)
  1007. {
  1008. sprintf(string,"_%d%cx",value,ord_type); // LANG=hu, special word for 1. 2. when there are no higher digits
  1009. found = Lookup(tr, string, ph_digits);
  1010. }
  1011. if(found == 0)
  1012. {
  1013. sprintf(string,"_%d%c",value,ord_type);
  1014. found = Lookup(tr, string, ph_digits);
  1015. }
  1016. found_ordinal = found;
  1017. }
  1018. if(found == 0)
  1019. {
  1020. if(control & 2)
  1021. {
  1022. // the final tens and units of a number
  1023. if(number_control & 1)
  1024. {
  1025. // look for 'e' variant
  1026. sprintf(string,"_%de",value);
  1027. found = Lookup(tr, string, ph_digits);
  1028. }
  1029. }
  1030. else
  1031. {
  1032. // followed by hundreds or thousands etc
  1033. sprintf(string,"_%da",value);
  1034. found = Lookup(tr, string, ph_digits);
  1035. }
  1036. if(!found)
  1037. {
  1038. sprintf(string,"_%d",value);
  1039. found = Lookup(tr, string, ph_digits);
  1040. }
  1041. }
  1042. }
  1043. // no, speak as tens+units
  1044. if((control & 0x10) && (value < 10))
  1045. {
  1046. // speak leading zero
  1047. Lookup(tr, "_0", ph_tens);
  1048. }
  1049. else
  1050. {
  1051. if(found)
  1052. {
  1053. ph_tens[0] = 0;
  1054. }
  1055. else
  1056. {
  1057. if((control & 1) &&
  1058. ((units == 0) || (tr->langopts.numbers & NUM_SWAP_TENS) || (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL)))
  1059. {
  1060. sprintf(string,"_%dX%c", tens, ord_type);
  1061. if(Lookup(tr, string, ph_tens) != 0)
  1062. {
  1063. found_ordinal = 1;
  1064. if((units != 0) && (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL))
  1065. {
  1066. // Use the ordinal form of tens as well as units. Add the ordinal ending
  1067. strcat(ph_tens, ph_ordinal2);
  1068. }
  1069. }
  1070. }
  1071. if(found_ordinal == 0)
  1072. {
  1073. sprintf(string,"_%dX", tens);
  1074. Lookup(tr, string, ph_tens);
  1075. }
  1076. if((ph_tens[0] == 0) && (tr->langopts.numbers & NUM_VIGESIMAL))
  1077. {
  1078. // tens not found, (for example) 73 is 60+13
  1079. units = (value % 20);
  1080. sprintf(string,"_%dX", tens & 0xfe);
  1081. Lookup(tr, string, ph_tens);
  1082. }
  1083. ph_digits[0] = 0;
  1084. if(units > 0)
  1085. {
  1086. found = 0;
  1087. if((control & 2) && (digit_lookup[0] != 0))
  1088. {
  1089. // we have an entry for this digit (possibly together with the next word)
  1090. strcpy(ph_digits, digit_lookup);
  1091. found_ordinal = 1;
  1092. ph_ordinal[0] = 0;
  1093. }
  1094. else
  1095. {
  1096. if(control & 8)
  1097. {
  1098. // is there a variant form of this number?
  1099. sprintf(string,"_%df",units);
  1100. found = Lookup(tr, string, ph_digits);
  1101. }
  1102. if((control & 1) && ((tr->langopts.numbers & NUM_SWAP_TENS) == 0))
  1103. {
  1104. // ordinal
  1105. sprintf(string,"_%d%c",units,ord_type);
  1106. if((found = Lookup(tr, string, ph_digits)) != 0)
  1107. {
  1108. found_ordinal = 1;
  1109. }
  1110. }
  1111. if(found == 0)
  1112. {
  1113. if((number_control & 1) && (control & 2))
  1114. {
  1115. // look for 'e' variant
  1116. sprintf(string,"_%de",units);
  1117. found = Lookup(tr, string, ph_digits);
  1118. }
  1119. else
  1120. if(((control & 2) == 0) || ((tr->langopts.numbers & NUM_SWAP_TENS) != 0))
  1121. {
  1122. // followed by hundreds or thousands (or tens)
  1123. sprintf(string,"_%da",units);
  1124. found = Lookup(tr, string, ph_digits);
  1125. }
  1126. }
  1127. if(found == 0)
  1128. {
  1129. sprintf(string,"_%d",units);
  1130. Lookup(tr, string, ph_digits);
  1131. }
  1132. }
  1133. }
  1134. }
  1135. }
  1136. if((control & 1) && (found_ordinal == 0) && (ph_ordinal[0] == 0))
  1137. {
  1138. if((value >= 20) && (((value % 10) == 0) || (tr->langopts.numbers & NUM_SWAP_TENS)))
  1139. Lookup(tr, "_ord20", ph_ordinal);
  1140. if(ph_ordinal[0] == 0)
  1141. Lookup(tr, "_ord", ph_ordinal);
  1142. }
  1143. if((tr->langopts.numbers & (NUM_SWAP_TENS | NUM_AND_UNITS)) && (ph_tens[0] != 0) && (ph_digits[0] != 0))
  1144. {
  1145. Lookup(tr, "_0and", ph_and);
  1146. if((control & 1) && (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL))
  1147. ph_and[0] = 0;
  1148. if(tr->langopts.numbers & NUM_SWAP_TENS)
  1149. sprintf(ph_out,"%s%s%s%s",ph_digits, ph_and, ph_tens, ph_ordinal);
  1150. else
  1151. sprintf(ph_out,"%s%s%s%s",ph_tens, ph_and, ph_digits, ph_ordinal);
  1152. used_and = 1;
  1153. }
  1154. else
  1155. {
  1156. if(tr->langopts.numbers & NUM_SINGLE_VOWEL)
  1157. {
  1158. // remove vowel from the end of tens if units starts with a vowel (LANG=Italian)
  1159. if(((ix = strlen(ph_tens)-1) >= 0) && (ph_digits[0] != 0))
  1160. {
  1161. if((next_phtype = phoneme_tab[(unsigned int)(ph_digits[0])]->type) == phSTRESS)
  1162. next_phtype = phoneme_tab[(unsigned int)(ph_digits[1])]->type;
  1163. if((phoneme_tab[(unsigned int)(ph_tens[ix])]->type == phVOWEL) && (next_phtype == phVOWEL))
  1164. ph_tens[ix] = 0;
  1165. }
  1166. }
  1167. sprintf(ph_out,"%s%s%s",ph_tens, ph_digits, ph_ordinal);
  1168. }
  1169. }
  1170. if(tr->langopts.numbers & NUM_SINGLE_STRESS)
  1171. {
  1172. // only one primary stress
  1173. found = 0;
  1174. for(ix=strlen(ph_out)-1; ix>=0; ix--)
  1175. {
  1176. if(ph_out[ix] == phonSTRESS_P)
  1177. {
  1178. if(found)
  1179. ph_out[ix] = phonSTRESS_3;
  1180. else
  1181. found = 1;
  1182. }
  1183. }
  1184. }
  1185. return(used_and);
  1186. } // end of LookupNum2
  1187. static int LookupNum3(Translator *tr, int value, char *ph_out, int suppress_null, int thousandplex, int control)
  1188. {//=============================================================================================================
  1189. // Translate a 3 digit number
  1190. // control bit 0, previous thousands
  1191. // bit 1, ordinal number
  1192. // bit 5 variant form of ordinal number
  1193. int found;
  1194. int hundreds;
  1195. int tensunits;
  1196. int x;
  1197. int ix;
  1198. int exact;
  1199. int ordinal;
  1200. int say_zero_hundred=0;
  1201. char string[12]; // for looking up entries in **_list
  1202. char buf1[100];
  1203. char buf2[100];
  1204. char ph_100[20];
  1205. char ph_10T[20];
  1206. char ph_digits[50];
  1207. char ph_thousands[50];
  1208. char ph_hundred_and[12];
  1209. char ph_thousand_and[12];
  1210. ordinal = control & 0x22;
  1211. hundreds = value / 100;
  1212. tensunits = value % 100;
  1213. buf1[0] = 0;
  1214. ph_thousands[0] = 0;
  1215. ph_thousand_and[0] = 0;
  1216. if((tr->langopts.numbers & NUM_ZERO_HUNDRED) && ((control & 1) || (hundreds >= 10)))
  1217. {
  1218. say_zero_hundred = 1; // lang=vi
  1219. }
  1220. if((hundreds > 0) || say_zero_hundred)
  1221. {
  1222. found = 0;
  1223. if(ordinal && (tensunits == 0))
  1224. {
  1225. // ordinal number, with no tens or units
  1226. found = Lookup(tr, "_0Co", ph_100);
  1227. }
  1228. if(found == 0)
  1229. {
  1230. if(tensunits==0)
  1231. {
  1232. // special form for exact hundreds?
  1233. found = Lookup(tr, "_0C0", ph_100);
  1234. }
  1235. if(!found)
  1236. {
  1237. Lookup(tr, "_0C", ph_100);
  1238. }
  1239. }
  1240. if(((tr->langopts.numbers & NUM_1900) != 0) && (hundreds == 19))
  1241. {
  1242. // speak numbers such as 1984 as years: nineteen-eighty-four
  1243. // ph_100[0] = 0; // don't say "hundred", we also need to surpess "and"
  1244. }
  1245. else
  1246. if(hundreds >= 10)
  1247. {
  1248. ph_digits[0] = 0;
  1249. exact = 0;
  1250. if ((value % 1000) == 0)
  1251. exact = 1;
  1252. if(LookupThousands(tr, hundreds / 10, thousandplex+1, exact | ordinal, ph_10T) == 0)
  1253. {
  1254. x = 0;
  1255. if(tr->langopts.numbers2 & (1 << (thousandplex+1)))
  1256. x = 8; // use variant (feminine) for before thousands and millions
  1257. LookupNum2(tr, hundreds/10, x, ph_digits);
  1258. }
  1259. if(tr->langopts.numbers2 & 0x200)
  1260. sprintf(ph_thousands,"%s%s",ph_10T,ph_digits); // say "thousands" before its number, not after
  1261. else
  1262. sprintf(ph_thousands,"%s%s",ph_digits,ph_10T);
  1263. hundreds %= 10;
  1264. if((hundreds == 0) && (say_zero_hundred == 0))
  1265. ph_100[0] = 0;
  1266. suppress_null = 1;
  1267. }
  1268. ph_digits[0] = 0;
  1269. if((hundreds > 0) || say_zero_hundred)
  1270. {
  1271. if((tr->langopts.numbers & NUM_AND_HUNDRED) && ((control & 1) || (ph_thousands[0] != 0)))
  1272. {
  1273. Lookup(tr, "_0and", ph_thousand_and);
  1274. }
  1275. suppress_null = 1;
  1276. found = 0;
  1277. if((ordinal)
  1278. && ((tensunits == 0) || (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL)))
  1279. {
  1280. // ordinal number
  1281. sprintf(string, "_%dCo", hundreds);
  1282. found = Lookup(tr, string, ph_digits);
  1283. if((tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL) && (tensunits > 0))
  1284. {
  1285. // Use ordinal form of hundreds, as well as for tens and units
  1286. // Add ordinal suffix to the hundreds
  1287. strcat(ph_digits, ph_ordinal2);
  1288. }
  1289. }
  1290. if((hundreds == 0) && say_zero_hundred)
  1291. {
  1292. Lookup(tr, "_0", ph_digits);
  1293. }
  1294. else
  1295. {
  1296. if((!found) && (tensunits == 0))
  1297. {
  1298. // is there a special pronunciation for exactly n00 ?
  1299. sprintf(string,"_%dC0",hundreds);
  1300. found = Lookup(tr, string, ph_digits);
  1301. }
  1302. if(!found)
  1303. {
  1304. sprintf(string,"_%dC",hundreds);
  1305. found = Lookup(tr, string, ph_digits); // is there a specific pronunciation for n-hundred ?
  1306. }
  1307. if(found)
  1308. {
  1309. ph_100[0] = 0;
  1310. }
  1311. else
  1312. {
  1313. if((hundreds > 1) || ((tr->langopts.numbers & NUM_OMIT_1_HUNDRED) == 0))
  1314. {
  1315. LookupNum2(tr, hundreds, 0, ph_digits);
  1316. }
  1317. }
  1318. }
  1319. }
  1320. sprintf(buf1,"%s%s%s%s",ph_thousands,ph_thousand_and,ph_digits,ph_100);
  1321. }
  1322. ph_hundred_and[0] = 0;
  1323. if(tensunits > 0)
  1324. {
  1325. if((control & 2) && (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL))
  1326. {
  1327. // Don't use "and" if we apply ordinal to both hundreds and units
  1328. }
  1329. else
  1330. {
  1331. if((value > 100) || ((control & 1) && (thousandplex==0)))
  1332. {
  1333. if((tr->langopts.numbers & NUM_HUNDRED_AND) || ((tr->langopts.numbers & NUM_HUNDRED_AND_DIGIT) && (tensunits < 10)))
  1334. {
  1335. Lookup(tr, "_0and", ph_hundred_and);
  1336. }
  1337. }
  1338. if((tr->langopts.numbers & NUM_THOUSAND_AND) && (hundreds == 0) && ((control & 1) || (ph_thousands[0] != 0)))
  1339. {
  1340. Lookup(tr, "_0and", ph_hundred_and);
  1341. }
  1342. }
  1343. }
  1344. buf2[0] = 0;
  1345. if((tensunits != 0) || (suppress_null == 0))
  1346. {
  1347. x = 0;
  1348. if(thousandplex==0)
  1349. {
  1350. x = 2; // allow "eins" for 1 rather than "ein"
  1351. if(ordinal)
  1352. x = 3; // ordinal number
  1353. if((value < 100) && !(control & 1))
  1354. x |= 4; // tens and units only, no higher digits
  1355. if(ordinal & 0x20)
  1356. x |= 0x20; // variant form of ordinal number
  1357. }
  1358. else
  1359. {
  1360. if(tr->langopts.numbers2 & (1 << thousandplex))
  1361. x = 8; // use variant (feminine) for before thousands and millions
  1362. }
  1363. if(LookupNum2(tr, tensunits, x, buf2) != 0)
  1364. {
  1365. if(tr->langopts.numbers & NUM_SINGLE_AND)
  1366. ph_hundred_and[0] = 0; // don't put 'and' after 'hundred' if there's 'and' between tens and units
  1367. }
  1368. }
  1369. else
  1370. {
  1371. if(ph_ordinal2[0] != 0)
  1372. {
  1373. ix = strlen(buf1);
  1374. if((ix > 0) && (buf1[ix-1] == phonPAUSE_SHORT))
  1375. buf1[ix-1] = 0; // remove pause before addding ordinal suffix
  1376. strcpy(buf2, ph_ordinal2);
  1377. }
  1378. }
  1379. sprintf(ph_out,"%s%s%s",buf1,ph_hundred_and,buf2);
  1380. return(0);
  1381. } // end of LookupNum3
  1382. static int TranslateNumber_1(Translator *tr, char *word, char *ph_out, unsigned int *flags, WORD_TAB *wtab, int control)
  1383. {//=====================================================================================================================
  1384. // Number translation with various options
  1385. // the "word" may be up to 4 digits
  1386. // "words" of 3 digits may be preceded by another number "word" for thousands or millions
  1387. int n_digits;
  1388. int value;
  1389. int ix;
  1390. int digix;
  1391. unsigned char c;
  1392. int suppress_null = 0;
  1393. int decimal_point = 0;
  1394. int thousandplex = 0;
  1395. int thousands_exact = 1;
  1396. int thousands_inc = 0;
  1397. int prev_thousands = 0;
  1398. int ordinal = 0;
  1399. int dot_ordinal;
  1400. int this_value;
  1401. int decimal_count;
  1402. int max_decimal_count;
  1403. int decimal_mode;
  1404. int suffix_ix;
  1405. int skipwords = 0;
  1406. char *p;
  1407. char string[32]; // for looking up entries in **_list
  1408. char buf1[100];
  1409. char ph_append[50];
  1410. char ph_buf[200];
  1411. char ph_buf2[50];
  1412. char ph_zeros[50];
  1413. char suffix[30]; // string[] must be long enough for sizeof(suffix)+2
  1414. char buf_digit_lookup[50];
  1415. static const char str_pause[2] = {phonPAUSE_NOLINK,0};
  1416. *flags = 0;
  1417. n_digit_lookup = 0;
  1418. buf_digit_lookup[0] = 0;
  1419. digit_lookup = buf_digit_lookup;
  1420. number_control = control;
  1421. for(ix=0; isdigit(word[ix]); ix++) ;
  1422. n_digits = ix;
  1423. value = this_value = atoi(word);
  1424. // is there a previous thousands part (as a previous "word") ?
  1425. if((n_digits == 3) && (word[-2] == tr->langopts.thousands_sep) && isdigit(word[-3]))
  1426. {
  1427. prev_thousands = 1;
  1428. }
  1429. else
  1430. if((tr->langopts.thousands_sep == ' ') || (tr->langopts.numbers & NUM_ALLOW_SPACE))
  1431. {
  1432. // thousands groups can be separated by spaces
  1433. if((n_digits == 3) && !(wtab->flags & FLAG_MULTIPLE_SPACES) && isdigit(word[-2]))
  1434. {
  1435. prev_thousands = 1;
  1436. }
  1437. }
  1438. if(prev_thousands == 0)
  1439. {
  1440. speak_missing_thousands = 0;
  1441. }
  1442. ph_ordinal2[0] = 0;
  1443. ph_zeros[0] = 0;
  1444. if(prev_thousands || (word[0] != '0'))
  1445. {
  1446. // don't check for ordinal if the number has a leading zero
  1447. if((ordinal = CheckDotOrdinal(tr, word, &word[ix], wtab, 0)) != 0)
  1448. dot_ordinal = 1;
  1449. }
  1450. if((word[ix] == '.') && !isdigit(word[ix+1]) && !isdigit(word[ix+2]) && !(wtab[1].flags & FLAG_NOSPACE))
  1451. {
  1452. // remove dot unless followed by another number
  1453. word[ix] = 0;
  1454. }
  1455. if((ordinal == 0) || (tr->translator_name == L('h','u')))
  1456. {
  1457. // NOTE lang=hu, allow both dot and ordinal suffix, eg. "december 21.-én"
  1458. // look for an ordinal number suffix after the number
  1459. ix++;
  1460. p = suffix;
  1461. if(wtab[0].flags & FLAG_HYPHEN_AFTER)
  1462. {
  1463. *p++ = '-';
  1464. ix++;
  1465. }
  1466. while((word[ix] != 0) && (word[ix] != ' ') && (ix < (int)(sizeof(suffix)-1)))
  1467. {
  1468. *p++ = word[ix++];
  1469. }
  1470. *p = 0;
  1471. if(suffix[0] != 0)
  1472. {
  1473. if((tr->langopts.ordinal_indicator != NULL) && (strcmp(suffix, tr->langopts.ordinal_indicator) == 0))
  1474. {
  1475. ordinal = 2;
  1476. }
  1477. else
  1478. if(!isdigit(suffix[0])) // not _#9 (tab)
  1479. {
  1480. sprintf(string,"_#%s",suffix);
  1481. if(Lookup(tr, string, ph_ordinal2))
  1482. {
  1483. // this is an ordinal suffix
  1484. ordinal = 2;
  1485. flags[0] |= FLAG_SKIPWORDS;
  1486. skipwords = 1;
  1487. }
  1488. }
  1489. }
  1490. }
  1491. if(wtab[0].flags & FLAG_ORDINAL)
  1492. ordinal = 2;
  1493. ph_append[0] = 0;
  1494. ph_buf2[0] = 0;
  1495. if((word[0] == '0') && (prev_thousands == 0) && (word[1] != ' ') && (word[1] != tr->langopts.decimal_sep))
  1496. {
  1497. if((n_digits == 2) && (word[3] == ':') && isdigit(word[5]) && isspace(word[7]))
  1498. {
  1499. // looks like a time 02:30, omit the leading zero
  1500. }
  1501. else
  1502. {
  1503. if(n_digits > 3)
  1504. {
  1505. flags[0] &= ~FLAG_SKIPWORDS;
  1506. return(0); // long number string with leading zero, speak as individual digits
  1507. }
  1508. // speak leading zeros
  1509. for(ix=0; (word[ix] == '0') && (ix < (n_digits-1)); ix++)
  1510. {
  1511. Lookup(tr, "_0", &ph_zeros[strlen(ph_zeros)]);
  1512. }
  1513. }
  1514. }
  1515. if((tr->langopts.numbers & NUM_ALLOW_SPACE) && (word[n_digits] == ' '))
  1516. thousands_inc = 1;
  1517. else
  1518. if(word[n_digits] == tr->langopts.thousands_sep)
  1519. thousands_inc = 2;
  1520. suffix_ix = n_digits+2;
  1521. if(thousands_inc > 0)
  1522. {
  1523. // if the following "words" are three-digit groups, count them and add
  1524. // a "thousand"/"million" suffix to this one
  1525. digix = n_digits + thousands_inc;
  1526. while(((wtab[thousandplex+1].flags & FLAG_MULTIPLE_SPACES) == 0) &&
  1527. isdigit(word[digix]) && isdigit(word[digix+1]) && isdigit(word[digix+2]) && !isdigit(word[digix+3]) && !isdigit(word[digix-1]))
  1528. {
  1529. if((word[digix] != '0') || (word[digix+1] != '0') || (word[digix+2] != '0'))
  1530. thousands_exact = 0;
  1531. thousandplex++;
  1532. digix += 3;
  1533. if((word[digix] == tr->langopts.thousands_sep) || ((tr->langopts.numbers & NUM_ALLOW_SPACE) && (word[digix] == ' ')))
  1534. {
  1535. suffix_ix = digix+2;
  1536. digix += thousands_inc;
  1537. }
  1538. else
  1539. break;
  1540. }
  1541. }
  1542. if((value == 0) && prev_thousands)
  1543. {
  1544. suppress_null = 1;
  1545. }
  1546. if(tr->translator_name == L('h','u'))
  1547. {
  1548. // variant form of numbers when followed by hyphen and a suffix starting with 'a' or 'e' (but not a, e, az, ez, azt, ezt
  1549. if((wtab[thousandplex].flags & FLAG_HYPHEN_AFTER) && (thousands_exact==1) && hu_number_e(&word[suffix_ix], thousandplex, value))
  1550. {
  1551. number_control |= 1; // use _1e variant of number
  1552. }
  1553. }
  1554. if((word[n_digits] == tr->langopts.decimal_sep) && isdigit(word[n_digits+1]))
  1555. {
  1556. // this "word" ends with a decimal point
  1557. Lookup(tr, "_dpt", ph_append);
  1558. decimal_point = 1;
  1559. }
  1560. else
  1561. if(suppress_null == 0)
  1562. {
  1563. if(thousands_inc > 0)
  1564. {
  1565. if((thousandplex > 0) && (value < 1000))
  1566. {
  1567. if((suppress_null == 0) && (LookupThousands(tr,value,thousandplex, thousands_exact, ph_append)))
  1568. {
  1569. // found an exact match for N thousand
  1570. value = 0;
  1571. suppress_null = 1;
  1572. }
  1573. }
  1574. }
  1575. }
  1576. else
  1577. if(speak_missing_thousands == 1)
  1578. {
  1579. // speak this thousandplex if there was no word for the previous thousandplex
  1580. sprintf(string,"_0M%d",thousandplex+1);
  1581. if(Lookup(tr, string, buf1)==0)
  1582. {
  1583. sprintf(string,"_0M%d",thousandplex);
  1584. Lookup(tr, string, ph_append);
  1585. }
  1586. }
  1587. if((ph_append[0] == 0) && (word[n_digits] == '.') && (thousandplex == 0))
  1588. {
  1589. Lookup(tr, "_.", ph_append);
  1590. }
  1591. if(thousandplex == 0)
  1592. {
  1593. char *p2;
  1594. // look for combinations of the number with the next word
  1595. p = word;
  1596. while(isdigit(p[1])) p++; // just use the last digit
  1597. if(isdigit(p[-1]))
  1598. {
  1599. p2 = p - 1;
  1600. if(LookupDictList(tr, &p2, buf_digit_lookup, flags, FLAG_SUFX, wtab)) // lookup 2 digits
  1601. {
  1602. n_digit_lookup = 2;
  1603. }
  1604. }
  1605. // if((buf_digit_lookup[0] == 0) && (*p != '0') && (dot_ordinal==0))
  1606. if((buf_digit_lookup[0] == 0) && (*p != '0'))
  1607. {
  1608. // not found, lookup only the last digit (?? but not if dot-ordinal has been found)
  1609. if(LookupDictList(tr, &p, buf_digit_lookup, flags, FLAG_SUFX, wtab)) // don't match '0', or entries with $only
  1610. {
  1611. n_digit_lookup = 1;
  1612. }
  1613. }
  1614. }
  1615. LookupNum3(tr, value, ph_buf, suppress_null, thousandplex, prev_thousands | ordinal);
  1616. if((thousandplex > 0) && (tr->langopts.numbers2 & 0x200))
  1617. sprintf(ph_out,"%s%s%s%s",ph_zeros,ph_append,ph_buf2,ph_buf); // say "thousands" before its number
  1618. else
  1619. sprintf(ph_out,"%s%s%s%s",ph_zeros,ph_buf2,ph_buf,ph_append);
  1620. while(decimal_point)
  1621. {
  1622. n_digits++;
  1623. decimal_count = 0;
  1624. while(isdigit(word[n_digits+decimal_count]))
  1625. decimal_count++;
  1626. // if(decimal_count > 1)
  1627. {
  1628. max_decimal_count = 2;
  1629. switch(decimal_mode = (tr->langopts.numbers & 0xe000))
  1630. {
  1631. case NUM_DFRACTION_4:
  1632. max_decimal_count = 5;
  1633. case NUM_DFRACTION_2:
  1634. // French/Polish decimal fraction
  1635. while(word[n_digits] == '0')
  1636. {
  1637. Lookup(tr, "_0", buf1);
  1638. strcat(ph_out,buf1);
  1639. decimal_count--;
  1640. n_digits++;
  1641. }
  1642. if((decimal_count <= max_decimal_count) && isdigit(word[n_digits]))
  1643. {
  1644. LookupNum3(tr, atoi(&word[n_digits]), buf1, 0,0,0);
  1645. strcat(ph_out,buf1);
  1646. n_digits += decimal_count;
  1647. }
  1648. break;
  1649. case NUM_DFRACTION_1: // italian, say "hundredths" if leading zero
  1650. case NUM_DFRACTION_5: // hungarian, always say "tenths" etc.
  1651. case NUM_DFRACTION_6: // kazakh, always say "tenths" etc, before the decimal fraction
  1652. LookupNum3(tr, atoi(&word[n_digits]), ph_buf, 0,0,0);
  1653. if((word[n_digits]=='0') || (decimal_mode != NUM_DFRACTION_1))
  1654. {
  1655. // decimal part has leading zeros, so add a "hundredths" or "thousandths" suffix
  1656. sprintf(string,"_0Z%d",decimal_count);
  1657. if(Lookup(tr, string, buf1) == 0)
  1658. break; // revert to speaking single digits
  1659. if(decimal_mode == NUM_DFRACTION_6)
  1660. strcat(ph_out, buf1);
  1661. else
  1662. strcat(ph_buf, buf1);
  1663. }
  1664. strcat(ph_out,ph_buf);
  1665. n_digits += decimal_count;
  1666. break;
  1667. case NUM_DFRACTION_3:
  1668. // Romanian decimal fractions
  1669. if((decimal_count <= 4) && (word[n_digits] != '0'))
  1670. {
  1671. LookupNum3(tr, atoi(&word[n_digits]), buf1, 0,0,0);
  1672. strcat(ph_out,buf1);
  1673. n_digits += decimal_count;
  1674. }
  1675. break;
  1676. }
  1677. }
  1678. while(isdigit(c = word[n_digits]) && (strlen(ph_out) < (N_WORD_PHONEMES - 10)))
  1679. {
  1680. // speak any remaining decimal fraction digits individually
  1681. value = word[n_digits++] - '0';
  1682. LookupNum2(tr, value, 2, buf1);
  1683. strcat(ph_out,buf1);
  1684. }
  1685. // something after the decimal part ?
  1686. if(Lookup(tr, "_dpt2", buf1))
  1687. strcat(ph_out,buf1);
  1688. if((c == tr->langopts.decimal_sep) && isdigit(word[n_digits+1]))
  1689. {
  1690. Lookup(tr, "_dpt", buf1);
  1691. strcat(ph_out,buf1);
  1692. }
  1693. else
  1694. {
  1695. decimal_point = 0;
  1696. }
  1697. }
  1698. if((ph_out[0] != 0) && (ph_out[0] != phonSWITCH))
  1699. {
  1700. int next_char;
  1701. char *p;
  1702. p = &word[n_digits+1];
  1703. p += utf8_in(&next_char,p);
  1704. if((tr->langopts.numbers & NUM_NOPAUSE) && (next_char == ' '))
  1705. utf8_in(&next_char,p);
  1706. if(!iswalpha(next_char) && !((wtab[thousandplex].flags & FLAG_HYPHEN_AFTER) && (thousands_exact != 0)))
  1707. strcat(ph_out,str_pause); // don't add pause for 100s, 6th, etc.
  1708. }
  1709. *flags |= FLAG_FOUND;
  1710. speak_missing_thousands--;
  1711. if(skipwords)
  1712. dictionary_skipwords = skipwords;
  1713. return(1);
  1714. } // end of TranslateNumber_1
  1715. int TranslateNumber(Translator *tr, char *word1, char *ph_out, unsigned int *flags, WORD_TAB *wtab, int control)
  1716. {//=============================================================================================================
  1717. if((option_sayas == SAYAS_DIGITS1) || (wtab[0].flags & FLAG_INDIVIDUAL_DIGITS))
  1718. return(0); // speak digits individually
  1719. if(tr->langopts.numbers != 0)
  1720. return(TranslateNumber_1(tr, word1, ph_out, flags, wtab, control));
  1721. return(0);
  1722. } // end of TranslateNumber