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 52KB

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