Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2010-02-10 15:36:29 +0300
committerCorinna Vinschen <corinna@vinschen.de>2010-02-10 15:36:29 +0300
commit96cbb3a380a7eb4a9528945211359eeba37b90b9 (patch)
tree37a8943034f884741aeba98b0edd4d7787bc2596
parent3b994b1249be43cdeeb252982a7cad518e9740ec (diff)
* getlocale.c (main): Revamp -a loop to avoid duplicates and to print
locales with the correct, supported modifiers.
-rw-r--r--winsup/utils/ChangeLog5
-rw-r--r--winsup/utils/getlocale.c92
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 <corinna@vinschen.de>
+
+ * getlocale.c (main): Revamp -a loop to avoid duplicates and to print
+ locales with the correct, supported modifiers.
+
2010-01-25 Corinna Vinschen <corinna@vinschen.de>
* 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 <stdio.h>
#include <getopt.h>
#include <string.h>
+#include <wchar.h>
#include <locale.h>
#define WINVER 0x0601
#include <windows.h>
@@ -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))