locale-zh.m4 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # locale-zh.m4 serial 6
  2. dnl Copyright (C) 2003, 2005-2010 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 (setlocale (LC_ALL, "") == NULL) return 1;
  30. /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
  31. On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
  32. is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
  33. On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
  34. succeeds but then nl_langinfo(CODESET) is "646". In this situation,
  35. some unit tests fail. */
  36. #if HAVE_LANGINFO_CODESET
  37. {
  38. const char *cs = nl_langinfo (CODESET);
  39. if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0)
  40. return 1;
  41. }
  42. #endif
  43. #ifdef __CYGWIN__
  44. /* On Cygwin, avoid locale names without encoding suffix, because the
  45. locale_charset() function relies on the encoding suffix. Note that
  46. LC_ALL is set on the command line. */
  47. if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
  48. #endif
  49. /* Check whether in a month name, no byte in the range 0x80..0x9F occurs.
  50. This excludes the UTF-8 encoding. */
  51. t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
  52. if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
  53. for (p = buf; *p != '\0'; p++)
  54. if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
  55. return 1;
  56. /* Check whether a typical GB18030 multibyte sequence is recognized as a
  57. single wide character. This excludes the GB2312 and GBK encodings. */
  58. if (mblen ("\203\062\332\066", 5) != 4)
  59. return 1;
  60. return 0;
  61. }
  62. changequote([,])dnl
  63. ])])
  64. if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
  65. # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
  66. # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
  67. # configure script would override the LC_ALL setting. Likewise for
  68. # LC_CTYPE, which is also set at the beginning of the configure script.
  69. # Test for the locale name without encoding suffix.
  70. if (LC_ALL=zh_CN LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
  71. gt_cv_locale_zh_CN=zh_CN
  72. else
  73. # Test for the locale name with explicit encoding suffix.
  74. if (LC_ALL=zh_CN.GB18030 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
  75. gt_cv_locale_zh_CN=zh_CN.GB18030
  76. else
  77. # None found.
  78. gt_cv_locale_zh_CN=none
  79. fi
  80. fi
  81. else
  82. # If there was a link error, due to mblen(), the system is so old that
  83. # it certainly doesn't have a chinese locale.
  84. gt_cv_locale_zh_CN=none
  85. fi
  86. rm -fr conftest*
  87. ])
  88. LOCALE_ZH_CN=$gt_cv_locale_zh_CN
  89. AC_SUBST([LOCALE_ZH_CN])
  90. ])