From bd608a845118871f0bb8175e0d364414c3039062 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sat, 12 Dec 2015 18:44:18 +0000 Subject: [PATCH] CompileIntonation: pass the file to log errors to as a parameter --- src/compiledata.cpp | 22 ++++++++-------------- src/espeakedit.cpp | 19 ++++++++++++++++--- src/include/espeak-ng/espeak_ng.h | 6 ++++-- src/libespeak-ng/compilembrola.c | 4 ++-- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/compiledata.cpp b/src/compiledata.cpp index 4fe92087..1c9b436f 100644 --- a/src/compiledata.cpp +++ b/src/compiledata.cpp @@ -32,6 +32,8 @@ #include "wx/progdlg.h" #include "speak_lib.h" +#include "espeak_ng.h" + #include "speech.h" #include "phoneme.h" #include "synthesize.h" @@ -58,7 +60,6 @@ extern int gui_flag; extern char voice_name2[40]; extern void FindPhonemesUsed(void); -extern void DisplayErrorFile(const char *fname); extern "C" int utf8_in(int *c, const char *buf); extern "C" int utf8_out(unsigned int c, char *buf); extern void DrawEnvelopes(); @@ -3778,7 +3779,7 @@ int LookupEnvelope(const char *name) } -void CompileIntonation() +espeak_ng_STATUS CompileIntonation(FILE *log) {//===================== int ix; char *p; @@ -3799,15 +3800,11 @@ void CompileIntonation() char name[12]; - char fname_errors[sizeof(path_source)+120]; char tune_names[N_TUNE_NAMES][12]; char buf[sizeof(path_source)+120]; error_count = 0; - - sprintf(fname_errors,"%s%s",path_source,"error_intonation"); - if((f_errors = fopen(fname_errors,"w")) == NULL) - f_errors = stderr; + f_errors = log; sprintf(buf,"%sintonation.txt",path_source); if((f_in = fopen(buf, "r")) == NULL) @@ -3817,7 +3814,7 @@ void CompileIntonation() { wxLogError(_T("Can't read file: ") + wxString(buf,wxConvLocal)); fclose(f_errors); - return; + return ENE_READ_ERROR; } } @@ -3875,7 +3872,7 @@ void CompileIntonation() fprintf(f_errors, "Failed to allocate data for tunes\n"); fclose(f_in); fclose(f_errors); - return; + return ENE_OUT_OF_MEMORY; } sprintf(buf,"%s/intonations",path_home); @@ -3885,7 +3882,7 @@ void CompileIntonation() fclose(f_in); fclose(f_errors); free(tune_data); - return; + return ENE_WRITE_ERROR; } while(!feof(f_in)) @@ -4078,12 +4075,9 @@ void CompileIntonation() report.Printf(_T("Compiled %d intonation tunes: %d errors."),n_tune_names, error_count); wxLogStatus(report); - if(error_count > 0) - { - DisplayErrorFile(fname_errors); - } LoadPhData(NULL); + return error_count > 0 ? ENE_COMPILE_ERRORS : ENS_OK; } // end of CompileIntonation diff --git a/src/espeakedit.cpp b/src/espeakedit.cpp index 11085472..cd5f3a59 100644 --- a/src/espeakedit.cpp +++ b/src/espeakedit.cpp @@ -65,7 +65,7 @@ extern void DictionarySort(const char *dictname); extern void init_z(); extern void CompilePhonemeData(void); extern void CompileSampleRate(void); -extern void CompileIntonation(); +extern espeak_ng_STATUS CompileIntonation(FILE *log); extern void InitSpectrumDisplay(); extern void InitProsodyDisplay(); extern void InitWaveDisplay(); @@ -147,7 +147,7 @@ if(argc > 1) exit(1); } CompilePhonemeData(); - CompileIntonation(); + CompileIntonation(stderr); } exit(0); } @@ -787,7 +787,20 @@ void MyFrame::OnTools(wxCommandEvent& event) break; case MENU_COMPILE_INTONATION: - CompileIntonation(); + { + FILE *f_errors; + char fname_errors[sizeof(path_source)+120]; + sprintf(fname_errors,"%s%s",path_source,"error_intonation"); + if((f_errors = fopen(fname_errors,"w")) == NULL) + f_errors = stderr; + + espeak_ng_STATUS status = CompileIntonation(f_errors); + if (f_errors != stderr) + fclose(f_errors); + + if (status == ENE_COMPILE_ERRORS) + DisplayErrorFile(fname_errors); + } break; case MENU_COMPILE_DICT_DEBUG: diff --git a/src/include/espeak-ng/espeak_ng.h b/src/include/espeak-ng/espeak_ng.h index fe5744bf..9b54eaa4 100644 --- a/src/include/espeak-ng/espeak_ng.h +++ b/src/include/espeak-ng/espeak_ng.h @@ -39,8 +39,10 @@ typedef enum { /* Error Codes (< 0) */ - ENE_NOT_FOUND = -1, - ENE_WRITE_FAILED = -2, + ENE_READ_ERROR = -1, + ENE_WRITE_ERROR = -2, + ENE_OUT_OF_MEMORY = -3, + ENE_COMPILE_ERRORS = -4, } espeak_ng_STATUS; ESPEAK_NG_API espeak_ng_STATUS diff --git a/src/libespeak-ng/compilembrola.c b/src/libespeak-ng/compilembrola.c index 824f2089..8c5b3199 100644 --- a/src/libespeak-ng/compilembrola.c +++ b/src/libespeak-ng/compilembrola.c @@ -80,7 +80,7 @@ espeak_ng_STATUS espeak_ng_CompileMbrolaVoice(const char *filepath, FILE *log) if((f_in = fopen(buf,"r")) == NULL) { fprintf(log, "Can't read: %s\n", filepath); - return ENE_NOT_FOUND; + return ENE_READ_ERROR; } while(fgets(buf,sizeof(phoneme),f_in) != NULL) @@ -126,7 +126,7 @@ espeak_ng_STATUS espeak_ng_CompileMbrolaVoice(const char *filepath, FILE *log) if((f_out = fopen(buf,"wb")) == NULL) { fprintf(log, "Can't write to: %s\n", buf); - return ENE_WRITE_FAILED; + return ENE_WRITE_ERROR; } data[count].name = 0; // list terminator