4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-22 00:38:06 +08:00

* getlocale.c (main): Rename local variable to avoid problems.

Avoid string comparisons, rather test language and sublanguage codes
	wheere possible.  Add more code to handle Serbian language/territory
	state identical on all Windows versions.  Fix handling for "@latin"
	modifier in Belarusian locale.
	* utils.sgml (getlocale): Try to make wording and example clearer.
This commit is contained in:
Corinna Vinschen 2010-02-11 11:39:23 +00:00
parent 87c0903113
commit 583c495774
3 changed files with 83 additions and 24 deletions

View File

@ -1,3 +1,12 @@
2010-02-11 Corinna Vinschen <corinna@vinschen.de>
* getlocale.c (main): Rename local variable to avoid problems.
Avoid string comparisons, rather test language and sublanguage codes
wheere possible. Add more code to handle Serbian language/territory
state identical on all Windows versions. Fix handling for "@latin"
modifier in Belarusian locale.
* utils.sgml (getlocale): Try to make wording and example clearer.
2010-02-10 Corinna Vinschen <corinna@vinschen.de> 2010-02-10 Corinna Vinschen <corinna@vinschen.de>
* getlocale.c (usage): Change text slightly. * getlocale.c (usage): Change text slightly.

View File

@ -84,6 +84,7 @@ int main (int argc, char **argv)
int all = 0; int all = 0;
const char *utf = ""; const char *utf = "";
char name[32]; char name[32];
DWORD cp;
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
while ((opt = getopt_long (argc, argv, opts, longopts, NULL)) != EOF) while ((opt = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
@ -112,7 +113,7 @@ int main (int argc, char **argv)
for (lang = 1; lang <= 0xff; ++lang) for (lang = 1; lang <= 0xff; ++lang)
{ {
struct { struct {
wchar_t lang[256]; wchar_t language[256];
wchar_t country[256]; wchar_t country[256];
char loc[32]; char loc[32];
} loc_list[32]; } loc_list[32];
@ -123,7 +124,7 @@ int main (int argc, char **argv)
lcid = (sublang << 10) | lang; lcid = (sublang << 10) | lang;
if (getlocale (lcid, name)) if (getlocale (lcid, name))
{ {
wchar_t lang[256]; wchar_t language[256];
wchar_t country[256]; wchar_t country[256];
int i; int i;
char *c, loc[32]; char *c, loc[32];
@ -131,29 +132,37 @@ int main (int argc, char **argv)
/* Go figure. Even the English name of a language or /* Go figure. Even the English name of a language or
locale might contain native characters. */ locale might contain native characters. */
GetLocaleInfoW (lcid, LOCALE_SENGLANGUAGE, lang, 256); GetLocaleInfoW (lcid, LOCALE_SENGLANGUAGE, language, 256);
GetLocaleInfoW (lcid, LOCALE_SENGCOUNTRY, country, 256); GetLocaleInfoW (lcid, LOCALE_SENGCOUNTRY, country, 256);
/* Avoid dups */ /* Avoid dups */
for (i = 0; i < lcnt; ++ i) for (i = 0; i < lcnt; ++ i)
if (!wcscmp (loc_list[i].lang, lang) if (!wcscmp (loc_list[i].language, language)
&& !wcscmp (loc_list[i].country, country)) && !wcscmp (loc_list[i].country, country))
break; break;
if (i < lcnt) if (i < lcnt)
continue; continue;
if (lcnt < 32) if (lcnt < 32)
{ {
wcscpy (loc_list[lcnt].lang, lang); wcscpy (loc_list[lcnt].language, language);
wcscpy (loc_list[lcnt].country, country); wcscpy (loc_list[lcnt].country, country);
} }
c = stpcpy (loc, name);
/* Convert old sr_SP silently to sr_CS on old systems.
Make sure sr_CS country is in recent shape. */
if (lang == LANG_SERBIAN
&& (sublang == SUBLANG_SERBIAN_LATIN
|| sublang == SUBLANG_SERBIAN_CYRILLIC))
{
c = stpcpy (loc, "sr_CS");
wcscpy (country, L"Serbia and Montenegro (Former)");
}
/* Now check certain conditions to figure out if that /* Now check certain conditions to figure out if that
locale requires a modifier. */ locale requires a modifier. */
c = stpcpy (loc, name); if (lang == LANG_SERBIAN && !strncmp (loc, "sr_", 3)
if (wcsstr (lang, L"(Latin)") && wcsstr (language, L"(Latin)"))
&& (!strncmp (loc, "sr_", 3)
|| !strcmp (loc, "be_BY")))
stpcpy (c, "@latin"); stpcpy (c, "@latin");
else if (wcsstr (lang, L"(Cyrillic)") else if (lang == LANG_UZBEK
&& !strcmp (loc, "uz_UZ")) && sublang == SUBLANG_UZBEK_CYRILLIC)
stpcpy (c, "@cyrillic"); stpcpy (c, "@cyrillic");
/* Avoid more dups */ /* Avoid more dups */
for (i = 0; i < lcnt; ++ i) for (i = 0; i < lcnt; ++ i)
@ -167,21 +176,55 @@ int main (int argc, char **argv)
if (lcnt < 32) if (lcnt < 32)
strcpy (loc_list[lcnt++].loc, loc); strcpy (loc_list[lcnt++].loc, loc);
/* Print */ /* Print */
printf ("%-16s %ls (%ls)\n", loc, lang, country); printf ("%-16s %ls (%ls)\n", loc, language, country);
/* Check for locales which sport a modifier for /* Check for locales which sport a modifier for
changing the codeset and other stuff. */ changing the codeset and other stuff. */
if (!strcmp (loc, "tt_RU")) if (lang == LANG_BELARUSIAN
&& sublang == SUBLANG_BELARUSIAN_BELARUS)
stpcpy (c, "@latin");
else if (lang == LANG_TATAR
&& sublang == SUBLANG_TATAR_RUSSIA)
stpcpy (c, "@iqtelif"); stpcpy (c, "@iqtelif");
else if (GetLocaleInfoW (lcid, LOCALE_SINTLSYMBOL, wbuf, 9) else if (GetLocaleInfoW (lcid,
LOCALE_IDEFAULTANSICODEPAGE
| LOCALE_RETURN_NUMBER,
(PWCHAR) &cp, sizeof cp)
&& cp == 1252 /* Latin1*/
&& GetLocaleInfoW (lcid, LOCALE_SINTLSYMBOL, wbuf, 9)
&& !wcsncmp (wbuf, L"EUR", 3)) && !wcsncmp (wbuf, L"EUR", 3))
stpcpy (c, "@euro"); stpcpy (c, "@euro");
else if (!strncmp (loc, "ja_", 3) else if (lang == LANG_JAPANESE
|| !strncmp (loc, "ko_", 3) || lang == LANG_KOREAN
|| !strncmp (loc, "zh_", 3)) || lang == LANG_CHINESE)
stpcpy (c, "@cjknarrow"); stpcpy (c, "@cjknarrow");
else else
continue; continue;
printf ("%-16s %ls (%ls)\n", loc, lang, country); printf ("%-16s %ls (%ls)\n", loc, language, country);
}
}
/* Check Serbian language for the available territories. Up to
Server 2003 we only had sr_SP (silently converted to sr_CS
above), in Vista we had only sr_CS. First starting with W7 we
have the actual sr_RS and sr_ME. However, all of them are
supported on all systems in Cygwin. So we fake them here, if
they are missing. */
if (lang == LANG_SERBIAN)
{
int sr_CS_idx = -1;
int sr_RS_idx = -1;
int i;
for (i = 0; i < lcnt; ++ i)
if (!strcmp (loc_list[i].loc, "sr_CS"))
sr_CS_idx = i;
else if (!strcmp (loc_list[i].loc, "sr_RS"))
sr_RS_idx = i;
if (sr_CS_idx > 0 && sr_RS_idx == -1)
{
puts ("sr_RS@latin Serbian (Latin) (Serbia)");
puts ("sr_RS Serbian (Latin) (Serbia)");
puts ("sr_ME@latin Serbian (Latin) (Montenegro)");
puts ("sr_ME Serbian (Latin) (Montenegro)");
} }
} }
} }

