Browse Source

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

master
Juho Hiltunen 2 years ago
parent
commit
c4d8976fbc

+ 2
- 0
Makefile.am View File

@@ -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 \

+ 1
- 0
android/jni/Android.mk View File

@@ -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 \

+ 54
- 0
src/libespeak-ng/common.c View File

@@ -0,0 +1,54 @@
/*
* Copyright (C) 2005 to 2013 by Jonathan Duddington
* email: [email protected]
* 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
- 0
src/libespeak-ng/common.h View File

@@ -0,0 +1,31 @@
/*
* Copyright (C) 2005 to 2007 by Jonathan Duddington
* email: [email protected]
* 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
- 0
src/libespeak-ng/compiledata.c View File

@@ -35,6 +35,7 @@
#include <espeak-ng/speak_lib.h>
#include <espeak-ng/encoding.h>

#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

+ 2
- 1
src/libespeak-ng/dictionary.c View File

@@ -32,11 +32,12 @@
#include <espeak-ng/speak_lib.h>
#include <espeak-ng/encoding.h>

#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...

+ 2
- 1
src/libespeak-ng/readclause.c View File

@@ -37,12 +37,13 @@
#include <ucd/ucd.h>

#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...

+ 2
- 1
src/libespeak-ng/soundicon.c View File

@@ -36,9 +36,10 @@
#include <ucd/ucd.h>

#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;

+ 1
- 12
src/libespeak-ng/speech.c View File

@@ -49,6 +49,7 @@
#include <espeak-ng/encoding.h>

#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)
{

+ 0
- 2
src/libespeak-ng/speech.h 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 ESPEAK_NG_API int GetFileLength(const char *filename);

#ifdef __cplusplus
}
#endif

+ 2
- 1
src/libespeak-ng/synth_mbrola.c View File

@@ -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"


+ 2
- 1
src/libespeak-ng/synthdata.c View File

@@ -32,9 +32,10 @@
#include <espeak-ng/encoding.h>

#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...

+ 2
- 1
src/libespeak-ng/voices.c View File

@@ -39,10 +39,11 @@
#include <espeak-ng/encoding.h>

#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

+ 1
- 1
tests/fuzzrunner.c View File

@@ -17,7 +17,7 @@
*/

#include "config.h"
#include "speech.h"
#include "common.h"

#include <errno.h>
#include <stdint.h>

Loading…
Cancel
Save