locale-zh.m4 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # locale-zh.m4 serial 5
  2. dnl Copyright (C) 2003, 2005-2009 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. macosx=
  14. changequote(,)dnl
  15. case "$host_os" in
  16. darwin[56]*) ;;
  17. darwin*) macosx=yes;;
  18. esac
  19. changequote([,])dnl
  20. if test -n "$macosx"; then
  21. # On Darwin 7 (MacOS X), the libc supports some locales in non-UTF-8
  22. # encodings, but the kernel does not support them. The documentation
  23. # says:
  24. # "... all code that calls BSD system routines should ensure
  25. # that the const *char parameters of these routines are in UTF-8
  26. # encoding. All BSD system functions expect their string
  27. # parameters to be in UTF-8 encoding and nothing else."
  28. # See the comments in config.charset. Therefore we bypass the test.
  29. gt_cv_locale_zh_CN=none
  30. else
  31. AC_LANG_CONFTEST([AC_LANG_SOURCE([
  32. changequote(,)dnl
  33. #include <locale.h>
  34. #include <stdlib.h>
  35. #include <time.h>
  36. #if HAVE_LANGINFO_CODESET
  37. # include <langinfo.h>
  38. #endif
  39. #include <stdlib.h>
  40. #include <string.h>
  41. struct tm t;
  42. char buf[16];
  43. int main ()
  44. {
  45. const char *p;
  46. /* Check whether the given locale name is recognized by the system. */
  47. if (setlocale (LC_ALL, "") == NULL) return 1;
  48. /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
  49. On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
  50. is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
  51. On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
  52. succeeds but then nl_langinfo(CODESET) is "646". In this situation,
  53. some unit tests fail. */
  54. #if HAVE_LANGINFO_CODESET
  55. {
  56. const char *cs = nl_langinfo (CODESET);
  57. if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0)
  58. return 1;
  59. }
  60. #endif
  61. #ifdef __CYGWIN__
  62. /* On Cygwin, avoid locale names without encoding suffix, because the
  63. locale_charset() function relies on the encoding suffix. Note that
  64. LC_ALL is set on the command line. */
  65. if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
  66. #endif
  67. /* Check whether in a month name, no byte in the range 0x80..0x9F occurs.
  68. This excludes the UTF-8 encoding. */
  69. t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
  70. if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
  71. for (p = buf; *p != '\0'; p++)
  72. if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
  73. return 1;
  74. /* Check whether a typical GB18030 multibyte sequence is recognized as a
  75. single wide character. This excludes the GB2312 and GBK encodings. */
  76. if (mblen ("\203\062\332\066", 5) != 4)
  77. return 1;
  78. return 0;
  79. }
  80. changequote([,])dnl
  81. ])])
  82. if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
  83. # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
  84. # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
  85. # configure script would override the LC_ALL setting. Likewise for
  86. # LC_CTYPE, which is also set at the beginning of the configure script.
  87. # Test for the locale name without encoding suffix.
  88. if (LC_ALL=zh_CN LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
  89. gt_cv_locale_zh_CN=zh_CN
  90. else
  91. # Test for the locale name with explicit encoding suffix.
  92. if (LC_ALL=zh_CN.GB18030 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
  93. gt_cv_locale_zh_CN=zh_CN.GB18030
  94. else
  95. # None found.
  96. gt_cv_locale_zh_CN=none
  97. fi
  98. fi
  99. else
  100. # If there was a link error, due to mblen(), the system is so old that
  101. # it certainly doesn't have a chinese locale.
  102. gt_cv_locale_zh_CN=none
  103. fi
  104. rm -fr conftest*
  105. fi
  106. ])
  107. LOCALE_ZH_CN=$gt_cv_locale_zh_CN
  108. AC_SUBST([LOCALE_ZH_CN])
  109. ])