* lib/string_.h (strncasecmp): Fix typo: this macro takes 3
[gnulib.git] / m4 / locale-zh.m4
1 # locale-zh.m4 serial 1
2 dnl Copyright (C) 2003, 2005-2007 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Bruno Haible.
8
9 dnl Determine the name of a chinese locale with GB18030 encoding.
10 AC_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     macosx=
16     case "$host_os" in
17       darwin[56]*) ;;
18       darwin*) macosx=yes;;
19     esac
20     if test -n "$macosx"; then
21       # On Darwin 7 (MacOS X), the libc supports some locales in non-UTF-8
22       # encodings, but the kernel does not support them. The documentation
23       # says:
24       #   "... all code that calls BSD system routines should ensure
25       #    that the const *char parameters of these routines are in UTF-8
26       #    encoding. All BSD system functions expect their string
27       #    parameters to be in UTF-8 encoding and nothing else."
28       # See the comments in config.charset. Therefore we bypass the test.
29       gt_cv_locale_zh_CN=none
30     else
31       AC_LANG_CONFTEST([AC_LANG_SOURCE([
32 changequote(,)dnl
33 #include <locale.h>
34 #include <stdlib.h>
35 #include <time.h>
36 #if HAVE_LANGINFO_CODESET
37 # include <langinfo.h>
38 #endif
39 struct tm t;
40 char buf[16];
41 int main ()
42 {
43   const char *p;
44   /* Check whether the given locale name is recognized by the system.  */
45   if (setlocale (LC_ALL, "") == NULL) return 1;
46   /* Check whether nl_langinfo(CODESET) is nonempty.
47      On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
48      is empty, and the behaviour of Tcl 8.4 in this locale is not useful.  */
49 #if HAVE_LANGINFO_CODESET
50   if (nl_langinfo (CODESET) [0] == '\0') return 1;
51 #endif
52   /* Check whether in a month name, no byte in the range 0x80..0x9F occurs.
53      This excludes the UTF-8 encoding.  */
54   t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
55   if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
56   for (p = buf; *p != '\0'; p++)
57     if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
58       return 1;
59   /* Check whether a typical GB18030 multibyte sequence is recognized as a
60      single wide character.  This excludes the GB2312 and GBK encodings.  */
61   if (mblen ("\203\062\332\066", 5) != 4)
62     return 1;
63   return 0;
64 }
65 changequote([,])dnl
66         ])])
67       if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
68         # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
69         # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
70         # configure script would override the LC_ALL setting. Likewise for
71         # LC_CTYPE, which is also set at the beginning of the configure script.
72         # Test for the locale name without encoding suffix.
73         if (LC_ALL=zh_CN LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
74           gt_cv_locale_zh_CN=zh_CN
75         else
76           # Test for the locale name with explicit encoding suffix.
77           if (LC_ALL=zh_CN.GB18030 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
78             gt_cv_locale_zh_CN=zh_CN.GB18030
79           else
80             # None found.
81             gt_cv_locale_zh_CN=none
82           fi
83         fi
84       else
85         # If there was a link error, due to mblen(), the system is so old that
86         # it certainly doesn't have a chinese locale.
87         gt_cv_locale_zh_CN=none
88       fi
89       rm -fr conftest*
90     fi
91   ])
92   LOCALE_ZH_CN=$gt_cv_locale_zh_CN
93   AC_SUBST([LOCALE_ZH_CN])
94 ])