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

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