locale-ja.m4 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # locale-ja.m4 serial 15
  2. dnl Copyright (C) 2003, 2005-2021 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. dnl From Bruno Haible.
  7. dnl Determine the name of a japanese locale with EUC-JP encoding.
  8. AC_DEFUN([gt_LOCALE_JA],
  9. [
  10. AC_REQUIRE([AC_CANONICAL_HOST])
  11. AC_REQUIRE([AM_LANGINFO_CODESET])
  12. AC_CACHE_CHECK([for a traditional japanese locale], [gt_cv_locale_ja], [
  13. AC_LANG_CONFTEST([AC_LANG_SOURCE([[
  14. #include <locale.h>
  15. #include <time.h>
  16. #if HAVE_LANGINFO_CODESET
  17. # include <langinfo.h>
  18. #endif
  19. #include <stdlib.h>
  20. #include <string.h>
  21. struct tm t;
  22. char buf[16];
  23. int main ()
  24. {
  25. /* On BeOS and Haiku, locales are not implemented in libc. Rather, libintl
  26. imitates locale dependent behaviour by looking at the environment
  27. variables, and all locales use the UTF-8 encoding. */
  28. #if defined __BEOS__ || defined __HAIKU__
  29. return 1;
  30. #else
  31. /* Check whether the given locale name is recognized by the system. */
  32. # if defined _WIN32 && !defined __CYGWIN__
  33. /* On native Windows, setlocale(category, "") looks at the system settings,
  34. not at the environment variables. Also, when an encoding suffix such
  35. as ".65001" or ".54936" is specified, it succeeds but sets the LC_CTYPE
  36. category of the locale to "C". */
  37. if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL
  38. || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
  39. return 1;
  40. # else
  41. if (setlocale (LC_ALL, "") == NULL) return 1;
  42. # endif
  43. /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
  44. On Mac OS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
  45. is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
  46. On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
  47. succeeds but then nl_langinfo(CODESET) is "646". In this situation,
  48. some unit tests fail.
  49. On MirBSD 10, when an unsupported locale is specified, setlocale()
  50. succeeds but then nl_langinfo(CODESET) is "UTF-8". */
  51. # if HAVE_LANGINFO_CODESET
  52. {
  53. const char *cs = nl_langinfo (CODESET);
  54. if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0
  55. || strcmp (cs, "UTF-8") == 0)
  56. return 1;
  57. }
  58. # endif
  59. # ifdef __CYGWIN__
  60. /* On Cygwin, avoid locale names without encoding suffix, because the
  61. locale_charset() function relies on the encoding suffix. Note that
  62. LC_ALL is set on the command line. */
  63. if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
  64. # endif
  65. /* Check whether MB_CUR_MAX is > 1. This excludes the dysfunctional locales
  66. on Cygwin 1.5.x. */
  67. if (MB_CUR_MAX == 1)
  68. return 1;
  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). */
  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. }
  79. return 0;
  80. #endif
  81. }
  82. ]])])
  83. if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
  84. case "$host_os" in
  85. # Handle native Windows specially, because there setlocale() interprets
  86. # "ar" as "Arabic" or "Arabic_Saudi Arabia.1256",
  87. # "fr" or "fra" as "French" or "French_France.1252",
  88. # "ge"(!) or "deu"(!) as "German" or "German_Germany.1252",
  89. # "ja" as "Japanese" or "Japanese_Japan.932",
  90. # and similar.
  91. mingw*)
  92. # Note that on native Windows, the Japanese locale is
  93. # Japanese_Japan.932, and CP932 is very different from EUC-JP, so we
  94. # cannot use it here.
  95. gt_cv_locale_ja=none
  96. ;;
  97. *)
  98. # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
  99. # otherwise on Mac OS X 10.3.5 the LC_TIME=C from the beginning of the
  100. # configure script would override the LC_ALL setting. Likewise for
  101. # LC_CTYPE, which is also set at the beginning of the configure script.
  102. # Test for the AIX locale name.
  103. if (LC_ALL=ja_JP LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
  104. gt_cv_locale_ja=ja_JP
  105. else
  106. # Test for the locale name with explicit encoding suffix.
  107. if (LC_ALL=ja_JP.EUC-JP LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
  108. gt_cv_locale_ja=ja_JP.EUC-JP
  109. else
  110. # Test for the HP-UX, OSF/1, NetBSD locale name.
  111. if (LC_ALL=ja_JP.eucJP LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
  112. gt_cv_locale_ja=ja_JP.eucJP
  113. else
  114. # Test for the IRIX, FreeBSD locale name.
  115. if (LC_ALL=ja_JP.EUC LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
  116. gt_cv_locale_ja=ja_JP.EUC
  117. else
  118. # Test for the Solaris 7 locale name.
  119. if (LC_ALL=ja LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
  120. gt_cv_locale_ja=ja
  121. else
  122. # Special test for NetBSD 1.6.
  123. if test -f /usr/share/locale/ja_JP.eucJP/LC_CTYPE; then
  124. gt_cv_locale_ja=ja_JP.eucJP
  125. else
  126. # None found.
  127. gt_cv_locale_ja=none
  128. fi
  129. fi
  130. fi
  131. fi
  132. fi
  133. fi
  134. ;;
  135. esac
  136. fi
  137. rm -fr conftest*
  138. ])
  139. LOCALE_JA=$gt_cv_locale_ja
  140. AC_SUBST([LOCALE_JA])
  141. ])