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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952
  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. char *ptr;
  465. ph_buf1[0] = 0;
  466. len = utf8_out(letter,&single_letter[2]);
  467. single_letter[len+2] = ' ';
  468. if(next_byte == -1)
  469. {
  470. // speaking normal text, not individual characters
  471. if(Lookup(tr, &single_letter[2], ph_buf1) != 0)
  472. return;
  473. single_letter[1] = '_';
  474. if(Lookup(tr, &single_letter[1], ph_buf3) != 0)
  475. return; // the character is specified as _* so ignore it when speaking normal text
  476. // check whether this character is specified for English
  477. if(tr->translator_name == L('e','n'))
  478. return; // we are already using English
  479. SetTranslator2("en");
  480. if(Lookup(translator2, &single_letter[2], ph_buf3) != 0)
  481. {
  482. // yes, switch to English and re-translate the word
  483. sprintf(ph_buf1,"%c",phonSWITCH);
  484. }
  485. SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
  486. return;
  487. }
  488. if((letter <= 32) || iswspace(letter))
  489. {
  490. // lookup space as _&32 etc.
  491. sprintf(&single_letter[1],"_#%d ",letter);
  492. Lookup(tr, &single_letter[1], ph_buf1);
  493. return;
  494. }
  495. if(next_byte != ' ')
  496. next_byte = RULE_SPELLING;
  497. single_letter[3+len] = next_byte; // follow by space-space if the end of the word, or space-31
  498. single_letter[1] = '_';
  499. // if the $accent flag is set for this letter, use the accents table (below)
  500. dict_flags[1] = 0;
  501. ptr = &single_letter[1];
  502. if(Lookup(tr, &single_letter[1], ph_buf3) == 0)
  503. {
  504. single_letter[1] = ' ';
  505. if(Lookup(tr, &single_letter[2], ph_buf3) == 0)
  506. {
  507. TranslateRules(tr, &single_letter[2], ph_buf3, sizeof(ph_buf3), NULL,FLAG_NO_TRACE,NULL);
  508. }
  509. }
  510. if(ph_buf3[0] == 0)
  511. {
  512. LookupAccentedLetter(tr, letter, ph_buf3);
  513. }
  514. strcpy(ph_buf1, ph_buf3);
  515. if((ph_buf1[0] == 0) || (ph_buf1[0] == phonSWITCH))
  516. {
  517. return;
  518. }
  519. dict_flags[0] = 0;
  520. dict_flags[1] = 0;
  521. SetWordStress(tr, ph_buf1, dict_flags, -1, control & 1);
  522. } // end of LookupLetter
  523. int TranslateLetter(Translator *tr, char *word, char *phonemes, int control)
  524. {//=========================================================================
  525. // get pronunciation for an isolated letter
  526. // return number of bytes used by the letter
  527. // control bit 0: a non-initial letter in a word
  528. // bit 1: say 'capital'
  529. int n_bytes;
  530. int letter;
  531. int len;
  532. int save_option_phonemes;
  533. char *p2;
  534. char *pbuf;
  535. char capital[20];
  536. char ph_buf[60];
  537. char ph_buf2[60];
  538. char hexbuf[6];
  539. ph_buf[0] = 0;
  540. capital[0] = 0;
  541. n_bytes = utf8_in(&letter,word);
  542. if((letter & 0xfff00) == 0x0e000)
  543. {
  544. letter &= 0xff; // uncode private usage area
  545. }
  546. if(control & 2)
  547. {
  548. // include CAPITAL information
  549. if(iswupper(letter))
  550. {
  551. Lookup(tr, "_cap", capital);
  552. }
  553. }
  554. letter = towlower2(letter);
  555. LookupLetter(tr, letter, word[n_bytes], ph_buf, control & 1);
  556. if(ph_buf[0] == phonSWITCH)
  557. {
  558. strcpy(phonemes,ph_buf);
  559. return(0);
  560. }
  561. if((ph_buf[0] == 0) && (tr->translator_name != L('e','n')))
  562. {
  563. // speak as English, check whether there is a translation for this character
  564. SetTranslator2("en");
  565. save_option_phonemes = option_phonemes;
  566. option_phonemes = 0;
  567. LookupLetter(translator2, letter, word[n_bytes], ph_buf, control & 1);
  568. SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table
  569. option_phonemes = save_option_phonemes;
  570. if(ph_buf[0] != 0)
  571. {
  572. sprintf(phonemes,"%cen",phonSWITCH);
  573. return(0);
  574. }
  575. }
  576. if(ph_buf[0] == 0)
  577. {
  578. // character name not found
  579. if(iswalpha(letter))
  580. Lookup(tr, "_?A", ph_buf);
  581. if((ph_buf[0]==0) && !iswspace(letter))
  582. Lookup(tr, "_??", ph_buf);
  583. if(ph_buf[0] != 0)
  584. {
  585. // speak the hexadecimal number of the character code
  586. sprintf(hexbuf,"%x",letter);
  587. pbuf = ph_buf;
  588. for(p2 = hexbuf; *p2 != 0; p2++)
  589. {
  590. pbuf += strlen(pbuf);
  591. *pbuf++ = phonPAUSE_VSHORT;
  592. LookupLetter(tr, *p2, 0, pbuf, 1);
  593. }
  594. }
  595. }
  596. len = strlen(phonemes);
  597. if(tr->langopts.accents & 2)
  598. sprintf(ph_buf2,"%c%s%s",0xff,ph_buf,capital);
  599. else
  600. sprintf(ph_buf2,"%c%s%s",0xff,capital,ph_buf); // the 0xff marker will be removed or replaced in SetSpellingStress()
  601. if((len + strlen(ph_buf2)) < N_WORD_PHONEMES)
  602. {
  603. strcpy(&phonemes[len],ph_buf2);
  604. }
  605. return(n_bytes);
  606. } // end of TranslateLetter
  607. void SetSpellingStress(Translator *tr, char *phonemes, int control, int n_chars)
  608. {//=============================================================================
  609. // Individual letter names, reduce the stress of some.
  610. int ix;
  611. unsigned int c;
  612. int n_stress=0;
  613. int count;
  614. unsigned char buf[N_WORD_PHONEMES];
  615. for(ix=0; (c = phonemes[ix]) != 0; ix++)
  616. {
  617. if(c == phonSTRESS_P)
  618. {
  619. n_stress++;
  620. }
  621. buf[ix] = c;
  622. }
  623. buf[ix] = 0;
  624. count = 0;
  625. for(ix=0; (c = buf[ix]) != 0; ix++)
  626. {
  627. if((c == phonSTRESS_P) && (n_chars > 1))
  628. {
  629. count++;
  630. if(tr->langopts.spelling_stress == 1)
  631. {
  632. // stress on initial letter when spelling
  633. if(count > 1)
  634. c = phonSTRESS_3;
  635. }
  636. else
  637. {
  638. if(count != n_stress)
  639. {
  640. if(((count % 3) != 0) || (count == n_stress-1))
  641. c = phonSTRESS_3; // reduce to secondary stress
  642. }
  643. }
  644. }
  645. else
  646. if(c == 0xff)
  647. {
  648. if((control < 2) || (ix==0))
  649. continue; // don't insert pauses
  650. if(control == 4)
  651. c = phonPAUSE; // pause after each character
  652. if(((count % 3) == 0) || (control > 2))
  653. c = phonPAUSE_NOLINK; // pause following a primary stress
  654. else
  655. c = phonPAUSE_VSHORT;
  656. // else
  657. // continue; // remove marker
  658. }
  659. *phonemes++ = c;
  660. }
  661. if(control >= 2)
  662. *phonemes++ = phonPAUSE_NOLINK;
  663. *phonemes = 0;
  664. } // end of SetSpellingStress
  665. // Numbers
  666. static char ph_ordinal2[12];
  667. static int CheckDotOrdinal(Translator *tr, char *word, char *word_end, WORD_TAB *wtab, int roman)
  668. {//==============================================================================================
  669. int ordinal = 0;
  670. int c2;
  671. int nextflags;
  672. if((tr->langopts.numbers & NUM_ORDINAL_DOT) && ((word_end[0] == '.') || (wtab[0].flags & FLAG_HAS_DOT)) && !(wtab[1].flags & FLAG_NOSPACE))
  673. {
  674. if(roman || !(wtab[1].flags & FLAG_FIRST_UPPER))
  675. {
  676. if(word_end[0] == '.')
  677. utf8_in(&c2, &word_end[2]);
  678. else
  679. utf8_in(&c2, &word_end[0]);
  680. if((word_end[0] != 0) && (word_end[1] != 0) && ((c2 == 0) || (wtab[0].flags & FLAG_COMMA_AFTER) || IsAlpha(c2)))
  681. {
  682. // ordinal number is indicated by dot after the number
  683. // but not if the next word starts with an upper-case letter
  684. // (c2 == 0) is for cases such as, "2.,"
  685. ordinal = 2;
  686. if(word_end[0] == '.')
  687. word_end[0] = ' ';
  688. if((roman==0) && (tr->translator_name == L('h','u')))
  689. {
  690. // lang=hu don't treat dot as ordinal indicator if the next word is a month name ($alt). It may have a suffix.
  691. nextflags = 0;
  692. if(IsAlpha(c2))
  693. {
  694. nextflags = TranslateWord(tr, &word_end[2], 0, NULL);
  695. }
  696. if((tr->prev_dict_flags & FLAG_ALT_TRANS) && ((c2 == 0) || (wtab[0].flags & FLAG_COMMA_AFTER) || iswdigit(c2)))
  697. ordinal = 0; // TEST 09.02.10
  698. if(nextflags & FLAG_ALT_TRANS)
  699. ordinal = 0;
  700. if(nextflags & FLAG_ALT3_TRANS)
  701. {
  702. if(word[-2] == '-')
  703. ordinal = 0; // eg. december 2-5. között
  704. if(tr->prev_dict_flags & (FLAG_ALT_TRANS | FLAG_ALT3_TRANS))
  705. ordinal = 0x22;
  706. }
  707. }
  708. }
  709. }
  710. }
  711. return(ordinal);
  712. } // end of CheckDotOrdinal
  713. static int hu_number_e(const char *word, int thousandplex, int value)
  714. {//==================================================================
  715. // 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
  716. if((word[0] == 'a') || (word[0] == 'e'))
  717. {
  718. if((word[1] == ' ') || (word[1] == 'z') || ((word[1] == 't') && (word[2] == 't')))
  719. return(0);
  720. if(((thousandplex==1) || ((value % 1000) == 0)) && (word[1] == 'l'))
  721. return(0); // 1000-el
  722. return(1);
  723. }
  724. return(0);
  725. } // end of hu_numnber_e
  726. int TranslateRoman(Translator *tr, char *word, char *ph_out, WORD_TAB *wtab)
  727. {//=========================================================================
  728. int c;
  729. char *p;
  730. const char *p2;
  731. int acc;
  732. int prev;
  733. int value;
  734. int subtract;
  735. int repeat = 0;
  736. int n_digits = 0;
  737. char *word_start;
  738. int num_control = 0;
  739. unsigned int flags[2];
  740. char ph_roman[30];
  741. char number_chars[N_WORD_BYTES];
  742. static const char *roman_numbers = "ixcmvld";
  743. static int roman_values[] = {1,10,100,1000,5,50,500};
  744. acc = 0;
  745. prev = 0;
  746. subtract = 0x7fff;
  747. ph_out[0] = 0;
  748. flags[0] = 0;
  749. flags[1] = 0;
  750. if(((tr->langopts.numbers & NUM_ROMAN_CAPITALS) && !(wtab[0].flags & FLAG_ALL_UPPER)) || isdigit(word[-2]))
  751. return(0); // not '2xx'
  752. word_start = word;
  753. while((c = *word++) != ' ')
  754. {
  755. if((p2 = strchr(roman_numbers,c)) == NULL)
  756. return(0);
  757. value = roman_values[p2 - roman_numbers];
  758. if(value == prev)
  759. {
  760. repeat++;
  761. if(repeat >= 3)
  762. return(0);
  763. }
  764. else
  765. repeat = 0;
  766. if((prev > 1) && (prev != 10) && (prev != 100))
  767. {
  768. if(value >= prev)
  769. return(0);
  770. }
  771. if((prev != 0) && (prev < value))
  772. {
  773. if(((acc % 10) != 0) || ((prev*10) < value))
  774. return(0);
  775. subtract = prev;
  776. value -= subtract;
  777. }
  778. else
  779. if(value >= subtract)
  780. return(0);
  781. else
  782. acc += prev;
  783. prev = value;
  784. n_digits++;
  785. }
  786. if(isdigit(word[0]))
  787. return(0); // eg. 'xx2'
  788. acc += prev;
  789. if(acc < tr->langopts.min_roman)
  790. return(0);
  791. if(acc > tr->langopts.max_roman)
  792. return(0);
  793. Lookup(tr, "_roman",ph_roman); // precede by "roman" if _rom is defined in *_list
  794. p = &ph_out[0];
  795. if((tr->langopts.numbers & NUM_ROMAN_AFTER) == 0)
  796. {
  797. strcpy(ph_out,ph_roman);
  798. p = &ph_out[strlen(ph_roman)];
  799. }
  800. sprintf(number_chars," %d ",acc);
  801. if(word[0] == '.')
  802. {
  803. // dot has not been removed. This implies that there was no space after it
  804. return(0);
  805. }
  806. if(CheckDotOrdinal(tr, word_start, word, wtab, 1))
  807. wtab[0].flags |= FLAG_ORDINAL;
  808. if(tr->langopts.numbers & NUM_ROMAN_ORDINAL)
  809. {
  810. if(tr->translator_name == L('h','u'))
  811. {
  812. if(!(wtab[0].flags & FLAG_ORDINAL))
  813. {
  814. if((wtab[0].flags & FLAG_HYPHEN_AFTER) && hu_number_e(word, 0, acc))
  815. {
  816. // should use the 'e' form of the number
  817. num_control |= 1;
  818. }
  819. else
  820. return(0);
  821. }
  822. }
  823. else
  824. {
  825. wtab[0].flags |= FLAG_ORDINAL;
  826. }
  827. }
  828. tr->prev_dict_flags = 0;
  829. TranslateNumber(tr, &number_chars[2], p, flags, wtab, num_control);
  830. if(tr->langopts.numbers & NUM_ROMAN_AFTER)
  831. strcat(ph_out,ph_roman);
  832. return(1);
  833. } // end of TranslateRoman
  834. static const char *M_Variant(int value)
  835. {//====================================
  836. // returns M, or perhaps MA for some cases
  837. if((translator->langopts.numbers2 & 0x100) && (value >= 2) && (value <= 4))
  838. return("0MA"); // Czech, Slovak
  839. else
  840. if(((value % 100) < 10) || ((value % 100) > 20)) // but not teens, 10 to 19
  841. {
  842. if ((translator->langopts.numbers2 & 0x40) &&
  843. ((value % 10)>=2) &&
  844. ((value % 10)<=4))
  845. {
  846. // for Polish language - two forms of plural!
  847. return("0MA");
  848. }
  849. if((translator->langopts.numbers2 & 0x80) &&
  850. ((value % 10)==1))
  851. {
  852. return("1MA");
  853. }
  854. }
  855. return("0M");
  856. }
  857. static int LookupThousands(Translator *tr, int value, int thousandplex, int thousands_exact, char *ph_out)
  858. {//=======================================================================================================
  859. // thousands_exact: bit 0 no hundreds,tens,or units, bit 1 ordinal numberr
  860. int found;
  861. int found_value=0;
  862. char string[12];
  863. char ph_of[12];
  864. char ph_thousands[40];
  865. char ph_buf[40];
  866. ph_of[0] = 0;
  867. // first look for a match with the exact value of thousands
  868. if(value > 0)
  869. {
  870. if(thousands_exact & 1)
  871. {
  872. if(thousands_exact & 2)
  873. {
  874. // ordinal number
  875. sprintf(string,"_%dM%do",value,thousandplex);
  876. found_value = Lookup(tr, string, ph_thousands);
  877. }
  878. if(!found_value & (number_control & 1))
  879. {
  880. // look for the 'e' variant
  881. sprintf(string,"_%dM%de",value,thousandplex);
  882. found_value = Lookup(tr, string, ph_thousands);
  883. }
  884. if(!found_value)
  885. {
  886. // is there a different pronunciation if there are no hundreds,tens,or units ? (LANG=ta)
  887. sprintf(string,"_%dM%dx",value,thousandplex);
  888. found_value = Lookup(tr, string, ph_thousands);
  889. }
  890. }
  891. if(found_value == 0)
  892. {
  893. sprintf(string,"_%dM%d",value,thousandplex);
  894. found_value = Lookup(tr, string, ph_thousands);
  895. }
  896. }
  897. if(found_value == 0)
  898. {
  899. if((value % 100) >= 20)
  900. {
  901. Lookup(tr, "_0of", ph_of);
  902. }
  903. found = 0;
  904. if(thousands_exact & 1)
  905. {
  906. if(thousands_exact & 2)
  907. {
  908. // ordinal number
  909. sprintf(string,"_%s%do",M_Variant(value), thousandplex);
  910. found = Lookup(tr, string, ph_thousands);
  911. }
  912. if(!found && (number_control & 1))
  913. {
  914. // look for the 'e' variant
  915. sprintf(string,"_%s%de",M_Variant(value), thousandplex);
  916. found = Lookup(tr, string, ph_thousands);
  917. }
  918. if(!found)
  919. {
  920. // is there a different pronunciation if there are no hundreds,tens,or units ?
  921. sprintf(string,"_%s%dx",M_Variant(value), thousandplex);
  922. found = Lookup(tr, string, ph_thousands);
  923. }
  924. }
  925. if(found == 0)
  926. {
  927. sprintf(string,"_%s%d",M_Variant(value), thousandplex);
  928. if(Lookup(tr, string, ph_thousands) == 0)
  929. {
  930. if(thousandplex > 3)
  931. {
  932. sprintf(string,"_0M%d", thousandplex-1);
  933. if(Lookup(tr, string, ph_buf) == 0)
  934. {
  935. // say "millions" if this name is not available and neither is the next lower
  936. Lookup(tr, "_0M2", ph_thousands);
  937. speak_missing_thousands = 3;
  938. }
  939. }
  940. if(ph_thousands[0] == 0)
  941. {
  942. // repeat "thousand" if higher order names are not available
  943. sprintf(string,"_%dM1",value);
  944. if((found_value = Lookup(tr, string, ph_thousands)) == 0)
  945. Lookup(tr, "_0M1", ph_thousands);
  946. speak_missing_thousands = 2;
  947. }
  948. }
  949. }
  950. }
  951. sprintf(ph_out,"%s%s",ph_of,ph_thousands);
  952. if((value == 1) && (thousandplex == 1) && (tr->langopts.numbers & NUM_OMIT_1_THOUSAND))
  953. return(1);
  954. return(found_value);
  955. } // end f LookupThousands
  956. static int LookupNum2(Translator *tr, int value, int control, char *ph_out)
  957. {//========================================================================
  958. // Lookup a 2 digit number
  959. // control bit 0: ordinal number
  960. // control bit 1: final tens and units (not number of thousands) (use special form of '1', LANG=de "eins")
  961. // control bit 2: tens and units only, no higher digits
  962. // control bit 3: use feminine form of '2' (for thousands
  963. // control bit 4: speak zero tens
  964. // control bit 5: variant of ordinal number (lang=hu)
  965. int found;
  966. int ix;
  967. int units;
  968. int tens;
  969. int used_and=0;
  970. int found_ordinal = 0;
  971. int next_phtype;
  972. int ord_type = 'o';
  973. char string[12]; // for looking up entries in *_list
  974. char ph_ordinal[20];
  975. char ph_tens[50];
  976. char ph_digits[50];
  977. char ph_and[12];
  978. units = value % 10;
  979. tens = value / 10;
  980. found = 0;
  981. ph_ordinal[0] = 0;
  982. ph_tens[0] = 0;
  983. ph_digits[0] = 0;
  984. ph_and[0] = 0;
  985. if(control & 0x20)
  986. {
  987. ord_type = 'q';
  988. }
  989. if((control & 2) && (n_digit_lookup == 2))
  990. {
  991. // pronunciation of the final 2 digits has already been found
  992. strcpy(ph_out, digit_lookup);
  993. }
  994. else
  995. {
  996. if(digit_lookup[0] == 0)
  997. {
  998. // is there a special pronunciation for this 2-digit number
  999. if(control & 8)
  1000. {
  1001. sprintf(string,"_%df",value);
  1002. found = Lookup(tr, string, ph_digits);
  1003. }
  1004. else
  1005. if(control & 1)
  1006. {
  1007. strcpy(ph_ordinal, ph_ordinal2);
  1008. if(control & 4)
  1009. {
  1010. sprintf(string,"_%d%cx",value,ord_type); // LANG=hu, special word for 1. 2. when there are no higher digits
  1011. found = Lookup(tr, string, ph_digits);
  1012. }
  1013. if(found == 0)
  1014. {
  1015. sprintf(string,"_%d%c",value,ord_type);
  1016. found = Lookup(tr, string, ph_digits);
  1017. }
  1018. found_ordinal = found;
  1019. }
  1020. if(found == 0)
  1021. {
  1022. if(control & 2)
  1023. {
  1024. // the final tens and units of a number
  1025. if(number_control & 1)
  1026. {
  1027. // look for 'e' variant
  1028. sprintf(string,"_%de",value);
  1029. found = Lookup(tr, string, ph_digits);
  1030. }
  1031. }
  1032. else
  1033. {
  1034. // followed by hundreds or thousands etc
  1035. sprintf(string,"_%da",value);
  1036. found = Lookup(tr, string, ph_digits);
  1037. }
  1038. if(!found)
  1039. {
  1040. sprintf(string,"_%d",value);
  1041. found = Lookup(tr, string, ph_digits);
  1042. }
  1043. }
  1044. }
  1045. // no, speak as tens+units
  1046. if((control & 0x10) && (value < 10))
  1047. {
  1048. // speak leading zero
  1049. Lookup(tr, "_0", ph_tens);
  1050. }
  1051. else
  1052. {
  1053. if(found)
  1054. {
  1055. ph_tens[0] = 0;
  1056. }
  1057. else
  1058. {
  1059. if((control & 1) &&
  1060. ((units == 0) || (tr->langopts.numbers & NUM_SWAP_TENS) || (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL)))
  1061. {
  1062. sprintf(string,"_%dX%c", tens, ord_type);
  1063. if(Lookup(tr, string, ph_tens) != 0)
  1064. {
  1065. found_ordinal = 1;
  1066. if((units != 0) && (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL))
  1067. {
  1068. // Use the ordinal form of tens as well as units. Add the ordinal ending
  1069. strcat(ph_tens, ph_ordinal2);
  1070. }
  1071. }
  1072. }
  1073. if(found_ordinal == 0)
  1074. {
  1075. sprintf(string,"_%dX", tens);
  1076. Lookup(tr, string, ph_tens);
  1077. }
  1078. if((ph_tens[0] == 0) && (tr->langopts.numbers & NUM_VIGESIMAL))
  1079. {
  1080. // tens not found, (for example) 73 is 60+13
  1081. units = (value % 20);
  1082. sprintf(string,"_%dX", tens & 0xfe);
  1083. Lookup(tr, string, ph_tens);
  1084. }
  1085. ph_digits[0] = 0;
  1086. if(units > 0)
  1087. {
  1088. found = 0;
  1089. if((control & 2) && (digit_lookup[0] != 0))
  1090. {
  1091. // we have an entry for this digit (possibly together with the next word)
  1092. strcpy(ph_digits, digit_lookup);
  1093. found_ordinal = 1;
  1094. ph_ordinal[0] = 0;
  1095. }
  1096. else
  1097. {
  1098. if(control & 8)
  1099. {
  1100. // is there a variant form of this number?
  1101. sprintf(string,"_%df",units);
  1102. found = Lookup(tr, string, ph_digits);
  1103. }
  1104. if((control & 1) && ((tr->langopts.numbers & NUM_SWAP_TENS) == 0))
  1105. {
  1106. // ordinal
  1107. sprintf(string,"_%d%c",units,ord_type);
  1108. if((found = Lookup(tr, string, ph_digits)) != 0)
  1109. {
  1110. found_ordinal = 1;
  1111. }
  1112. }
  1113. if(found == 0)
  1114. {
  1115. if((number_control & 1) && (control & 2))
  1116. {
  1117. // look for 'e' variant
  1118. sprintf(string,"_%de",units);
  1119. found = Lookup(tr, string, ph_digits);
  1120. }
  1121. else
  1122. if(((control & 2) == 0) || ((tr->langopts.numbers & NUM_SWAP_TENS) != 0))
  1123. {
  1124. // followed by hundreds or thousands (or tens)
  1125. sprintf(string,"_%da",units);
  1126. found = Lookup(tr, string, ph_digits);
  1127. }
  1128. }
  1129. if(found == 0)
  1130. {
  1131. sprintf(string,"_%d",units);
  1132. Lookup(tr, string, ph_digits);
  1133. }
  1134. }
  1135. }
  1136. }
  1137. }
  1138. if((control & 1) && (found_ordinal == 0) && (ph_ordinal[0] == 0))
  1139. {
  1140. if((value >= 20) && (((value % 10) == 0) || (tr->langopts.numbers & NUM_SWAP_TENS)))
  1141. Lookup(tr, "_ord20", ph_ordinal);
  1142. if(ph_ordinal[0] == 0)
  1143. Lookup(tr, "_ord", ph_ordinal);
  1144. }
  1145. if((tr->langopts.numbers & (NUM_SWAP_TENS | NUM_AND_UNITS)) && (ph_tens[0] != 0) && (ph_digits[0] != 0))
  1146. {
  1147. Lookup(tr, "_0and", ph_and);
  1148. if((control & 1) && (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL))
  1149. ph_and[0] = 0;
  1150. if(tr->langopts.numbers & NUM_SWAP_TENS)
  1151. sprintf(ph_out,"%s%s%s%s",ph_digits, ph_and, ph_tens, ph_ordinal);
  1152. else
  1153. sprintf(ph_out,"%s%s%s%s",ph_tens, ph_and, ph_digits, ph_ordinal);
  1154. used_and = 1;
  1155. }
  1156. else
  1157. {
  1158. if(tr->langopts.numbers & NUM_SINGLE_VOWEL)
  1159. {
  1160. // remove vowel from the end of tens if units starts with a vowel (LANG=Italian)
  1161. if(((ix = strlen(ph_tens)-1) >= 0) && (ph_digits[0] != 0))
  1162. {
  1163. if((next_phtype = phoneme_tab[(unsigned int)(ph_digits[0])]->type) == phSTRESS)
  1164. next_phtype = phoneme_tab[(unsigned int)(ph_digits[1])]->type;
  1165. if((phoneme_tab[(unsigned int)(ph_tens[ix])]->type == phVOWEL) && (next_phtype == phVOWEL))
  1166. ph_tens[ix] = 0;
  1167. }
  1168. }
  1169. sprintf(ph_out,"%s%s%s",ph_tens, ph_digits, ph_ordinal);
  1170. }
  1171. }
  1172. if(tr->langopts.numbers & NUM_SINGLE_STRESS)
  1173. {
  1174. // only one primary stress
  1175. found = 0;
  1176. for(ix=strlen(ph_out)-1; ix>=0; ix--)
  1177. {
  1178. if(ph_out[ix] == phonSTRESS_P)
  1179. {
  1180. if(found)
  1181. ph_out[ix] = phonSTRESS_3;
  1182. else
  1183. found = 1;
  1184. }
  1185. }
  1186. }
  1187. return(used_and);
  1188. } // end of LookupNum2
  1189. static int LookupNum3(Translator *tr, int value, char *ph_out, int suppress_null, int thousandplex, int control)
  1190. {//=============================================================================================================
  1191. // Translate a 3 digit number
  1192. // control bit 0, previous thousands
  1193. // bit 1, ordinal number
  1194. // bit 5 variant form of ordinal number
  1195. int found;
  1196. int hundreds;
  1197. int tensunits;
  1198. int x;
  1199. int ix;
  1200. int exact;
  1201. int ordinal;
  1202. int say_zero_hundred=0;
  1203. char string[12]; // for looking up entries in **_list
  1204. char buf1[100];
  1205. char buf2[100];
  1206. char ph_100[20];
  1207. char ph_10T[20];
  1208. char ph_digits[50];
  1209. char ph_thousands[50];
  1210. char ph_hundred_and[12];
  1211. char ph_thousand_and[12];
  1212. ordinal = control & 0x22;
  1213. hundreds = value / 100;
  1214. tensunits = value % 100;
  1215. buf1[0] = 0;
  1216. ph_thousands[0] = 0;
  1217. ph_thousand_and[0] = 0;
  1218. if((tr->langopts.numbers & NUM_ZERO_HUNDRED) && ((control & 1) || (hundreds >= 10)))
  1219. {
  1220. say_zero_hundred = 1; // lang=vi
  1221. }
  1222. if((hundreds > 0) || say_zero_hundred)
  1223. {
  1224. found = 0;
  1225. if(ordinal && (tensunits == 0))
  1226. {
  1227. // ordinal number, with no tens or units
  1228. found = Lookup(tr, "_0Co", ph_100);
  1229. }
  1230. if(found == 0)
  1231. {
  1232. if(tensunits==0)
  1233. {
  1234. // special form for exact hundreds?
  1235. found = Lookup(tr, "_0C0", ph_100);
  1236. }
  1237. if(!found)
  1238. {
  1239. Lookup(tr, "_0C", ph_100);
  1240. }
  1241. }
  1242. if(((tr->langopts.numbers & NUM_1900) != 0) && (hundreds == 19))
  1243. {
  1244. // speak numbers such as 1984 as years: nineteen-eighty-four
  1245. // ph_100[0] = 0; // don't say "hundred", we also need to surpess "and"
  1246. }
  1247. else
  1248. if(hundreds >= 10)
  1249. {
  1250. ph_digits[0] = 0;
  1251. exact = 0;
  1252. if ((value % 1000) == 0)
  1253. exact = 1;
  1254. if(LookupThousands(tr, hundreds / 10, thousandplex+1, exact | ordinal, ph_10T) == 0)
  1255. {
  1256. x = 0;
  1257. if(tr->langopts.numbers2 & (1 << (thousandplex+1)))
  1258. x = 8; // use variant (feminine) for before thousands and millions
  1259. LookupNum2(tr, hundreds/10, x, ph_digits);
  1260. }
  1261. if(tr->langopts.numbers2 & 0x200)
  1262. sprintf(ph_thousands,"%s%s",ph_10T,ph_digits); // say "thousands" before its number, not after
  1263. else
  1264. sprintf(ph_thousands,"%s%s",ph_digits,ph_10T);
  1265. hundreds %= 10;
  1266. if((hundreds == 0) && (say_zero_hundred == 0))
  1267. ph_100[0] = 0;
  1268. suppress_null = 1;
  1269. }
  1270. ph_digits[0] = 0;
  1271. if((hundreds > 0) || say_zero_hundred)
  1272. {
  1273. if((tr->langopts.numbers & NUM_AND_HUNDRED) && ((control & 1) || (ph_thousands[0] != 0)))
  1274. {
  1275. Lookup(tr, "_0and", ph_thousand_and);
  1276. }
  1277. suppress_null = 1;
  1278. found = 0;
  1279. if((ordinal)
  1280. && ((tensunits == 0) || (tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL)))
  1281. {
  1282. // ordinal number
  1283. sprintf(string, "_%dCo", hundreds);
  1284. found = Lookup(tr, string, ph_digits);
  1285. if((tr->langopts.numbers2 & NUM2_MULTIPLE_ORDINAL) && (tensunits > 0))
  1286. {
  1287. // Use ordinal form of hundreds, as well as for tens and units
  1288. // Add ordinal suffix to the hundreds
  1289. strcat(ph_digits, ph_ordinal2);
  1290. }
  1291. }
  1292. if((hundreds == 0) && say_zero_hundred)
  1293. {
  1294. Lookup(tr, "_0", ph_digits);
  1295. }
  1296. else
  1297. {
  1298. if((!found) && (tensunits == 0))
  1299. {
  1300. // is there a special pronunciation for exactly n00 ?
  1301. sprintf(string,"_%dC0",hundreds);
  1302. found = Lookup(tr, string, ph_digits);
  1303. }
  1304. if(!found)
  1305. {
  1306. sprintf(string,"_%dC",hundreds);
  1307. found = Lookup(tr, string, ph_digits); // is there a specific pronunciation for n-hundred ?
  1308. }
  1309. if(found)
  1310. {
  1311. ph_100[0] = 0;
  1312. }
  1313. else
  1314. {
  1315. if((hundreds > 1) || ((tr->langopts.numbers & NUM_OMIT_1_HUNDRED) == 0))
  1316. {
  1317. LookupNum2(tr, hundreds, 0, ph_digits);
  1318. }
  1319. }
  1320. }
  1321. }
  1322. sprintf(buf1,"%s%s%s%s",ph_thousands,ph_thousand_and,ph_digits,ph_100);
  1323. }
  1324. ph_hundred_and[0] = 0;
  1325. if(tensunits > 0)
  1326. {
  1327. if((value > 100) || ((control & 1) && (thousandplex==0)))
  1328. {
  1329. if((tr->langopts.numbers & NUM_HUNDRED_AND) || ((tr->langopts.numbers & NUM_HUNDRED_AND_DIGIT) && (tensunits < 10)))
  1330. {
  1331. Lookup(tr, "_0and", ph_hundred_and);
  1332. }
  1333. }
  1334. if((tr->langopts.numbers & NUM_THOUSAND_AND) && (hundreds == 0) && ((control & 1) || (ph_thousands[0] != 0)))
  1335. {
  1336. Lookup(tr, "_0and", ph_hundred_and);
  1337. }
  1338. }
  1339. buf2[0] = 0;
  1340. if((tensunits != 0) || (suppress_null == 0))
  1341. {
  1342. x = 0;
  1343. if(thousandplex==0)
  1344. {
  1345. x = 2; // allow "eins" for 1 rather than "ein"
  1346. if(ordinal)
  1347. x = 3; // ordinal number
  1348. if((value < 100) && !(control & 1))
  1349. x |= 4; // tens and units only, no higher digits
  1350. if(ordinal & 0x20)
  1351. x |= 0x20; // variant form of ordinal number
  1352. }
  1353. else
  1354. {
  1355. if(tr->langopts.numbers2 & (1 << thousandplex))
  1356. x = 8; // use variant (feminine) for before thousands and millions
  1357. }
  1358. if(LookupNum2(tr, tensunits, x, buf2) != 0)
  1359. {
  1360. if(tr->langopts.numbers & NUM_SINGLE_AND)
  1361. ph_hundred_and[0] = 0; // don't put 'and' after 'hundred' if there's 'and' between tens and units
  1362. }
  1363. }
  1364. else
  1365. {
  1366. if(ph_ordinal2[0] != 0)
  1367. {
  1368. ix = strlen(buf1);
  1369. if((ix > 0) && (buf1[ix-1] == phonPAUSE_SHORT))
  1370. buf1[ix-1] = 0; // remove pause before addding ordinal suffix
  1371. strcpy(buf2, ph_ordinal2);
  1372. }
  1373. }
  1374. sprintf(ph_out,"%s%s%s",buf1,ph_hundred_and,buf2);
  1375. return(0);
  1376. } // end of LookupNum3
  1377. static int TranslateNumber_1(Translator *tr, char *word, char *ph_out, unsigned int *flags, WORD_TAB *wtab, int control)
  1378. {//=====================================================================================================================
  1379. // Number translation with various options
  1380. // the "word" may be up to 4 digits
  1381. // "words" of 3 digits may be preceded by another number "word" for thousands or millions
  1382. int n_digits;
  1383. int value;
  1384. int ix;
  1385. int digix;
  1386. unsigned char c;
  1387. int suppress_null = 0;
  1388. int decimal_point = 0;
  1389. int thousandplex = 0;
  1390. int thousands_exact = 1;
  1391. int thousands_inc = 0;
  1392. int prev_thousands = 0;
  1393. int ordinal = 0;
  1394. int dot_ordinal;
  1395. int this_value;
  1396. int decimal_count;
  1397. int max_decimal_count;
  1398. int decimal_mode;
  1399. int hyphen;
  1400. int suffix_ix;
  1401. int skipwords = 0;
  1402. char *p;
  1403. char string[32]; // for looking up entries in **_list
  1404. char buf1[100];
  1405. char ph_append[50];
  1406. char ph_buf[200];
  1407. char ph_buf2[50];
  1408. char ph_zeros[50];
  1409. char suffix[30]; // string[] must be long enough for sizeof(suffix)+2
  1410. char buf_digit_lookup[50];
  1411. static const char str_pause[2] = {phonPAUSE_NOLINK,0};
  1412. *flags = 0;
  1413. n_digit_lookup = 0;
  1414. buf_digit_lookup[0] = 0;
  1415. digit_lookup = buf_digit_lookup;
  1416. number_control = control;
  1417. for(ix=0; isdigit(word[ix]); ix++) ;
  1418. n_digits = ix;
  1419. value = this_value = atoi(word);
  1420. // is there a previous thousands part (as a previous "word") ?
  1421. if((n_digits == 3) && (word[-2] == tr->langopts.thousands_sep) && isdigit(word[-3]))
  1422. {
  1423. prev_thousands = 1;
  1424. }
  1425. else
  1426. if((tr->langopts.thousands_sep == ' ') || (tr->langopts.numbers & NUM_ALLOW_SPACE))
  1427. {
  1428. // thousands groups can be separated by spaces
  1429. if((n_digits == 3) && !(wtab->flags & FLAG_MULTIPLE_SPACES) && isdigit(word[-2]))
  1430. {
  1431. prev_thousands = 1;
  1432. }
  1433. }
  1434. if(prev_thousands == 0)
  1435. {
  1436. speak_missing_thousands = 0;
  1437. }
  1438. ph_ordinal2[0] = 0;
  1439. ph_zeros[0] = 0;
  1440. if(prev_thousands || (word[0] != '0'))
  1441. {
  1442. // don't check for ordinal if the number has a leading zero
  1443. if((ordinal = CheckDotOrdinal(tr, word, &word[ix], wtab, 0)) != 0)
  1444. dot_ordinal = 1;
  1445. }
  1446. if((word[ix] == '.') && !isdigit(word[ix+1]) && !isdigit(word[ix+2]) && !(wtab[1].flags & FLAG_NOSPACE))
  1447. {
  1448. // remove dot unless followed by another number
  1449. word[ix] = 0;
  1450. }
  1451. if((ordinal == 0) || (tr->translator_name == L('h','u')))
  1452. {
  1453. // NOTE lang=hu, allow both dot and ordinal suffix, eg. "december 21.-én"
  1454. // look for an ordinal number suffix after the number
  1455. ix++;
  1456. hyphen = 0;
  1457. p = suffix;
  1458. if(wtab[0].flags & FLAG_HYPHEN_AFTER)
  1459. {
  1460. *p++ = '-';
  1461. hyphen = 1;
  1462. ix++;
  1463. }
  1464. while((word[ix] != 0) && (word[ix] != ' ') && (ix < (int)(sizeof(suffix)-1)))
  1465. {
  1466. *p++ = word[ix++];
  1467. }
  1468. *p = 0;
  1469. if(suffix[0] != 0)
  1470. {
  1471. if((tr->langopts.ordinal_indicator != NULL) && (strcmp(suffix, tr->langopts.ordinal_indicator) == 0))
  1472. {
  1473. ordinal = 2;
  1474. }
  1475. else
  1476. if(!isdigit(suffix[0])) // not _#9 (tab)
  1477. {
  1478. sprintf(string,"_#%s",suffix);
  1479. if(Lookup(tr, string, ph_ordinal2))
  1480. {
  1481. // this is an ordinal suffix
  1482. ordinal = 2;
  1483. flags[0] |= FLAG_SKIPWORDS;
  1484. skipwords = 1;
  1485. }
  1486. }
  1487. }
  1488. }
  1489. if(wtab[0].flags & FLAG_ORDINAL)
  1490. ordinal = 2;
  1491. ph_append[0] = 0;
  1492. ph_buf2[0] = 0;
  1493. if((word[0] == '0') && (prev_thousands == 0) && (word[1] != ' ') && (word[1] != tr->langopts.decimal_sep))
  1494. {
  1495. if((n_digits == 2) && (word[3] == ':') && isdigit(word[5]) && isspace(word[7]))
  1496. {
  1497. // looks like a time 02:30, omit the leading zero
  1498. }
  1499. else
  1500. {
  1501. if(n_digits > 3)
  1502. {
  1503. flags[0] &= ~FLAG_SKIPWORDS;
  1504. return(0); // long number string with leading zero, speak as individual digits
  1505. }
  1506. // speak leading zeros
  1507. for(ix=0; (word[ix] == '0') && (ix < (n_digits-1)); ix++)
  1508. {
  1509. Lookup(tr, "_0", &ph_zeros[strlen(ph_zeros)]);
  1510. }
  1511. }
  1512. }
  1513. if((tr->langopts.numbers & NUM_ALLOW_SPACE) && (word[n_digits] == ' '))
  1514. thousands_inc = 1;
  1515. else
  1516. if(word[n_digits] == tr->langopts.thousands_sep)
  1517. thousands_inc = 2;
  1518. suffix_ix = n_digits+2;
  1519. if(thousands_inc > 0)
  1520. {
  1521. // if the following "words" are three-digit groups, count them and add
  1522. // a "thousand"/"million" suffix to this one
  1523. digix = n_digits + thousands_inc;
  1524. while(((wtab[thousandplex+1].flags & FLAG_MULTIPLE_SPACES) == 0) &&
  1525. isdigit(word[digix]) && isdigit(word[digix+1]) && isdigit(word[digix+2]) && !isdigit(word[digix+3]) && !isdigit(word[digix-1]))
  1526. {
  1527. if((word[digix] != '0') || (word[digix+1] != '0') || (word[digix+2] != '0'))
  1528. thousands_exact = 0;
  1529. thousandplex++;
  1530. digix += 3;
  1531. if((word[digix] == tr->langopts.thousands_sep) || ((tr->langopts.numbers & NUM_ALLOW_SPACE) && (word[digix] == ' ')))
  1532. {
  1533. suffix_ix = digix+2;
  1534. digix += thousands_inc;
  1535. }
  1536. else
  1537. break;
  1538. }
  1539. }
  1540. if((value == 0) && prev_thousands)
  1541. {
  1542. suppress_null = 1;
  1543. }
  1544. if(tr->translator_name == L('h','u'))
  1545. {
  1546. // variant form of numbers when followed by hyphen and a suffix starting with 'a' or 'e' (but not a, e, az, ez, azt, ezt
  1547. if((wtab[thousandplex].flags & FLAG_HYPHEN_AFTER) && (thousands_exact==1) && hu_number_e(&word[suffix_ix], thousandplex, value))
  1548. {
  1549. number_control |= 1; // use _1e variant of number
  1550. }
  1551. }
  1552. if((word[n_digits] == tr->langopts.decimal_sep) && isdigit(word[n_digits+1]))
  1553. {
  1554. // this "word" ends with a decimal point
  1555. Lookup(tr, "_dpt", ph_append);
  1556. decimal_point = 1;
  1557. }
  1558. else
  1559. if(suppress_null == 0)
  1560. {
  1561. if(thousands_inc > 0)
  1562. {
  1563. if((thousandplex > 0) && (value < 1000))
  1564. {
  1565. if((suppress_null == 0) && (LookupThousands(tr,value,thousandplex, thousands_exact, ph_append)))
  1566. {
  1567. // found an exact match for N thousand
  1568. value = 0;
  1569. suppress_null = 1;
  1570. }
  1571. }
  1572. }
  1573. }
  1574. else
  1575. if(speak_missing_thousands == 1)
  1576. {
  1577. // speak this thousandplex if there was no word for the previous thousandplex
  1578. sprintf(string,"_0M%d",thousandplex+1);
  1579. if(Lookup(tr, string, buf1)==0)
  1580. {
  1581. sprintf(string,"_0M%d",thousandplex);
  1582. Lookup(tr, string, ph_append);
  1583. }
  1584. }
  1585. if((ph_append[0] == 0) && (word[n_digits] == '.') && (thousandplex == 0))
  1586. {
  1587. Lookup(tr, "_.", ph_append);
  1588. }
  1589. if(thousandplex == 0)
  1590. {
  1591. char *p2;
  1592. // look for combinations of the number with the next word
  1593. p = word;
  1594. while(isdigit(p[1])) p++; // just use the last digit
  1595. if(isdigit(p[-1]))
  1596. {
  1597. p2 = p - 1;
  1598. if(LookupDictList(tr, &p2, buf_digit_lookup, flags, FLAG_SUFX, wtab)) // lookup 2 digits
  1599. {
  1600. n_digit_lookup = 2;
  1601. }
  1602. }
  1603. // if((buf_digit_lookup[0] == 0) && (*p != '0') && (dot_ordinal==0))
  1604. if((buf_digit_lookup[0] == 0) && (*p != '0'))
  1605. {
  1606. // not found, lookup only the last digit (?? but not if dot-ordinal has been found)
  1607. if(LookupDictList(tr, &p, buf_digit_lookup, flags, FLAG_SUFX, wtab)) // don't match '0', or entries with $only
  1608. {
  1609. n_digit_lookup = 1;
  1610. }
  1611. }
  1612. }
  1613. LookupNum3(tr, value, ph_buf, suppress_null, thousandplex, prev_thousands | ordinal);
  1614. if((thousandplex > 0) && (tr->langopts.numbers2 & 0x200))
  1615. sprintf(ph_out,"%s%s%s%s",ph_zeros,ph_append,ph_buf2,ph_buf); // say "thousands" before its number
  1616. else
  1617. sprintf(ph_out,"%s%s%s%s",ph_zeros,ph_buf2,ph_buf,ph_append);
  1618. while(decimal_point)
  1619. {
  1620. n_digits++;
  1621. decimal_count = 0;
  1622. while(isdigit(word[n_digits+decimal_count]))
  1623. decimal_count++;
  1624. // if(decimal_count > 1)
  1625. {
  1626. max_decimal_count = 2;
  1627. switch(decimal_mode = (tr->langopts.numbers & 0xe000))
  1628. {
  1629. case NUM_DFRACTION_4:
  1630. max_decimal_count = 5;
  1631. case NUM_DFRACTION_2:
  1632. // French/Polish decimal fraction
  1633. while(word[n_digits] == '0')
  1634. {
  1635. Lookup(tr, "_0", buf1);
  1636. strcat(ph_out,buf1);
  1637. decimal_count--;
  1638. n_digits++;
  1639. }
  1640. if((decimal_count <= max_decimal_count) && isdigit(word[n_digits]))
  1641. {
  1642. LookupNum3(tr, atoi(&word[n_digits]), buf1, 0,0,0);
  1643. strcat(ph_out,buf1);
  1644. n_digits += decimal_count;
  1645. }
  1646. break;
  1647. case NUM_DFRACTION_1: // italian, say "hundredths" if leading zero
  1648. case NUM_DFRACTION_5: // hungarian, always say "tenths" etc.
  1649. LookupNum3(tr, atoi(&word[n_digits]), ph_buf, 0,0,0);
  1650. if((word[n_digits]=='0') || (decimal_mode == NUM_DFRACTION_5))
  1651. {
  1652. // decimal part has leading zeros, so add a "hundredths" or "thousandths" suffix
  1653. sprintf(string,"_0Z%d",decimal_count);
  1654. if(Lookup(tr, string, buf1) == 0)
  1655. break; // revert to speaking single digits
  1656. strcat(ph_buf,buf1);
  1657. }
  1658. strcat(ph_out,ph_buf);
  1659. n_digits += decimal_count;
  1660. break;
  1661. case NUM_DFRACTION_3:
  1662. // Romanian decimal fractions
  1663. if((decimal_count <= 4) && (word[n_digits] != '0'))
  1664. {
  1665. LookupNum3(tr, atoi(&word[n_digits]), buf1, 0,0,0);
  1666. strcat(ph_out,buf1);
  1667. n_digits += decimal_count;
  1668. }
  1669. break;
  1670. }
  1671. }
  1672. while(isdigit(c = word[n_digits]) && (strlen(ph_out) < (N_WORD_PHONEMES - 10)))
  1673. {
  1674. // speak any remaining decimal fraction digits individually
  1675. value = word[n_digits++] - '0';
  1676. LookupNum2(tr, value, 2, buf1);
  1677. strcat(ph_out,buf1);
  1678. }
  1679. // something after the decimal part ?
  1680. if(Lookup(tr, "_dpt2", buf1))
  1681. strcat(ph_out,buf1);
  1682. if((c == tr->langopts.decimal_sep) && isdigit(word[n_digits+1]))
  1683. {
  1684. Lookup(tr, "_dpt", buf1);
  1685. strcat(ph_out,buf1);
  1686. }
  1687. else
  1688. {
  1689. decimal_point = 0;
  1690. }
  1691. }
  1692. if((ph_out[0] != 0) && (ph_out[0] != phonSWITCH))
  1693. {
  1694. int next_char;
  1695. char *p;
  1696. p = &word[n_digits+1];
  1697. p += utf8_in(&next_char,p);
  1698. if((tr->langopts.numbers & NUM_NOPAUSE) && (next_char == ' '))
  1699. utf8_in(&next_char,p);
  1700. if(!iswalpha(next_char) && !((wtab[thousandplex].flags & FLAG_HYPHEN_AFTER) && (thousands_exact != 0)))
  1701. strcat(ph_out,str_pause); // don't add pause for 100s, 6th, etc.
  1702. }
  1703. *flags |= FLAG_FOUND;
  1704. speak_missing_thousands--;
  1705. if(skipwords)
  1706. dictionary_skipwords = skipwords;
  1707. return(1);
  1708. } // end of TranslateNumber_1
  1709. int TranslateNumber(Translator *tr, char *word1, char *ph_out, unsigned int *flags, WORD_TAB *wtab, int control)
  1710. {//=============================================================================================================
  1711. if((option_sayas == SAYAS_DIGITS1) || (wtab[0].flags & FLAG_INDIVIDUAL_DIGITS))
  1712. return(0); // speak digits individually
  1713. if(tr->langopts.numbers != 0)
  1714. return(TranslateNumber_1(tr, word1, ph_out, flags, wtab, control));
  1715. return(0);
  1716. } // end of TranslateNumber