dnl AM_MULTIBYTE_ABLE version: 8 updated: 2009/12/24 04:20:51
dnl -----------------
dnl
dnl check for required multibyte/widechar functions
dnl Urs Janssen <urs@tin.org> 20021006
dnl Usage: AM_MULTIBYTE_ABLE
AC_DEFUN([AM_MULTIBYTE_ABLE],
[
  AC_CACHE_CHECK([for wide char and multibyte support], am_cv_multibyte_able,
   [AC_TRY_LINK([#include <stdio.h>
#ifdef HAVE_STDLIB_H
#	include <stdlib.h>
#endif /* HAVE_STDLIB_H */
#ifdef HAVE_WCHAR_H
#	include <wchar.h>
#endif /* HAVE_WCHAR_H */
#ifdef HAVE_WCTYPE_H
#	include <wctype.h>
#endif /* HAVE_WCTYPE_H */
],
     [const char icb[5] = {0xa4, 0xa4, 0xa4, 0xe5, 0x00};
      char ocb[5];
      wchar_t wcb[5];
      wchar_t wcb2[5];
      wchar_t format[3];

      putwc(0, 0);
      fputwc(0, 0);
      fwide(0, 0);
      mbtowc(wcb, icb, MB_CUR_MAX);
      mbstowcs(wcb, icb, 5);
      (void) iswalnum((wint_t) wcb[0]);
      (void) iswcntrl((wint_t) wcb[0]);
      (void) iswdigit((wint_t) wcb[0]);
      (void) iswgraph((wint_t) wcb[0]);
      (void) iswprint((wint_t) wcb[0]);
      (void) iswspace((wint_t) wcb[0]);
      (void) towupper((wint_t) wcb[0]);
      /* (void) iswupper((wint_t) wcb[0]); */
      /* (void) towlower((wint_t) wcb[0]); */
      /* (void) iswlower((wint_t) wcb[0]); */
      /* (void) iswalpha((wint_t) wcb[0]); */
      /* (void) iswblank((wint_t) wcb[0]); */
      /* (void) iswpunct((wint_t) wcb[0]); */
      /* (void) iswxdigit((wint_t) wcb[0]); */
      /* (void) iswctype((wint_t) wcb[0], wctype("print")); */
      /* (void) towctranse((wint_t) wcb[0], wctrans("toupper")); */
      (void) wcslen(wcb);
      /* (void) wcsnlen(wcb, 4); */
      wcwidth((wint_t) wcb[0]);
      wcswidth(wcb, 5);
      wcstombs(ocb, wcb, 5);
      wctomb(ocb, wcb[0]);
      wcscat(wcb2, wcb);
      wcscpy(wcb2, wcb);
      mbstowcs(format, "%s", 2);
      swprintf(wcb, 5, format, "test");
      wcsncat(wcb2, wcb, 5);],
     am_cv_multibyte_able=yes,
     [cf_save_LIBS="$LIBS"
      LIBS="-lutf8 $LIBS"
      AC_TRY_LINK([#include <libutf8.h>],
       [const char icb[5] = {0xa4, 0xa4, 0xa4, 0xe5, 0x00};
        char ocb[5];
        wchar_t wcb[5];
        wchar_t wcb2[5];
        wchar_t format[3];

        putwc(0, 0);
        fputwc(0, 0);
        fwide(0, 0);
        mbtowc(wcb, icb, MB_CUR_MAX);
        mbstowcs(wcb, icb, 5);
        (void) iswalnum((wint_t) wcb[0]);
        (void) iswcntrl((wint_t) wcb[0]);
        (void) iswdigit((wint_t) wcb[0]);
        (void) iswgraph((wint_t) wcb[0]);
        (void) iswprint((wint_t) wcb[0]);
        (void) iswspace((wint_t) wcb[0]);
        (void) towupper((wint_t) wcb[0]);
        /* (void) iswupper((wint_t) wcb[0]); */
        /* (void) towlower((wint_t) wcb[0]); */
        /* (void) iswlower((wint_t) wcb[0]); */
        /* (void) iswalpha((wint_t) wcb[0]); */
        /* (void) iswblank((wint_t) wcb[0]); */
        /* (void) iswpunct((wint_t) wcb[0]); */
        /* (void) iswxdigit((wint_t) wcb[0]); */
        /* (void) iswctype((wint_t) wcb[0], wctype("print")); */
        /* (void) towctranse((wint_t) wcb[0], wctrans("toupper")); */
        (void) wcslen(wcb);
        /* (void) wcsnlen(wcb, 4); */
        wcwidth((wint_t) wcb[0]);
        wcswidth(wcb, 5);
        wcstombs(ocb, wcb, 5);
        wctomb(ocb, wcb[0]);
        wcscat(wcb2, wcb);
        wcscpy(wcb2, wcb);
        mbstowcs(format, "%s", 2);
        swprintf(wcb, 5, format, "test");
        wcsncat(wcb2, wcb, 5);],
        [am_cv_multibyte_able=libutf8],
        [am_cv_multibyte_able=no])
      LIBS="$cf_save_LIBS"
   ])
  ])
  if test "$am_cv_multibyte_able" != no; then
    if test "$am_cv_multibyte_able" = libutf8; then
      AC_DEFINE(HAVE_LIBUTF8_H)
      LIBS="-lutf8 $LIBS"
    fi
    AC_DEFINE(MULTIBYTE_ABLE, 1,
      [Define if you have swprintf() and co.])
  fi
])
