diff --git a/src/espeak-ng.c b/src/espeak-ng.c index db5d1043..ef27493a 100644 --- a/src/espeak-ng.c +++ b/src/espeak-ng.c @@ -598,8 +598,17 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } case 0x110: // --compile-phonemes + { espeak_ng_InitializePath(data_path); - return (espeak_ng_CompilePhonemeData(22050, stdout) == ENS_OK) ? EXIT_SUCCESS : EXIT_FAILURE; + espeak_ng_ERROR_CONTEXT context = NULL; + espeak_ng_STATUS result = espeak_ng_CompilePhonemeData(22050, stdout, &context); + if (result != ENS_OK) { + espeak_ng_PrintStatusCodeMessage(result, stderr, context); + espeak_ng_ClearErrorContext(&context); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; + } default: exit(0); } diff --git a/src/include/espeak-ng/espeak_ng.h b/src/include/espeak-ng/espeak_ng.h index fd20ee6c..e270fcb2 100644 --- a/src/include/espeak-ng/espeak_ng.h +++ b/src/include/espeak-ng/espeak_ng.h @@ -148,7 +148,8 @@ espeak_ng_CompileMbrolaVoice(const char *path, ESPEAK_NG_API espeak_ng_STATUS espeak_ng_CompilePhonemeData(long rate, - FILE *log); + FILE *log, + espeak_ng_ERROR_CONTEXT *context); ESPEAK_NG_API espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log, diff --git a/src/libespeak-ng/compiledata.c b/src/libespeak-ng/compiledata.c index 8cb519f4..cbec5ce3 100644 --- a/src/libespeak-ng/compiledata.c +++ b/src/libespeak-ng/compiledata.c @@ -2635,7 +2635,7 @@ static void CompilePhonemeFiles() phoneme_tab2[n_phcodes+1].mnemonic = 0; // terminator } -static espeak_ng_STATUS CompilePhonemeData2(const char *source, FILE *log) +static espeak_ng_STATUS CompilePhonemeData2(const char *source, FILE *log, espeak_ng_ERROR_CONTEXT *context) { char fname[sizeof(path_home)+40]; sprintf(fname, "%s/../phsource", path_home); @@ -2648,19 +2648,15 @@ static espeak_ng_STATUS CompilePhonemeData2(const char *source, FILE *log) f_errors = log; - if (!access(fname, 755)) { - fprintf(log, "Can't find phoneme source directory: %s\n", fname); - return errno; - } + if (!access(fname, 755)) + return create_file_error_context(context, errno, fname); strncpy0(current_fname, source, sizeof(current_fname)); sprintf(fname, "%s/../phsource/phonemes", path_home); - f_in = fopen_log(f_errors, fname, "rb"); - if (f_in == NULL) { - fprintf(log, "Can't read master phonemes file: %s\n", fname); - return errno; - } + f_in = fopen(fname, "rb"); + if (f_in == NULL) + return create_file_error_context(context, errno, fname); sprintf(fname, "%s/../phsource/%s", path_home, "compile_report"); f_report = fopen_log(f_errors, fname, "w"); @@ -2686,16 +2682,31 @@ static espeak_ng_STATUS CompilePhonemeData2(const char *source, FILE *log) "# ------- ---------\n"); sprintf(fname, "%s/%s", path_home, "phondata"); - f_phdata = fopen_log(f_errors, fname, "wb"); + f_phdata = fopen(fname, "wb"); + if (f_phdata == NULL) { + int error = errno; + fclose(f_in); + return create_file_error_context(context, errno, fname); + } sprintf(fname, "%s/%s", path_home, "phonindex"); - f_phindex = fopen_log(f_errors, fname, "wb"); + f_phindex = fopen(fname, "wb"); + if (f_phindex == NULL) { + int error = errno; + fclose(f_in); + fclose(f_phdata); + return create_file_error_context(context, errno, fname); + } sprintf(fname, "%s/%s", path_home, "phontab"); - f_phtab = fopen_log(f_errors, fname, "wb"); - - if (f_phdata == NULL || f_phindex == NULL || f_phtab == NULL) - return errno; + f_phtab = fopen(fname, "wb"); + if (f_phtab == NULL) { + int error = errno; + fclose(f_in); + fclose(f_phdata); + fclose(f_phindex); + return create_file_error_context(context, errno, fname); + } sprintf(fname, "%s/../phsource/compile_prog_log", path_home); f_prog_log = fopen_log(f_errors, fname, "wb"); @@ -3033,12 +3044,12 @@ espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log, espeak_ng_ERROR_CONTEXT return error_count > 0 ? ENS_COMPILE_ERROR : ENS_OK; } -espeak_ng_STATUS espeak_ng_CompilePhonemeData(long rate, FILE *log) +espeak_ng_STATUS espeak_ng_CompilePhonemeData(long rate, FILE *log, espeak_ng_ERROR_CONTEXT *context) { if (!log) log = stderr; WavegenInit(rate, 0); WavegenSetVoice(voice); - return CompilePhonemeData2("phonemes", log); + return CompilePhonemeData2("phonemes", log, context); } #pragma GCC visibility pop diff --git a/src/speak-ng.c b/src/speak-ng.c index a5a9ea00..c717f562 100644 --- a/src/speak-ng.c +++ b/src/speak-ng.c @@ -585,8 +585,17 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } case 0x110: // --compile-phonemes + { espeak_ng_InitializePath(data_path); - return (espeak_ng_CompilePhonemeData(22050, stdout) == ENS_OK) ? EXIT_SUCCESS : EXIT_FAILURE; + espeak_ng_ERROR_CONTEXT context = NULL; + espeak_ng_STATUS result = espeak_ng_CompilePhonemeData(22050, stdout, &context); + if (result != ENS_OK) { + espeak_ng_PrintStatusCodeMessage(result, stderr, context); + espeak_ng_ClearErrorContext(&context); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; + } default: exit(0); }