Browse Source

code cleanup: reduce return of static buffers

master
Yury Popov 2 years ago
parent
commit
100df4c067
No account linked to committer's email address

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

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


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
src/libespeak-ng/readclause.c View File

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)
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
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;
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;
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;
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;
} 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
src/libespeak-ng/readclause.h View File



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
src/libespeak-ng/translateword.c View File

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
src/libespeak-ng/voices.c View File



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

MAKE_MEM_UNDEFINED(&buf, sizeof(buf));
char buf[60];


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)

Loading…
Cancel
Save