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

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