From 95e5c4458d3387c26730882a3666b600279b7cc3 Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Sat, 5 Nov 2022 11:46:45 +0200 Subject: [PATCH] cleanup: remove duplication with DecodeWithPhonemeMode(). TODO: think of a better function name. --- src/libespeak-ng/readclause.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/libespeak-ng/readclause.c b/src/libespeak-ng/readclause.c index b406b102..34524811 100644 --- a/src/libespeak-ng/readclause.c +++ b/src/libespeak-ng/readclause.c @@ -51,6 +51,7 @@ #define N_XML_BUF 500 +static void DecodeWithPhonemeMode(char *buf, char *phonemes, Translator *tr, Translator *tr2, unsigned int flags[]); static void TerminateBufWithSpaceAndZero(char *buf, int index); static const char *xmlbase = ""; // base URL from @@ -192,10 +193,7 @@ static const char *LookupSpecial(Translator *tr, const char *string, char *text_ flags[0] = flags[1] = 0; if (LookupDictList(tr, &string1, phonemes, flags, 0, NULL)) { - char phonemes2[55]; - SetWordStress(tr, phonemes, flags, -1, 0); - DecodePhonemes(phonemes, phonemes2); - sprintf(text_out, "[\002%s]]", phonemes2); + DecodeWithPhonemeMode(text_out, phonemes, tr, NULL, flags); return text_out; } return NULL; @@ -256,16 +254,11 @@ static const char *LookupCharName(Translator *tr, int c, int only) } if (phonemes[0]) { - char phonemes2[60]; if (lang_name) { - SetWordStress(translator2, phonemes, flags, -1, 0); - DecodePhonemes(phonemes, phonemes2); - sprintf(buf, "[\002_^_%s %s _^_%s]]", ESPEAKNG_DEFAULT_VOICE, phonemes2, WordToString2(tr->translator_name)); + DecodeWithPhonemeMode(buf, phonemes, tr, translator2, flags); SelectPhonemeTable(voice->phoneme_tab_ix); // revert to original phoneme table } else { - SetWordStress(tr, phonemes, flags, -1, 0); - DecodePhonemes(phonemes, phonemes2); - sprintf(buf, "[\002%s]] ", phonemes2); + DecodeWithPhonemeMode(buf, phonemes, tr, NULL, flags); } } else if (only == 0) strcpy(buf, "[\002(X1)(X1)(X1)]]"); @@ -1018,4 +1011,17 @@ void InitText2(void) static void TerminateBufWithSpaceAndZero(char *buf, int index) { buf[index] = ' '; buf[index+1] = 0; +} + +static void DecodeWithPhonemeMode(char *buf, char *phonemes, Translator *tr, Translator *tr2, unsigned int flags[]) { + char phonemes2[55]; + if (tr2 == NULL) { + SetWordStress(tr, phonemes, flags, -1, 0); + DecodePhonemes(phonemes, phonemes2); + sprintf(buf, "[\002%s]]", phonemes2); + } else { + SetWordStress(tr2, phonemes, flags, -1, 0); + DecodePhonemes(phonemes, phonemes2); + sprintf(buf, "[\002_^_%s %s _^_%s]]", ESPEAKNG_DEFAULT_VOICE, phonemes2, WordToString2(tr->translator_name)); + } } \ No newline at end of file