From 57eb9628d62a9e74acf57a03ddda1ef4475cdcaf Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Mon, 4 Jan 2016 13:28:38 +0000 Subject: [PATCH] Use the error context API in espeak_ng_CompileIntonation. --- src/espeak-ng.c | 11 ++++++++++- src/include/espeak-ng/espeak_ng.h | 3 ++- src/libespeak-ng/compiledata.c | 13 ++++++------- src/speak-ng.c | 11 ++++++++++- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/espeak-ng.c b/src/espeak-ng.c index 8a522792..db5d1043 100644 --- a/src/espeak-ng.c +++ b/src/espeak-ng.c @@ -586,8 +586,17 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } case 0x10f: // --compile-intonations + { espeak_ng_InitializePath(data_path); - return (espeak_ng_CompileIntonation(stdout) == ENS_OK) ? EXIT_SUCCESS : EXIT_FAILURE; + espeak_ng_ERROR_CONTEXT context = NULL; + espeak_ng_STATUS result = espeak_ng_CompileIntonation(stdout, &context); + if (result != ENS_OK) { + espeak_ng_PrintStatusCodeMessage(result, stderr, context); + espeak_ng_ClearErrorContext(&context); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; + } case 0x110: // --compile-phonemes espeak_ng_InitializePath(data_path); return (espeak_ng_CompilePhonemeData(22050, stdout) == ENS_OK) ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/src/include/espeak-ng/espeak_ng.h b/src/include/espeak-ng/espeak_ng.h index 2fc0a86a..fd20ee6c 100644 --- a/src/include/espeak-ng/espeak_ng.h +++ b/src/include/espeak-ng/espeak_ng.h @@ -151,7 +151,8 @@ espeak_ng_CompilePhonemeData(long rate, FILE *log); ESPEAK_NG_API espeak_ng_STATUS -espeak_ng_CompileIntonation(FILE *log); +espeak_ng_CompileIntonation(FILE *log, + espeak_ng_ERROR_CONTEXT *context); #ifdef __cplusplus } diff --git a/src/libespeak-ng/compiledata.c b/src/libespeak-ng/compiledata.c index 828df277..8cb519f4 100644 --- a/src/libespeak-ng/compiledata.c +++ b/src/libespeak-ng/compiledata.c @@ -33,6 +33,7 @@ #include "speak_lib.h" #include "espeak_ng.h" +#include "error.h" #include "speech.h" #include "phoneme.h" #include "synthesize.h" @@ -2783,7 +2784,7 @@ int LookupEnvelopeName(const char *name) #pragma GCC visibility push(default) -espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) +espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log, espeak_ng_ERROR_CONTEXT *context) { if (!log) log = stderr; @@ -2812,11 +2813,10 @@ espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) sprintf(buf, "%s/../phsource/intonation.txt", path_home); if ((f_in = fopen(buf, "r")) == NULL) { sprintf(buf, "%s/../phsource/intonation", path_home); - if ((f_in = fopen_log(f_errors, buf, "r")) == NULL) { + if ((f_in = fopen(buf, "r")) == NULL) { int error = errno; - fprintf(log, "Can't read file: %s\n", buf); fclose(f_errors); - return error; + return create_file_error_context(context, error, buf); } } @@ -2860,20 +2860,19 @@ espeak_ng_STATUS espeak_ng_CompileIntonation(FILE *log) tune_data = (TUNE *)calloc(sizeof(TUNE), n_tune_names); if (tune_data == NULL) { - fprintf(f_errors, "Failed to allocate data for tunes\n"); fclose(f_in); fclose(f_errors); return ENOMEM; } sprintf(buf, "%s/intonations", path_home); - f_out = fopen_log(f_errors, buf, "wb"); + f_out = fopen(buf, "wb"); if (f_out == NULL) { int error = errno; fclose(f_in); fclose(f_errors); free(tune_data); - return error; + return create_file_error_context(context, error, buf); } while (!feof(f_in)) { diff --git a/src/speak-ng.c b/src/speak-ng.c index 0b4a5aa0..a5a9ea00 100644 --- a/src/speak-ng.c +++ b/src/speak-ng.c @@ -573,8 +573,17 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } case 0x10f: // --compile-intonations + { espeak_ng_InitializePath(data_path); - return (espeak_ng_CompileIntonation(stdout) == ENS_OK) ? EXIT_SUCCESS : EXIT_FAILURE; + espeak_ng_ERROR_CONTEXT context = NULL; + espeak_ng_STATUS result = espeak_ng_CompileIntonation(stdout, &context); + if (result != ENS_OK) { + espeak_ng_PrintStatusCodeMessage(result, stderr, context); + espeak_ng_ClearErrorContext(&context); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; + } case 0x110: // --compile-phonemes espeak_ng_InitializePath(data_path); return (espeak_ng_CompilePhonemeData(22050, stdout) == ENS_OK) ? EXIT_SUCCESS : EXIT_FAILURE;