locale-ja.m4 5.4 KB

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