eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

numbers.cpp 53KB

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