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.c 59KB

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