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

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