| int length; | int length; | ||||
| char *p; | char *p; | ||||
| if (f_log != NULL) { | |||||
| #ifdef OUTPUT_FORMAT | |||||
| for (hash = 0; hash < N_HASH_DICT; hash++) { | |||||
| fprintf(f_log, "%8d", hash_counts[hash]); | |||||
| if ((hash & 7) == 7) | |||||
| fputc('\n', f_log); | |||||
| } | |||||
| fflush(f_log); | |||||
| #endif | |||||
| } | |||||
| for (hash = 0; hash < N_HASH_DICT; hash++) { | for (hash = 0; hash < N_HASH_DICT; hash++) { | ||||
| p = hash_chains[hash]; | p = hash_chains[hash]; | ||||
| hash_counts[hash] = (int)ftell(f_out); | hash_counts[hash] = (int)ftell(f_out); | ||||
| return a->start-b->start; | return a->start-b->start; | ||||
| } | } | ||||
| #ifdef OUTPUT_FORMAT | |||||
| static void print_rule_group(FILE *f_out, int n_rules, char **rules, char *name) | |||||
| { | |||||
| int rule; | |||||
| int ix; | |||||
| unsigned char c; | |||||
| int len1; | |||||
| int len2; | |||||
| int spaces; | |||||
| char *p; | |||||
| char *pout; | |||||
| int condition; | |||||
| char buf[80]; | |||||
| char suffix[12]; | |||||
| static unsigned char symbols[] = { '@', '&', '%', '+', '#', '$', 'D', 'Z', 'A', 'B', 'C', 'F' }; | |||||
| fprintf(f_out, "\n$group %s\n", name); | |||||
| for (rule = 0; rule < n_rules; rule++) { | |||||
| p = rules[rule]; | |||||
| len1 = strlen(p) + 1; | |||||
| p = &p[len1]; | |||||
| len2 = strlen(p); | |||||
| rule_match[0] = 0; | |||||
| rule_pre[0] = 0; | |||||
| rule_post[0] = 0; | |||||
| condition = 0; | |||||
| pout = rule_match; | |||||
| for (ix = 0; ix < len2; ix++) { | |||||
| switch (c = p[ix]) | |||||
| { | |||||
| case RULE_PRE: | |||||
| *pout = 0; | |||||
| pout = rule_pre; | |||||
| break; | |||||
| case RULE_POST: | |||||
| *pout = 0; | |||||
| pout = rule_post; | |||||
| break; | |||||
| case RULE_CONDITION: | |||||
| condition = p[++ix]; | |||||
| break; | |||||
| case RULE_ENDING: | |||||
| sprintf(suffix, "$%d[%x]", (p[ix+2]), p[ix+1] & 0x7f); | |||||
| ix += 2; | |||||
| strcpy(pout, suffix); | |||||
| pout += strlen(suffix); | |||||
| break; | |||||
| default: | |||||
| if (c <= RULE_LETTER7) | |||||
| c = symbols[c-RULE_SYLLABLE]; | |||||
| if (c == ' ') | |||||
| c = '_'; | |||||
| *pout++ = c; | |||||
| break; | |||||
| } | |||||
| } | |||||
| *pout = 0; | |||||
| spaces = 12; | |||||
| if (condition > 0) { | |||||
| sprintf(buf, "?%d ", condition); | |||||
| spaces -= strlen(buf); | |||||
| fprintf(f_out, "%s", buf); | |||||
| } | |||||
| if (rule_pre[0] != 0) { | |||||
| p = buf; | |||||
| for (ix = strlen(rule_pre)-1; ix >= 0; ix--) | |||||
| *p++ = rule_pre[ix]; | |||||
| sprintf(p, ") "); | |||||
| spaces -= strlen(buf); | |||||
| for (ix = 0; ix < spaces; ix++) | |||||
| fputc(' ', f_out); | |||||
| fprintf(f_out, "%s", buf); | |||||
| spaces = 0; | |||||
| } | |||||
| for (ix = 0; ix < spaces; ix++) | |||||
| fputc(' ', f_out); | |||||
| spaces = 14; | |||||
| sprintf(buf, " %s ", rule_match); | |||||
| if (rule_post[0] != 0) { | |||||
| p = &buf[strlen(buf)]; | |||||
| sprintf(p, "(%s ", rule_post); | |||||
| } | |||||
| fprintf(f_out, "%s", buf); | |||||
| spaces -= strlen(buf); | |||||
| for (ix = 0; ix < spaces; ix++) | |||||
| fputc(' ', f_out); | |||||
| DecodePhonemes(rules[rule], buf); | |||||
| fprintf(f_out, "%s\n", buf); // phonemes | |||||
| } | |||||
| } | |||||
| #endif | |||||
| static void output_rule_group(FILE *f_out, int n_rules, char **rules, char *name) | static void output_rule_group(FILE *f_out, int n_rules, char **rules, char *name) | ||||
| { | { | ||||
| int ix; | int ix; | ||||
| len_name = strlen(name); | len_name = strlen(name); | ||||
| #ifdef OUTPUT_FORMAT | |||||
| print_rule_group(f_log, n_rules, rules, name); | |||||
| #endif | |||||
| // sort the rules in this group by their phoneme string | // sort the rules in this group by their phoneme string | ||||
| common = ""; | common = ""; | ||||
| qsort((void *)rules, n_rules, sizeof(char *), (int(__cdecl *)(const void *, const void *))string_sorter); | qsort((void *)rules, n_rules, sizeof(char *), (int(__cdecl *)(const void *, const void *))string_sorter); | ||||
| fwrite(p, len1, 1, f_out); | fwrite(p, len1, 1, f_out); | ||||
| } | } | ||||
| } | } | ||||
| #ifdef LIST_GROUP_INFO | |||||
| for (ix = 32; ix < 256; ix++) { | |||||
| if (nextchar_count[ix] > 30) | |||||
| printf("Group %s %c %d\n", name, ix, nextchar_count[ix]); | |||||
| } | |||||
| #endif | |||||
| } | } | ||||
| static int compile_lettergroup(char *input, FILE *f_out) | static int compile_lettergroup(char *input, FILE *f_out) |