Browse Source

cleanup: reduce variable scopes in translate.c

Contributes to #9.

Found with cppcheck static code analyzer variableScope parameter.
master
Juho Hiltunen 2 years ago
parent
commit
39ea6e3a90
1 changed files with 19 additions and 26 deletions
  1. 19
    26
      src/libespeak-ng/translate.c

+ 19
- 26
src/libespeak-ng/translate.c View File

{ {
char words_phonemes[N_WORD_PHONEMES]; // a word translated into phoneme codes char words_phonemes[N_WORD_PHONEMES]; // a word translated into phoneme codes
char *phonemes = words_phonemes; char *phonemes = words_phonemes;
int available = N_WORD_PHONEMES;
bool first_word = true;



int flags = TranslateWord3(tr, word_start, wtab, word_out, &any_stressed_words, current_alphabet, word_phonemes, sizeof(word_phonemes)); int flags = TranslateWord3(tr, word_start, wtab, word_out, &any_stressed_words, current_alphabet, word_phonemes, sizeof(word_phonemes));
if (flags & FLAG_TEXTMODE && word_out) { if (flags & FLAG_TEXTMODE && word_out) {
strcpy(word+2, word_out); strcpy(word+2, word_out);
word_out = word+2; word_out = word+2;


bool first_word = true;
int available = N_WORD_PHONEMES;
while (*word_out && available > 1) { while (*word_out && available > 1) {
int c; int c;
utf8_in(&c, word_out); utf8_in(&c, word_out);
{ {
// Process embedded commands for emphasis, sayas, and break // Process embedded commands for emphasis, sayas, and break
int embedded_cmd; int embedded_cmd;
int value;

do { do {
embedded_cmd = embedded_list[embedded_read++]; embedded_cmd = embedded_list[embedded_read++];
value = embedded_cmd >> 8;
int value = embedded_cmd >> 8;


switch (embedded_cmd & 0x1f) switch (embedded_cmd & 0x1f)
{ {
bool first_phoneme = true; bool first_phoneme = true;
int source_ix; int source_ix;
int len; int len;
int ix;
const char *new_language;
int bad_phoneme; int bad_phoneme;
int word_flags; int word_flags;
int word_copy_len;
char word_copy[N_WORD_BYTES+1]; char word_copy[N_WORD_BYTES+1];
char word_replaced[N_WORD_BYTES+1]; char word_replaced[N_WORD_BYTES+1];
char old_dictionary_name[40]; char old_dictionary_name[40];
flags = FLAG_FOUND; flags = FLAG_FOUND;
} else { } else {
int c2; int c2;
ix = 0;
int ix = 0;
int word_copy_len;
while (((c2 = word_copy[ix] = word[ix]) != ' ') && (c2 != 0) && (ix < N_WORD_BYTES)) ix++; while (((c2 = word_copy[ix] = word[ix]) != ' ') && (c2 != 0) && (ix < N_WORD_BYTES)) ix++;
word_copy_len = ix; word_copy_len = ix;


// this word uses a different language // this word uses a different language
memcpy(word, word_copy, word_copy_len); memcpy(word, word_copy, word_copy_len);


const char *new_language;
new_language = (char *)(&p[1]); new_language = (char *)(&p[1]);
if (new_language[0] == 0) if (new_language[0] == 0)
new_language = ESPEAKNG_DEFAULT_VOICE; new_language = ESPEAKNG_DEFAULT_VOICE;
// To allow language specific examination and replacement of characters // To allow language specific examination and replacement of characters


int code; int code;
int initial;
int medial;
int final;
int next2; int next2;


static const unsigned char hangul_compatibility[0x34] = { static const unsigned char hangul_compatibility[0x34] = {
// check for Korean Hangul letters // check for Korean Hangul letters
if (((code = c - 0xac00) >= 0) && (c <= 0xd7af)) { if (((code = c - 0xac00) >= 0) && (c <= 0xd7af)) {
// break a syllable hangul into 2 or 3 individual jamo // break a syllable hangul into 2 or 3 individual jamo
initial = (code/28)/21;
medial = (code/28) % 21;
final = code % 28;
int initial = (code/28)/21;
int medial = (code/28) % 21;
int final = code % 28;


if (initial == 11) { if (initial == 11) {
// null initial // null initial


static int UpperCaseInWord(Translator *tr, char *word, int c) static int UpperCaseInWord(Translator *tr, char *word, int c)
{ {
int ix;
int len;
const char *p;

if (tr->translator_name == L('g', 'a')) { if (tr->translator_name == L('g', 'a')) {
// Irish
int ix;
const char *p;

for (ix = 0;; ix++) { for (ix = 0;; ix++) {
int len;
if ((p = UCase_ga[ix]) == NULL) if ((p = UCase_ga[ix]) == NULL)
break; break;


int c; int c;
int cc = 0; int cc = 0;
unsigned int source_index = 0; unsigned int source_index = 0;
unsigned int prev_source_index = 0;
int source_index_word = 0; int source_index_word = 0;
int prev_in; int prev_in;
int prev_out = ' '; int prev_out = ' ';
int prev_out2;
int prev_in_save = 0; int prev_in_save = 0;
int next_in; int next_in;
int next_in_nbytes; int next_in_nbytes;


words[0].length = CalcWordLength(source_index, charix_top, charix, words, 0); words[0].length = CalcWordLength(source_index, charix_top, charix, words, 0);


int prev_out2;
while (!finished && (ix < (int)sizeof(sbuf) - 1)) { while (!finished && (ix < (int)sizeof(sbuf) - 1)) {
prev_out2 = prev_out; prev_out2 = prev_out;
utf8_in2(&prev_out, &sbuf[ix-1], 1); utf8_in2(&prev_out, &sbuf[ix-1], 1);
} else if (source_index > 0) } else if (source_index > 0)
utf8_in2(&prev_in, &source[source_index-1], 1); utf8_in2(&prev_in, &source[source_index-1], 1);


prev_source_index = source_index;
unsigned int prev_source_index = source_index;


if (char_inserted) { if (char_inserted) {
c = char_inserted; c = char_inserted;
int c_temp; int c_temp;
char *pn; char *pn;
char *pw; char *pw;
int nw;
char number_buf[150]; char number_buf[150];
WORD_TAB num_wtab[50]; // copy of 'words', when splitting numbers into parts WORD_TAB num_wtab[50]; // copy of 'words', when splitting numbers into parts




if (n_digits > 4 && n_digits <= 32) { if (n_digits > 4 && n_digits <= 32) {
// word is entirely digits, insert commas and break into 3 digit "words" // word is entirely digits, insert commas and break into 3 digit "words"
int nw = 0;

number_buf[0] = ' '; number_buf[0] = ' ';
number_buf[1] = ' '; number_buf[1] = ' ';
number_buf[2] = ' '; number_buf[2] = ' ';
pn = &number_buf[3]; pn = &number_buf[3];
nx = n_digits; nx = n_digits;
nw = 0;


if ((n_digits > tr->langopts.max_digits) || (word[0] == '0')) if ((n_digits > tr->langopts.max_digits) || (word[0] == '0'))
words[ix].flags |= FLAG_INDIVIDUAL_DIGITS; words[ix].flags |= FLAG_INDIVIDUAL_DIGITS;
static void SwitchLanguage(char *word, char *word_phonemes) { static void SwitchLanguage(char *word, char *word_phonemes) {
char lang_name[12]; char lang_name[12];
int ix; int ix;
int c1;


word += 3; word += 3;


for (ix = 0;;) { for (ix = 0;;) {
int c1;
c1 = *word++; c1 = *word++;
if ((c1 == ' ') || (c1 == 0)) if ((c1 == ' ') || (c1 == 0))
break; break;

Loading…
Cancel
Save