locale-zh.m4 5.4 KB

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