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

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