code cleanup: reduce return of static buffers

This commit is contained in:
Yury Popov
2022-11-19 17:52:16 +03:00
parent 29f7afc688
commit 100df4c067
5 changed files with 16 additions and 19 deletions
+3 -2
View File
@@ -2084,6 +2084,7 @@ int TranslateRules(Translator *tr, char *p_start, char *phonemes, int ph_size, c
int ix; int ix;
unsigned int digit_count = 0; unsigned int digit_count = 0;
char *p; char *p;
char word_buf[5];
const ALPHABET *alphabet; const ALPHABET *alphabet;
int dict_flags0 = 0; int dict_flags0 = 0;
MatchRecord match1 = { 0 }; MatchRecord match1 = { 0 };
@@ -2240,12 +2241,12 @@ int TranslateRules(Translator *tr, char *p_start, char *phonemes, int ph_size, c
if (((alphabet = AlphabetFromChar(letter)) != NULL) && (alphabet->offset != tr->letter_bits_offset)) { if (((alphabet = AlphabetFromChar(letter)) != NULL) && (alphabet->offset != tr->letter_bits_offset)) {
if (tr->langopts.alt_alphabet == alphabet->offset) { if (tr->langopts.alt_alphabet == alphabet->offset) {
sprintf(phonemes, "%c%s", phonSWITCH, WordToString2(tr->langopts.alt_alphabet_lang)); sprintf(phonemes, "%c%s", phonSWITCH, WordToString2(word_buf, tr->langopts.alt_alphabet_lang));
return 0; return 0;
} }
if (alphabet->flags & AL_WORDS) { if (alphabet->flags & AL_WORDS) {
// switch to the nominated language for this alphabet // switch to the nominated language for this alphabet
sprintf(phonemes, "%c%s", phonSWITCH, WordToString2(alphabet->language)); sprintf(phonemes, "%c%s", phonSWITCH, WordToString2(word_buf, alphabet->language));
return 0; return 0;
} }
} }
+9 -12
View File
@@ -167,15 +167,12 @@ static void UngetC(int c)
ungot_char = c; ungot_char = c;
} }
const char *WordToString2(unsigned int word) const char *WordToString2(char buf[5], unsigned int word)
{ {
// Convert a language mnemonic word into a string // Convert a language mnemonic word into a string
int ix; int ix;
static char buf[5];
char *p; char *p;
MAKE_MEM_UNDEFINED(&buf, sizeof(buf));
p = buf; p = buf;
for (ix = 3; ix >= 0; ix--) { for (ix = 3; ix >= 0; ix--) {
if ((*p = word >> (ix*8)) != 0) if ((*p = word >> (ix*8)) != 0)
@@ -199,7 +196,7 @@ static const char *LookupSpecial(Translator *tr, const char *string, char *text_
return NULL; return NULL;
} }
static const char *LookupCharName(Translator *tr, int c, bool only) static const char *LookupCharName(char buf[60], Translator *tr, int c, bool only)
{ {
// Find the phoneme string (in ascii) to speak the name of character c // Find the phoneme string (in ascii) to speak the name of character c
// Used for punctuation characters and symbols // Used for punctuation characters and symbols
@@ -210,9 +207,6 @@ static const char *LookupCharName(Translator *tr, int c, bool only)
char phonemes[60]; char phonemes[60];
const char *lang_name = NULL; const char *lang_name = NULL;
char *string; char *string;
static char buf[60];
MAKE_MEM_UNDEFINED(&buf, sizeof(buf));
buf[0] = 0; buf[0] = 0;
flags[0] = 0; flags[0] = 0;
@@ -284,6 +278,7 @@ static int AnnouncePunctuation(Translator *tr, int c1, int *c2_ptr, char *output
int bufix1; int bufix1;
char buf[200]; char buf[200];
char ph_buf[30]; char ph_buf[30];
char cn_buf[60];
c2 = *c2_ptr; c2 = *c2_ptr;
buf[0] = 0; buf[0] = 0;
@@ -298,7 +293,7 @@ static int AnnouncePunctuation(Translator *tr, int c1, int *c2_ptr, char *output
punctname = ph_buf; // use word for 'period' instead of 'dot' punctname = ph_buf; // use word for 'period' instead of 'dot'
} }
if (punctname == NULL) if (punctname == NULL)
punctname = LookupCharName(tr, c1, false); punctname = LookupCharName(cn_buf, tr, c1, false);
if (punctname == NULL) if (punctname == NULL)
return -1; return -1;
@@ -833,7 +828,8 @@ int ReadClause(Translator *tr, char *buf, short *charix, int *charix_top, int n_
char *p2; char *p2;
p2 = &buf[ix]; p2 = &buf[ix];
sprintf(p2, "%s", LookupCharName(tr, c1, true)); char cn_buf[60];
sprintf(p2, "%s", LookupCharName(cn_buf, tr, c1, true));
if (p2[0] != 0) { if (p2[0] != 0) {
ix += strlen(p2); ix += strlen(p2);
announced_punctuation = c1; announced_punctuation = c1;
@@ -1020,6 +1016,7 @@ static void DecodeWithPhonemeMode(char *buf, char *phonemes, Translator *tr, Tra
} else { } else {
SetWordStress(tr2, phonemes, flags, -1, 0); SetWordStress(tr2, phonemes, flags, -1, 0);
DecodePhonemes(phonemes, phonemes2); DecodePhonemes(phonemes, phonemes2);
sprintf(buf, "[\002_^_%s %s _^_%s]]", ESPEAKNG_DEFAULT_VOICE, phonemes2, WordToString2(tr->translator_name)); char wbuf[5];
sprintf(buf, "[\002_^_%s %s _^_%s]]", ESPEAKNG_DEFAULT_VOICE, phonemes2, WordToString2(wbuf, tr->translator_name));
} }
} }
+1 -1
View File
@@ -36,7 +36,7 @@ extern PARAM_STACK param_stack[];
int clause_type_from_codepoint(uint32_t c); int clause_type_from_codepoint(uint32_t c);
int Eof(void); int Eof(void);
const char *WordToString2(unsigned int word); const char *WordToString2(char buf[5], unsigned int word);
int AddNameData(const char *name, int AddNameData(const char *name,
int wide); int wide);
int ReadClause(Translator *tr, int ReadClause(Translator *tr,
+2 -1
View File
@@ -918,7 +918,8 @@ static int TranslateLetter(Translator *tr, char *word, char *phonemes, int contr
char hangul_buf[12]; char hangul_buf[12];
// speak in the language for this alphabet (or English) // speak in the language for this alphabet (or English)
ph_buf[2] = SetTranslator3(WordToString2(language)); char word_buf[5];
ph_buf[2] = SetTranslator3(WordToString2(word_buf, language));
if (translator3 != NULL) { if (translator3 != NULL) {
int code; int code;
+1 -3
View File
@@ -1072,9 +1072,7 @@ char const *SelectVoice(espeak_VOICE *voice_select, int *found)
if ((voice_select2.languages == NULL) || (voice_select2.languages[0] == 0)) { if ((voice_select2.languages == NULL) || (voice_select2.languages[0] == 0)) {
// no language is specified. Get language from the named voice // no language is specified. Get language from the named voice
static char buf[60]; char buf[60];
MAKE_MEM_UNDEFINED(&buf, sizeof(buf));
if (voice_select2.name == NULL) { if (voice_select2.name == NULL) {
if ((voice_select2.name = voice_select2.identifier) == NULL) if ((voice_select2.name = voice_select2.identifier) == NULL)