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