3 dnl Copyright (C) 2003, 2005-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
10 dnl Determine the name of a chinese locale with GB18030 encoding.
11 AC_DEFUN_ONCE([gt_LOCALE_ZH_CN],
13 AC_REQUIRE([AC_CANONICAL_HOST])
14 AC_REQUIRE([AM_LANGINFO_CODESET])
15 AC_CACHE_CHECK([for a transitional chinese locale], [gt_cv_locale_zh_CN], [
16 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
20 #if HAVE_LANGINFO_CODESET
21 # include <langinfo.h>
30 /* On BeOS and Haiku, locales are not implemented in libc. Rather, libintl
31 imitates locale dependent behaviour by looking at the environment
32 variables, and all locales use the UTF-8 encoding. */
33 #if defined __BEOS__ || defined __HAIKU__
36 /* Check whether the given locale name is recognized by the system. */
37 # if defined _WIN32 && !defined __CYGWIN__
38 /* On native Windows, setlocale(category, "") looks at the system settings,
39 not at the environment variables. Also, when an encoding suffix such
40 as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE
41 category of the locale to "C". */
42 if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL
43 || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
46 if (setlocale (LC_ALL, "") == NULL) return 1;
48 /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
49 On Mac OS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
50 is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
51 On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
52 succeeds but then nl_langinfo(CODESET) is "646". In this situation,
54 On MirBSD 10, when an unsupported locale is specified, setlocale()
55 succeeds but then nl_langinfo(CODESET) is "UTF-8". */
56 # if HAVE_LANGINFO_CODESET
58 const char *cs = nl_langinfo (CODESET);
59 if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0
60 || strcmp (cs, "UTF-8") == 0)
65 /* On Cygwin, avoid locale names without encoding suffix, because the
66 locale_charset() function relies on the encoding suffix. Note that
67 LC_ALL is set on the command line. */
68 if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
70 /* Check whether in a month name, no byte in the range 0x80..0x9F occurs.
71 This excludes the UTF-8 encoding (except on MirBSD). */
74 t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
75 if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
76 for (p = buf; *p != '\0'; p++)
77 if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
80 /* Check whether a typical GB18030 multibyte sequence is recognized as a
81 single wide character. This excludes the GB2312 and GBK encodings. */
82 if (mblen ("\203\062\332\066", 5) != 4)
84 /* Check whether mbrtowc accept this character one byte at a time.
85 This excludes NetBSD 10.0. */
86 if (sizeof (wchar_t) > 2)
90 memset (&state, 0, sizeof (state));
91 if (!(mbrtowc (&wc, "\203", 1, &state) == (size_t)(-2)
92 && mbrtowc (&wc, "\062", 1, &state) == (size_t)(-2)
93 && mbrtowc (&wc, "\332", 1, &state) == (size_t)(-2)
94 && mbrtowc (&wc, "\066", 1, &state) == 1))
101 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
103 # Handle native Windows specially, because there setlocale() interprets
104 # "ar" as "Arabic" or "Arabic_Saudi Arabia.1256",
105 # "fr" or "fra" as "French" or "French_France.1252",
106 # "ge"(!) or "deu"(!) as "German" or "German_Germany.1252",
107 # "ja" as "Japanese" or "Japanese_Japan.932",
110 # Test for the hypothetical native Windows locale name.
111 if (LC_ALL=Chinese_China.54936 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
112 gt_cv_locale_zh_CN=Chinese_China.54936
115 gt_cv_locale_zh_CN=none
119 # On Solaris 8, the locales zh_CN.GB18030, zh_CN.GBK, zh.GBK are
120 # broken. One witness is the test case in gl_MBRTOWC_SANITYCHECK.
121 # Another witness is that "LC_ALL=zh_CN.GB18030 bash -c true" dumps core.
122 gt_cv_locale_zh_CN=none
125 # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
126 # otherwise on Mac OS X 10.3.5 the LC_TIME=C from the beginning of the
127 # configure script would override the LC_ALL setting. Likewise for
128 # LC_CTYPE, which is also set at the beginning of the configure script.
129 # Test for the locale name without encoding suffix.
130 if (LC_ALL=zh_CN LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
131 gt_cv_locale_zh_CN=zh_CN
133 # Test for the locale name with explicit encoding suffix.
134 if (LC_ALL=zh_CN.GB18030 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
135 gt_cv_locale_zh_CN=zh_CN.GB18030
138 gt_cv_locale_zh_CN=none
144 # If there was a link error, due to mblen(), the system is so old that
145 # it certainly doesn't have a chinese locale.
146 gt_cv_locale_zh_CN=none
150 LOCALE_ZH_CN=$gt_cv_locale_zh_CN
151 case $LOCALE_ZH_CN in #(
152 '' | *[[[:space:]\"\$\'*@<:@]]*)
153 dnl This locale name might cause trouble with sh or make.
154 AC_MSG_WARN([invalid locale "$LOCALE_ZH_CN"; assuming "none"])
157 AC_SUBST([LOCALE_ZH_CN])