Debian Codegraph @

external/espeak/compiledict.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2005 to 2014 by Jonathan Duddington
3 * email: [email protected]
4 * Copyright (C) 2015-2017 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, write see:
18 * <http://www.gnu.org/licenses/>.
19 */
20
21 #include "espeak__config.h"cxx . . $ `<file>/external/espeak/espeak__config.h`/
22
23 #include <ctype.h>
24 #include <errno.h>
25 #include <stdbool.h>
26 #include <stdint.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include "wctype_portable.h"cxx . . $ `<file>/kar/wctype_portable.h`/
31
32 #include "espeak_ng.h"cxx . . $ `<file>/external/espeak/espeak_ng.h`/
33 #include "speak_lib.h"cxx . . $ `<file>/external/espeak/speak_lib.h`/
34 #include "encoding.h"cxx . . $ `<file>/external/espeak/encoding.h`/
35
36 #include "common.h"cxx . . $ `<file>/external/espeak/common.h`/ // for strncpy0
37 #include "compiledict.h"cxx . . $ `<file>/external/espeak/compiledict.h`/
38 #include "dictionary.h"cxx . . $ `<file>/external/espeak/dictionary.h`/ // for EncodePhonemes, HashDicti...
39 #include "error.h"cxx . . $ `<file>/external/espeak/error.h`/ // for create_file_error_context
40 #include "mnemonics.h"cxx . . $ `<file>/external/espeak/mnemonics.h`/ // for LookupMnemName, MNEM_TAB
41 #include "phoneme.h"cxx . . $ `<file>/external/espeak/phoneme.h`/ // for PHONEME_TAB_LIST, phonSWITCH, phone...
42 #include "speech.h"cxx . . $ `<file>/external/espeak/speech.h`/ // for path_home
43 #include "synthesize.h"cxx . . $ `<file>/external/espeak/synthesize.h`/ // for Write4Bytes
44
45 static const MNEM_TAB mnem_rulescxx . . $ mnem_rules.[] = {
46 { "unpr", DOLLAR_UNPRcxx . . $ `external/espeak/translate.h:195:9`! },
47 { "noprefix", DOLLAR_NOPREFIXcxx . . $ `external/espeak/translate.h:196:9`! }, // rule fails if a prefix has been removed
48 { "list", DOLLAR_LISTcxx . . $ `external/espeak/translate.h:197:9`! }, // a pronunciation is given in the *_list file
49
50 { "w_alt1", 0x11 },
51 { "w_alt2", 0x12 },
52 { "w_alt3", 0x13 },
53 { "w_alt4", 0x14 },
54 { "w_alt5", 0x15 },
55 { "w_alt6", 0x16 },
56 { "w_alt", 0x11 }, // note: put longer names before their sub-strings
57
58 { "p_alt1", 0x21 },
59 { "p_alt2", 0x22 },
60 { "p_alt3", 0x23 },
61 { "p_alt4", 0x24 },
62 { "p_alt5", 0x25 },
63 { "p_alt6", 0x26 },
64 { "p_alt", 0x21 },
65
66 { NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!, -1 }
67 };
68
69 static const MNEM_TAB mnem_flagscxx . . $ mnem_flags.[] = {
70 // these in the first group put a value in bits0-3 of dictionary_flags
71 { "$1", 0x41 }, // stress on 1st syllable
72 { "$2", 0x42 }, // stress on 2nd syllable
73 { "$3", 0x43 },
74 { "$4", 0x44 },
75 { "$5", 0x45 },
76 { "$6", 0x46 },
77 { "$7", 0x47 },
78 { "$u", 0x48 }, // reduce to unstressed
79 { "$u1", 0x49 },
80 { "$u2", 0x4a },
81 { "$u3", 0x4b },
82 { "$u+", 0x4c }, // reduce to unstressed, but stress at end of clause
83 { "$u1+", 0x4d },
84 { "$u2+", 0x4e },
85 { "$u3+", 0x4f },
86
87 // these set the corresponding numbered bit if dictionary_flags
88 { "$pause", 8 }, // ensure pause before this word
89 { "$strend", 9 }, // full stress if at end of clause
90 { "$strend2", 10 }, // full stress if at end of clause, or only followed by unstressed
91 { "$unstressend", 11 }, // reduce stress at end of clause
92 { "$accent_before", 12 }, // used with accent names, say this accent name before the letter name
93 { "$abbrev", 13 }, // use this pronuciation rather than split into letters
94
95 // language specific
96 { "$double", 14 }, // IT double the initial consonant of next word
97 { "$alt", 15 }, // use alternative pronunciation
98 { "$alt1", 15 }, // synonym for $alt
99 { "$alt2", 16 },
100 { "$alt3", 17 },
101 { "$alt4", 18 },
102 { "$alt5", 19 },
103 { "$alt6", 20 },
104 { "$alt7", 21 },
105
106 { "$combine", 23 }, // Combine with the next word
107
108 { "$dot", 24 }, // ignore '.' after this word (abbreviation)
109 { "$hasdot", 25 }, // use this pronunciation if there is a dot after the word
110
111 { "$max3", 27 }, // limit to 3 repetitions
112 { "$brk", 28 }, // a shorter $pause
113 { "$text", 29 }, // word translates to replcement text, not phonemes
114
115 // flags in dictionary word 2
116 { "$verbf", 0x20 }, // verb follows
117 { "$verbsf", 0x21 }, // verb follows, allow -s suffix
118 { "$nounf", 0x22 }, // noun follows
119 { "$pastf", 0x23 }, // past tense follows
120 { "$verb", 0x24 }, // use this pronunciation when its a verb
121 { "$noun", 0x25 }, // use this pronunciation when its a noun
122 { "$past", 0x26 }, // use this pronunciation when its past tense
123 { "$verbextend", 0x28 }, // extend influence of 'verb follows'
124 { "$capital", 0x29 }, // use this pronunciation if initial letter is upper case
125 { "$allcaps", 0x2a }, // use this pronunciation if initial letter is upper case
126 { "$accent", 0x2b }, // character name is base-character name + accent name
127 { "$sentence", 0x2d }, // only if this clause is a sentence (i.e. terminator is {. ? !} not {, ; :}
128 { "$only", 0x2e }, // only match on this word without suffix
129 { "$onlys", 0x2f }, // only match with none, or with 's' suffix
130 { "$stem", 0x30 }, // must have a suffix
131 { "$atend", 0x31 }, // use this pronunciation if at end of clause
132 { "$atstart", 0x32 }, // use this pronunciation at start of clause
133 { "$native", 0x33 }, // not if we've switched translators
134
135 // doesn't set dictionary_flags
136 { "$?", 100 }, // conditional rule, followed by byte giving the condition number
137
138 { "$textmode", 200 },
139 { "$phonememode", 201 },
140
141 { NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!, -1 }
142 };
143
144 #define LEN_GROUP_NAMEcxx . . $ `external/espeak/compiledict.cpp:144:9`! 12
145
146 typedef structcxx . . $ $anonymous_type_34d0db98ae374eb3_0# {
147 char namecxx . . $ $anonymous_type_34d0db98ae374eb3_0#name.[LEN_GROUP_NAMEcxx . . $ `external/espeak/compiledict.cpp:144:9`!+1];
148 void *startcxx . . $ $anonymous_type_34d0db98ae374eb3_0#start.;
149 size_t lengthcxx . . $ $anonymous_type_34d0db98ae374eb3_0#length.;
150 int group3_ixcxx . . $ $anonymous_type_34d0db98ae374eb3_0#group3_ix.;
151 } RGROUPcxx . . $ RGROUP#;
152
153 typedef enumcxx . . $ $anonymous_type_34d0db98ae374eb3_1#
154 {
155 LINE_PARSER_WORDcxx . . $ LINE_PARSER_WORD. = 0,
156 LINE_PARSER_END_OF_WORDcxx . . $ LINE_PARSER_END_OF_WORD. = 1,
157 LINE_PARSER_MULTIPLE_WORDScxx . . $ LINE_PARSER_MULTIPLE_WORDS. = 2,
158 LINE_PARSER_END_OF_WORDScxx . . $ LINE_PARSER_END_OF_WORDS. = 3,
159 LINE_PARSER_PRONUNCIATIONcxx . . $ LINE_PARSER_PRONUNCIATION. = 4,
160 LINE_PARSER_END_OF_PRONUNCIATIONcxx . . $ LINE_PARSER_END_OF_PRONUNCIATION. = 5,
161 } LINE_PARSER_STATEScxx . . $ LINE_PARSER_STATES#;
162
163 typedef structcxx . . $ $anonymous_type_34d0db98ae374eb3_2# {
164 FILE *f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log.;
165
166 char word_phonemescxx . . $ $anonymous_type_34d0db98ae374eb3_2#word_phonemes.[N_WORD_PHONEMEScxx . . $ `external/espeak/translate.h:40:9`!]; // a word translated into phoneme codes
167
168 int linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum.;
169 int error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.;
170 bool text_modecxx . . $ $anonymous_type_34d0db98ae374eb3_2#text_mode.;
171 int debug_flagcxx . . $ $anonymous_type_34d0db98ae374eb3_2#debug_flag.;
172 int error_need_dictionarycxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_need_dictionary.;
173
174 // A hash chain is a linked-list of hash chain entry objects:
175 // struct hash_chain_entry {
176 // hash_chain_entry *next_entry;
177 // // dict_line output from compile_line:
178 // uint8_t length;
179 // char contents[length];
180 // };
181 char *hash_chainscxx . . $ $anonymous_type_34d0db98ae374eb3_2#hash_chains.[N_HASH_DICTcxx . . $ `external/espeak/translate.h:47:9`!];
182
183 char letterGroupsDefinedcxx . . $ $anonymous_type_34d0db98ae374eb3_2#letterGroupsDefined.[N_LETTER_GROUPScxx . . $ `external/espeak/translate.h:48:9`!];
184
185 char rule_condcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_cond.[80];
186 char rule_precxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_pre.[80];
187 char rule_postcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_post.[80];
188 char rule_matchcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_match.[80];
189 char rule_phonemescxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_phonemes.[80];
190 char group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name.[LEN_GROUP_NAMEcxx . . $ `external/espeak/compiledict.cpp:144:9`!+1];
191 int group3_ixcxx . . $ $anonymous_type_34d0db98ae374eb3_2#group3_ix.;
192 } CompileContextcxx . . $ CompileContext#;
193
194 static void clean_contextcxx . . $ clean_context(9f2cdca689c1a14e).(CompileContextcxx . . $ CompileContext# *ctx) {
195 for (int i = 0; i < N_HASH_DICTcxx . . $ `external/espeak/translate.h:47:9`!; i++) {
196 char *p;
197 while ((p = ctx->hash_chainscxx . . $ $anonymous_type_34d0db98ae374eb3_2#hash_chains.[i])) {
198 memcpy(&p, ctx->hash_chainscxx . . $ $anonymous_type_34d0db98ae374eb3_2#hash_chains.[i], sizeof(char*));
199 freecxx . . $ free(bd21765a0afc8e3c).(ctx->hash_chainscxx . . $ $anonymous_type_34d0db98ae374eb3_2#hash_chains.[i]);
200 ctx->hash_chainscxx . . $ $anonymous_type_34d0db98ae374eb3_2#hash_chains.[i] = p;
201 }
202 }
203 freecxx . . $ free(bd21765a0afc8e3c).(ctx);
204 }
205
206 void print_dictionary_flagscxx . . $ print_dictionary_flags(8821d3e1c5a7b37e).(unsigned int *flags, char *buf, int buf_len)
207 {
208 int stress;
209 int ix;
210 const char *name;
211 int len;
212 int total = 0;
213
214 buf[0] = 0;
215 if ((stress = flags[0] & 0xf) != 0) {
216 sprintf(buf, "%s", LookupMnemName(mnem_flagscxx . . $ mnem_flags., stress + 0x40));
217 total = strlen(buf);
218 buf += total;
219 }
220
221 for (ix = 8; ix < 64; ix++) {
222 if (((ix < 30) && (flags[0] & (1 << ix))) || ((ix >= 0x20) && (flags[1] & (1 << (ix-0x20))))) {
223 name = LookupMnemName(mnem_flagscxx . . $ mnem_flags., ix);
224 len = strlen(name) + 1;
225 total += len;
226 if (total >= buf_len)
227 continue;
228 sprintf(buf, " %s", name);
229 buf += len;
230 }
231 }
232 }
233
234 char *DecodeRulecxx . . $ DecodeRule(b1993facefe1e95b).(const char *group_chars, int group_length, char *rule, int control, char *output)
235 {
236 // Convert compiled match template to ascii
237
238 unsigned char rb;
239 unsigned char c;
240 char *p;
241 char *p_end;
242 int ix;
243 int match_type;
244 bool finished = false;
245 int value;
246 int linenum = 0;
247 int flags;
248 int suffix_char;
249 int condition_num = 0;
250 bool at_start = false;
251 const char *name;
252 char buf[200];
253 char buf_pre[200];
254 char suffix[20];
255
256 static const char symbols[] = {
257 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
258 '&', '%', '+', '#', 'S', 'D', 'Z', 'A', 'L', '!',
259 ' ', '@', '?', 'J', 'N', 'K', 'V', '?', 'T', 'X',
260 '?', 'W'
261 };
262
263 static const char symbols_lg[] = { 'A', 'B', 'C', 'H', 'F', 'G', 'Y' };
264
265 match_type = 0;
266 buf_pre[0] = 0;
267
268 for (ix = 0; ix < group_length; ix++)
269 buf[ix] = group_chars[ix];
270 buf[ix] = 0;
271
272 p = &buf[strlen(buf)];
273 while (!finished) {
274 rb = *rule++;
275
276 if (rb <= RULE_LINENUMcxx . . $ `external/espeak/translate.h:168:9`!) {
277 switch (rb)
278 {
279 case 0:
280 case RULE_PHONEMEScxx . . $ `external/espeak/translate.h:162:9`!:
281 finished = true;
282 break;
283 case RULE_PRE_ATSTARTcxx . . $ `external/espeak/translate.h:167:9`!:
284 at_start = true;
285 // fallthrough:
286 case RULE_PREcxx . . $ `external/espeak/translate.h:160:9`!:
287 match_type = RULE_PREcxx . . $ `external/espeak/translate.h:160:9`!;
288 *p = 0;
289 p = buf_pre;
290 break;
291 case RULE_POSTcxx . . $ `external/espeak/translate.h:161:9`!:
292 match_type = RULE_POSTcxx . . $ `external/espeak/translate.h:161:9`!;
293 *p = 0;
294 strcat(buf, " (");
295 p = &buf[strlen(buf)];
296 break;
297 case RULE_PH_COMMONcxx . . $ `external/espeak/translate.h:163:9`!:
298 break;
299 case RULE_CONDITIONcxx . . $ `external/espeak/translate.h:164:9`!:
300 // conditional rule, next byte gives condition number
301 condition_num = *rule++;
302 break;
303 case RULE_LINENUMcxx . . $ `external/espeak/translate.h:168:9`!:
304 value = (rule[1] & 0xff) - 1;
305 linenum = (rule[0] & 0xff) - 1 + (value * 255);
306 rule += 2;
307 break;
308 }
309 continue;
310 }
311
312 if (rb == RULE_DOLLARcxx . . $ `external/espeak/translate.h:186:9`!) {
313 value = *rule++ & 0xff;
314 if ((value != 0x01) || (control & FLAG_UNPRON_TESTcxx . . $ `external/espeak/translate.h:137:9`!)) {
315 // TODO write the string backwards if in RULE_PRE
316 p[0] = '$';
317 name = LookupMnemName(mnem_rulescxx . . $ mnem_rules., value);
318 strcpy(&p[1], name);
319 p += (strlen(name)+1);
320 }
321 c = ' ';
322 } else if (rb == RULE_ENDINGcxx . . $ `external/espeak/translate.h:174:9`!) {
323 static const char flag_chars[] = "eipvdfq tba ";
324 flags = ((rule[0] & 0x7f)<< 8) + (rule[1] & 0x7f);
325 suffix_char = 'S';
326 if (flags & (SUFX_Pcxx . . $ `external/espeak/translate.h:142:9`! >> 8))
327 suffix_char = 'P';
328 sprintf(suffix, "%c%d", suffix_char, rule[2] & 0x7f);
329 rule += 3;
330 for (ix = 0; ix < 9; ix++) {
331 if (flags & 1)
332 sprintf(&suffix[strlen(suffix)], "%c", flag_chars[ix]);
333 flags = (flags >> 1);
334 }
335 strcpy(p, suffix);
336 p += strlen(suffix);
337 c = ' ';
338 } else if (rb == RULE_LETTERGPcxx . . $ `external/espeak/translate.h:177:9`!)
339 c = symbols_lg[*rule++ - 'A'];
340 else if (rb == RULE_LETTERGP2cxx . . $ `external/espeak/translate.h:178:9`!) {
341 value = *rule++ - 'A';
342 if (value < 0)
343 value += 256;
344 p[0] = 'L';
345 p[1] = (value / 10) + '0';
346 c = (value % 10) + '0';
347
348 if (match_type == RULE_PREcxx . . $ `external/espeak/translate.h:160:9`!) {
349 p[0] = c;
350 c = 'L';
351 }
352 p += 2;
353 } else if (rb <= RULE_LAST_RULEcxx . . $ `external/espeak/translate.h:189:9`!)
354 c = symbols[rb];
355 else if (rb == RULE_SPACEcxx . . $ `external/espeak/translate.h:192:9`!)
356 c = '_';
357 else
358 c = rb;
359 *p++ = c;
360 }
361 *p = 0;
362
363 p = output;
364 p_end = p + sizeof(output) - 1;
365
366 if (linenum > 0) {
367 sprintf(p, "%5d:\t", linenum);
368 p += 7;
369 }
370 if (condition_num > 0) {
371 sprintf(p, "?%d ", condition_num);
372 p = &p[strlen(p)];
373 }
374 if (((ix = strlen(buf_pre)) > 0) || at_start) {
375 if (at_start)
376 *p++ = '_';
377 while ((--ix >= 0) && (p < p_end-3))
378 *p++ = buf_pre[ix];
379 *p++ = ')';
380 *p++ = ' ';
381 }
382 *p = 0;
383
384 buf[p_end - p] = 0; // prevent overflow in output[]
385 strcat(p, buf);
386 ix = strlen(output);
387 while (ix < 8)
388 output[ix++] = ' ';
389 output[ix] = 0;
390 return output;
391 }
392
393 static int compile_linecxx . . $ compile_line(f949114ba2e970f6).(CompileContextcxx . . $ CompileContext# *ctx, char *linebuf, char *dict_line, int n_dict_line, int *hash)
394 {
395 // Compile a line in the language_list file
396 unsigned char c;
397 char *p;
398 char *word;
399 char *phonetic;
400 char *phonetic_end;
401 unsigned int ix;
402 LINE_PARSER_STATEScxx . . $ LINE_PARSER_STATES# step;
403 unsigned int n_flag_codes = 0;
404 int flagnum;
405 int flag_offset;
406 int length;
407 int multiple_words = 0;
408 bool multiple_numeric_hyphen = false;
409 char *multiple_string = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
410 char *multiple_string_end = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
411
412 int len_word;
413 int len_phonetic;
414 bool text_not_phonemes = false; // this word specifies replacement text, not phonemes
415 unsigned int wc;
416 bool all_upper_case;
417
418 char *mnemptr;
419 unsigned char flag_codes[100];
420 char encoded_ph[200];
421 char bad_phoneme_str[4];
422 int bad_phoneme;
423 static const char nullstring[] = { 0 };
424
425 phonetic = word = (char*)nullstring;
426
427 p = linebuf;
428
429 step = LINE_PARSER_WORDcxx . . $ LINE_PARSER_WORD.;
430
431 c = *p;
432 while (c != '\n' && c != '\0') {
433 c = *p;
434
435 if ((c == '?') && (step == 0)) {
436 // conditional rule, allow only if the numbered condition is set for the voice
437 flag_offset = 100;
438
439 p++;
440 if (*p == '!') {
441 // allow only if the numbered condition is NOT set
442 flag_offset = 132;
443 p++;
444 }
445
446 ix = 0;
447 if (IsDigit09cxx . . $ IsDigit09(4c679297bf94b9eb).(*p)) {
448 ix += (*p-'0');
449 p++;
450 }
451 if (IsDigit09cxx . . $ IsDigit09(4c679297bf94b9eb).(*p)) {
452 ix = ix*10 + (*p-'0');
453 p++;
454 }
455 flag_codes[n_flag_codes++] = ix + flag_offset;
456 c = *p;
457 }
458
459 if ((c == '$') && isalnum(p[1])) {
460 // read keyword parameter
461 mnemptr = p;
462 while (!isspace2cxx . . $ isspace2(4c679297bf94b9eb).(c = *p)) p++;
463 *p = 0;
464
465 flagnum = LookupMnem(mnem_flagscxx . . $ mnem_flags., mnemptr);
466 if (flagnum > 0) {
467 if (flagnum == 200)
468 ctx->text_modecxx . . $ $anonymous_type_34d0db98ae374eb3_2#text_mode. = true;
469 else if (flagnum == 201)
470 ctx->text_modecxx . . $ $anonymous_type_34d0db98ae374eb3_2#text_mode. = false;
471 else if (flagnum == BITNUM_FLAG_TEXTMODEcxx . . $ `external/espeak/translate.h:76:9`!)
472 text_not_phonemes = true;
473 else
474 flag_codes[n_flag_codes++] = flagnum;
475 } else {
476 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: Unknown keyword: %s\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum., mnemptr);
477 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
478 }
479 }
480
481 if ((c == '/') && (p[1] == '/') && (multiple_words == 0))
482 c = '\n'; // "//" treat comment as end of line
483
484 switch (step)
485 {
486 case LINE_PARSER_WORDcxx . . $ LINE_PARSER_WORD.:
487 if (c == '(') {
488 multiple_words = 1;
489 word = p+1;
490 step = LINE_PARSER_END_OF_WORDcxx . . $ LINE_PARSER_END_OF_WORD.;
491 } else if (!isspace2cxx . . $ isspace2(4c679297bf94b9eb).(c)) {
492 word = p;
493 step = LINE_PARSER_END_OF_WORDcxx . . $ LINE_PARSER_END_OF_WORD.;
494 }
495 break;
496 case LINE_PARSER_END_OF_WORDcxx . . $ LINE_PARSER_END_OF_WORD.:
497 if ((c == '-') && multiple_words) {
498 if (IsDigit09cxx . . $ IsDigit09(4c679297bf94b9eb).(word[0]))
499 multiple_numeric_hyphen = true;
500 flag_codes[n_flag_codes++] = BITNUM_FLAG_HYPHENATEDcxx . . $ `external/espeak/translate.h:103:9`!;
501 c = ' ';
502 }
503 if (isspace2cxx . . $ isspace2(4c679297bf94b9eb).(c)) {
504 p[0] = 0; // terminate english word
505
506 if (multiple_words) {
507 multiple_string = multiple_string_end = p+1;
508 step = LINE_PARSER_MULTIPLE_WORDScxx . . $ LINE_PARSER_MULTIPLE_WORDS.;
509 } else
510 step = LINE_PARSER_END_OF_WORDScxx . . $ LINE_PARSER_END_OF_WORDS.;
511 } else if (c == ')') {
512 if (multiple_words) {
513 p[0] = 0;
514 multiple_words = 0;
515 step = LINE_PARSER_END_OF_WORDScxx . . $ LINE_PARSER_END_OF_WORDS.;
516 } else if (word[0] != '_') {
517 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: Missing '('\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum.);
518 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
519 step = LINE_PARSER_END_OF_WORDScxx . . $ LINE_PARSER_END_OF_WORDS.;
520 }
521 }
522 break;
523 case LINE_PARSER_MULTIPLE_WORDScxx . . $ LINE_PARSER_MULTIPLE_WORDS.:
524 if (isspace2cxx . . $ isspace2(4c679297bf94b9eb).(c))
525 multiple_words++;
526 else if (c == ')') {
527 p[0] = ' '; // terminate extra string
528 multiple_string_end = p+1;
529 step = LINE_PARSER_END_OF_WORDScxx . . $ LINE_PARSER_END_OF_WORDS.;
530 }
531 break;
532 case LINE_PARSER_END_OF_WORDScxx . . $ LINE_PARSER_END_OF_WORDS.:
533 if (!isspace2cxx . . $ isspace2(4c679297bf94b9eb).(c)) {
534 phonetic = p;
535 step = LINE_PARSER_PRONUNCIATIONcxx . . $ LINE_PARSER_PRONUNCIATION.;
536 }
537 break;
538 case LINE_PARSER_PRONUNCIATIONcxx . . $ LINE_PARSER_PRONUNCIATION.:
539 if (isspace2cxx . . $ isspace2(4c679297bf94b9eb).(c)) {
540 phonetic_end = p;
541 p[0] = 0; // terminate phonetic
542 step = LINE_PARSER_END_OF_PRONUNCIATIONcxx . . $ LINE_PARSER_END_OF_PRONUNCIATION.;
543 }
544 break;
545 case LINE_PARSER_END_OF_PRONUNCIATIONcxx . . $ LINE_PARSER_END_OF_PRONUNCIATION.:
546 if (!isspace2cxx . . $ isspace2(4c679297bf94b9eb).(c)) {
547 *phonetic_end = ' ';
548 step = LINE_PARSER_PRONUNCIATIONcxx . . $ LINE_PARSER_PRONUNCIATION.;
549 }
550 break;
551 }
552 p++;
553 }
554
555 if (word[0] == 0)
556 return 0; // blank line
557
558 if (ctx->text_modecxx . . $ $anonymous_type_34d0db98ae374eb3_2#text_mode.)
559 text_not_phonemes = true;
560
561 if (text_not_phonemes) {
562 if (word[0] == '_') {
563 // This is a special word, used by eSpeak. Translate this into phonemes now
564 strcat(phonetic, " "); // need a space to indicate word-boundary
565
566 // PROBLEM vowel reductions are not applied to the translated phonemes
567 // condition rules are not applied
568 TranslateWord(translator, phonetic, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!);
569 text_not_phonemes = false;
570 strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(encoded_ph, ctx->word_phonemescxx . . $ $anonymous_type_34d0db98ae374eb3_2#word_phonemes., N_WORD_BYTEScxx . . $ `external/espeak/translate.h:41:9`!-4);
571
572 if ((ctx->word_phonemescxx . . $ $anonymous_type_34d0db98ae374eb3_2#word_phonemes.[0] == 0) && (ctx->error_need_dictionarycxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_need_dictionary. < 3)) {
573 // the dictionary was not loaded, we need a second attempt
574 ctx->error_need_dictionarycxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_need_dictionary.++;
575 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: Need to compile dictionary again\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum.);
576 }
577 } else
578 // this is replacement text, so don't encode as phonemes. Restrict the length of the replacement word
579 strncpy0cxx . . $ strncpy0(3366d352079c3ed6).(encoded_ph, phonetic, N_WORD_BYTEScxx . . $ `external/espeak/translate.h:41:9`!-4);
580 } else {
581 EncodePhonemes(phonetic, encoded_ph, &bad_phoneme);
582 if (strchr(encoded_ph, phonSWITCHcxx . . $ `external/espeak/phoneme.h:218:9`!) != 0)
583 flag_codes[n_flag_codes++] = BITNUM_FLAG_ONLY_Scxx . . $ `external/espeak/translate.h:105:9`!; // don't match on suffixes (except 's') when switching languages
584
585 // check for errors in the phonemes codes
586 if (bad_phoneme != 0) {
587 // unrecognised phoneme, report error
588 bad_phoneme_str[utf8_outcxx . . $ utf8_out(fa84e865f2d62ca9).(bad_phoneme, bad_phoneme_str)] = 0;
589 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: Bad phoneme [%s] (U+%x) in: %s %s\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum., bad_phoneme_str, bad_phoneme, word, phonetic);
590 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
591 }
592 }
593
594 if (text_not_phonemes != translator->langopts.textmode)
595 flag_codes[n_flag_codes++] = BITNUM_FLAG_TEXTMODEcxx . . $ `external/espeak/translate.h:76:9`!;
596
597 if (sscanf(word, "U+%x", &wc) == 1) {
598 // Character code
599 ix = utf8_outcxx . . $ utf8_out(fa84e865f2d62ca9).(wc, word);
600 word[ix] = 0;
601 } else if (word[0] != '_') {
602 // convert to lower case, and note if the word is all-capitals
603 int c2;
604
605 all_upper_case = true;
606 for (p = word;;) {
607 // this assumes that the lower case char is the same length as the upper case char
608 // OK, except for Turkish "I", but use towlower() rather than towlower2()
609 ix = utf8_incxx . . $ utf8_in(80e674cbced5dd06).(&c2, p);
610 if (c2 == 0)
611 break;
612 if (iswupper_portable(c2))
613 utf8_outcxx . . $ utf8_out(fa84e865f2d62ca9).(towlower2cxx . . $ towlower2(5533d3025d482fd5).(c2, translator), p);
614 else
615 all_upper_case = false;
616 p += ix;
617 }
618 if (all_upper_case)
619 flag_codes[n_flag_codes++] = BITNUM_FLAG_ALLCAPScxx . . $ `external/espeak/translate.h:102:9`!;
620 }
621
622 len_word = strlen(word);
623
624 if (translator->transpose_min > 0)
625 len_word = TransposeAlphabet(translator, word);
626
627 *hash = HashDictionary(word);
628 len_phonetic = strlen(encoded_ph);
629
630 dict_line[1] = len_word; // bit 6 indicates whether the word has been compressed
631 len_word &= 0x3f;
632
633 memcpy(&dict_line[2], word, len_word);
634
635 if (len_phonetic == 0) {
636 // no phonemes specified. set bit 7
637 dict_line[1] |= 0x80;
638 length = len_word + 2;
639 } else {
640 length = len_word + len_phonetic + 3;
641 if (length < n_dict_line) {
642 strcpy(&dict_line[(len_word)+2], encoded_ph);
643 } else {
644 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: Dictionary line length would overflow the data buffer: %d\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum., length);
645 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
646 // no phonemes specified. set bit 7
647 dict_line[1] |= 0x80;
648 length = len_word + 2;
649 }
650 }
651
652 for (ix = 0; ix < n_flag_codes; ix++)
653 dict_line[ix+length] = flag_codes[ix];
654 length += n_flag_codes;
655
656 if ((multiple_string != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) && (multiple_words > 0)) {
657 if (multiple_words > 10) {
658 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: Two many parts in a multi-word entry: %d\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum., multiple_words);
659 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
660 } else {
661 dict_line[length++] = 80 + multiple_words;
662 ix = multiple_string_end - multiple_string;
663 if (multiple_numeric_hyphen)
664 dict_line[length++] = ' '; // ???
665 memcpy(&dict_line[length], multiple_string, ix);
666 length += ix;
667 }
668 }
669 *((uint8_tcxx . . $ uint8_t# *)dict_line) = (uint8_tcxx . . $ uint8_t#)length;
670
671 return length;
672 }
673
674 static void compile_dictlist_startcxx . . $ compile_dictlist_start(9f2cdca689c1a14e).(CompileContextcxx . . $ CompileContext# *ctx)
675 {
676 // initialise dictionary list
677 int ix;
678 char *p;
679 char *p2;
680
681 for (ix = 0; ix < N_HASH_DICTcxx . . $ `external/espeak/translate.h:47:9`!; ix++) {
682 p = ctx->hash_chainscxx . . $ $anonymous_type_34d0db98ae374eb3_2#hash_chains.[ix];
683 while (p != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
684 memcpy(&p2, p, sizeof(char *));
685 freecxx . . $ free(bd21765a0afc8e3c).(p);
686 p = p2;
687 }
688 ctx->hash_chainscxx . . $ $anonymous_type_34d0db98ae374eb3_2#hash_chains.[ix] = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
689 }
690 }
691
692 static void compile_dictlist_endcxx . . $ compile_dictlist_end(b16d811d85dbfdad).(CompileContextcxx . . $ CompileContext# *ctx, FILE *f_out)
693 {
694 // Write out the compiled dictionary list
695 int hash;
696 int length;
697 char *p;
698
699 for (hash = 0; hash < N_HASH_DICTcxx . . $ `external/espeak/translate.h:47:9`!; hash++) {
700 p = ctx->hash_chainscxx . . $ $anonymous_type_34d0db98ae374eb3_2#hash_chains.[hash];
701
702 while (p != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
703 length = *(uint8_tcxx . . $ uint8_t# *)(p+sizeof(char *));
704 fwrite(p+sizeof(char *), length, 1, f_out);
705 memcpy(&p, p, sizeof(char *));
706 }
707 fputc(0, f_out);
708 }
709 }
710
711 static int compile_dictlist_filecxx . . $ compile_dictlist_file(172ff442181800ce).(CompileContextcxx . . $ CompileContext# *ctx, const char *path, const char *filename)
712 {
713 int length;
714 int hash;
715 char *p;
716 int count = 0;
717 FILE *f_in;
718 char buf[200];
719 char fname[sizeof(path_home)+45];
720 char dict_line[256]; // length is uint8_t, so an entry can't take up more than 256 bytes
721
722 ctx->text_modecxx . . $ $anonymous_type_34d0db98ae374eb3_2#text_mode. = false;
723
724 // try with and without '.txt' extension
725 sprintf(fname, "%s%s.txt", path, filename);
726 if ((f_in = fopen(fname, "r")) == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
727 sprintf(fname, "%s%s", path, filename);
728 if ((f_in = fopen(fname, "r")) == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
729 return -1;
730 }
731
732 if (ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
733 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "Compiling: '%s'\n", fname);
734
735 ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum. = 0;
736
737 while (fgets(buf, sizeof(buf), f_in) != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
738 ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum.++;
739
740 length = compile_linecxx . . $ compile_line(f949114ba2e970f6).(ctx, buf, dict_line, sizeof(dict_line), &hash);
741 if (length == 0) continue; // blank line
742
743 p = (char *)malloccxx . . $ malloc(9f008b2a9698428b).(length+sizeof(char *));
744 if (p == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
745 if (ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
746 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "Can't allocate memory\n");
747 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
748 }
749 break;
750 }
751
752 memcpy(p, &ctx->hash_chainscxx . . $ $anonymous_type_34d0db98ae374eb3_2#hash_chains.[hash], sizeof(char *));
753 ctx->hash_chainscxx . . $ $anonymous_type_34d0db98ae374eb3_2#hash_chains.[hash] = p;
754 // NOTE: dict_line[0] is the entry length (0-255)
755 memcpy(p+sizeof(char *), dict_line, length);
756 count++;
757 }
758
759 if (ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
760 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "\t%d entries\n", count);
761 fclose(f_in);
762 return 0;
763 }
764
765 #define N_RULEScxx . . $ `external/espeak/compiledict.cpp:765:9`! 3000 // max rules for each group
766
767 static int isHexDigitcxx . . $ isHexDigit(7864480464b09eea).(int c)
768 {
769 if ((c >= '0') && (c <= '9'))
770 return c - '0';
771 if ((c >= 'a') && (c <= 'f'))
772 return c - 'a' + 10;
773 if ((c >= 'A') && (c <= 'F'))
774 return c - 'A' + 10;
775 return -1;
776 }
777
778 static void copy_rule_stringcxx . . $ copy_rule_string(b393f284d89f4ee8).(CompileContextcxx . . $ CompileContext# *ctx, char *string, int *state_out)
779 {
780 // state 0: conditional, 1=pre, 2=match, 3=post, 4=phonemes
781 char * const outbuf[5] = { ctx->rule_condcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_cond., ctx->rule_precxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_pre., ctx->rule_matchcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_match., ctx->rule_postcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_post., ctx->rule_phonemescxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_phonemes. };
782 static const int next_state[5] = { 2, 2, 4, 4, 4 };
783 char *output;
784 char *p;
785 int ix;
786 int len;
787 char c;
788 int c2, c3;
789 int sxflags;
790 int value;
791 bool literal;
792 bool hexdigit_input = false;
793 int state = *state_out;
794 const MNEM_TAB *mr;
795
796 if (string[0] == 0) return;
797
798 output = outbuf[state];
799 if (state == 4) {
800 // append to any previous phoneme string, i.e. allow spaces in the phoneme string
801 len = strlen(ctx->rule_phonemescxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_phonemes.);
802 if (len > 0)
803 ctx->rule_phonemescxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_phonemes.[len++] = ' ';
804 output = &ctx->rule_phonemescxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_phonemes.[len];
805 }
806 sxflags = 0x808000; // to ensure non-zero bytes
807
808 for (p = string, ix = 0;;) {
809 literal = false;
810 c = *p++;
811 if ((c == '0') && (p[0] == 'x') && (isHexDigitcxx . . $ isHexDigit(7864480464b09eea).(p[1]) >= 0) && (isHexDigitcxx . . $ isHexDigit(7864480464b09eea).(p[2]) >= 0)) {
812 hexdigit_input = true;
813 c = p[1];
814 p += 2;
815 }
816 if (c == '\\') {
817 c = *p++; // treat next character literally
818 if ((c >= '0') && (c <= '3') && (p[0] >= '0') && (p[0] <= '7') && (p[1] >= '0') && (p[1] <= '7')) {
819 // character code given by 3 digit octal value;
820 c = (c-'0')*64 + (p[0]-'0')*8 + (p[1]-'0');
821 p += 2;
822 }
823 literal = true;
824 }
825 if (hexdigit_input) {
826 if (((c2 = isHexDigitcxx . . $ isHexDigit(7864480464b09eea).(c)) >= 0) && ((c3 = isHexDigitcxx . . $ isHexDigit(7864480464b09eea).(p[0])) >= 0)) {
827 c = c2 * 16 + c3;
828 literal = true;
829 p++;
830 } else
831 hexdigit_input = false;
832 }
833 if ((state == 1) || (state == 3)) {
834 // replace special characters (note: 'E' is reserved for a replaced silent 'e')
835 if (literal == false) {
836 static const char lettergp_letters[9] = { LETTERGP_Acxx . . $ `external/espeak/translate.h:199:9`!, LETTERGP_Bcxx . . $ `external/espeak/translate.h:200:9`!, LETTERGP_Ccxx . . $ `external/espeak/translate.h:201:9`!, 0, 0, LETTERGP_Fcxx . . $ `external/espeak/translate.h:203:9`!, LETTERGP_Gcxx . . $ `external/espeak/translate.h:204:9`!, LETTERGP_Hcxx . . $ `external/espeak/translate.h:202:9`!, LETTERGP_Ycxx . . $ `external/espeak/translate.h:205:9`! };
837 switch (c)
838 {
839 case '_':
840 c = RULE_SPACEcxx . . $ `external/espeak/translate.h:192:9`!;
841 break;
842
843 case 'Y':
844 c = 'I';
845 // fallthrough:
846 case 'A': // vowel
847 case 'B':
848 case 'C':
849 case 'H':
850 case 'F':
851 case 'G':
852 if (state == 1) {
853 // pre-rule, put the number before the RULE_LETTERGP;
854 output[ix++] = lettergp_letters[c-'A'] + 'A';
855 c = RULE_LETTERGPcxx . . $ `external/espeak/translate.h:177:9`!;
856 } else {
857 output[ix++] = RULE_LETTERGPcxx . . $ `external/espeak/translate.h:177:9`!;
858 c = lettergp_letters[c-'A'] + 'A';
859 }
860 break;
861 case 'D':
862 c = RULE_DIGITcxx . . $ `external/espeak/translate.h:175:9`!;
863 break;
864 case 'K':
865 c = RULE_NOTVOWELcxx . . $ `external/espeak/translate.h:184:9`!;
866 break;
867 case 'N':
868 c = RULE_NO_SUFFIXcxx . . $ `external/espeak/translate.h:183:9`!;
869 break;
870 case 'V':
871 c = RULE_IFVERBcxx . . $ `external/espeak/translate.h:185:9`!;
872 break;
873 case 'Z':
874 c = RULE_NONALPHAcxx . . $ `external/espeak/translate.h:176:9`!;
875 break;
876 case '+':
877 c = RULE_INC_SCOREcxx . . $ `external/espeak/translate.h:172:9`!;
878 break;
879 case '<': // Can't use - as opposite for + because it is used literally as part of word
880 c = RULE_DEC_SCOREcxx . . $ `external/espeak/translate.h:193:9`!;
881 break;
882 case '@':
883 c = RULE_SYLLABLEcxx . . $ `external/espeak/translate.h:181:9`!;
884 break;
885 case '&':
886 c = RULE_STRESSEDcxx . . $ `external/espeak/translate.h:170:9`!;
887 break;
888 case '%':
889 c = RULE_DOUBLEcxx . . $ `external/espeak/translate.h:171:9`!;
890 break;
891 case '#':
892 c = RULE_DEL_FWDcxx . . $ `external/espeak/translate.h:173:9`!;
893 break;
894 case '!':
895 c = RULE_CAPITALcxx . . $ `external/espeak/translate.h:179:9`!;
896 break;
897 case 'T':
898 output[ix++] = RULE_DOLLARcxx . . $ `external/espeak/translate.h:186:9`!;
899 c = 0x11;
900 break;
901 case 'W':
902 c = RULE_SPELLINGcxx . . $ `external/espeak/translate.h:188:9`!;
903 break;
904 case 'X':
905 c = RULE_NOVOWELScxx . . $ `external/espeak/translate.h:187:9`!;
906 break;
907 case 'J':
908 c = RULE_SKIPCHARScxx . . $ `external/espeak/translate.h:182:9`!;
909 break;
910 case 'L':
911 // expect two digits
912 c = *p++ - '0';
913 value = *p++ - '0';
914 c = c * 10 + value;
915 if ((value < 0) || (value > 9)) {
916 c = 0;
917 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: Expected 2 digits after 'L'\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum.);
918 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
919 } else if ((c <= 0) || (c >= N_LETTER_GROUPScxx . . $ `external/espeak/translate.h:48:9`!) || (ctx->letterGroupsDefinedcxx . . $ $anonymous_type_34d0db98ae374eb3_2#letterGroupsDefined.[(int)c] == 0)) {
920 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: Letter group L%.2d not defined\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum., c);
921 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
922 }
923 c += 'A';
924 if (state == 1) {
925 // pre-rule, put the group number before the RULE_LETTERGP command
926 output[ix++] = c;
927 c = RULE_LETTERGP2cxx . . $ `external/espeak/translate.h:178:9`!;
928 } else
929 output[ix++] = RULE_LETTERGP2cxx . . $ `external/espeak/translate.h:178:9`!;
930 break;
931 case '$':
932 value = 0;
933 mr = mnem_rulescxx . . $ mnem_rules.;
934 while (mr->mnem != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
935 len = strlen(mr->mnem);
936 if (strncmp(p, mr->mnem, len) == 0) {
937 value = mr->value;
938 p += len;
939 break;
940 }
941 mr++;
942 }
943
944 if (state == 1) {
945 // pre-rule, put the number before the RULE_DOLLAR
946 output[ix++] = value;
947 c = RULE_DOLLARcxx . . $ `external/espeak/translate.h:186:9`!;
948 } else {
949 output[ix++] = RULE_DOLLARcxx . . $ `external/espeak/translate.h:186:9`!;
950 c = value;
951 }
952
953 if (value == 0) {
954 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: $ command not recognized\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum.);
955 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
956 }
957 break;
958 case 'P': // Prefix
959 sxflags |= SUFX_Pcxx . . $ `external/espeak/translate.h:142:9`!;
960 // fallthrough
961 case 'S': // Suffix
962 output[ix++] = RULE_ENDINGcxx . . $ `external/espeak/translate.h:174:9`!;
963 value = 0;
964 while (!isspace2cxx . . $ isspace2(4c679297bf94b9eb).(c = *p++) && (c != 0)) {
965 switch (c)
966 {
967 case 'e':
968 sxflags |= SUFX_Ecxx . . $ `external/espeak/translate.h:140:9`!;
969 break;
970 case 'i':
971 sxflags |= SUFX_Icxx . . $ `external/espeak/translate.h:141:9`!;
972 break;
973 case 'p': // obsolete, replaced by 'P' above
974 sxflags |= SUFX_Pcxx . . $ `external/espeak/translate.h:142:9`!;
975 break;
976 case 'v':
977 sxflags |= SUFX_Vcxx . . $ `external/espeak/translate.h:143:9`!;
978 break;
979 case 'd':
980 sxflags |= SUFX_Dcxx . . $ `external/espeak/translate.h:144:9`!;
981 break;
982 case 'f':
983 sxflags |= SUFX_Fcxx . . $ `external/espeak/translate.h:145:9`!;
984 break;
985 case 'q':
986 sxflags |= SUFX_Qcxx . . $ `external/espeak/translate.h:146:9`!;
987 break;
988 case 't':
989 sxflags |= SUFX_Tcxx . . $ `external/espeak/translate.h:147:9`!;
990 break;
991 case 'b':
992 sxflags |= SUFX_Bcxx . . $ `external/espeak/translate.h:148:9`!;
993 break;
994 case 'a':
995 sxflags |= SUFX_Acxx . . $ `external/espeak/translate.h:149:9`!;
996 break;
997 case 'm':
998 sxflags |= SUFX_Mcxx . . $ `external/espeak/translate.h:150:9`!;
999 break;
1000 default:
1001 if (IsDigit09cxx . . $ IsDigit09(4c679297bf94b9eb).(c))
1002 value = (value*10) + (c - '0');
1003 break;
1004 }
1005 }
1006 p--;
1007 output[ix++] = sxflags >> 16;
1008 output[ix++] = sxflags >> 8;
1009 c = value | 0x80;
1010 break;
1011 }
1012 }
1013 }
1014 output[ix++] = c;
1015 if (c == 0) break;
1016 }
1017
1018 *state_out = next_state[state];
1019 }
1020
1021 static char *compile_rulecxx . . $ compile_rule(23a82a26a671453a).(CompileContextcxx . . $ CompileContext# *ctx, char *input)
1022 {
1023 int ix;
1024 unsigned char c;
1025 int wc;
1026 char *p;
1027 char *prule;
1028 int len;
1029 int len_name;
1030 int start;
1031 int state = 2;
1032 bool finish = false;
1033 char buf[80];
1034 char output[150];
1035 int bad_phoneme;
1036 char bad_phoneme_str[4];
1037
1038 buf[0] = 0;
1039 ctx->rule_condcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_cond.[0] = 0;
1040 ctx->rule_precxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_pre.[0] = 0;
1041 ctx->rule_postcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_post.[0] = 0;
1042 ctx->rule_matchcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_match.[0] = 0;
1043 ctx->rule_phonemescxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_phonemes.[0] = 0;
1044
1045 p = buf;
1046
1047 for (ix = 0; finish == false; ix++) {
1048 switch (c = input[ix])
1049 {
1050 case ')': // end of prefix section
1051 *p = 0;
1052 state = 1;
1053 copy_rule_stringcxx . . $ copy_rule_string(b393f284d89f4ee8).(ctx, buf, &state);
1054 p = buf;
1055 break;
1056 case '(': // start of suffix section
1057 *p = 0;
1058 state = 2;
1059 copy_rule_stringcxx . . $ copy_rule_string(b393f284d89f4ee8).(ctx, buf, &state);
1060 state = 3;
1061 p = buf;
1062 if (input[ix+1] == ' ') {
1063 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: Syntax error. Space after (, or negative score for previous rule\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum.);
1064 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
1065 }
1066 break;
1067 case '\n': // end of line
1068 case '\r':
1069 case 0: // end of line
1070 *p = 0;
1071 copy_rule_stringcxx . . $ copy_rule_string(b393f284d89f4ee8).(ctx, buf, &state);
1072 finish = true;
1073 break;
1074 case '\t': // end of section section
1075 case ' ':
1076 *p = 0;
1077 copy_rule_stringcxx . . $ copy_rule_string(b393f284d89f4ee8).(ctx, buf, &state);
1078 p = buf;
1079 break;
1080 case '?':
1081 if (state == 2)
1082 state = 0;
1083 else
1084 *p++ = c;
1085 break;
1086 default:
1087 *p++ = c;
1088 break;
1089 }
1090 }
1091
1092 if (strcmp(ctx->rule_matchcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_match., "$group") == 0)
1093 strcpy(ctx->rule_matchcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_match., ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name.);
1094
1095 if (ctx->rule_matchcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_match.[0] == 0) {
1096 if (ctx->rule_postcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_post.[0] != 0) {
1097 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: Syntax error\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum.);
1098 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
1099 }
1100 return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
1101 }
1102
1103 EncodePhonemes(ctx->rule_phonemescxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_phonemes., buf, &bad_phoneme);
1104 if (bad_phoneme != 0) {
1105 bad_phoneme_str[utf8_outcxx . . $ utf8_out(fa84e865f2d62ca9).(bad_phoneme, bad_phoneme_str)] = 0;
1106 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: Bad phoneme [%s] (U+%x) in: %s\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum., bad_phoneme_str, bad_phoneme, input);
1107 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
1108 }
1109 strcpy(output, buf);
1110 len = strlen(buf)+1;
1111
1112 len_name = strlen(ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name.);
1113 if ((len_name > 0) && (memcmp(ctx->rule_matchcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_match., ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name., len_name) != 0)) {
1114 utf8_incxx . . $ utf8_in(80e674cbced5dd06).(&wc, ctx->rule_matchcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_match.);
1115 if ((ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name.[0] == '9') && IsDigitcxx . . $ IsDigit(4c679297bf94b9eb).(wc)) {
1116 // numeric group, rule_match starts with a digit, so OK
1117 } else {
1118 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: Wrong initial letters '%s' for group '%s'\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum., ctx->rule_matchcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_match., ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name.);
1119 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
1120 }
1121 }
1122 strcpy(&output[len], ctx->rule_matchcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_match.);
1123 len += strlen(ctx->rule_matchcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_match.);
1124
1125 if (ctx->debug_flagcxx . . $ $anonymous_type_34d0db98ae374eb3_2#debug_flag.) {
1126 output[len] = RULE_LINENUMcxx . . $ `external/espeak/translate.h:168:9`!;
1127 output[len+1] = (ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum. % 255) + 1;
1128 output[len+2] = (ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum. / 255) + 1;
1129 len += 3;
1130 }
1131
1132 if (ctx->rule_condcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_cond.[0] != 0) {
1133 if (ctx->rule_condcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_cond.[0] == '!') {
1134 // allow the rule only if the condition number is NOT set for the voice
1135 ix = atoicxx . . $ atoi(f5ecf3191ed0cd93).(&ctx->rule_condcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_cond.[1]) + 32;
1136 } else {
1137 // allow the rule only if the condition number is set for the voice
1138 ix = atoicxx . . $ atoi(f5ecf3191ed0cd93).(ctx->rule_condcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_cond.);
1139 }
1140
1141 if ((ix > 0) && (ix < 255)) {
1142 output[len++] = RULE_CONDITIONcxx . . $ `external/espeak/translate.h:164:9`!;
1143 output[len++] = ix;
1144 } else {
1145 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: bad condition number ?%d\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum., ix);
1146 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
1147 }
1148 }
1149 if (ctx->rule_precxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_pre.[0] != 0) {
1150 start = 0;
1151 if (ctx->rule_precxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_pre.[0] == RULE_SPACEcxx . . $ `external/espeak/translate.h:192:9`!) {
1152 // omit '_' at the beginning of the pre-string and imply it by using RULE_PRE_ATSTART
1153 c = RULE_PRE_ATSTARTcxx . . $ `external/espeak/translate.h:167:9`!;
1154 start = 1;
1155 } else
1156 c = RULE_PREcxx . . $ `external/espeak/translate.h:160:9`!;
1157 output[len++] = c;
1158
1159 // output PRE string in reverse order
1160 for (ix = strlen(ctx->rule_precxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_pre.)-1; ix >= start; ix--)
1161 output[len++] = ctx->rule_precxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_pre.[ix];
1162 }
1163
1164 if (ctx->rule_postcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_post.[0] != 0) {
1165 sprintf(&output[len], "%c%s", RULE_POSTcxx . . $ `external/espeak/translate.h:161:9`!, ctx->rule_postcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_post.);
1166 len += (strlen(ctx->rule_postcxx . . $ $anonymous_type_34d0db98ae374eb3_2#rule_post.)+1);
1167 }
1168 output[len++] = 0;
1169 if ((prule = (char *)malloccxx . . $ malloc(9f008b2a9698428b).(len)) != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
1170 memcpy(prule, output, len);
1171 return prule;
1172 }
1173
1174 static int __cdeclcxx . . $ `external/espeak/speech.h:74:9`! string_sortercxx . . $ string_sorter(1c2bee554d4ac597).(char **a, char **b)
1175 {
1176 char *pa, *pb;
1177 int ix;
1178
1179 if ((ix = strcmp(pa = *a, pb = *b)) != 0)
1180 return ix;
1181 pa += (strlen(pa)+1);
1182 pb += (strlen(pb)+1);
1183 return strcmp(pa, pb);
1184 }
1185
1186 static int __cdeclcxx . . $ `external/espeak/speech.h:74:9`! rgroup_sortercxx . . $ rgroup_sorter(d5e10b17ebed0ba7).(RGROUPcxx . . $ RGROUP# *a, RGROUPcxx . . $ RGROUP# *b)
1187 {
1188 // Sort long names before short names
1189 int ix;
1190 ix = strlen(b->namecxx . . $ $anonymous_type_34d0db98ae374eb3_0#name.) - strlen(a->namecxx . . $ $anonymous_type_34d0db98ae374eb3_0#name.);
1191 if (ix != 0) return ix;
1192 ix = strcmp(a->namecxx . . $ $anonymous_type_34d0db98ae374eb3_0#name., b->namecxx . . $ $anonymous_type_34d0db98ae374eb3_0#name.);
1193 if (ix != 0) return ix;
1194 return (uintptr_tcxx . . $ uintptr_t#)a->startcxx . . $ $anonymous_type_34d0db98ae374eb3_0#start. - (uintptr_tcxx . . $ uintptr_t#)b->startcxx . . $ $anonymous_type_34d0db98ae374eb3_0#start.;
1195 }
1196
1197 static void* output_rule_groupcxx . . $ output_rule_group(fa1bebfa593478ef).(int n_rules, char **rules, char *name, size_t *outsize)
1198 {
1199 int ix;
1200 int len1;
1201 int len2;
1202 int len_name;
1203 char *p;
1204 char *p2, *p3;
1205 const char *common;
1206 char *outptr = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
1207 size_t outpos, outlen = 0;
1208
1209 short nextchar_count[256];
1210 memset(nextchar_count, 0, sizeof(nextchar_count));
1211
1212 len_name = strlen(name);
1213
1214 // sort the rules in this group by their phoneme string
1215 common = "";
1216 qsortcxx . . $ qsort(ebb60b13a65e77d7).((void *)rules, n_rules, sizeof(char *), (int(__cdeclcxx . . $ `external/espeak/speech.h:74:9`! *)(const void *, const void *))string_sortercxx . . $ string_sorter(1c2bee554d4ac597).);
1217
1218 if (strcmp(name, "9") == 0)
1219 len_name = 0; // don't remove characters from numeric match strings
1220
1221 for (ix = 0; ix < n_rules; ix++) {
1222 p = rules[ix];
1223 len1 = strlen(p) + 1; // phoneme string
1224 p3 = &p[len1];
1225 p2 = p3 + len_name; // remove group name from start of match string
1226 len2 = strlen(p2);
1227
1228 nextchar_count[(unsigned char)(p2[0])]++; // the next byte after the group name
1229
1230 outpos = outlen;
1231 if ((common[0] != 0) && (strcmp(p, common) == 0)) {
1232 outlen += len2 + 1;
1233 outptr = (char *) realloccxx . . $ realloc(42b2a9dd8f084bf2).(outptr, outlen);
1234 memmove(outptr + outpos, p2, len2);
1235 outptr[outlen-1] = 0;
1236 } else {
1237 if ((ix < n_rules-1) && (strcmp(p, rules[ix+1]) == 0)) {
1238 outlen ++;
1239 outptr = (char *) realloccxx . . $ realloc(42b2a9dd8f084bf2).(outptr, outlen);
1240 common = rules[ix]; // phoneme string is same as next, set as common
1241 outptr[outpos++] = RULE_PH_COMMONcxx . . $ `external/espeak/translate.h:163:9`!;
1242 }
1243
1244 outlen += len2 + 1 + len1;
1245 outptr = (char *) realloccxx . . $ realloc(42b2a9dd8f084bf2).(outptr, outlen);
1246 memmove(outptr + outpos, p2, len2);
1247 outpos += len2;
1248 outptr[outpos++] = RULE_PHONEMEScxx . . $ `external/espeak/translate.h:162:9`!;
1249 memmove(outptr + outpos, p, len1);
1250 }
1251 }
1252 if (outsize) *outsize = outlen;
1253 return outptr;
1254 }
1255
1256 static int compile_lettergroupcxx . . $ compile_lettergroup(7d9b47338bc2a458).(CompileContextcxx . . $ CompileContext# *ctx, char *input, FILE *f_out)
1257 {
1258 char *p;
1259 char *p_start;
1260 int group;
1261 int ix;
1262 int n_items;
1263 int length;
1264 int max_length = 0;
1265
1266 #define N_LETTERGP_ITEMScxx . . $ `external/espeak/compiledict.cpp:1266:10`! 200
1267 char *items[N_LETTERGP_ITEMScxx . . $ `external/espeak/compiledict.cpp:1266:10`!];
1268 char item_length[N_LETTERGP_ITEMScxx . . $ `external/espeak/compiledict.cpp:1266:10`!];
1269
1270 p = input;
1271 if (!IsDigit09cxx . . $ IsDigit09(4c679297bf94b9eb).(p[0]) || !IsDigit09cxx . . $ IsDigit09(4c679297bf94b9eb).(p[1])) {
1272 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: Expected 2 digits after '.L'\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum.);
1273 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
1274 return 1;
1275 }
1276
1277 group = atoicxx . . $ atoi(f5ecf3191ed0cd93).(&p[0]);
1278 if (group >= N_LETTER_GROUPScxx . . $ `external/espeak/translate.h:48:9`!) {
1279 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: lettergroup out of range (01-%.2d)\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum., N_LETTER_GROUPScxx . . $ `external/espeak/translate.h:48:9`!-1);
1280 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
1281 return 1;
1282 }
1283
1284 while (!isspace2cxx . . $ isspace2(4c679297bf94b9eb).(*p)) p++;
1285
1286 fputc(RULE_GROUP_STARTcxx . . $ `external/espeak/translate.h:165:9`!, f_out);
1287 fputc(RULE_LETTERGP2cxx . . $ `external/espeak/translate.h:178:9`!, f_out);
1288 fputc(group + 'A', f_out);
1289 if (ctx->letterGroupsDefinedcxx . . $ $anonymous_type_34d0db98ae374eb3_2#letterGroupsDefined.[group] != 0) {
1290 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: lettergroup L%.2d is already defined\n", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum., group);
1291 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
1292 }
1293 ctx->letterGroupsDefinedcxx . . $ $anonymous_type_34d0db98ae374eb3_2#letterGroupsDefined.[group] = 1;
1294
1295 n_items = 0;
1296 while (n_items < N_LETTERGP_ITEMScxx . . $ `external/espeak/compiledict.cpp:1266:10`!) {
1297 while (isspace2cxx . . $ isspace2(4c679297bf94b9eb).(*p)) p++;
1298 if (*p == 0)
1299 break;
1300
1301 items[n_items] = p_start = p;
1302 while ((*p & 0xff) > ' ') {
1303 if (*p == '_') *p = ' '; // allow '_' for word break
1304 p++;
1305 }
1306 *p++ = 0;
1307 length = p - p_start;
1308 if (length > max_length)
1309 max_length = length;
1310 item_length[n_items++] = length;
1311 }
1312
1313 // write out the items, longest first
1314 while (max_length > 1) {
1315 for (ix = 0; ix < n_items; ix++) {
1316 if (item_length[ix] == max_length)
1317 fwrite(items[ix], 1, max_length, f_out);
1318 }
1319 max_length--;
1320 }
1321
1322 fputc(RULE_GROUP_ENDcxx . . $ `external/espeak/translate.h:166:9`!, f_out);
1323
1324 return 0;
1325 }
1326
1327 static void free_rulescxx . . $ free_rules(a50bc8ce1fe710a2).(char **rules, int n_rules)
1328 {
1329 for (int i = 0; i < n_rules; ++i) {
1330 freecxx . . $ free(bd21765a0afc8e3c).(*rules);
1331 *rules++ = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
1332 }
1333 }
1334
1335 static espeak_ng_STATUS compile_dictrulescxx . . $ compile_dictrules(af3b743b0712e186).(CompileContextcxx . . $ CompileContext# *ctx, FILE *f_in, FILE *f_out)
1336 {
1337 char *prule;
1338 unsigned char *p;
1339 int ix;
1340 int c;
1341 int gp;
1342 int n_rules = 0;
1343 int count = 0;
1344 int different;
1345 int wc;
1346 int err_n_rules = 0;
1347 const char *prev_rgroup_name;
1348 unsigned int char_code;
1349 int compile_mode = 0;
1350 char *buf;
1351 char buf1[500];
1352 char *rules[N_RULEScxx . . $ `external/espeak/compiledict.cpp:765:9`!];
1353
1354 int n_rgroups = 0;
1355 int n_groups3 = 0;
1356 RGROUPcxx . . $ RGROUP# rgroup[N_RULE_GROUP2cxx . . $ `external/espeak/translate.h:46:9`!];
1357
1358 ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum. = 0;
1359 ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name.[0] = 0;
1360
1361 for (;;) {
1362 ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum.++;
1363 buf = fgets(buf1, sizeof(buf1), f_in);
1364 if (buf != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
1365 if ((p = (unsigned char *)strstr(buf, "//")) != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
1366 *p = 0;
1367
1368 if (buf[0] == '\r') buf++; // ignore extra \r in \r\n
1369 }
1370
1371 if ((buf == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) || (buf[0] == '.')) {
1372 // next .group or end of file, write out the previous group
1373
1374 if (n_rules > 0) {
1375 strcpy(rgroup[n_rgroups].namecxx . . $ $anonymous_type_34d0db98ae374eb3_0#name., ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name.);
1376 rgroup[n_rgroups].group3_ixcxx . . $ $anonymous_type_34d0db98ae374eb3_0#group3_ix. = ctx->group3_ixcxx . . $ $anonymous_type_34d0db98ae374eb3_2#group3_ix.;
1377 rgroup[n_rgroups].startcxx . . $ $anonymous_type_34d0db98ae374eb3_0#start. = output_rule_groupcxx . . $ output_rule_group(fa1bebfa593478ef).(n_rules, rules, ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name., &rgroup[n_rgroups].lengthcxx . . $ $anonymous_type_34d0db98ae374eb3_0#length.);
1378 n_rgroups++;
1379
1380 count += n_rules;
1381 free_rulescxx . . $ free_rules(a50bc8ce1fe710a2).(rules, n_rules);
1382 }
1383 n_rules = 0;
1384 err_n_rules = 0;
1385
1386 if (compile_mode == 2) {
1387 // end of the character replacements section
1388 fwrite(&n_rules, 1, 4, f_out); // write a zero word to terminate the replacemenmt list
1389 fputc(RULE_GROUP_ENDcxx . . $ `external/espeak/translate.h:166:9`!, f_out);
1390 compile_mode = 0;
1391 }
1392
1393 if (buf == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) break; // end of file
1394
1395 if (memcmp(buf, ".L", 2) == 0) {
1396 compile_lettergroupcxx . . $ compile_lettergroup(7d9b47338bc2a458).(ctx, &buf[2], f_out);
1397 continue;
1398 }
1399
1400 if (memcmp(buf, ".replace", 8) == 0) {
1401 compile_mode = 2;
1402 fputc(RULE_GROUP_STARTcxx . . $ `external/espeak/translate.h:165:9`!, f_out);
1403 fputc(RULE_REPLACEMENTScxx . . $ `external/espeak/translate.h:180:9`!, f_out);
1404
1405 // advance to next word boundary
1406 while ((ftell(f_out) & 3) != 0)
1407 fputc(0, f_out);
1408 }
1409
1410 if (memcmp(buf, ".group", 6) == 0) {
1411 compile_mode = 1;
1412
1413 p = (unsigned char *)&buf[6];
1414 while ((p[0] == ' ') || (p[0] == '\t')) p++; // Note: Windows isspace(0xe1) gives TRUE !
1415 ix = 0;
1416 while ((*p > ' ') && (ix < LEN_GROUP_NAMEcxx . . $ `external/espeak/compiledict.cpp:144:9`!))
1417 ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name.[ix++] = *p++;
1418 ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name.[ix] = 0;
1419 ctx->group3_ixcxx . . $ $anonymous_type_34d0db98ae374eb3_2#group3_ix. = 0;
1420
1421 if (sscanf(ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name., "0x%x", &char_code) == 1) {
1422 // group character is given as a character code (max 16 bits)
1423 p = (unsigned char *)ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name.;
1424
1425 if (char_code > 0x100)
1426 *p++ = (char_code >> 8);
1427 *p++ = char_code;
1428 *p = 0;
1429 } else {
1430 if (translator->letter_bits_offset > 0) {
1431 utf8_incxx . . $ utf8_in(80e674cbced5dd06).(&wc, ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name.);
1432 if (((ix = (wc - translator->letter_bits_offset)) >= 0) && (ix < 128))
1433 ctx->group3_ixcxx . . $ $anonymous_type_34d0db98ae374eb3_2#group3_ix. = ix+1; // not zero
1434 }
1435 }
1436
1437 if ((ctx->group3_ixcxx . . $ $anonymous_type_34d0db98ae374eb3_2#group3_ix. == 0) && (strlen(ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name.) > 2)) {
1438 if (utf8_incxx . . $ utf8_in(80e674cbced5dd06).(&c, ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name.) < 2) {
1439 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "%5d: Group name longer than 2 bytes (UTF8)", ctx->linenumcxx . . $ $anonymous_type_34d0db98ae374eb3_2#linenum.);
1440 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
1441 }
1442
1443 ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name.[2] = 0;
1444 }
1445 }
1446
1447 continue;
1448 }
1449
1450 switch (compile_mode)
1451 {
1452 case 1: // .group
1453 prule = compile_rulecxx . . $ compile_rule(23a82a26a671453a).(ctx, buf);
1454 if (prule != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
1455 if (n_rules < N_RULEScxx . . $ `external/espeak/compiledict.cpp:765:9`!)
1456 rules[n_rules++] = prule;
1457 else {
1458 if (err_n_rules == 0) {
1459 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\nExceeded limit of rules (%d) in group '%s'\n", N_RULEScxx . . $ `external/espeak/compiledict.cpp:765:9`!, ctx->group_namecxx . . $ $anonymous_type_34d0db98ae374eb3_2#group_name.);
1460 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count.++;
1461 err_n_rules = 1;
1462 }
1463 }
1464
1465 }
1466 break;
1467 case 2: // .replace
1468 p = (unsigned char *)buf;
1469
1470 while (isspace2cxx . . $ isspace2(4c679297bf94b9eb).(*p)) p++;
1471 if ((unsigned char)(*p) > 0x20) {
1472 while ((unsigned char)(*p) > 0x20) { // not space or zero-byte
1473 fputc(*p, f_out);
1474 p++;
1475 }
1476 fputc(0, f_out);
1477
1478 while (isspace2cxx . . $ isspace2(4c679297bf94b9eb).(*p)) p++;
1479 while ((unsigned char)(*p) > 0x20) {
1480 fputc(*p, f_out);
1481 p++;
1482 }
1483 fputc(0, f_out);
1484 }
1485 break;
1486 }
1487 }
1488
1489 qsortcxx . . $ qsort(ebb60b13a65e77d7).((void *)rgroup, n_rgroups, sizeof(rgroup[0]), (int(__cdeclcxx . . $ `external/espeak/speech.h:74:9`! *)(const void *, const void *))rgroup_sortercxx . . $ rgroup_sorter(d5e10b17ebed0ba7).);
1490
1491 prev_rgroup_name = "\n";
1492
1493 for (gp = 0; gp < n_rgroups; gp++) {
1494 if ((different = strcmp(rgroup[gp].namecxx . . $ $anonymous_type_34d0db98ae374eb3_0#name., prev_rgroup_name)) != 0) {
1495 // not the same as the previous group
1496 if (gp > 0)
1497 fputc(RULE_GROUP_ENDcxx . . $ `external/espeak/translate.h:166:9`!, f_out);
1498 fputc(RULE_GROUP_STARTcxx . . $ `external/espeak/translate.h:165:9`!, f_out);
1499
1500 if (rgroup[gp].group3_ixcxx . . $ $anonymous_type_34d0db98ae374eb3_0#group3_ix. != 0) {
1501 n_groups3++;
1502 fputc(1, f_out);
1503 fputc(rgroup[gp].group3_ixcxx . . $ $anonymous_type_34d0db98ae374eb3_0#group3_ix., f_out);
1504 } else
1505 fprintf(f_out, "%s", prev_rgroup_name = rgroup[gp].namecxx . . $ $anonymous_type_34d0db98ae374eb3_0#name.);
1506 fputc(0, f_out);
1507 }
1508
1509 fwrite(rgroup[gp].startcxx . . $ $anonymous_type_34d0db98ae374eb3_0#start., rgroup[gp].lengthcxx . . $ $anonymous_type_34d0db98ae374eb3_0#length., 1, f_out);
1510 }
1511 fputc(RULE_GROUP_ENDcxx . . $ `external/espeak/translate.h:166:9`!, f_out);
1512 fputc(0, f_out);
1513
1514 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "\t%d rules, %d groups (%d)\n\n", count, n_rgroups, n_groups3);
1515 free_rulescxx . . $ free_rules(a50bc8ce1fe710a2).(rules, n_rules);
1516 for (gp = 0; gp < n_rgroups; gp++) {
1517 freecxx . . $ free(bd21765a0afc8e3c).(rgroup[gp].startcxx . . $ $anonymous_type_34d0db98ae374eb3_0#start.);
1518 }
1519 return ENS_OK;
1520 }
1521
1522 #pragma GCC visibility push(default)
1523 ESPEAK_NG_APIcxx . . $ `external/espeak/espeak_ng.h:36:9`! espeak_ng_STATUS espeak_ng_CompileDictionarycxx . . $ espeak_ng_CompileDictionary(2aa35fc6a003d79).(const char *dsource, const char *dict_name, FILE *log, int flags, espeak_ng_ERROR_CONTEXT *context)
1524 {
1525 if (!log) log = stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!;
1526 if (!dict_name) dict_name = dictionary_name;
1527
1528 // fname: space to write the filename in case of error
1529 // flags: bit 0: include source line number information, for debug purposes.
1530
1531 FILE *f_in;
1532 FILE *f_out;
1533 int offset_rules = 0;
1534 int value;
1535 char fname_in[sizeof(path_home)+45];
1536 char fname_out[sizeof(path_home)+15];
1537 char path[sizeof(path_home)+40]; // path_dsource+20
1538
1539 CompileContextcxx . . $ CompileContext# *ctx = (CompileContextcxx . . $ CompileContext# *) calloccxx . . $ calloc(95acc9b79bb49189).(1, sizeof(CompileContextcxx . . $ CompileContext#));
1540
1541 ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count. = 0;
1542 ctx->error_need_dictionarycxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_need_dictionary. = 0;
1543 memset(ctx->letterGroupsDefinedcxx . . $ $anonymous_type_34d0db98ae374eb3_2#letterGroupsDefined., 0, sizeof(ctx->letterGroupsDefinedcxx . . $ $anonymous_type_34d0db98ae374eb3_2#letterGroupsDefined.));
1544
1545 ctx->debug_flagcxx . . $ $anonymous_type_34d0db98ae374eb3_2#debug_flag. = flags & 1;
1546
1547 if (dsource == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
1548 dsource = "";
1549
1550 ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log. = log;
1551 if (ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
1552 ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log. = stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!;
1553
1554 // try with and without '.txt' extension
1555 sprintf(path, "%s%s_", dsource, dict_name);
1556 sprintf(fname_in, "%srules.txt", path);
1557 if ((f_in = fopen(fname_in, "r")) == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
1558 sprintf(fname_in, "%srules", path);
1559 if ((f_in = fopen(fname_in, "r")) == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
1560 clean_contextcxx . . $ clean_context(9f2cdca689c1a14e).(ctx);
1561 return create_file_error_context(context, static_cast<espeak_ng_STATUS> (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!), fname_in);
1562 }
1563 }
1564
1565 sprintf(fname_out, "%s%c%s_dict", path_home, PATHSEPcxx . . $ `external/espeak/speech.h:71:9`!, dict_name);
1566 if ((f_out = fopen(fname_out, "wb+")) == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
1567 int error = errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!;
1568 fclose(f_in);
1569 clean_contextcxx . . $ clean_context(9f2cdca689c1a14e).(ctx);
1570 return create_file_error_context(context, static_cast<espeak_ng_STATUS> (error), fname_out);
1571 }
1572
1573 value = N_HASH_DICTcxx . . $ `external/espeak/translate.h:47:9`!;
1574 Write4Bytes(f_out, value);
1575 Write4Bytes(f_out, offset_rules);
1576
1577 compile_dictlist_startcxx . . $ compile_dictlist_start(9f2cdca689c1a14e).(ctx);
1578
1579 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "Using phonemetable: '%s'\n", phoneme_tab_list[phoneme_tab_number].name);
1580 compile_dictlist_filecxx . . $ compile_dictlist_file(172ff442181800ce).(ctx, path, "roots");
1581 if (translator->langopts.listx) {
1582 compile_dictlist_filecxx . . $ compile_dictlist_file(172ff442181800ce).(ctx, path, "list");
1583 compile_dictlist_filecxx . . $ compile_dictlist_file(172ff442181800ce).(ctx, path, "listx");
1584 } else {
1585 compile_dictlist_filecxx . . $ compile_dictlist_file(172ff442181800ce).(ctx, path, "listx");
1586 compile_dictlist_filecxx . . $ compile_dictlist_file(172ff442181800ce).(ctx, path, "list");
1587 }
1588 compile_dictlist_filecxx . . $ compile_dictlist_file(172ff442181800ce).(ctx, path, "emoji");
1589 compile_dictlist_filecxx . . $ compile_dictlist_file(172ff442181800ce).(ctx, path, "extra");
1590
1591 compile_dictlist_endcxx . . $ compile_dictlist_end(b16d811d85dbfdad).(ctx, f_out);
1592 offset_rules = ftell(f_out);
1593
1594 fprintf(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log., "Compiling: '%s'\n", fname_in);
1595
1596 espeak_ng_STATUS status = compile_dictrulescxx . . $ compile_dictrules(af3b743b0712e186).(ctx, f_in, f_out);
1597 fclose(f_in);
1598
1599 fseek(f_out, 4, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!);
1600 Write4Bytes(f_out, offset_rules);
1601 fclose(f_out);
1602 fflush(ctx->f_logcxx . . $ $anonymous_type_34d0db98ae374eb3_2#f_log.);
1603
1604 if (status != ENS_OK) {
1605 clean_contextcxx . . $ clean_context(9f2cdca689c1a14e).(ctx);
1606 return status;
1607 }
1608
1609 LoadDictionary(translator, dict_name, 0);
1610
1611 status = ctx->error_countcxx . . $ $anonymous_type_34d0db98ae374eb3_2#error_count. > 0 ? ENS_COMPILE_ERROR : ENS_OK;
1612 clean_contextcxx . . $ clean_context(9f2cdca689c1a14e).(ctx);
1613 return status;
1614 }
1615 #pragma GCC visibility pop