code cleanup: Add new source file common.h for misc functions.

This commit is contained in:
Juho Hiltunen
2022-09-03 21:19:37 +03:00
parent 001ad3ab8d
commit c4d8976fbc
14 changed files with 103 additions and 21 deletions
+2
View File
@@ -155,6 +155,7 @@ src_libespeak_ng_la_SOURCES = \
src/ucd-tools/src/proplist.c \ src/ucd-tools/src/proplist.c \
src/ucd-tools/src/scripts.c \ src/ucd-tools/src/scripts.c \
src/ucd-tools/src/tostring.c \ src/ucd-tools/src/tostring.c \
src/libespeak-ng/common.c \
src/libespeak-ng/compiledata.c \ src/libespeak-ng/compiledata.c \
src/libespeak-ng/compiledict.c \ src/libespeak-ng/compiledict.c \
src/libespeak-ng/compilembrola.c \ src/libespeak-ng/compilembrola.c \
@@ -184,6 +185,7 @@ src_libespeak_ng_la_SOURCES = \
src/libespeak-ng/wavegen.c src/libespeak-ng/wavegen.c
noinst_HEADERS = \ noinst_HEADERS = \
src/libespeak-ng/common.h \
src/libespeak-ng/compiledict.h \ src/libespeak-ng/compiledict.h \
src/libespeak-ng/dictionary.h \ src/libespeak-ng/dictionary.h \
src/libespeak-ng/error.h \ src/libespeak-ng/error.h \
+1
View File
@@ -19,6 +19,7 @@ SPEECHPLAYER_SRC_FILES := \
LOCAL_SRC_FILES += $(SPEECHPLAYER_SRC_FILES) LOCAL_SRC_FILES += $(SPEECHPLAYER_SRC_FILES)
ESPEAK_SOURCES := \ ESPEAK_SOURCES := \
src/libespeak-ng/common.c \
src/libespeak-ng/compiledata.c \ src/libespeak-ng/compiledata.c \
src/libespeak-ng/compiledict.c \ src/libespeak-ng/compiledict.c \
src/libespeak-ng/compilembrola.c \ src/libespeak-ng/compilembrola.c \
+54
View File
@@ -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: <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <ctype.h>
#include <errno.h>
#include <locale.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <espeak-ng/espeak_ng.h>
#include <espeak-ng/speak_lib.h>
#include <espeak-ng/encoding.h>
#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
+31
View File
@@ -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: <http://www.gnu.org/licenses/>.
*/
#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
+1
View File
@@ -35,6 +35,7 @@
#include <espeak-ng/speak_lib.h> #include <espeak-ng/speak_lib.h>
#include <espeak-ng/encoding.h> #include <espeak-ng/encoding.h>
#include "common.h" // for GetFileLength
#include "dictionary.h" // for strncpy0 #include "dictionary.h" // for strncpy0
#include "error.h" // for create_file_error_context #include "error.h" // for create_file_error_context
#include "mnemonics.h" // for LookupMnemName, MNEM_TAB #include "mnemonics.h" // for LookupMnemName, MNEM_TAB
+2 -1
View File
@@ -32,11 +32,12 @@
#include <espeak-ng/speak_lib.h> #include <espeak-ng/speak_lib.h>
#include <espeak-ng/encoding.h> #include <espeak-ng/encoding.h>
#include "common.h" // for GetFileLength
#include "dictionary.h" #include "dictionary.h"
#include "numbers.h" // for LookupAccentedLetter, Look... #include "numbers.h" // for LookupAccentedLetter, Look...
#include "phoneme.h" // for PHONEME_TAB, phVOWEL, phon... #include "phoneme.h" // for PHONEME_TAB, phVOWEL, phon...
#include "readclause.h" // for WordToString2, is_str_tota... #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 "compiledict.h" // for DecodeRule
#include "synthdata.h" // for PhonemeCode, InterpretPhoneme #include "synthdata.h" // for PhonemeCode, InterpretPhoneme
#include "synthesize.h" // for STRESS_IS_PRIMARY, phoneme... #include "synthesize.h" // for STRESS_IS_PRIMARY, phoneme...
+2 -1
View File
@@ -37,12 +37,13 @@
#include <ucd/ucd.h> #include <ucd/ucd.h>
#include "readclause.h" #include "readclause.h"
#include "common.h" // for GetFileLength
#include "config.h" // for HAVE_MKSTEMP #include "config.h" // for HAVE_MKSTEMP
#include "dictionary.h" // for LookupDictList, DecodePhonemes, Set... #include "dictionary.h" // for LookupDictList, DecodePhonemes, Set...
#include "error.h" // for create_file_error_context #include "error.h" // for create_file_error_context
#include "phoneme.h" // for phonSWITCH #include "phoneme.h" // for phonSWITCH
#include "soundicon.h" // for LookupSoundIcon #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 "ssml.h" // for SSML_STACK, ProcessSsmlTag, N_PARAM...
#include "synthdata.h" // for SelectPhonemeTable #include "synthdata.h" // for SelectPhonemeTable
#include "translate.h" // for Translator, utf8_out, CLAUSE_OPTION... #include "translate.h" // for Translator, utf8_out, CLAUSE_OPTION...
+2 -1
View File
@@ -36,9 +36,10 @@
#include <ucd/ucd.h> #include <ucd/ucd.h>
#include "soundicon.h" #include "soundicon.h"
#include "common.h" // for GetFileLength
#include "error.h" // for create_file_error_context #include "error.h" // for create_file_error_context
#include "readclause.h" // for Read4Bytes #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 #include "synthesize.h" // for samplerate
int n_soundicon_tab = 0; int n_soundicon_tab = 0;
+1 -12
View File
@@ -49,6 +49,7 @@
#include <espeak-ng/encoding.h> #include <espeak-ng/encoding.h>
#include "speech.h" #include "speech.h"
#include "common.h" // for GetFileLength
#include "dictionary.h" // for GetTranslatedPhonemeString, strncpy0 #include "dictionary.h" // for GetTranslatedPhonemeString, strncpy0
#include "espeak_command.h" // for delete_espeak_command, SetParameter #include "espeak_command.h" // for delete_espeak_command, SetParameter
#include "event.h" // for event_declare, event_clear_all, eve... #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; 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) ESPEAK_NG_API void espeak_ng_InitializePath(const char *path)
{ {
-2
View File
@@ -78,8 +78,6 @@ void cancel_audio(void);
extern char path_home[N_PATH_HOME]; // this is the espeak-ng-data directory 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 #ifdef __cplusplus
} }
#endif #endif
+2 -1
View File
@@ -40,9 +40,10 @@
#include "wavegen.h" #include "wavegen.h"
#include "speech.h" #include "common.h"
#include "phoneme.h" #include "phoneme.h"
#include "voice.h" #include "voice.h"
#include "speech.h"
#include "synthesize.h" #include "synthesize.h"
#include "translate.h" #include "translate.h"
+2 -1
View File
@@ -32,9 +32,10 @@
#include <espeak-ng/encoding.h> #include <espeak-ng/encoding.h>
#include "synthdata.h" #include "synthdata.h"
#include "common.h" // for GetFileLength
#include "error.h" // for create_file_error_context, crea... #include "error.h" // for create_file_error_context, crea...
#include "phoneme.h" // for PHONEME_TAB, PHONEME_TAB_LIST #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 "mbrola.h" // for mbrola_name
#include "soundicon.h" // for soundicon_tab #include "soundicon.h" // for soundicon_tab
#include "synthesize.h" // for PHONEME_LIST, frameref_t, PHONE... #include "synthesize.h" // for PHONEME_LIST, frameref_t, PHONE...
+2 -1
View File
@@ -39,10 +39,11 @@
#include <espeak-ng/encoding.h> #include <espeak-ng/encoding.h>
#include "voice.h" // for voice_t, DoVoiceChange, N_PEAKS #include "voice.h" // for voice_t, DoVoiceChange, N_PEAKS
#include "common.h" // for GetFileLength
#include "dictionary.h" // for strncpy0, LoadDictionary #include "dictionary.h" // for strncpy0, LoadDictionary
#include "mnemonics.h" // for LookupMnemName, MNEM_TAB #include "mnemonics.h" // for LookupMnemName, MNEM_TAB
#include "phoneme.h" // for REPLACE_PHONEMES, n_replace_pho... #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 "mbrola.h" // for LoadMbrolaTable
#include "synthdata.h" // for SelectPhonemeTableName, LookupP... #include "synthdata.h" // for SelectPhonemeTableName, LookupP...
#include "synthesize.h" // for SetSpeed, SPEED_FACTORS, speed #include "synthesize.h" // for SetSpeed, SPEED_FACTORS, speed
+1 -1
View File
@@ -17,7 +17,7 @@
*/ */
#include "config.h" #include "config.h"
#include "speech.h" #include "common.h"
#include <errno.h> #include <errno.h>
#include <stdint.h> #include <stdint.h>