View File

@ -520,7 +520,8 @@ Options:
current user's Windows default locale to stdout. The <literal>-s</literal> current user's Windows default locale to stdout. The <literal>-s</literal>
option prints the systems default locale instead. With the option prints the systems default locale instead. With the
<literal>-u</literal> option <command>getlocale</command> appends a ".UTF-8". <literal>-u</literal> option <command>getlocale</command> appends a ".UTF-8".
This can be used in scripts to set the Cygwin locale, for instance: This can be used in scripts to set the Cygwin locale to the Windows user
or system default, for instance, for a US-based user:
</para> </para>
<screen> <screen>
@ -530,21 +531,27 @@ en_US.UTF-8
</screen> </screen>
<para>The <literal>-a</literal> option is helpful to learn which locales <para>The <literal>-a</literal> option is helpful to learn which locales
are supported by your Windows machine. It prints the locales and their are supported by your Windows machine. It prints all available locales,
actual meaning, like this:</para> their meaning, and the allowed modifiers. Example:</para>
<screen> <screen>
bash$ getlocale -a bash$ getlocale -a
ar_SA Arabic (Saudi Arabia) ar_SA Arabic (Saudi Arabia)
ar_IQ Arabic (Iraq) ar_IQ Arabic (Iraq)
...
zh_TW Chinese (Traditional) (Taiwan) zh_TW Chinese (Traditional) (Taiwan)
zh_CN Chinese (Simplified) (People's Republic of China) zh_TW@cjknarrow Chinese (Traditional) (Taiwan)
zh_HK Chinese (Traditional) (Hong Kong S.A.R.) ...
da_DK Danish (Denmark) de_AT German (Austria)
de_AT@euro German (Austria)
...
en_US English (United States) en_US English (United States)
en_GB English (United Kingdom) en_GB English (United Kingdom)
en_AU English (Australia) en_AU English (Australia)
... ...
sr_RS Serbian (Cyrillic) (Serbia)
sr_RS@latin Serbian (Latin) (Serbia)
...
</screen> </screen>
</sect2> </sect2>