Browse Source

Use the error context API in the compile_dictrules helper function.

master
Reece H. Dunn 9 years ago
parent
commit
3f80fd712e
1 changed files with 10 additions and 18 deletions
  1. 10
    18
      src/libespeak-ng/compiledict.c

+ 10
- 18
src/libespeak-ng/compiledict.c View File

#include "espeak_ng.h" #include "espeak_ng.h"
#include "speak_lib.h" #include "speak_lib.h"


#include "error.h"
#include "speech.h" #include "speech.h"
#include "phoneme.h" #include "phoneme.h"
#include "synthesize.h" #include "synthesize.h"
return 1; return 1;
} }


static FILE *fopen_log(const char *fname, const char *access)
{
// performs fopen, but produces error message to f_log if it fails
FILE *f;

if ((f = fopen(fname, access)) == NULL) {
if (f_log != NULL)
fprintf(f_log, "Can't access (%s) file '%s'\n", access, fname);
}
return f;
}

// Lookup a mnemonic string in a table, return its name // Lookup a mnemonic string in a table, return its name
const char *LookupMnemName(MNEM_TAB *table, const int value) const char *LookupMnemName(MNEM_TAB *table, const int value)
{ {
return 0; return 0;
} }


static int compile_dictrules(FILE *f_in, FILE *f_out, char *fname_temp)
static espeak_ng_STATUS compile_dictrules(FILE *f_in, FILE *f_out, char *fname_temp, espeak_ng_ERROR_CONTEXT *context)
{ {
char *prule; char *prule;
unsigned char *p; unsigned char *p;
linenum = 0; linenum = 0;
group_name[0] = 0; group_name[0] = 0;


if ((f_temp = fopen_log(fname_temp, "wb")) == NULL)
return 1;
if ((f_temp = fopen(fname_temp, "wb")) == NULL)
return create_file_error_context(context, errno, fname_temp);


for (;;) { for (;;) {
linenum++; linenum++;
qsort((void *)rgroup, n_rgroups, sizeof(rgroup[0]), (int(__cdecl *)(const void *, const void *))rgroup_sorter); qsort((void *)rgroup, n_rgroups, sizeof(rgroup[0]), (int(__cdecl *)(const void *, const void *))rgroup_sorter);


if ((f_temp = fopen(fname_temp, "rb")) == NULL) if ((f_temp = fopen(fname_temp, "rb")) == NULL)
return 2;
return create_file_error_context(context, errno, fname_temp);


prev_rgroup_name = "\n"; prev_rgroup_name = "\n";


remove(fname_temp); remove(fname_temp);


fprintf(f_log, "\t%d rules, %d groups (%d)\n\n", count, n_rgroups, n_groups3); fprintf(f_log, "\t%d rules, %d groups (%d)\n\n", count, n_rgroups, n_groups3);
return 0;
return ENS_OK;
} }


#pragma GCC visibility push(default) #pragma GCC visibility push(default)


fprintf(f_log, "Compiling: '%s'\n", fname_in); fprintf(f_log, "Compiling: '%s'\n", fname_in);


compile_dictrules(f_in, f_out, fname_temp);
espeak_ng_STATUS status = compile_dictrules(f_in, f_out, fname_temp, context);
fclose(f_in); fclose(f_in);


fseek(f_out, 4, SEEK_SET); fseek(f_out, 4, SEEK_SET);
fclose(f_out); fclose(f_out);
fflush(f_log); fflush(f_log);


if (status != ENS_OK)
return status;

LoadDictionary(translator, dict_name, 0); LoadDictionary(translator, dict_name, 0);


return error_count > 0 ? ENS_COMPILE_ERROR : ENS_OK; return error_count > 0 ? ENS_COMPILE_ERROR : ENS_OK;

Loading…
Cancel
Save