From 96cbb3a380a7eb4a9528945211359eeba37b90b9 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 10 Feb 2010 12:36:29 +0000 Subject: [PATCH] * getlocale.c (main): Revamp -a loop to avoid duplicates and to print locales with the correct, supported modifiers. --- winsup/utils/ChangeLog | 5 +++ winsup/utils/getlocale.c | 92 +++++++++++++++++++++++++++++++++------- 2 files changed, 81 insertions(+), 16 deletions(-) diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog index 83318f3da..c07a4ff26 100644 --- a/winsup/utils/ChangeLog +++ b/winsup/utils/ChangeLog @@ -1,3 +1,8 @@ +2010-02-10 Corinna Vinschen + + * getlocale.c (main): Revamp -a loop to avoid duplicates and to print + locales with the correct, supported modifiers. + 2010-01-25 Corinna Vinschen * getlocale.c (main): Use setlocale and fetch string from Windows diff --git a/winsup/utils/getlocale.c b/winsup/utils/getlocale.c index 024dee762..6b3340d35 100644 --- a/winsup/utils/getlocale.c +++ b/winsup/utils/getlocale.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #define WINVER 0x0601 #include @@ -109,22 +110,81 @@ int main (int argc, char **argv) unsigned lang, sublang; for (lang = 1; lang <= 0x3ff; ++lang) - for (sublang = 1; sublang <= 0x3f; ++sublang) - { - lcid = (sublang << 10) | lang; - if (getlocale (lcid, name)) - { - wchar_t lang[256]; - wchar_t country[256]; - char loc[32]; - /* Go figure. Even the English name of a language or - locale might contain native characters. */ - GetLocaleInfoW (lcid, LOCALE_SENGLANGUAGE, lang, 256); - GetLocaleInfoW (lcid, LOCALE_SENGCOUNTRY, country, 256); - stpcpy (stpcpy (loc, name), utf); - printf ("%-16s %ls (%ls)\n", loc, lang, country); - } - } + { + struct { + wchar_t lang[256]; + wchar_t country[256]; + char loc[32]; + } loc_list[32]; + int lcnt = 0; + + for (sublang = 1; sublang <= 0x3f; ++sublang) + { + lcid = (sublang << 10) | lang; + if (getlocale (lcid, name)) + { + wchar_t lang[256]; + wchar_t country[256]; + int i; + char *c, loc[32]; + wchar_t wbuf[9]; + + /* Go figure. Even the English name of a language or + locale might contain native characters. */ + GetLocaleInfoW (lcid, LOCALE_SENGLANGUAGE, lang, 256); + GetLocaleInfoW (lcid, LOCALE_SENGCOUNTRY, country, 256); + /* Avoid dups */ + for (i = 0; i < lcnt; ++ i) + if (!wcscmp (loc_list[i].lang, lang) + && !wcscmp (loc_list[i].country, country)) + break; + if (i < lcnt) + continue; + if (lcnt < 32) + { + wcscpy (loc_list[lcnt].lang, lang); + wcscpy (loc_list[lcnt].country, country); + } + /* Now check certain conditions to figure out if that + locale requires a modifier. */ + c = stpcpy (loc, name); + if (wcsstr (lang, L"(Latin)") + && (!strncmp (loc, "sr_", 3) + || !strcmp (loc, "be_BY"))) + stpcpy (c, "@latin"); + else if (wcsstr (lang, L"(Cyrillic)") + && !strcmp (loc, "uz_UZ")) + stpcpy (c, "@cyrillic"); + /* Avoid more dups */ + for (i = 0; i < lcnt; ++ i) + if (!strcmp (loc_list[i].loc, loc)) + { + lcnt++; + break; + } + if (i < lcnt) + continue; + if (lcnt < 32) + strcpy (loc_list[lcnt++].loc, loc); + /* Print */ + printf ("%-16s %ls (%ls)\n", loc, lang, country); + /* Check for locales which sport a modifier for + changing the codeset and other stuff. */ + if (!strcmp (loc, "tt_RU")) + stpcpy (c, "@iqtelif"); + else if (GetLocaleInfoW (lcid, LOCALE_SINTLSYMBOL, wbuf, 9) + && !wcsncmp (wbuf, L"EUR", 3)) + stpcpy (c, "@euro"); + else if (!strncmp (loc, "ja_", 3) + || !strncmp (loc, "ko_", 3) + || !strncmp (loc, "zh_", 3)) + stpcpy (c, "@cjknarrow"); + else + continue; + printf ("%-16s %ls (%ls)\n", loc, lang, country); + } + } + } return 0; } if (getlocale (lcid, name))