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

numbers.c 49KB

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