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

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