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.

compiledict.cpp 32KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2007 by Jonathan Duddington *
  3. * email: [email protected] *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 3 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write see: *
  17. * <http://www.gnu.org/licenses/>. *
  18. ***************************************************************************/
  19. #include "StdAfx.h"
  20. #include <stdio.h>
  21. #include <ctype.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <wctype.h>
  25. #include "speak_lib.h"
  26. #include "speech.h"
  27. #include "phoneme.h"
  28. #include "synthesize.h"
  29. #include "translate.h"
  30. //#define OPT_FORMAT // format the text and write formatted copy to Log file
  31. //#define OUTPUT_FORMAT
  32. extern void Write4Bytes(FILE *f, int value);
  33. int HashDictionary(const char *string);
  34. static FILE *f_log = NULL;
  35. extern char *dir_dictionary;
  36. int linenum;
  37. static int error_count;
  38. static int transpose_offset; // transpose character range for LookupDictList()
  39. static int transpose_min;
  40. static int transpose_max;
  41. static int text_mode = 0;
  42. static int debug_flag = 0;
  43. int hash_counts[N_HASH_DICT];
  44. char *hash_chains[N_HASH_DICT];
  45. MNEM_TAB mnem_flags[] = {
  46. // these in the first group put a value in bits0-3 of dictionary_flags
  47. {"$1", 0x41}, // stress on 1st syllable
  48. {"$2", 0x42}, // stress on 2nd syllable
  49. {"$3", 0x43},
  50. {"$4", 0x44},
  51. {"$5", 0x45},
  52. {"$6", 0x46},
  53. {"$7", 0x47},
  54. {"$u", 0x48}, // reduce to unstressed
  55. {"$u1", 0x49},
  56. {"$u2", 0x4a},
  57. {"$u3", 0x4b},
  58. {"$u+", 0x4c}, // reduce to unstressed, but stress at end of clause
  59. {"$u1+", 0x4d},
  60. {"$u2+", 0x4e},
  61. {"$u3+", 0x4f},
  62. // these set the corresponding numbered bit if dictionary_flags
  63. {"$pause", 8}, /* ensure pause before this word */
  64. {"$only", 9}, /* only match on this word without suffix */
  65. {"$onlys", 10}, /* only match with none, or with 's' suffix */
  66. {"$strend", 11}, /* full stress if at end of clause */
  67. {"$strend2", 12}, /* full stress if at end of clause, or only followed by unstressed */
  68. {"$unstressend",13}, /* reduce stress at end of clause */
  69. {"$atend", 14}, /* use this pronunciation if at end of clause */
  70. {"$dot", 16}, /* ignore '.' after this word (abbreviation) */
  71. {"$abbrev", 17}, /* use this pronuciation rather than split into letters */
  72. {"$stem", 18}, // must have a suffix
  73. // language specific
  74. {"$double", 19}, // IT double the initial consonant of next word
  75. {"$alt", 20}, // use alternative pronunciation
  76. {"$alt2", 21},
  77. {"$brk", 28}, // a shorter $pause
  78. {"$text", 29}, // word translates to replcement text, not phonemes
  79. // flags in dictionary word 2
  80. {"$verbf", 0x20}, /* verb follows */
  81. {"$verbsf", 0x21}, /* verb follows, allow -s suffix */
  82. {"$nounf", 0x22}, /* noun follows */
  83. {"$pastf", 0x23}, /* past tense follows */
  84. {"$verb", 0x24}, /* use this pronunciation when its a verb */
  85. {"$noun", 0x25}, /* use this pronunciation when its a noun */
  86. {"$past", 0x26}, /* use this pronunciation when its past tense */
  87. {"$verbextend",0x28}, /* extend influence of 'verb follows' */
  88. {"$capital", 0x29}, /* use this pronunciation if initial letter is upper case */
  89. {"$allcaps", 0x2a}, /* use this pronunciation if initial letter is upper case */
  90. {"$accent", 0x2b}, // character name is base-character name + accent name
  91. // doesn't set dictionary_flags
  92. {"$?", 100}, // conditional rule, followed by byte giving the condition number
  93. {"$textmode", 200},
  94. {"$phonememode", 201},
  95. {NULL, -1}
  96. };
  97. typedef struct {
  98. char name[6];
  99. unsigned int start;
  100. unsigned int length;
  101. } RGROUP;
  102. int isspace2(unsigned int c)
  103. {//=========================
  104. // can't use isspace() because on Windows, isspace(0xe1) gives TRUE !
  105. int c2;
  106. if(((c2 = (c & 0xff)) == 0) || (c > ' '))
  107. return(0);
  108. return(1);
  109. }
  110. static FILE *fopen_log(const char *fname,const char *access)
  111. {//==================================================
  112. // performs fopen, but produces error message to f_log if it fails
  113. FILE *f;
  114. if((f = fopen(fname,access)) == NULL)
  115. {
  116. if(f_log != NULL)
  117. fprintf(f_log,"Can't access (%s) file '%s'\n",access,fname);
  118. }
  119. return(f);
  120. }
  121. #ifdef OPT_FORMAT
  122. static const char *lookup_mnem(MNEM_TAB *table, int value)
  123. //========================================================
  124. /* Lookup a mnemonic string in a table, return its name */
  125. {
  126. while(table->mnem != NULL)
  127. {
  128. if(table->value==value)
  129. return(table->mnem);
  130. table++;
  131. }
  132. return("??"); /* not found */
  133. } /* end of mnem */
  134. #endif
  135. int compile_line(char *linebuf, char *dict_line, int *hash)
  136. {//========================================================
  137. // Compile a line in the language_list file
  138. unsigned char c;
  139. char *p;
  140. char *word;
  141. char *phonetic;
  142. unsigned int ix;
  143. int step;
  144. unsigned int n_flag_codes = 0;
  145. int flag_offset;
  146. int length;
  147. int multiple_words = 0;
  148. char *multiple_string = NULL;
  149. char *multiple_string_end = NULL;
  150. int len_word;
  151. int len_phonetic;
  152. int text_not_phonemes; // this word specifies replacement text, not phonemes
  153. char *mnemptr;
  154. char *comment;
  155. unsigned char flag_codes[100];
  156. char encoded_ph[200];
  157. unsigned char bad_phoneme[4];
  158. static char nullstring[] = {0};
  159. comment = NULL;
  160. text_not_phonemes = 0;
  161. phonetic = word = nullstring;
  162. p = linebuf;
  163. // while(isspace2(*p)) p++;
  164. #ifdef deleted
  165. if(*p == '$')
  166. {
  167. if(memcmp(p,"$textmode",9) == 0)
  168. {
  169. text_mode = 1;
  170. return(0);
  171. }
  172. if(memcmp(p,"$phonememode",12) == 0)
  173. {
  174. text_mode = 0;
  175. return(0);
  176. }
  177. }
  178. #endif
  179. step = 0;
  180. c = 0;
  181. while(c != '\n')
  182. {
  183. c = *p;
  184. if((c == '?') && (step==0))
  185. {
  186. // conditional rule, allow only if the numbered condition is set for the voice
  187. flag_offset = 100;
  188. p++;
  189. if(*p == '!')
  190. {
  191. // allow only if the numbered condition is NOT set
  192. flag_offset = 132;
  193. p++;
  194. }
  195. ix = 0;
  196. if(isdigit(*p))
  197. {
  198. ix += (*p-'0');
  199. p++;
  200. }
  201. if(isdigit(*p))
  202. {
  203. ix = ix*10 + (*p-'0');
  204. p++;
  205. }
  206. flag_codes[n_flag_codes++] = ix + flag_offset;
  207. c = *p;
  208. }
  209. if((c == '$') && isalnum(p[1]))
  210. {
  211. /* read keyword parameter */
  212. mnemptr = p;
  213. while(!isspace2(c = *p)) p++;
  214. *p = 0;
  215. ix = LookupMnem(mnem_flags,mnemptr);
  216. if(ix > 0)
  217. {
  218. if(ix == 200)
  219. {
  220. text_mode = 1;
  221. }
  222. else
  223. if(ix == 201)
  224. {
  225. text_mode = 0;
  226. }
  227. else
  228. if(ix == BITNUM_FLAG_TEXTMODE)
  229. {
  230. text_not_phonemes = 1;
  231. }
  232. else
  233. {
  234. flag_codes[n_flag_codes++] = ix;
  235. }
  236. }
  237. else
  238. {
  239. fprintf(f_log,"%5d: Unknown keyword: %s\n",linenum,mnemptr);
  240. error_count++;
  241. }
  242. }
  243. if((c == '/') && (p[1] == '/') && (multiple_words==0))
  244. {
  245. c = '\n'; /* "//" treat comment as end of line */
  246. comment = p;
  247. }
  248. switch(step)
  249. {
  250. case 0:
  251. if(c == '(')
  252. {
  253. multiple_words = 1;
  254. word = p+1;
  255. step = 1;
  256. }
  257. else
  258. if(!isspace2(c))
  259. {
  260. word = p;
  261. step = 1;
  262. }
  263. break;
  264. case 1:
  265. if(isspace2(c))
  266. {
  267. p[0] = 0; /* terminate english word */
  268. if(multiple_words)
  269. {
  270. multiple_string = multiple_string_end = p+1;
  271. step = 2;
  272. }
  273. else
  274. {
  275. step = 3;
  276. }
  277. }
  278. else
  279. if((c == ')') && multiple_words)
  280. {
  281. p[0] = 0;
  282. step = 3;
  283. multiple_words = 0;
  284. }
  285. break;
  286. case 2:
  287. if(isspace2(c))
  288. {
  289. multiple_words++;
  290. }
  291. else
  292. if(c == ')')
  293. {
  294. p[0] = ' '; // terminate extra string
  295. multiple_string_end = p+1;
  296. step = 3;
  297. }
  298. break;
  299. case 3:
  300. if(!isspace2(c))
  301. {
  302. phonetic = p;
  303. step = 4;
  304. }
  305. break;
  306. case 4:
  307. if(isspace2(c))
  308. {
  309. p[0] = 0; /* terminate phonetic */
  310. step = 5;
  311. }
  312. break;
  313. case 5:
  314. break;
  315. }
  316. p++;
  317. }
  318. if(word[0] == 0)
  319. {
  320. #ifdef OPT_FORMAT
  321. if(comment != NULL)
  322. fprintf(f_log,"%s",comment);
  323. else
  324. fputc('\n',f_log);
  325. #endif
  326. return(0); /* blank line */
  327. }
  328. if(text_mode)
  329. text_not_phonemes = 1;
  330. if(text_not_phonemes != translator->langopts.textmode)
  331. {
  332. flag_codes[n_flag_codes++] = BITNUM_FLAG_TEXTMODE;
  333. }
  334. if(text_not_phonemes)
  335. {
  336. // this is replacement text, so don't encode as phonemes. Restrict the length of the replacement word
  337. strncpy0(encoded_ph,phonetic,N_WORD_BYTES-4);
  338. }
  339. else
  340. {
  341. EncodePhonemes(phonetic,encoded_ph,bad_phoneme);
  342. if(strchr(encoded_ph,phonSWITCH) != 0)
  343. {
  344. flag_codes[n_flag_codes++] = BITNUM_FLAG_ONLY_S; // don't match on suffixes (except 's') when switching languages
  345. }
  346. // check for errors in the phonemes codes
  347. for(ix=0; ix<sizeof(encoded_ph); ix++)
  348. {
  349. c = encoded_ph[ix];
  350. if(c == 0) break;
  351. if(c == 255)
  352. {
  353. /* unrecognised phoneme, report error */
  354. fprintf(f_log,"%5d: Bad phoneme [%c] (0x%x) in: %s %s\n",linenum,bad_phoneme[0],bad_phoneme[0],word,phonetic);
  355. error_count++;
  356. }
  357. }
  358. }
  359. if((word[0] & 0x80)==0) // 7 bit ascii only
  360. {
  361. // If first letter is uppercase, convert to lower case. (Only if it's 7bit ascii)
  362. // ??? need to consider utf8 here
  363. word[0] = tolower(word[0]);
  364. }
  365. len_word = strlen(word);
  366. if(transpose_offset > 0)
  367. {
  368. len_word = TransposeAlphabet(word, transpose_offset, transpose_min, transpose_max);
  369. }
  370. *hash = HashDictionary(word);
  371. len_phonetic = strlen(encoded_ph);
  372. dict_line[1] = len_word; // bit 6 indicates whether the word has been compressed
  373. len_word &= 0x3f;
  374. memcpy(&dict_line[2],word,len_word);
  375. if(len_phonetic == 0)
  376. {
  377. // no phonemes specified. set bit 7
  378. dict_line[1] |= 0x80;
  379. length = len_word + 2;
  380. }
  381. else
  382. {
  383. length = len_word + len_phonetic + 3;
  384. strcpy(&dict_line[(len_word)+2],encoded_ph);
  385. }
  386. for(ix=0; ix<n_flag_codes; ix++)
  387. {
  388. dict_line[ix+length] = flag_codes[ix];
  389. }
  390. length += n_flag_codes;
  391. if((multiple_string != NULL) && (multiple_words > 0))
  392. {
  393. if(multiple_words > 10)
  394. {
  395. fprintf(f_log,"%5d: Two many parts in a multi-word entry: %d\n",linenum,multiple_words);
  396. }
  397. else
  398. {
  399. dict_line[length++] = 80 + multiple_words;
  400. ix = multiple_string_end - multiple_string;
  401. memcpy(&dict_line[length],multiple_string,ix);
  402. length += ix;
  403. }
  404. }
  405. dict_line[0] = length;
  406. #ifdef OPT_FORMAT
  407. spaces = 16;
  408. for(ix=0; ix<n_flag_codes; ix++)
  409. {
  410. if(flag_codes[ix] >= 100)
  411. {
  412. fprintf(f_log,"?%d ",flag_codes[ix]-100);
  413. spaces -= 3;
  414. }
  415. }
  416. fprintf(f_log,"%s",word);
  417. spaces -= strlen(word);
  418. DecodePhonemes(encoded_ph,decoded_ph);
  419. while(spaces-- > 0) fputc(' ',f_log);
  420. spaces += (14 - strlen(decoded_ph));
  421. fprintf(f_log," %s",decoded_ph);
  422. while(spaces-- > 0) fputc(' ',f_log);
  423. for(ix=0; ix<n_flag_codes; ix++)
  424. {
  425. if(flag_codes[ix] < 100)
  426. fprintf(f_log," %s",lookup_mnem(mnem_flags,flag_codes[ix]));
  427. }
  428. if(comment != NULL)
  429. fprintf(f_log," %s",comment);
  430. else
  431. fputc('\n',f_log);
  432. #endif
  433. return(length);
  434. } /* end of compile_line */
  435. void compile_dictlist_start(void)
  436. {//==============================
  437. // initialise dictionary list
  438. int ix;
  439. char *p;
  440. char *p2;
  441. for(ix=0; ix<N_HASH_DICT; ix++)
  442. {
  443. p = hash_chains[ix];
  444. while(p != NULL)
  445. {
  446. memcpy(&p2,p,sizeof(char *));
  447. free(p);
  448. p = p2;
  449. }
  450. hash_chains[ix] = NULL;
  451. hash_counts[ix]=0;
  452. }
  453. }
  454. void compile_dictlist_end(FILE *f_out)
  455. {//===================================
  456. // Write out the compiled dictionary list
  457. int hash;
  458. int length;
  459. char *p;
  460. if(f_log != NULL)
  461. {
  462. #ifdef OUTPUT_FORMAT
  463. for(hash=0; hash<N_HASH_DICT; hash++)
  464. {
  465. fprintf(f_log,"%8d",hash_counts[hash]);
  466. if((hash & 7) == 7)
  467. fputc('\n',f_log);
  468. }
  469. fflush(f_log);
  470. #endif
  471. }
  472. for(hash=0; hash<N_HASH_DICT; hash++)
  473. {
  474. p = hash_chains[hash];
  475. hash_counts[hash] = (int)ftell(f_out);
  476. while(p != NULL)
  477. {
  478. length = *(p+sizeof(char *));
  479. fwrite(p+sizeof(char *),length,1,f_out);
  480. memcpy(&p,p,sizeof(char *));
  481. }
  482. fputc(0,f_out);
  483. }
  484. }
  485. int compile_dictlist_file(const char *path, const char* filename)
  486. {//==============================================================
  487. int length;
  488. int hash;
  489. char *p;
  490. int count=0;
  491. FILE *f_in;
  492. char buf[200];
  493. char fname[sizeof(path_home)+45];
  494. char dict_line[128];
  495. text_mode = 0;
  496. sprintf(fname,"%s%s",path,filename);
  497. if((f_in = fopen(fname,"r")) == NULL)
  498. return(-1);
  499. fprintf(f_log,"Compiling: '%s'\n",fname);
  500. linenum=0;
  501. while(fgets(buf,sizeof(buf),f_in) != NULL)
  502. {
  503. linenum++;
  504. length = compile_line(buf,dict_line,&hash);
  505. if(length == 0) continue; /* blank line */
  506. hash_counts[hash]++;
  507. p = (char *)malloc(length+sizeof(char *));
  508. if(p == NULL)
  509. {
  510. if(f_log != NULL)
  511. {
  512. fprintf(f_log,"Can't allocate memory\n");
  513. error_count++;
  514. }
  515. break;
  516. }
  517. memcpy(p,&hash_chains[hash],sizeof(char *));
  518. hash_chains[hash] = p;
  519. memcpy(p+sizeof(char *),dict_line,length);
  520. count++;
  521. }
  522. fprintf(f_log,"\t%d entries\n",count);
  523. fclose(f_in);
  524. return(0);
  525. } /* end of compile_dictlist_file */
  526. char rule_cond[80];
  527. char rule_pre[80];
  528. char rule_post[80];
  529. char rule_match[80];
  530. char rule_phonemes[80];
  531. char group_name[12];
  532. #define N_RULES 2000 // max rules for each group
  533. int hexdigit(char c)
  534. {//=================
  535. if(isdigit(c))
  536. return(c - '0');
  537. return(tolower(c) - 'a' + 10);
  538. }
  539. void copy_rule_string(char *string, int &state)
  540. {//============================================
  541. // state 0: conditional, 1=pre, 2=match, 3=post, 4=phonemes
  542. static char *outbuf[5] = {rule_cond, rule_pre, rule_match, rule_post, rule_phonemes};
  543. static int next_state[5] = {2,2,4,4,4};
  544. char *output;
  545. char *p;
  546. int ix;
  547. int len;
  548. char c;
  549. int sxflags;
  550. int value;
  551. int literal;
  552. if(string[0] == 0) return;
  553. output = outbuf[state];
  554. if(state==4)
  555. {
  556. // append to any previous phoneme string, i.e. allow spaces in the phoneme string
  557. len = strlen(rule_phonemes);
  558. if(len > 0)
  559. rule_phonemes[len++] = ' ';
  560. output = &rule_phonemes[len];
  561. }
  562. sxflags = 0x808000; // to ensure non-zero bytes
  563. for(p=string,ix=0;;)
  564. {
  565. literal = 0;
  566. c = *p++;
  567. if(c == '\\')
  568. {
  569. c = *p++; // treat next character literally
  570. if((c >= '0') && (c <= '3') && (p[0] >= '0') && (p[0] <= '7') && (p[1] >= '0') && (p[1] <= '7'))
  571. {
  572. // character code given by 3 digit octal value;
  573. c = (c-'0')*64 + (p[0]-'0')*8 + (p[1]-'0');
  574. p += 2;
  575. }
  576. literal = 1;
  577. }
  578. if((state==1) || (state==3))
  579. {
  580. // replace special characters (note: 'E' is reserved for a replaced silent 'e')
  581. if(literal == 0)
  582. {
  583. static const char lettergp_letters[9] = {LETTERGP_A,LETTERGP_B,LETTERGP_C,0,0,LETTERGP_F,LETTERGP_G,LETTERGP_H,LETTERGP_Y};
  584. switch(c)
  585. {
  586. case '_':
  587. c = RULE_SPACE;
  588. break;
  589. case 'Y':
  590. c = 'I'; // drop through to next case
  591. case 'A': // vowel
  592. case 'B':
  593. case 'C':
  594. case 'H':
  595. case 'F':
  596. case 'G':
  597. if(state == 1)
  598. {
  599. // pre-rule, put the number before the RULE_LETTERGP;
  600. output[ix++] = lettergp_letters[c-'A'] + 'A';
  601. c = RULE_LETTERGP;
  602. }
  603. else
  604. {
  605. output[ix++] = RULE_LETTERGP;
  606. c = lettergp_letters[c-'A'] + 'A';
  607. }
  608. break;
  609. case 'D':
  610. c = RULE_DIGIT;
  611. break;
  612. case 'K':
  613. c = RULE_NOTVOWEL;
  614. break;
  615. case 'N':
  616. c = RULE_NO_SUFFIX;
  617. break;
  618. case 'V':
  619. c = RULE_IFVERB;
  620. break;
  621. case 'Z':
  622. c = RULE_NONALPHA;
  623. break;
  624. case '+':
  625. c = RULE_INC_SCORE;
  626. break;
  627. case '@':
  628. c = RULE_SYLLABLE;
  629. break;
  630. case '&':
  631. c = RULE_STRESSED;
  632. break;
  633. case '%':
  634. c = RULE_DOUBLE;
  635. break;
  636. case '#':
  637. c = RULE_DEL_FWD;
  638. break;
  639. case '!':
  640. c = RULE_CAPITAL;
  641. break;
  642. case 'T':
  643. c = RULE_ALT1;
  644. break;
  645. case 'W':
  646. c = RULE_SPELLING;
  647. break;
  648. case 'X':
  649. c = RULE_NOVOWELS;
  650. break;
  651. case 'L':
  652. // expect two digits
  653. c = *p++ - '0';
  654. value = *p++ - '0';
  655. c = c * 10 + value;
  656. if((value < 0) || (value > 9) || (c <= 0) || (c >= N_LETTER_GROUPS))
  657. {
  658. c = 0;
  659. fprintf(f_log,"%5d: Expected 2 digits after 'L'",linenum);
  660. error_count++;
  661. }
  662. c += 'A';
  663. if(state == 1)
  664. {
  665. // pre-rule, put the group number before the RULE_LETTERGP command
  666. output[ix++] = c;
  667. c = RULE_LETTERGP2;
  668. }
  669. else
  670. {
  671. output[ix++] = RULE_LETTERGP2;
  672. }
  673. break;
  674. case 'P':
  675. sxflags |= SUFX_P; // Prefix, now drop through to Suffix
  676. case '$': // obsolete, replaced by S
  677. case 'S':
  678. output[ix++] = RULE_ENDING;
  679. value = 0;
  680. while(!isspace2(c = *p++) && (c != 0))
  681. {
  682. switch(c)
  683. {
  684. case 'e':
  685. sxflags |= SUFX_E;
  686. break;
  687. case 'i':
  688. sxflags |= SUFX_I;
  689. break;
  690. case 'p': // obsolete, replaced by 'P' above
  691. sxflags |= SUFX_P;
  692. break;
  693. case 'v':
  694. sxflags |= SUFX_V;
  695. break;
  696. case 'd':
  697. sxflags |= SUFX_D;
  698. break;
  699. case 'f':
  700. sxflags |= SUFX_F;
  701. break;
  702. case 'q':
  703. sxflags |= SUFX_Q;
  704. break;
  705. case 't':
  706. sxflags |= SUFX_T;
  707. break;
  708. case 'b':
  709. sxflags |= SUFX_B;
  710. break;
  711. default:
  712. if(isdigit(c))
  713. value = (value*10) + (c - '0');
  714. break;
  715. }
  716. }
  717. p--;
  718. output[ix++] = sxflags >> 16;
  719. output[ix++] = sxflags >> 8;
  720. c = value | 0x80;
  721. break;
  722. }
  723. }
  724. }
  725. output[ix++] = c;
  726. if(c == 0) break;
  727. }
  728. state = next_state[state];
  729. } // end of copy_rule_string
  730. char *compile_rule(char *input)
  731. {//============================
  732. int ix;
  733. unsigned char c;
  734. int wc;
  735. char *p;
  736. char *prule;
  737. int len;
  738. int len_name;
  739. int state=2;
  740. int finish=0;
  741. int pre_bracket=0;
  742. char buf[80];
  743. char output[150];
  744. unsigned char bad_phoneme[4];
  745. buf[0]=0;
  746. rule_cond[0]=0;
  747. rule_pre[0]=0;
  748. rule_post[0]=0;
  749. rule_match[0]=0;
  750. rule_phonemes[0]=0;
  751. p = buf;
  752. for(ix=0; finish==0; ix++)
  753. {
  754. c = input[ix];
  755. switch(c = input[ix])
  756. {
  757. case ')': // end of prefix section
  758. *p = 0;
  759. state = 1;
  760. pre_bracket = 1;
  761. copy_rule_string(buf,state);
  762. p = buf;
  763. break;
  764. case '(': // start of suffix section
  765. *p = 0;
  766. state = 2;
  767. copy_rule_string(buf,state);
  768. state = 3;
  769. p = buf;
  770. break;
  771. case '\n': // end of line
  772. case '\r':
  773. case 0: // end of line
  774. *p = 0;
  775. copy_rule_string(buf,state);
  776. finish=1;
  777. break;
  778. case '\t': // end of section section
  779. case ' ':
  780. *p = 0;
  781. copy_rule_string(buf,state);
  782. p = buf;
  783. break;
  784. case '?':
  785. if(state==2)
  786. state=0;
  787. else
  788. *p++ = c;
  789. break;
  790. default:
  791. *p++ = c;
  792. break;
  793. }
  794. }
  795. if(strcmp(rule_match,"$group")==0)
  796. strcpy(rule_match,group_name);
  797. if(rule_match[0]==0)
  798. return(NULL);
  799. EncodePhonemes(rule_phonemes,buf,bad_phoneme);
  800. for(ix=0;; ix++)
  801. {
  802. if((c = buf[ix])==0) break;
  803. if(c==255)
  804. {
  805. fprintf(f_log,"%5d: Bad phoneme [%c] in %s",linenum,bad_phoneme[0],input);
  806. error_count++;
  807. break;
  808. }
  809. }
  810. strcpy(output,buf);
  811. len = strlen(buf)+1;
  812. len_name = strlen(group_name);
  813. if((len_name > 0) && (memcmp(rule_match,group_name,len_name) != 0))
  814. {
  815. utf8_in(&wc,rule_match,0);
  816. if((group_name[0] == '9') && IsDigit(wc))
  817. {
  818. // numeric group, rule_match starts with a digit, so OK
  819. }
  820. else
  821. {
  822. fprintf(f_log,"%5d: Wrong initial letters '%s' for group '%s'\n",linenum,rule_match,group_name);
  823. error_count++;
  824. }
  825. }
  826. strcpy(&output[len],rule_match);
  827. len += strlen(rule_match);
  828. if(debug_flag)
  829. {
  830. output[len] = RULE_LINENUM;
  831. output[len+1] = (linenum % 255) + 1;
  832. output[len+2] = (linenum / 255) + 1;
  833. len+=3;
  834. }
  835. if(rule_cond[0] != 0)
  836. {
  837. ix = -1;
  838. if(rule_cond[0] == '!')
  839. {
  840. // allow the rule only if the condition number is NOT set for the voice
  841. ix = atoi(&rule_cond[1]) + 32;
  842. }
  843. else
  844. {
  845. // allow the rule only if the condition number is set for the voice
  846. ix = atoi(rule_cond);
  847. }
  848. if((ix > 0) && (ix < 255))
  849. {
  850. output[len++] = RULE_CONDITION;
  851. output[len++] = ix;
  852. }
  853. else
  854. {
  855. fprintf(f_log,"%5d: bad condition number ?%d\n",linenum,ix);
  856. error_count++;
  857. }
  858. }
  859. if(rule_pre[0] != 0)
  860. {
  861. output[len++] = RULE_PRE;
  862. // output PRE string in reverse order
  863. for(ix = strlen(rule_pre)-1; ix>=0; ix--)
  864. output[len++] = rule_pre[ix];
  865. }
  866. if(rule_post[0] != 0)
  867. {
  868. sprintf(&output[len],"%c%s",RULE_POST,rule_post);
  869. len += (strlen(rule_post)+1);
  870. }
  871. output[len++]=0;
  872. prule = (char *)malloc(len);
  873. memcpy(prule,output,len);
  874. return(prule);
  875. } // end of compile_rule
  876. static int __cdecl string_sorter(char **a, char **b)
  877. {//=================================================
  878. char *pa, *pb;
  879. int ix;
  880. if((ix = strcmp(pa = *a,pb = *b)) != 0)
  881. return(ix);
  882. pa += (strlen(pa)+1);
  883. pb += (strlen(pb)+1);
  884. return(strcmp(pa,pb));
  885. } /* end of string_sorter */
  886. static int __cdecl rgroup_sorter(RGROUP *a, RGROUP *b)
  887. {//===================================================
  888. int ix;
  889. ix = strcmp(a->name,b->name);
  890. if(ix != 0) return(ix);
  891. return(a->start-b->start);
  892. }
  893. #ifdef OUTPUT_FORMAT
  894. void print_rule_group(FILE *f_out, int n_rules, char **rules, char *name)
  895. {//======================================================================
  896. int rule;
  897. int ix;
  898. unsigned char c;
  899. int len1;
  900. int len2;
  901. int spaces;
  902. char *p;
  903. char *pout;
  904. int condition;
  905. char buf[80];
  906. char suffix[12];
  907. static unsigned char symbols[] = {'@','&','%','+','#','$','D','Z','A','B','C','F'};
  908. fprintf(f_out,"\n$group %s\n",name);
  909. for(rule=0; rule<n_rules; rule++)
  910. {
  911. p = rules[rule];
  912. len1 = strlen(p) + 1;
  913. p = &p[len1];
  914. len2 = strlen(p);
  915. rule_match[0]=0;
  916. rule_pre[0]=0;
  917. rule_post[0]=0;
  918. condition = 0;
  919. pout = rule_match;
  920. for(ix=0; ix<len2; ix++)
  921. {
  922. switch(c = p[ix])
  923. {
  924. case RULE_PRE:
  925. *pout = 0;
  926. pout = rule_pre;
  927. break;
  928. case RULE_POST:
  929. *pout = 0;
  930. pout = rule_post;
  931. break;
  932. case RULE_CONDITION:
  933. condition = p[++ix];
  934. break;
  935. case RULE_ENDING:
  936. sprintf(suffix,"$%d[%x]",(p[ix+2]),p[ix+1] & 0x7f);
  937. ix += 2;
  938. strcpy(pout,suffix);
  939. pout += strlen(suffix);
  940. break;
  941. default:
  942. if(c <= RULE_LETTER7)
  943. c = symbols[c-RULE_SYLLABLE];
  944. if(c == ' ')
  945. c = '_';
  946. *pout++ = c;
  947. break;
  948. }
  949. }
  950. *pout = 0;
  951. spaces = 12;
  952. if(condition > 0)
  953. {
  954. sprintf(buf,"?%d ",condition);
  955. spaces -= strlen(buf);
  956. fprintf(f_out,"%s",buf);
  957. }
  958. if(rule_pre[0] != 0)
  959. {
  960. p = buf;
  961. for(ix=strlen(rule_pre)-1;ix>=0;ix--)
  962. *p++ = rule_pre[ix];
  963. sprintf(p,") ");
  964. spaces -= strlen(buf);
  965. for(ix=0; ix<spaces; ix++)
  966. fputc(' ',f_out);
  967. fprintf(f_out,"%s",buf);
  968. spaces = 0;
  969. }
  970. for(ix=0; ix<spaces; ix++)
  971. fputc(' ',f_out);
  972. spaces = 14;
  973. sprintf(buf," %s ",rule_match);
  974. if(rule_post[0] != 0)
  975. {
  976. p = &buf[strlen(buf)];
  977. sprintf(p,"(%s ",rule_post);
  978. }
  979. fprintf(f_out,"%s",buf);
  980. spaces -= strlen(buf);
  981. for(ix=0; ix<spaces; ix++)
  982. fputc(' ',f_out);
  983. DecodePhonemes(rules[rule],buf);
  984. fprintf(f_out,"%s\n",buf); // phonemes
  985. }
  986. }
  987. #endif
  988. //#define LIST_GROUP_INFO
  989. void output_rule_group(FILE *f_out, int n_rules, char **rules, char *name)
  990. {//=======================================================================
  991. int ix;
  992. int len1;
  993. int len2;
  994. int len_name;
  995. char *p;
  996. char *p2, *p3;
  997. const char *common;
  998. short nextchar_count[256];
  999. memset(nextchar_count,0,sizeof(nextchar_count));
  1000. len_name = strlen(name);
  1001. #ifdef OUTPUT_FORMAT
  1002. print_rule_group(f_log,n_rules,rules,name);
  1003. #endif
  1004. // sort the rules in this group by their phoneme string
  1005. common = "";
  1006. qsort((void *)rules,n_rules,sizeof(char *),(int (__cdecl *)(const void *,const void *))string_sorter);
  1007. if(strcmp(name,"9")==0)
  1008. len_name = 0; // don't remove characters from numeric match strings
  1009. for(ix=0; ix<n_rules; ix++)
  1010. {
  1011. p = rules[ix];
  1012. len1 = strlen(p) + 1; // phoneme string
  1013. p3 = &p[len1];
  1014. p2 = p3 + len_name; // remove group name from start of match string
  1015. len2 = strlen(p2);
  1016. nextchar_count[(unsigned char)(p2[0])]++; // the next byte after the group name
  1017. if((common[0] != 0) && (strcmp(p,common)==0))
  1018. {
  1019. fwrite(p2,len2,1,f_out);
  1020. fputc(0,f_out); // no phoneme string, it's the same as previous rule
  1021. }
  1022. else
  1023. {
  1024. if((ix < n_rules-1) && (strcmp(p,rules[ix+1])==0))
  1025. {
  1026. common = rules[ix]; // phoneme string is same as next, set as common
  1027. fputc(RULE_PH_COMMON,f_out);
  1028. }
  1029. fwrite(p2,len2,1,f_out);
  1030. fputc(RULE_PHONEMES,f_out);
  1031. fwrite(p,len1,1,f_out);
  1032. }
  1033. }
  1034. #ifdef LIST_GROUP_INFO
  1035. for(ix=32; ix<256; ix++)
  1036. {
  1037. if(nextchar_count[ix] > 30)
  1038. printf("Group %s %c %d\n",name,ix,nextchar_count[ix]);
  1039. }
  1040. #endif
  1041. } // end of output_rule_group
  1042. static int compile_lettergroup(char *input, FILE *f_out)
  1043. {//=====================================================
  1044. char *p;
  1045. int group;
  1046. p = input;
  1047. if(!isdigit(p[0]) || !isdigit(p[1]))
  1048. {
  1049. return(1);
  1050. }
  1051. group = atoi(&p[1]);
  1052. if(group >= N_LETTER_GROUPS)
  1053. return(1);
  1054. while(!isspace2(*p)) p++;
  1055. fputc(RULE_GROUP_START,f_out);
  1056. fputc(RULE_LETTERGP2,f_out);
  1057. fputc(group + 'A', f_out);
  1058. for(;;)
  1059. {
  1060. while(isspace2(*p)) p++;
  1061. if(*p == 0)
  1062. break;
  1063. while((*p & 0xff) > ' ')
  1064. {
  1065. fputc(*p++, f_out);
  1066. }
  1067. fputc(0,f_out);
  1068. }
  1069. fputc(RULE_GROUP_END,f_out);
  1070. return(0);
  1071. }
  1072. static int compile_dictrules(FILE *f_in, FILE *f_out, char *fname_temp)
  1073. {//====================================================================
  1074. char *prule;
  1075. unsigned char *p;
  1076. int ix;
  1077. int c;
  1078. int gp;
  1079. FILE *f_temp;
  1080. int n_rules=0;
  1081. int count=0;
  1082. int different;
  1083. const char *prev_rgroup_name;
  1084. unsigned int char_code;
  1085. int compile_mode=0;
  1086. char *buf;
  1087. char buf1[200];
  1088. char *rules[N_RULES];
  1089. int n_rgroups = 0;
  1090. RGROUP rgroup[N_RULE_GROUP2];
  1091. linenum = 0;
  1092. group_name[0] = 0;
  1093. if((f_temp = fopen_log(fname_temp,"wb")) == NULL)
  1094. return(1);
  1095. for(;;)
  1096. {
  1097. linenum++;
  1098. buf = fgets(buf1,sizeof(buf1),f_in);
  1099. if(buf != NULL)
  1100. {
  1101. if((p = (unsigned char *)strstr(buf,"//")) != NULL)
  1102. *p = 0;
  1103. if(buf[0] == '\r') buf++; // ignore extra \r in \r\n
  1104. }
  1105. if((buf == NULL) || (buf[0] == '.'))
  1106. {
  1107. // next .group or end of file, write out the previous group
  1108. if(n_rules > 0)
  1109. {
  1110. strcpy(rgroup[n_rgroups].name,group_name);
  1111. rgroup[n_rgroups].start = ftell(f_temp);
  1112. output_rule_group(f_temp,n_rules,rules,group_name);
  1113. rgroup[n_rgroups].length = ftell(f_temp) - rgroup[n_rgroups].start;
  1114. n_rgroups++;
  1115. count += n_rules;
  1116. }
  1117. n_rules = 0;
  1118. if(compile_mode == 2)
  1119. {
  1120. // end of the character replacements section
  1121. fwrite(&n_rules,1,4,f_out); // write a zero word to terminate the replacemenmt list
  1122. compile_mode = 0;
  1123. }
  1124. if(buf == NULL) break; // end of file
  1125. if(memcmp(buf,".L",2)==0)
  1126. {
  1127. if(compile_lettergroup(&buf[2], f_out) != 0)
  1128. {
  1129. fprintf(f_log,"%5d: Bad lettergroup\n",linenum);
  1130. error_count++;
  1131. }
  1132. continue;
  1133. }
  1134. if(memcmp(buf,".replace",8)==0)
  1135. {
  1136. compile_mode = 2;
  1137. fputc(RULE_GROUP_START,f_out);
  1138. fputc(RULE_REPLACEMENTS,f_out);
  1139. // advance to next word boundary
  1140. while((ftell(f_out) & 3) != 0)
  1141. fputc(0,f_out);
  1142. }
  1143. if(memcmp(buf,".group",6)==0)
  1144. {
  1145. compile_mode = 1;
  1146. p = (unsigned char *)&buf[6];
  1147. while((p[0]==' ') || (p[0]=='\t')) p++; // Note: Windows isspace(0xe1) gives TRUE !
  1148. ix = 0;
  1149. while((*p > ' ') && (ix<12))
  1150. group_name[ix++] = *p++;
  1151. group_name[ix]=0;
  1152. if(sscanf(group_name,"0x%x",&char_code)==1)
  1153. {
  1154. // group character is given as a character code (max 16 bits)
  1155. p = (unsigned char *)group_name;
  1156. if(char_code > 0x100)
  1157. {
  1158. *p++ = (char_code >> 8);
  1159. }
  1160. *p++ = char_code;
  1161. *p = 0;
  1162. }
  1163. if(strlen(group_name) > 2)
  1164. {
  1165. if(utf8_in(&c,group_name,0) < 2)
  1166. {
  1167. fprintf(f_log,"%5d: Group name longer than 2 bytes (UTF8)",linenum);
  1168. error_count++;
  1169. }
  1170. group_name[2] = 0;
  1171. }
  1172. }
  1173. continue;
  1174. }
  1175. switch(compile_mode)
  1176. {
  1177. case 1: // .group
  1178. prule = compile_rule(buf);
  1179. if((prule != NULL) && (n_rules < N_RULES))
  1180. {
  1181. rules[n_rules++] = prule;
  1182. }
  1183. break;
  1184. case 2: // .replace
  1185. {
  1186. int replace1;
  1187. int replace2;
  1188. char *p;
  1189. p = buf;
  1190. replace1 = 0;
  1191. replace2 = 0;
  1192. while(isspace2(*p)) p++;
  1193. ix = 0;
  1194. while((unsigned char)(*p) > 0x20) // not space or zero-byte
  1195. {
  1196. p += utf8_in(&c,p,0);
  1197. replace1 += (c << ix);
  1198. ix += 16;
  1199. }
  1200. while(isspace2(*p)) p++;
  1201. ix = 0;
  1202. while((unsigned char)(*p) > 0x20)
  1203. {
  1204. p += utf8_in(&c,p,0);
  1205. replace2 += (c << ix);
  1206. ix += 16;
  1207. }
  1208. if(replace1 != 0)
  1209. {
  1210. Write4Bytes(f_out,replace1); // write as little-endian
  1211. Write4Bytes(f_out,replace2); // if big-endian, reverse the bytes in LoadDictionary()
  1212. }
  1213. }
  1214. break;
  1215. }
  1216. }
  1217. fclose(f_temp);
  1218. qsort((void *)rgroup,n_rgroups,sizeof(rgroup[0]),(int (__cdecl *)(const void *,const void *))rgroup_sorter);
  1219. if((f_temp = fopen(fname_temp,"rb"))==NULL)
  1220. return(2);
  1221. prev_rgroup_name = "\n";
  1222. for(gp = 0; gp < n_rgroups; gp++)
  1223. {
  1224. fseek(f_temp,rgroup[gp].start,SEEK_SET);
  1225. if((different = strcmp(rgroup[gp].name, prev_rgroup_name)) != 0)
  1226. {
  1227. // not the same as the previous group
  1228. if(gp > 0)
  1229. fputc(RULE_GROUP_END,f_out);
  1230. fputc(RULE_GROUP_START,f_out);
  1231. fprintf(f_out, prev_rgroup_name = rgroup[gp].name);
  1232. fputc(0,f_out);
  1233. }
  1234. for(ix=rgroup[gp].length; ix>0; ix--)
  1235. {
  1236. c = fgetc(f_temp);
  1237. fputc(c,f_out);
  1238. }
  1239. if(different)
  1240. {
  1241. }
  1242. }
  1243. fputc(RULE_GROUP_END,f_out);
  1244. fputc(0,f_out);
  1245. fclose(f_temp);
  1246. remove(fname_temp);
  1247. fprintf(f_log,"\t%d rules, %d groups\n\n",count,n_rgroups);
  1248. return(0);
  1249. } // end of compile_dictrules
  1250. int CompileDictionary(const char *dsource, const char *dict_name, FILE *log, char *fname_err, int flags)
  1251. {//=====================================================================================================
  1252. // fname: space to write the filename in case of error
  1253. // flags: bit 0: include source line number information, for debug purposes.
  1254. FILE *f_in;
  1255. FILE *f_out;
  1256. int offset_rules=0;
  1257. int value;
  1258. char fname_in[sizeof(path_home)+45];
  1259. char fname_out[sizeof(path_home)+15];
  1260. char fname_temp[sizeof(path_home)+15];
  1261. char path[sizeof(path_home)+40]; // path_dsource+20
  1262. error_count = 0;
  1263. debug_flag = flags & 1;
  1264. if(dsource == NULL)
  1265. dsource = "";
  1266. f_log = log;
  1267. //f_log = fopen("log2.txt","w");
  1268. if(f_log == NULL)
  1269. f_log = stderr;
  1270. sprintf(path,"%s%s_",dsource,dict_name);
  1271. sprintf(fname_in,"%srules",path);
  1272. f_in = fopen_log(fname_in,"r");
  1273. if(f_in == NULL)
  1274. {
  1275. if(fname_err)
  1276. strcpy(fname_err,fname_in);
  1277. return(-1);
  1278. }
  1279. sprintf(fname_out,"%s%c%s_dict",path_home,PATHSEP,dict_name);
  1280. if((f_out = fopen_log(fname_out,"wb+")) == NULL)
  1281. {
  1282. if(fname_err)
  1283. strcpy(fname_err,fname_in);
  1284. return(-1);
  1285. }
  1286. sprintf(fname_temp,"%s%ctemp",path_home,PATHSEP);
  1287. transpose_offset = 0;
  1288. if(strcmp(dict_name,"ru") == 0)
  1289. {
  1290. // transpose cyrillic alphabet from unicode to iso8859-5
  1291. // transpose_offset = 0x430-0xd0;
  1292. transpose_offset = 0x42f; // range 0x01 to 0x22
  1293. transpose_min = 0x430;
  1294. transpose_max = 0x451;
  1295. }
  1296. value = N_HASH_DICT;
  1297. fwrite(&value,4,1,f_out);
  1298. fwrite(&offset_rules,4,1,f_out);
  1299. compile_dictlist_start();
  1300. fprintf(f_log,"Using phonemetable: '%s'\n",PhonemeTabName());
  1301. compile_dictlist_file(path,"roots");
  1302. compile_dictlist_file(path,"list");
  1303. compile_dictlist_file(path,"listx");
  1304. compile_dictlist_file(path,"extra");
  1305. compile_dictlist_end(f_out);
  1306. offset_rules = ftell(f_out);
  1307. fprintf(f_log,"Compiling: '%s'\n",fname_in);
  1308. compile_dictrules(f_in,f_out,fname_temp);
  1309. fclose(f_in);
  1310. fseek(f_out,4,SEEK_SET);
  1311. fwrite(&offset_rules,4,1,f_out);
  1312. fclose(f_out);
  1313. translator->LoadDictionary(dict_name,0);
  1314. return(error_count);
  1315. } // end of compile_dictionary