Debian Codegraph @

m4/locale-zh.m4

raw
1 # locale-zh.m4
2 # serial 20
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.
7 dnl This file is offered as-is, without any warranty.
8
9 dnl From Bruno Haible.
10
11 dnl Determine the name of a chinese locale with GB18030 encoding.
12 AC_DEFUN_ONCE([gt_LOCALE_ZH_CN],
13 [
14 AC_REQUIRE([AC_CANONICAL_HOST])
15 AC_REQUIRE([AM_LANGINFO_CODESET])
16 AC_CACHE_CHECK([for a transitional chinese locale], [gt_cv_locale_zh_CN], [
17 AC_LANG_CONFTEST([AC_LANG_SOURCE([[
18 #include <locale.h>
19 #include <stdlib.h>
20 #include <time.h>
21 #if HAVE_LANGINFO_CODESET
22 # include <langinfo.h>
23 #endif
24 #include <stdlib.h>
25 #include <string.h>
26 #include <wchar.h>
27 struct tm t;
28 char buf[16];
29 int main ()
30 {
31 /* On BeOS and Haiku, locales are not implemented in libc. Rather, libintl
32 imitates locale dependent behaviour by looking at the environment
33 variables, and all locales use the UTF-8 encoding. */
34 #if defined __BEOS__ || defined __HAIKU__
35 return 1;
36 #else
37 /* Check whether the given locale name is recognized by the system. */
38 # if defined _WIN32 && !defined __CYGWIN__
39 /* On native Windows, setlocale(category, "") looks at the system settings,
40 not at the environment variables. Also, when an encoding suffix such
41 as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE
42 category of the locale to "C". */
43 if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL
44 || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
45 return 1;
46 # else
47 if (setlocale (LC_ALL, "") == NULL) return 1;
48 # endif
49 /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
50 On Mac OS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
51 is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
52 On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
53 succeeds but then nl_langinfo(CODESET) is "646". In this situation,
54 some unit tests fail.
55 On MirBSD 10, when an unsupported locale is specified, setlocale()
56 succeeds but then nl_langinfo(CODESET) is "UTF-8". */
57 # if HAVE_LANGINFO_CODESET
58 {
59 const char *cs = nl_langinfo (CODESET);
60 if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0
61 || strcmp (cs, "UTF-8") == 0)
62 return 1;
63 }
64 # endif
65 # ifdef __CYGWIN__
66 /* On Cygwin, avoid locale names without encoding suffix, because the
67 locale_charset() function relies on the encoding suffix. Note that
68 LC_ALL is set on the command line. */
69 if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
70 # endif
71 /* Check whether in a month name, no byte in the range 0x80..0x9F occurs.
72 This excludes the UTF-8 encoding (except on MirBSD). */
73 {
74 const char *p;
75 t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
76 if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
77 for (p = buf; *p != '\0'; p++)
78 if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
79 return 1;
80 }
81 /* Check whether a typical GB18030 multibyte sequence is recognized as a
82 single wide character. This excludes the GB2312 and GBK encodings. */
83 if (mblen ("\203\062\332\066", 5) != 4)
84 return 1;
85 /* Check whether mbrtowc accept this character one byte at a time.
86 This excludes NetBSD 10.0. */
87 if (sizeof (wchar_t) > 2)
88 {
89 wchar_t wc;
90 mbstate_t state;
91 memset (&state, 0, sizeof (state));
92 if (!(mbrtowc (&wc, "\203", 1, &state) == (size_t)(-2)
93 && mbrtowc (&wc, "\062", 1, &state) == (size_t)(-2)
94 && mbrtowc (&wc, "\332", 1, &state) == (size_t)(-2)
95 && mbrtowc (&wc, "\066", 1, &state) == 1))
96 return 1;
97 }
98 return 0;
99 #endif
100 }
101 ]])])
102 if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
103 case "$host_os" in
104 # Handle native Windows specially, because there setlocale() interprets
105 # "ar" or "ara" as "Arabic" or "Arabic_Saudi Arabia.1256",
106 # "en" or "eng" as "English" or "English_United States.1252",
107 # "fr" or "fra" as "French" or "French_France.1252",
108 # "ge"(!) or "deu"(!) as "German" or "German_Germany.1252",
109 # "ja" or "jpn" as "Japanese" or "Japanese_Japan.932",
110 # and similar.
111 mingw* | windows*)
112 # Test for the hypothetical native Windows locale name.
113 if (LC_ALL=Chinese_China.54936 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
114 gt_cv_locale_zh_CN=Chinese_China.54936
115 else
116 # None found.
117 gt_cv_locale_zh_CN=none
118 fi
119 ;;
120 solaris2.8)
121 # On Solaris 8, the locales zh_CN.GB18030, zh_CN.GBK, zh.GBK are
122 # broken. One witness is the test case in gl_MBRTOWC_SANITYCHECK.
123 # Another witness is that "LC_ALL=zh_CN.GB18030 bash -c true" dumps core.
124 gt_cv_locale_zh_CN=none
125 ;;
126 *)
127 # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
128 # otherwise on Mac OS X 10.3.5 the LC_TIME=C from the beginning of the
129 # configure script would override the LC_ALL setting. Likewise for
130 # LC_CTYPE, which is also set at the beginning of the configure script.
131 # Test for the locale name without encoding suffix.
132 if (LC_ALL=zh_CN LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
133 gt_cv_locale_zh_CN=zh_CN
134 else
135 # Test for the locale name with explicit encoding suffix.
136 if (LC_ALL=zh_CN.GB18030 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
137 gt_cv_locale_zh_CN=zh_CN.GB18030
138 else
139 # None found.
140 gt_cv_locale_zh_CN=none
141 fi
142 fi
143 ;;
144 esac
145 else
146 # If there was a link error, due to mblen(), the system is so old that
147 # it certainly doesn't have a chinese locale.
148 gt_cv_locale_zh_CN=none
149 fi
150 rm -fr conftest*
151 ])
152 LOCALE_ZH_CN=$gt_cv_locale_zh_CN
153 case $LOCALE_ZH_CN in #(
154 '' | *[[[:space:]\"\$\'*@<:@]]*)
155 dnl This locale name might cause trouble with sh or make.
156 AC_MSG_WARN([invalid locale "$LOCALE_ZH_CN"; assuming "none"])
157 LOCALE_ZH_CN=none;;
158 esac
159 AC_SUBST([LOCALE_ZH_CN])
160 ])