From c4d8976fbc02c251bddd325dc428a11e125ae6e0 Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Sat, 3 Sep 2022 21:19:37 +0300 Subject: [PATCH] code cleanup: Add new source file common.h for misc functions. --- Makefile.am | 2 ++ android/jni/Android.mk | 1 + src/libespeak-ng/common.c | 54 +++++++++++++++++++++++++++++++++ src/libespeak-ng/common.h | 31 +++++++++++++++++++ src/libespeak-ng/compiledata.c | 1 + src/libespeak-ng/dictionary.c | 3 +- src/libespeak-ng/readclause.c | 3 +- src/libespeak-ng/soundicon.c | 3 +- src/libespeak-ng/speech.c | 13 +------- src/libespeak-ng/speech.h | 2 -- src/libespeak-ng/synth_mbrola.c | 3 +- src/libespeak-ng/synthdata.c | 3 +- src/libespeak-ng/voices.c | 3 +- tests/fuzzrunner.c | 2 +- 14 files changed, 103 insertions(+), 21 deletions(-) create mode 100644 src/libespeak-ng/common.c create mode 100644 src/libespeak-ng/common.h diff --git a/Makefile.am b/Makefile.am index c235b7b2..b0ec3a11 100644 --- a/Makefile.am +++ b/Makefile.am @@ -155,6 +155,7 @@ src_libespeak_ng_la_SOURCES = \ src/ucd-tools/src/proplist.c \ src/ucd-tools/src/scripts.c \ src/ucd-tools/src/tostring.c \ + src/libespeak-ng/common.c \ src/libespeak-ng/compiledata.c \ src/libespeak-ng/compiledict.c \ src/libespeak-ng/compilembrola.c \ @@ -184,6 +185,7 @@ src_libespeak_ng_la_SOURCES = \ src/libespeak-ng/wavegen.c noinst_HEADERS = \ + src/libespeak-ng/common.h \ src/libespeak-ng/compiledict.h \ src/libespeak-ng/dictionary.h \ src/libespeak-ng/error.h \ diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 9c9f3dba..c88f52f7 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -19,6 +19,7 @@ SPEECHPLAYER_SRC_FILES := \ LOCAL_SRC_FILES += $(SPEECHPLAYER_SRC_FILES) ESPEAK_SOURCES := \ + src/libespeak-ng/common.c \ src/libespeak-ng/compiledata.c \ src/libespeak-ng/compiledict.c \ src/libespeak-ng/compilembrola.c \ diff --git a/src/libespeak-ng/common.c b/src/libespeak-ng/common.c new file mode 100644 index 00000000..d8776d78 --- /dev/null +++ b/src/libespeak-ng/common.c @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2005 to 2013 by Jonathan Duddington + * email: jonsd@users.sourceforge.net + * Copyright (C) 2013-2017 Reece H. Dunn + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see: . + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +#include "common.h" + +#pragma GCC visibility push(default) + +int GetFileLength(const char *filename) +{ + struct stat statbuf; + + if (stat(filename, &statbuf) != 0) + return -errno; + + if (S_ISDIR(statbuf.st_mode)) + return -EISDIR; + + return statbuf.st_size; +} + +#pragma GCC visibility pop diff --git a/src/libespeak-ng/common.h b/src/libespeak-ng/common.h new file mode 100644 index 00000000..b011dd27 --- /dev/null +++ b/src/libespeak-ng/common.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2005 to 2007 by Jonathan Duddington + * email: jonsd@users.sourceforge.net + * Copyright (C) 2013-2015 Reece H. Dunn + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see: . + */ + +#ifndef ESPEAK_NG_COMMON_H +#define ESPEAK_NG_COMMON_H + +#include "espeak-ng/espeak_ng.h" + +extern ESPEAK_NG_API int GetFileLength(const char *filename); + +#ifdef __cplusplus +} +#endif + +#endif // SPEECH_H diff --git a/src/libespeak-ng/compiledata.c b/src/libespeak-ng/compiledata.c index 772f10e1..da1063ca 100644 --- a/src/libespeak-ng/compiledata.c +++ b/src/libespeak-ng/compiledata.c @@ -35,6 +35,7 @@ #include #include +#include "common.h" // for GetFileLength #include "dictionary.h" // for strncpy0 #include "error.h" // for create_file_error_context #include "mnemonics.h" // for LookupMnemName, MNEM_TAB diff --git a/src/libespeak-ng/dictionary.c b/src/libespeak-ng/dictionary.c index 858fafbb..2dbcd451 100644 --- a/src/libespeak-ng/dictionary.c +++ b/src/libespeak-ng/dictionary.c @@ -32,11 +32,12 @@ #include #include +#include "common.h" // for GetFileLength #include "dictionary.h" #include "numbers.h" // for LookupAccentedLetter, Look... #include "phoneme.h" // for PHONEME_TAB, phVOWEL, phon... #include "readclause.h" // for WordToString2, is_str_tota... -#include "speech.h" // for GetFileLength, path_home +#include "speech.h" // for path_home #include "compiledict.h" // for DecodeRule #include "synthdata.h" // for PhonemeCode, InterpretPhoneme #include "synthesize.h" // for STRESS_IS_PRIMARY, phoneme... diff --git a/src/libespeak-ng/readclause.c b/src/libespeak-ng/readclause.c index 07b2547d..28db89f8 100644 --- a/src/libespeak-ng/readclause.c +++ b/src/libespeak-ng/readclause.c @@ -37,12 +37,13 @@ #include #include "readclause.h" +#include "common.h" // for GetFileLength #include "config.h" // for HAVE_MKSTEMP #include "dictionary.h" // for LookupDictList, DecodePhonemes, Set... #include "error.h" // for create_file_error_context #include "phoneme.h" // for phonSWITCH #include "soundicon.h" // for LookupSoundIcon -#include "speech.h" // for GetFileLength, LookupMnem, PATHSEP +#include "speech.h" // for LookupMnem, PATHSEP #include "ssml.h" // for SSML_STACK, ProcessSsmlTag, N_PARAM... #include "synthdata.h" // for SelectPhonemeTable #include "translate.h" // for Translator, utf8_out, CLAUSE_OPTION... diff --git a/src/libespeak-ng/soundicon.c b/src/libespeak-ng/soundicon.c index 8b350045..abab72f7 100644 --- a/src/libespeak-ng/soundicon.c +++ b/src/libespeak-ng/soundicon.c @@ -36,9 +36,10 @@ #include #include "soundicon.h" +#include "common.h" // for GetFileLength #include "error.h" // for create_file_error_context #include "readclause.h" // for Read4Bytes -#include "speech.h" // for path_home, GetFileLength, PATHSEP +#include "speech.h" // for path_home, PATHSEP #include "synthesize.h" // for samplerate int n_soundicon_tab = 0; diff --git a/src/libespeak-ng/speech.c b/src/libespeak-ng/speech.c index 4258191f..8534bac0 100644 --- a/src/libespeak-ng/speech.c +++ b/src/libespeak-ng/speech.c @@ -49,6 +49,7 @@ #include #include "speech.h" +#include "common.h" // for GetFileLength #include "dictionary.h" // for GetTranslatedPhonemeString, strncpy0 #include "espeak_command.h" // for delete_espeak_command, SetParameter #include "event.h" // for event_declare, event_clear_all, eve... @@ -302,18 +303,6 @@ ESPEAK_NG_API espeak_ng_STATUS espeak_ng_InitializeOutput(espeak_ng_OUTPUT_MODE return ENS_OK; } -int GetFileLength(const char *filename) -{ - struct stat statbuf; - - if (stat(filename, &statbuf) != 0) - return -errno; - - if (S_ISDIR(statbuf.st_mode)) - return -EISDIR; - - return statbuf.st_size; -} ESPEAK_NG_API void espeak_ng_InitializePath(const char *path) { diff --git a/src/libespeak-ng/speech.h b/src/libespeak-ng/speech.h index bf37aa96..01f8ae94 100644 --- a/src/libespeak-ng/speech.h +++ b/src/libespeak-ng/speech.h @@ -78,8 +78,6 @@ void cancel_audio(void); extern char path_home[N_PATH_HOME]; // this is the espeak-ng-data directory -extern ESPEAK_NG_API int GetFileLength(const char *filename); - #ifdef __cplusplus } #endif diff --git a/src/libespeak-ng/synth_mbrola.c b/src/libespeak-ng/synth_mbrola.c index 68e1f5e2..fab55884 100644 --- a/src/libespeak-ng/synth_mbrola.c +++ b/src/libespeak-ng/synth_mbrola.c @@ -40,9 +40,10 @@ #include "wavegen.h" -#include "speech.h" +#include "common.h" #include "phoneme.h" #include "voice.h" +#include "speech.h" #include "synthesize.h" #include "translate.h" diff --git a/src/libespeak-ng/synthdata.c b/src/libespeak-ng/synthdata.c index 272fec74..a2d7ae10 100644 --- a/src/libespeak-ng/synthdata.c +++ b/src/libespeak-ng/synthdata.c @@ -32,9 +32,10 @@ #include #include "synthdata.h" +#include "common.h" // for GetFileLength #include "error.h" // for create_file_error_context, crea... #include "phoneme.h" // for PHONEME_TAB, PHONEME_TAB_LIST -#include "speech.h" // for path_home, GetFileLength, PATHSEP +#include "speech.h" // for path_home, PATHSEP #include "mbrola.h" // for mbrola_name #include "soundicon.h" // for soundicon_tab #include "synthesize.h" // for PHONEME_LIST, frameref_t, PHONE... diff --git a/src/libespeak-ng/voices.c b/src/libespeak-ng/voices.c index c96e326c..151ad585 100644 --- a/src/libespeak-ng/voices.c +++ b/src/libespeak-ng/voices.c @@ -39,10 +39,11 @@ #include #include "voice.h" // for voice_t, DoVoiceChange, N_PEAKS +#include "common.h" // for GetFileLength #include "dictionary.h" // for strncpy0, LoadDictionary #include "mnemonics.h" // for LookupMnemName, MNEM_TAB #include "phoneme.h" // for REPLACE_PHONEMES, n_replace_pho... -#include "speech.h" // for GetFileLength, PATHSEP +#include "speech.h" // for PATHSEP #include "mbrola.h" // for LoadMbrolaTable #include "synthdata.h" // for SelectPhonemeTableName, LookupP... #include "synthesize.h" // for SetSpeed, SPEED_FACTORS, speed diff --git a/tests/fuzzrunner.c b/tests/fuzzrunner.c index 41d411dd..288b326c 100644 --- a/tests/fuzzrunner.c +++ b/tests/fuzzrunner.c @@ -17,7 +17,7 @@ */ #include "config.h" -#include "speech.h" +#include "common.h" #include #include