indent i18n.c i18n.h

This commit is contained in:
Bill Kendrick 2017-10-15 10:56:18 -07:00
parent 967d37d8a7
commit 5b4e0dd53f
2 changed files with 365 additions and 364 deletions

View file

@ -426,13 +426,12 @@ static const language_to_locale_struct language_to_locale_array[] = {
/* Show available languages: */ /* Show available languages: */
static void show_lang_usage(int exitcode) static void show_lang_usage(int exitcode)
{ {
FILE * f = exitcode ? stderr : stdout; FILE *f = exitcode ? stderr : stdout;
const char *const prg = "tuxpaint"; const char *const prg = "tuxpaint";
fprintf(f,
"\n" fprintf(f, "\n" "Usage: %s [--lang LANGUAGE]\n" "\n" "LANGUAGE may be one of:\n"
"Usage: %s [--lang LANGUAGE]\n" "\n" "LANGUAGE may be one of:\n"
/* C */ " english american-english\n" /* C */ " english american-english\n"
/* ach */" acholi acoli\n" /* ach */ " acholi acoli\n"
/* af */ " afrikaans\n" /* af */ " afrikaans\n"
/* ak */ " akan twi-fante\n" /* ak */ " akan twi-fante\n"
/* sq */ " albanian\n" /* sq */ " albanian\n"
@ -441,7 +440,7 @@ static void show_lang_usage(int exitcode)
/* an */ " aragones\n" /* an */ " aragones\n"
/* hy */ " armenian hayeren\n" /* hy */ " armenian hayeren\n"
/* as */ " assamese\n" /* as */ " assamese\n"
/* ast */" asturian\n" /* ast */ " asturian\n"
/* en_AU */ " australian-english\n" /* en_AU */ " australian-english\n"
/* az */ " azerbaijani\n" /* az */ " azerbaijani\n"
/* bm */ " bambara\n" /* bm */ " bambara\n"
@ -475,7 +474,7 @@ static void show_lang_usage(int exitcode)
/* ka */ " georgian\n" /* ka */ " georgian\n"
/* de */ " german deutsch\n" /* de */ " german deutsch\n"
/* el */ " greek\n" /* el */ " greek\n"
/* gos */" gronings zudelk-veenkelonioals\n" /* gos */ " gronings zudelk-veenkelonioals\n"
/* gu */ " gujarati\n" /* gu */ " gujarati\n"
/* he */ " hebrew\n" /* he */ " hebrew\n"
/* hi */ " hindi\n" /* hi */ " hindi\n"
@ -490,18 +489,18 @@ static void show_lang_usage(int exitcode)
/* ks@devanagari */ " kashmiri-devanagari\n" /* ks@devanagari */ " kashmiri-devanagari\n"
/* ks */ " kashmiri-perso-arabic\n" /* ks */ " kashmiri-perso-arabic\n"
/* km */ " khmer\n" /* km */ " khmer\n"
/* cgg */" kiga chiga\n" /* cgg */ " kiga chiga\n"
/* rw */ " kinyarwanda\n" /* rw */ " kinyarwanda\n"
/* tlh */" klingon tlhIngan\n" /* tlh */ " klingon tlhIngan\n"
/* kok */" konkani-devaganari\n" /* kok */ " konkani-devaganari\n"
/* kok@roman */" konkani-roman\n" /* kok@roman */ " konkani-roman\n"
/* ko */ " korean\n" /* ko */ " korean\n"
/* ku */ " kurdish\n" /* ku */ " kurdish\n"
/* lv */ " latvian\n" /* lv */ " latvian\n"
/* lt */ " lithuanian lietuviu\n" /* lt */ " lithuanian lietuviu\n"
/* lg */ " luganda\n" /* lg */ " luganda\n"
/* lb */ " luxembourgish letzebuergesch\n" /* lb */ " luxembourgish letzebuergesch\n"
/* mai */" maithili\n" /* mai */ " maithili\n"
/* mk */ " macedonian\n" /* mk */ " macedonian\n"
/* ms */ " malay\n" /* ms */ " malay\n"
/* ml */ " malayalam\n" /* ml */ " malayalam\n"
@ -512,7 +511,7 @@ static void show_lang_usage(int exitcode)
/* mn */ " mongolian\n" /* mn */ " mongolian\n"
/* nr */ " ndebele\n" /* nr */ " ndebele\n"
/* ne */ " nepali\n" /* ne */ " nepali\n"
/* nso */" northern-sotho sesotho-sa-leboa\n" /* nso */ " northern-sotho sesotho-sa-leboa\n"
/* nn */ " norwegian nynorsk norsk\n" /* nn */ " norwegian nynorsk norsk\n"
/* oc */ " occitan\n" /* oc */ " occitan\n"
/* or */ " odia oriya\n" /* or */ " odia oriya\n"
@ -524,8 +523,8 @@ static void show_lang_usage(int exitcode)
/* ro */ " romanian\n" /* ro */ " romanian\n"
/* ru */ " russian russkiy\n" /* ru */ " russian russkiy\n"
/* sa */ " sanskrit\n" /* sa */ " sanskrit\n"
/* sat */" santali-devaganari\n" /* sat */ " santali-devaganari\n"
/* sat@olchiki */" santali-ol-chiki\n" /* sat@olchiki */ " santali-ol-chiki\n"
/* gd */ " scottish scottish-gaelic ghaidhlig\n" /* gd */ " scottish scottish-gaelic ghaidhlig\n"
/* sr */ " serbian\n" /* sr */ " serbian\n"
/* sr@latin */ " serbian-latin\n" /* sr@latin */ " serbian-latin\n"
@ -552,13 +551,13 @@ static void show_lang_usage(int exitcode)
/* ur */ " urdu\n" /* ur */ " urdu\n"
/* ca@valencia */ " valencian valencia\n" /* ca@valencia */ " valencian valencia\n"
/* ve */ " venda\n" /* ve */ " venda\n"
/* vec */" venetian veneto\n" /* vec */ " venetian veneto\n"
/* vi */ " vietnamese\n" /* vi */ " vietnamese\n"
/* wa */ " walloon walon\n" /* wa */ " walloon walon\n"
/* wo */ " wolof\n" /* wo */ " wolof\n"
/* cy */ " welsh cymraeg\n" /* cy */ " welsh cymraeg\n"
/* xh */ " xhosa\n" /* xh */ " xhosa\n"
/* zam */" zapotec miahuatlan-zapotec\n" /* zam */ " zapotec miahuatlan-zapotec\n"
/* zu */ " zulu\n" /* zu */ " zulu\n"
"\n", prg); "\n", prg);
exit(exitcode); exit(exitcode);
@ -699,10 +698,7 @@ static void show_locale_usage(FILE * f, const char *const prg)
" wa_BE (Walloon)\n" " wa_BE (Walloon)\n"
" wo_SN (Wolof)\n" " wo_SN (Wolof)\n"
" cy_GB (Welsh Cymraeg)\n" " cy_GB (Welsh Cymraeg)\n"
" xh_ZA (Xhosa)\n" " xh_ZA (Xhosa)\n" " zam (Zapoteco-Miahuatlan)\n" " zu_ZA (Zulu)\n" "\n", prg);
" zam (Zapoteco-Miahuatlan)\n"
" zu_ZA (Zulu)\n"
"\n", prg);
} }
@ -732,15 +728,17 @@ static void ctype_utf8(void)
#ifndef _WIN32 #ifndef _WIN32
/* FIXME: should this iterate over more locales? /* FIXME: should this iterate over more locales?
A zapotec speaker may have es_MX.UTF-8 available but not have en_US.UTF-8 for example */ A zapotec speaker may have es_MX.UTF-8 available but not have en_US.UTF-8 for example */
const char *names[] = {"en_US.UTF8","en_US.UTF-8","UTF8","UTF-8","C.UTF-8"}; const char *names[] = { "en_US.UTF8", "en_US.UTF-8", "UTF8", "UTF-8", "C.UTF-8" };
int i = sizeof(names)/sizeof(names[0]); int i = sizeof(names) / sizeof(names[0]);
for(;;){
if(iswprint((wchar_t)0xf7)) // division symbol -- which is in Latin-1 :-/ for (;;)
{
if (iswprint((wchar_t) 0xf7)) // division symbol -- which is in Latin-1 :-/
return; return;
if(--i < 0) if (--i < 0)
break; break;
setlocale(LC_CTYPE,names[i]); setlocale(LC_CTYPE, names[i]);
setlocale(LC_MESSAGES,names[i]); setlocale(LC_MESSAGES, names[i]);
} }
fprintf(stderr, "Failed to find a locale with iswprint() working!\n"); fprintf(stderr, "Failed to find a locale with iswprint() working!\n");
#endif #endif
@ -750,6 +748,7 @@ static void ctype_utf8(void)
static const char *language_to_locale(const char *langstr) static const char *language_to_locale(const char *langstr)
{ {
int i = sizeof language_to_locale_array / sizeof language_to_locale_array[0]; int i = sizeof language_to_locale_array / sizeof language_to_locale_array[0];
while (i--) while (i--)
{ {
if (!strcmp(langstr, language_to_locale_array[i].language)) if (!strcmp(langstr, language_to_locale_array[i].language))
@ -774,6 +773,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
size_t len_baseloc; size_t len_baseloc;
int found = 0; int found = 0;
int i; int i;
// printf("langint %i\n", langint); // printf("langint %i\n", langint);
if (!loc) if (!loc)
@ -787,7 +787,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
as a last resource reverse the scanning as a last resource reverse the scanning
*/ */
if(dot) if (dot)
*dot = '\0'; *dot = '\0';
if (cntrycode) if (cntrycode)
@ -801,7 +801,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
ataux = strdup(at); ataux = strdup(at);
*at = '\0'; *at = '\0';
if(cntrycode) if (cntrycode)
{ {
/* ll_CC@variant */ /* ll_CC@variant */
//if (found == 0) printf("ll_CC@variant check\n"); //if (found == 0) printf("ll_CC@variant check\n");
@ -810,8 +810,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
for (i = 0; i < NUM_LANGS && found == 0; i++) for (i = 0; i < NUM_LANGS && found == 0; i++)
{ {
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.) // Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i]) && if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(straux, lang_prefixes[i], len_baseloc))
!strncasecmp(straux, lang_prefixes[i], len_baseloc))
{ {
langint = i; langint = i;
found = 1; found = 1;
@ -819,15 +818,14 @@ static void set_langint_from_locale_string(const char *restrict loc)
} }
} }
/* ll@variant*/ /* ll@variant */
//if (found == 0) printf("ll@variant check\n"); //if (found == 0) printf("ll@variant check\n");
snprintf(straux, 255, "%s%s", baseloc, ataux); snprintf(straux, 255, "%s%s", baseloc, ataux);
len_baseloc = strlen(straux); len_baseloc = strlen(straux);
for (i = 0; i < NUM_LANGS && found == 0; i++) for (i = 0; i < NUM_LANGS && found == 0; i++)
{ {
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.) // Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i]) && if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(straux, lang_prefixes[i], len_baseloc))
!strncasecmp(straux, lang_prefixes[i], len_baseloc))
{ {
langint = i; langint = i;
found = 1; found = 1;
@ -835,11 +833,11 @@ static void set_langint_from_locale_string(const char *restrict loc)
} }
} }
if(cntrycode) if (cntrycode)
{ {
/* ll_CC */ /* ll_CC */
//if (found == 0) printf("ll_CC check\n"); //if (found == 0) printf("ll_CC check\n");
snprintf(straux, 255, "%s%s",baseloc, ccodeaux); snprintf(straux, 255, "%s%s", baseloc, ccodeaux);
len_baseloc = strlen(straux); len_baseloc = strlen(straux);
/* Which, if any, of the locales is it? */ /* Which, if any, of the locales is it? */
@ -864,8 +862,7 @@ static void set_langint_from_locale_string(const char *restrict loc)
for (i = 0; i < NUM_LANGS && found == 0; i++) for (i = 0; i < NUM_LANGS && found == 0; i++)
{ {
// Case-insensitive (both "pt_BR" and "pt_br" work, etc.) // Case-insensitive (both "pt_BR" and "pt_br" work, etc.)
if (len_baseloc == strlen(lang_prefixes[i]) && if (len_baseloc == strlen(lang_prefixes[i]) && !strncasecmp(baseloc, lang_prefixes[i], strlen(lang_prefixes[i])))
!strncasecmp(baseloc, lang_prefixes[i], strlen(lang_prefixes[i])))
{ {
langint = i; langint = i;
found = 1; found = 1;
@ -907,8 +904,9 @@ static void mysetenv(const char *name, const char *value)
#ifdef HAVE_SETENV #ifdef HAVE_SETENV
setenv(name, value, 1); setenv(name, value, 1);
#else #else
int len = strlen(name)+1+strlen(value)+1; int len = strlen(name) + 1 + strlen(value) + 1;
char *str = malloc(len); char *str = malloc(len);
sprintf(str, "%s=%s", name, value); sprintf(str, "%s=%s", name, value);
putenv(str); putenv(str);
#endif #endif
@ -916,11 +914,11 @@ static void mysetenv(const char *name, const char *value)
static int set_current_language(const char *restrict locale_choice) MUST_CHECK; static int set_current_language(const char *restrict locale_choice) MUST_CHECK;
static int set_current_language(const char *restrict loc) static int set_current_language(const char *restrict loc)
{ {
int i; int i;
int y_nudge = 0; int y_nudge = 0;
char * oldloc; char *oldloc;
char *env_language; char *env_language;
@ -949,13 +947,13 @@ static int set_current_language(const char *restrict loc)
after that, ctype_utf8() call will test the compatibility with utf8 and try to load after that, ctype_utf8() call will test the compatibility with utf8 and try to load
a different locale if the resulting one is not compatible. */ a different locale if the resulting one is not compatible. */
#ifdef DEBUG #ifdef DEBUG
printf ("Locale BEFORE is: %s\n", setlocale(LC_ALL,NULL));//EP printf("Locale BEFORE is: %s\n", setlocale(LC_ALL, NULL)); //EP
#endif #endif
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
setlocale(LC_ALL, loc); setlocale(LC_ALL, loc);
ctype_utf8(); ctype_utf8();
#ifdef DEBUG #ifdef DEBUG
printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP printf("Locale AFTER is: %s\n", setlocale(LC_ALL, NULL)); //EP
#endif #endif
bindtextdomain("tuxpaint", LOCALEDIR); bindtextdomain("tuxpaint", LOCALEDIR);
@ -974,7 +972,8 @@ printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP
loc = setlocale(LC_MESSAGES, NULL); loc = setlocale(LC_MESSAGES, NULL);
#endif #endif
if (strcmp(oldloc, "") != 0 && strcmp(loc, oldloc) != 0) { if (strcmp(oldloc, "") != 0 && strcmp(loc, oldloc) != 0)
{
/* System doesn't recognize that locale! Hack, per Albert C., is to set LC_ALL to a valid UTF-8 locale, then set LANGUAGE to the locale we want to force -bjk 2010.10.05 */ /* System doesn't recognize that locale! Hack, per Albert C., is to set LC_ALL to a valid UTF-8 locale, then set LANGUAGE to the locale we want to force -bjk 2010.10.05 */
/* Albert's comments from December 2009: /* Albert's comments from December 2009:
@ -1003,7 +1002,9 @@ printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP
mysetenv("LANGUAGE", oldloc); mysetenv("LANGUAGE", oldloc);
set_langint_from_locale_string(oldloc); set_langint_from_locale_string(oldloc);
} else { }
else
{
#ifdef _WIN32 #ifdef _WIN32
if (getenv("LANGUAGE") == NULL) if (getenv("LANGUAGE") == NULL)
mysetenv("LANGUAGE", loc); mysetenv("LANGUAGE", loc);
@ -1015,6 +1016,7 @@ printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP
env_language = strdup(getenv("LANGUAGE")); env_language = strdup(getenv("LANGUAGE"));
int j = 0; int j = 0;
char *env_language_lang; char *env_language_lang;
if (*env_language) if (*env_language)
{ {
env_language_lang = strtok(env_language, ":"); env_language_lang = strtok(env_language, ":");
@ -1073,9 +1075,7 @@ printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP
#endif #endif
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: Language is %s (%d) %s/%s\n", fprintf(stderr, "DEBUG: Language is %s (%d) %s/%s\n",
lang_prefix, langint, lang_prefix, langint, need_right_to_left ? "(RTL)" : "", need_right_to_left_word ? "(RTL words)" : "");
need_right_to_left ? "(RTL)" : "",
need_right_to_left_word ? "(RTL words)" : "");
fflush(stderr); fflush(stderr);
#endif #endif
@ -1095,18 +1095,18 @@ int setup_i18n(const char *restrict lang, const char *restrict locale)
printf("lang \"%s\", locale \"%s\"\n", lang, locale); printf("lang \"%s\", locale \"%s\"\n", lang, locale);
#endif #endif
if(locale) if (locale)
{ {
if(!strcmp(locale,"help")) if (!strcmp(locale, "help"))
{ {
show_locale_usage(stdout,"tuxpaint"); show_locale_usage(stdout, "tuxpaint");
exit(0); exit(0);
} }
} }
else else
locale = ""; locale = "";
if(lang) if (lang)
locale = language_to_locale(lang); locale = language_to_locale(lang);
#ifdef __APPLE__ #ifdef __APPLE__
patch_i18n(locale); //EP patch_i18n(locale); //EP

View file

@ -114,7 +114,7 @@ enum
LANG_ML, /* Malayalam */ LANG_ML, /* Malayalam */
LANG_MK, /* Macedonian */ LANG_MK, /* Macedonian */
LANG_MN, /* Mongolian */ LANG_MN, /* Mongolian */
LANG_MNI_BENGALI, /* Manipuri (Bengali script)*/ LANG_MNI_BENGALI, /* Manipuri (Bengali script) */
LANG_MNI_METEI_MAYEK, /* Manipuri (Metei Mayek script) */ LANG_MNI_METEI_MAYEK, /* Manipuri (Metei Mayek script) */
LANG_MR, /* Marath */ LANG_MR, /* Marath */
LANG_MS, /* Malay */ LANG_MS, /* Malay */
@ -207,8 +207,9 @@ extern w_langs wished_langs[255];
int get_current_language(void); int get_current_language(void);
int setup_i18n(const char *restrict lang, const char *restrict locale) MUST_CHECK; int setup_i18n(const char *restrict lang, const char *restrict locale) MUST_CHECK;
#ifdef NO_SDLPANGO #ifdef NO_SDLPANGO
int smash_i18n(void) MUST_CHECK; int smash_i18n(void) MUST_CHECK;
#endif #endif
#endif #endif