locale-zh.m4 5.1 KB

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