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

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