Browse Source

Use an enum and named values for the steps in compile_line to make the logic easier to read.

master
Reece H. Dunn 8 years ago
parent
commit
94376c2d5f
1 changed files with 27 additions and 17 deletions
  1. 27
    17
      src/libespeak-ng/compiledict.c

+ 27
- 17
src/libespeak-ng/compiledict.c View File

return output; return output;
} }


typedef enum
{
LINE_PARSER_WORD = 0,
LINE_PARSER_END_OF_WORD = 1,
LINE_PARSER_MULTIPLE_WORDS = 2,
LINE_PARSER_END_OF_WORDS = 3,
LINE_PARSER_PRONUNCIATION = 4,
LINE_PARSER_END = 5,
} LINE_PARSER_STATES;

static int compile_line(char *linebuf, char *dict_line, int *hash) static int compile_line(char *linebuf, char *dict_line, int *hash)
{ {
// Compile a line in the language_list file // Compile a line in the language_list file
char *word; char *word;
char *phonetic; char *phonetic;
unsigned int ix; unsigned int ix;
int step;
LINE_PARSER_STATES step;
unsigned int n_flag_codes = 0; unsigned int n_flag_codes = 0;
int flagnum; int flagnum;
int flag_offset; int flag_offset;


p = linebuf; p = linebuf;


step = 0;
step = LINE_PARSER_WORD;


c = 0; c = 0;
while (c != '\n') { while (c != '\n') {


switch (step) switch (step)
{ {
case 0:
case LINE_PARSER_WORD:
if (c == '(') { if (c == '(') {
multiple_words = 1; multiple_words = 1;
word = p+1; word = p+1;
step = 1;
step = LINE_PARSER_END_OF_WORD;
} else if (!isspace2(c)) { } else if (!isspace2(c)) {
word = p; word = p;
step = 1;
step = LINE_PARSER_END_OF_WORD;
} }
break; break;
case 1:
case LINE_PARSER_END_OF_WORD:
if ((c == '-') && multiple_words) { if ((c == '-') && multiple_words) {
if (IsDigit09(word[0])) if (IsDigit09(word[0]))
multiple_numeric_hyphen = 1; multiple_numeric_hyphen = 1;


if (multiple_words) { if (multiple_words) {
multiple_string = multiple_string_end = p+1; multiple_string = multiple_string_end = p+1;
step = 2;
step = LINE_PARSER_MULTIPLE_WORDS;
} else } else
step = 3;
step = LINE_PARSER_END_OF_WORDS;
} else if (c == ')') { } else if (c == ')') {
if (multiple_words) { if (multiple_words) {
p[0] = 0; p[0] = 0;
multiple_words = 0; multiple_words = 0;
step = 3;
step = LINE_PARSER_END_OF_WORDS;
} else if (word[0] != '_') { } else if (word[0] != '_') {
fprintf(f_log, "%5d: Missing '('\n", linenum); fprintf(f_log, "%5d: Missing '('\n", linenum);
error_count++; error_count++;
step = 3;
step = LINE_PARSER_END_OF_WORDS;
} }
} }
break; break;
case 2:
case LINE_PARSER_MULTIPLE_WORDS:
if (isspace2(c)) if (isspace2(c))
multiple_words++; multiple_words++;
else if (c == ')') { else if (c == ')') {
p[0] = ' '; // terminate extra string p[0] = ' '; // terminate extra string
multiple_string_end = p+1; multiple_string_end = p+1;
step = 3;
step = LINE_PARSER_END_OF_WORDS;
} }
break; break;
case 3:
case LINE_PARSER_END_OF_WORDS:
if (!isspace2(c)) { if (!isspace2(c)) {
phonetic = p; phonetic = p;
step = 4;
step = LINE_PARSER_PRONUNCIATION;
} }
break; break;
case 4:
case LINE_PARSER_PRONUNCIATION:
if (isspace2(c)) { if (isspace2(c)) {
p[0] = 0; // terminate phonetic p[0] = 0; // terminate phonetic
step = 5;
step = LINE_PARSER_END;
} }
break; break;
case 5:
case LINE_PARSER_END:
break; break;
} }
p++; p++;

Loading…
Cancel
Save