]> git.cworth.org Git - tar/blob - m4/locale-ja.m4
Imported Upstream version 1.24
[tar] / m4 / locale-ja.m4
1 # locale-ja.m4 serial 8
2 dnl Copyright (C) 2003, 2005-2010 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 japanese locale with EUC-JP encoding.
10 AC_DEFUN([gt_LOCALE_JA],
11 [
12   AC_REQUIRE([AC_CANONICAL_HOST])
13   AC_REQUIRE([AM_LANGINFO_CODESET])
14   AC_CACHE_CHECK([for a traditional japanese locale], [gt_cv_locale_ja], [
15     AC_LANG_CONFTEST([AC_LANG_SOURCE([
16 changequote(,)dnl
17 #include <locale.h>
18 #include <time.h>
19 #if HAVE_LANGINFO_CODESET
20 # include <langinfo.h>
21 #endif
22 #include <stdlib.h>
23 #include <string.h>
24 struct tm t;
25 char buf[16];
26 int main ()
27 {
28   const char *p;
29   /* Check whether the given locale name is recognized by the system.  */
30   if (setlocale (LC_ALL, "") == NULL) return 1;
31   /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
32      On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
33      is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
34      On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
35      succeeds but then nl_langinfo(CODESET) is "646". In this situation,
36      some unit tests fail.
37      On MirBSD 10, when an unsupported locale is specified, setlocale()
38      succeeds but then nl_langinfo(CODESET) is "UTF-8".  */
39 #if HAVE_LANGINFO_CODESET
40   {
41     const char *cs = nl_langinfo (CODESET);
42     if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0
43         || strcmp (cs, "UTF-8") == 0)
44       return 1;
45   }
46 #endif
47 #ifdef __CYGWIN__
48   /* On Cygwin, avoid locale names without encoding suffix, because the
49      locale_charset() function relies on the encoding suffix.  Note that
50      LC_ALL is set on the command line.  */
51   if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
52 #endif
53   /* Check whether MB_CUR_MAX is > 1.  This excludes the dysfunctional locales
54      on Cygwin 1.5.x.  */
55   if (MB_CUR_MAX == 1)
56     return 1;
57   /* Check whether in a month name, no byte in the range 0x80..0x9F occurs.
58      This excludes the UTF-8 encoding (except on MirBSD).  */
59   t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
60   if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
61   for (p = buf; *p != '\0'; p++)
62     if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
63       return 1;
64   return 0;
65 }
66 changequote([,])dnl
67       ])])
68     if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
69       # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
70       # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
71       # configure script would override the LC_ALL setting. Likewise for
72       # LC_CTYPE, which is also set at the beginning of the configure script.
73       # Test for the AIX locale name.
74       if (LC_ALL=ja_JP LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
75         gt_cv_locale_ja=ja_JP
76       else
77         # Test for the locale name with explicit encoding suffix.
78         if (LC_ALL=ja_JP.EUC-JP LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
79           gt_cv_locale_ja=ja_JP.EUC-JP
80         else
81           # Test for the HP-UX, OSF/1, NetBSD locale name.
82           if (LC_ALL=ja_JP.eucJP LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
83             gt_cv_locale_ja=ja_JP.eucJP
84           else
85             # Test for the IRIX, FreeBSD locale name.
86             if (LC_ALL=ja_JP.EUC LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
87               gt_cv_locale_ja=ja_JP.EUC
88             else
89               # Test for the Solaris 7 locale name.
90               if (LC_ALL=ja LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
91                 gt_cv_locale_ja=ja
92               else
93                 # Special test for NetBSD 1.6.
94                 if test -f /usr/share/locale/ja_JP.eucJP/LC_CTYPE; then
95                   gt_cv_locale_ja=ja_JP.eucJP
96                 else
97                   # None found.
98                   gt_cv_locale_ja=none
99                 fi
100               fi
101             fi
102           fi
103         fi
104       fi
105     fi
106     rm -fr conftest*
107   ])
108   LOCALE_JA=$gt_cv_locale_ja
109   AC_SUBST([LOCALE_JA])
110 ])