guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: git head fails to build


From: Ludovic Courtès
Subject: Re: git head fails to build
Date: Wed, 14 Jan 2009 22:30:21 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux)

Hello Neil,

I've been working on this in parallel, so I thought it'd be better to
get in sync.  ;-)

I had (hopefully) fixed the problem by reverting your commits in reverse
order and starting anew (attached patch).  The problem is that commit
4a462e35440fdc3f10b0f88b3fb737fa76ed146d touches way too many files: it
adds generated `.h' files (which is boring since they then have to be
removed before one can `pull' or `checkout'), it modifies
`m4/.gitignore' (which we don't want precisely because we commit
Gnulib's M4 files), it adds `lib/.gitignore', it modifies `INSTALL',
etc.

I find it tricky to update Gnulib files since we store them in the repo.
It's easy when one doesn't store them in the repository because it
updates `.gitignore', etc., but it gets harder when one stores them in
the repo.  We should use "gnulib-update --no-vc-files" actually (info
"(gnulib) VCS Issues"), but we still have to make sure we don't commit
generated files.

Thanks,
Ludo'.

>From 96de7d124652bcbba7a0654ee750c117ea02102e Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Ludovic=20Court=C3=A8s?= <address@hidden>
Date: Wed, 14 Jan 2009 22:14:40 +0100
Subject: [PATCH] Use Gnulib's `alloca-opt' module.

This commit is a repetition of 4a462e35440fdc3f10b0f88b3fb737fa76ed146d
("Make sure that we have a real on-the-stack alloca()") but it doesn't
add/modify unnecessary files (generated `.h' files, etc.).

Gnulib files come from Gnulib commit 9c975b1969d7103da881b81e29381c7586c3f968,
dated Jan. 14th, 2009.

* m4/gnulib-cache.m4 (gl_MODULES): Add `alloca-opt'.
---
 lib/Makefile.am     |  197 +++++++++++++++++++--
 lib/alloca.c        |  489 ---------------------------------------------------
 lib/strftime.c      |    9 +-
 lib/unistd.in.h     |    1 +
 lib/wchar.in.h      |  191 ++++++++++++++++++++
 m4/alloca.m4        |    6 +-
 m4/codeset.m4       |   21 +++
 m4/extensions.m4    |   14 ++-
 m4/glibc21.m4       |   30 +++
 m4/gnulib-cache.m4  |    6 +-
 m4/gnulib-common.m4 |    6 +-
 m4/gnulib-comp.m4   |   34 +++-
 m4/inline.m4        |    6 +-
 m4/localcharset.m4  |   16 ++
 m4/locale-fr.m4     |  204 +++++++++++++++++++++
 m4/locale-ja.m4     |  126 +++++++++++++
 m4/locale-zh.m4     |  111 ++++++++++++
 m4/mbrlen.m4        |  197 +++++++++++++++++++++
 m4/mbrtowc.m4       |  325 ++++++++++++++++++++++++++++++++++
 m4/mbsinit.m4       |   30 +++
 m4/mbstate_t.m4     |   16 +-
 m4/stdbool.m4       |    4 +-
 m4/strcase.m4       |   10 +-
 m4/strftime.m4      |    8 +-
 m4/tm_gmtoff.m4     |    6 +-
 m4/wchar.m4         |   34 ++++-
 m4/wint_t.m4        |   10 +-
 27 files changed, 1549 insertions(+), 558 deletions(-)
 delete mode 100644 lib/alloca.c
 create mode 100644 m4/codeset.m4
 create mode 100644 m4/glibc21.m4
 create mode 100644 m4/localcharset.m4
 create mode 100644 m4/locale-fr.m4
 create mode 100644 m4/locale-ja.m4
 create mode 100644 m4/locale-zh.m4
 create mode 100644 m4/mbrlen.m4
 create mode 100644 m4/mbrtowc.m4
 create mode 100644 m4/mbsinit.m4

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 9d47816..c7a2726 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,6 +1,6 @@
 ## DO NOT EDIT! GENERATED AUTOMATICALLY!
 ## Process this file with automake to produce Makefile.in.
-# Copyright (C) 2002-2008 Free Software Foundation, Inc.
+# Copyright (C) 2002-2009 Free Software Foundation, Inc.
 #
 # This file is free software, distributed under the terms of the GNU
 # General Public License.  As a special exception to the GNU General
@@ -9,7 +9,7 @@
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib 
--m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --lgpl 
--libtool --macro-prefix=gl alloca autobuild count-one-bits extensions 
full-read full-write strcase strftime
+# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib 
--m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --lgpl 
--libtool --macro-prefix=gl alloca-opt autobuild count-one-bits extensions 
full-read full-write strcase strftime
 
 AUTOMAKE_OPTIONS = 1.5 gnits
 
@@ -36,17 +36,6 @@ libgnu_la_DEPENDENCIES = $(gl_LTLIBOBJS)
 EXTRA_libgnu_la_SOURCES =
 libgnu_la_LDFLAGS = $(AM_LDFLAGS)
 
-## begin gnulib module alloca
-
-
-EXTRA_DIST += alloca.c
-
-EXTRA_libgnu_la_SOURCES += alloca.c
-
-libgnu_la_LIBADD += @LTALLOCA@
-libgnu_la_DEPENDENCIES += @LTALLOCA@
-## end   gnulib module alloca
-
 ## begin gnulib module alloca-opt
 
 BUILT_SOURCES += $(ALLOCA_H)
@@ -64,6 +53,62 @@ EXTRA_DIST += alloca.in.h
 
 ## end   gnulib module alloca-opt
 
+## begin gnulib module configmake
+
+# Retrieve values of the variables through 'configure' followed by
+# 'make', not directly through 'configure', so that a user who
+# sets some of these variables consistently on the 'make' command
+# line gets correct results.
+#
+# One advantage of this approach, compared to the classical
+# approach of adding -DLIBDIR=\"$(libdir)\" etc. to AM_CPPFLAGS,
+# is that it protects against the use of undefined variables.
+# If, say, $(libdir) is not set in the Makefile, LIBDIR is not
+# defined by this module, and code using LIBDIR gives a
+# compilation error.
+#
+# Another advantage is that 'make' output is shorter.
+#
+# Listed in the same order as the GNU makefile conventions.
+# The Automake-defined pkg* macros are appended, in the order
+# listed in the Automake 1.10a+ documentation.
+configmake.h: Makefile
+       rm -f address@hidden $@
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         echo '#define PREFIX "$(prefix)"'; \
+         echo '#define EXEC_PREFIX "$(exec_prefix)"'; \
+         echo '#define BINDIR "$(bindir)"'; \
+         echo '#define SBINDIR "$(sbindir)"'; \
+         echo '#define LIBEXECDIR "$(libexecdir)"'; \
+         echo '#define DATAROOTDIR "$(datarootdir)"'; \
+         echo '#define DATADIR "$(datadir)"'; \
+         echo '#define SYSCONFDIR "$(sysconfdir)"'; \
+         echo '#define SHAREDSTATEDIR "$(sharedstatedir)"'; \
+         echo '#define LOCALSTATEDIR "$(localstatedir)"'; \
+         echo '#define INCLUDEDIR "$(includedir)"'; \
+         echo '#define OLDINCLUDEDIR "$(oldincludedir)"'; \
+         echo '#define DOCDIR "$(docdir)"'; \
+         echo '#define INFODIR "$(infodir)"'; \
+         echo '#define HTMLDIR "$(htmldir)"'; \
+         echo '#define DVIDIR "$(dvidir)"'; \
+         echo '#define PDFDIR "$(pdfdir)"'; \
+         echo '#define PSDIR "$(psdir)"'; \
+         echo '#define LIBDIR "$(libdir)"'; \
+         echo '#define LISPDIR "$(lispdir)"'; \
+         echo '#define LOCALEDIR "$(localedir)"'; \
+         echo '#define MANDIR "$(mandir)"'; \
+         echo '#define MANEXT "$(manext)"'; \
+         echo '#define PKGDATADIR "$(pkgdatadir)"'; \
+         echo '#define PKGINCLUDEDIR "$(pkgincludedir)"'; \
+         echo '#define PKGLIBDIR "$(pkglibdir)"'; \
+         echo '#define PKGLIBEXECDIR "$(pkglibexecdir)"'; \
+       } | sed '/""/d' > address@hidden
+       mv address@hidden $@
+BUILT_SOURCES += configmake.h
+CLEANFILES += configmake.h configmake.h-t
+
+## end   gnulib module configmake
+
 ## begin gnulib module count-one-bits
 
 
@@ -91,6 +136,91 @@ EXTRA_DIST += $(top_srcdir)/build-aux/link-warning.h
 
 ## end   gnulib module link-warning
 
+## begin gnulib module localcharset
+
+libgnu_la_SOURCES += localcharset.h localcharset.c
+
+# We need the following in order to install a simple file in $(libdir)
+# which is shared with other installed packages. We use a list of referencing
+# packages so that "make uninstall" will remove the file if and only if it
+# is not used by another installed package.
+# On systems with glibc-2.1 or newer, the file is redundant, therefore we
+# avoid installing it.
+
+all-local: charset.alias ref-add.sed ref-del.sed
+
+charset_alias = $(DESTDIR)$(libdir)/charset.alias
+charset_tmp = $(DESTDIR)$(libdir)/charset.tmp
+install-exec-local: all-local
+       test $(GLIBC21) != no || $(mkinstalldirs) $(DESTDIR)$(libdir)
+       if test -f $(charset_alias); then \
+         sed -f ref-add.sed $(charset_alias) > $(charset_tmp) ; \
+         $(INSTALL_DATA) $(charset_tmp) $(charset_alias) ; \
+         rm -f $(charset_tmp) ; \
+       else \
+         if test $(GLIBC21) = no; then \
+           sed -f ref-add.sed charset.alias > $(charset_tmp) ; \
+           $(INSTALL_DATA) $(charset_tmp) $(charset_alias) ; \
+           rm -f $(charset_tmp) ; \
+         fi ; \
+       fi
+
+uninstall-local: all-local
+       if test -f $(charset_alias); then \
+         sed -f ref-del.sed $(charset_alias) > $(charset_tmp); \
+         if grep '^# Packages using this file: $$' $(charset_tmp) \
+             > /dev/null; then \
+           rm -f $(charset_alias); \
+         else \
+           $(INSTALL_DATA) $(charset_tmp) $(charset_alias); \
+         fi; \
+         rm -f $(charset_tmp); \
+       fi
+
+charset.alias: config.charset
+       rm -f t-$@ $@
+       $(SHELL) $(srcdir)/config.charset '$(host)' > t-$@
+       mv t-$@ $@
+
+SUFFIXES += .sed .sin
+.sin.sed:
+       rm -f t-$@ $@
+       sed -e '/^#/d' -e 's/@''PACKAGE''@/$(PACKAGE)/g' $< > t-$@
+       mv t-$@ $@
+
+CLEANFILES += charset.alias ref-add.sed ref-del.sed
+
+EXTRA_DIST += config.charset ref-add.sin ref-del.sin
+
+## end   gnulib module localcharset
+
+## begin gnulib module mbrlen
+
+
+EXTRA_DIST += mbrlen.c
+
+EXTRA_libgnu_la_SOURCES += mbrlen.c
+
+## end   gnulib module mbrlen
+
+## begin gnulib module mbrtowc
+
+
+EXTRA_DIST += mbrtowc.c
+
+EXTRA_libgnu_la_SOURCES += mbrtowc.c
+
+## end   gnulib module mbrtowc
+
+## begin gnulib module mbsinit
+
+
+EXTRA_DIST += mbsinit.c
+
+EXTRA_libgnu_la_SOURCES += mbsinit.c
+
+## end   gnulib module mbsinit
+
 ## begin gnulib module safe-read
 
 
@@ -136,6 +266,13 @@ EXTRA_libgnu_la_SOURCES += strcasecmp.c strncasecmp.c
 
 ## end   gnulib module strcase
 
+## begin gnulib module streq
+
+
+EXTRA_DIST += streq.h
+
+## end   gnulib module streq
+
 ## begin gnulib module strftime
 
 
@@ -291,10 +428,40 @@ wchar.h: wchar.in.h
          sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''NEXT_WCHAR_H''@|$(NEXT_WCHAR_H)|g' \
-             -e 's/@''HAVE_WCHAR_H''@/$(HAVE_WCHAR_H)/g' \
+             -e 's|@''HAVE_WCHAR_H''@|$(HAVE_WCHAR_H)|g' \
+             -e 's|@''GNULIB_BTOWC''@|$(GNULIB_BTOWC)|g' \
+             -e 's|@''GNULIB_WCTOB''@|$(GNULIB_WCTOB)|g' \
+             -e 's|@''GNULIB_MBSINIT''@|$(GNULIB_MBSINIT)|g' \
+             -e 's|@''GNULIB_MBRTOWC''@|$(GNULIB_MBRTOWC)|g' \
+             -e 's|@''GNULIB_MBRLEN''@|$(GNULIB_MBRLEN)|g' \
+             -e 's|@''GNULIB_MBSRTOWCS''@|$(GNULIB_MBSRTOWCS)|g' \
+             -e 's|@''GNULIB_MBSNRTOWCS''@|$(GNULIB_MBSNRTOWCS)|g' \
+             -e 's|@''GNULIB_WCRTOMB''@|$(GNULIB_WCRTOMB)|g' \
+             -e 's|@''GNULIB_WCSRTOMBS''@|$(GNULIB_WCSRTOMBS)|g' \
+             -e 's|@''GNULIB_WCSNRTOMBS''@|$(GNULIB_WCSNRTOMBS)|g' \
              -e 's|@''GNULIB_WCWIDTH''@|$(GNULIB_WCWIDTH)|g' \
-             -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \
+             -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \
+             -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \
+             -e 's|@''HAVE_MBSINIT''@|$(HAVE_MBSINIT)|g' \
+             -e 's|@''HAVE_MBRTOWC''@|$(HAVE_MBRTOWC)|g' \
+             -e 's|@''HAVE_MBRLEN''@|$(HAVE_MBRLEN)|g' \
+             -e 's|@''HAVE_MBSRTOWCS''@|$(HAVE_MBSRTOWCS)|g' \
+             -e 's|@''HAVE_MBSNRTOWCS''@|$(HAVE_MBSNRTOWCS)|g' \
+             -e 's|@''HAVE_WCRTOMB''@|$(HAVE_WCRTOMB)|g' \
+             -e 's|@''HAVE_WCSRTOMBS''@|$(HAVE_WCSRTOMBS)|g' \
+             -e 's|@''HAVE_WCSNRTOMBS''@|$(HAVE_WCSNRTOMBS)|g' \
+             -e 's|@''HAVE_DECL_WCTOB''@|$(HAVE_DECL_WCTOB)|g' \
              -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \
+             -e 's|@''REPLACE_MBSTATE_T''@|$(REPLACE_MBSTATE_T)|g' \
+             -e 's|@''REPLACE_BTOWC''@|$(REPLACE_BTOWC)|g' \
+             -e 's|@''REPLACE_WCTOB''@|$(REPLACE_WCTOB)|g' \
+             -e 's|@''REPLACE_MBSINIT''@|$(REPLACE_MBSINIT)|g' \
+             -e 's|@''REPLACE_MBRTOWC''@|$(REPLACE_MBRTOWC)|g' \
+             -e 's|@''REPLACE_MBRLEN''@|$(REPLACE_MBRLEN)|g' \
+             -e 's|@''REPLACE_MBSRTOWCS''@|$(REPLACE_MBSRTOWCS)|g' \
+             -e 's|@''REPLACE_MBSNRTOWCS''@|$(REPLACE_MBSNRTOWCS)|g' \
+             -e 's|@''REPLACE_WCRTOMB''@|$(REPLACE_WCRTOMB)|g' \
+             -e 's|@''REPLACE_WCSRTOMBS''@|$(REPLACE_WCSRTOMBS)|g' \
              -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \
              -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
            < $(srcdir)/wchar.in.h; \
diff --git a/lib/alloca.c b/lib/alloca.c
deleted file mode 100644
index 3a1f4e2..0000000
--- a/lib/alloca.c
+++ /dev/null
@@ -1,489 +0,0 @@
-/* alloca.c -- allocate automatically reclaimed memory
-   (Mostly) portable public-domain implementation -- D A Gwyn
-
-   This implementation of the PWB library alloca function,
-   which is used to allocate space off the run-time stack so
-   that it is automatically reclaimed upon procedure exit,
-   was inspired by discussions with J. Q. Johnson of Cornell.
-   J.Otto Tennant <address@hidden> contributed the Cray support.
-
-   There are some preprocessor constants that can
-   be defined when compiling for your specific system, for
-   improved efficiency; however, the defaults should be okay.
-
-   The general concept of this implementation is to keep
-   track of all alloca-allocated blocks, and reclaim any
-   that are found to be deeper in the stack than the current
-   invocation.  This heuristic does not reclaim storage as
-   soon as it becomes invalid, but it will do so eventually.
-
-   As a special case, alloca(0) reclaims storage without
-   allocating any.  It is a good idea to use alloca(0) in
-   your main control loop, etc. to force garbage collection.  */
-
-#include <config.h>
-
-#include <alloca.h>
-
-#include <string.h>
-#include <stdlib.h>
-
-#ifdef emacs
-# include "lisp.h"
-# include "blockinput.h"
-# ifdef EMACS_FREE
-#  undef free
-#  define free EMACS_FREE
-# endif
-#else
-# define memory_full() abort ()
-#endif
-
-/* If compiling with GCC 2, this file's not needed.  */
-#if !defined (__GNUC__) || __GNUC__ < 2
-
-/* If someone has defined alloca as a macro,
-   there must be some other way alloca is supposed to work.  */
-# ifndef alloca
-
-#  ifdef emacs
-#   ifdef static
-/* actually, only want this if static is defined as ""
-   -- this is for usg, in which emacs must undefine static
-   in order to make unexec workable
-   */
-#    ifndef STACK_DIRECTION
-you
-lose
--- must know STACK_DIRECTION at compile-time
-/* Using #error here is not wise since this file should work for
-   old and obscure compilers.  */
-#    endif /* STACK_DIRECTION undefined */
-#   endif /* static */
-#  endif /* emacs */
-
-/* If your stack is a linked list of frames, you have to
-   provide an "address metric" ADDRESS_FUNCTION macro.  */
-
-#  if defined (CRAY) && defined (CRAY_STACKSEG_END)
-long i00afunc ();
-#   define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
-#  else
-#   define ADDRESS_FUNCTION(arg) &(arg)
-#  endif
-
-/* Define STACK_DIRECTION if you know the direction of stack
-   growth for your system; otherwise it will be automatically
-   deduced at run-time.
-
-   STACK_DIRECTION > 0 => grows toward higher addresses
-   STACK_DIRECTION < 0 => grows toward lower addresses
-   STACK_DIRECTION = 0 => direction of growth unknown  */
-
-#  ifndef STACK_DIRECTION
-#   define STACK_DIRECTION     0       /* Direction unknown.  */
-#  endif
-
-#  if STACK_DIRECTION != 0
-
-#   define STACK_DIR   STACK_DIRECTION /* Known at compile-time.  */
-
-#  else /* STACK_DIRECTION == 0; need run-time code.  */
-
-static int stack_dir;          /* 1 or -1 once known.  */
-#   define STACK_DIR   stack_dir
-
-static void
-find_stack_direction (void)
-{
-  static char *addr = NULL;    /* Address of first `dummy', once known.  */
-  auto char dummy;             /* To get stack address.  */
-
-  if (addr == NULL)
-    {                          /* Initial entry.  */
-      addr = ADDRESS_FUNCTION (dummy);
-
-      find_stack_direction (); /* Recurse once.  */
-    }
-  else
-    {
-      /* Second entry.  */
-      if (ADDRESS_FUNCTION (dummy) > addr)
-       stack_dir = 1;          /* Stack grew upward.  */
-      else
-       stack_dir = -1;         /* Stack grew downward.  */
-    }
-}
-
-#  endif /* STACK_DIRECTION == 0 */
-
-/* An "alloca header" is used to:
-   (a) chain together all alloca'ed blocks;
-   (b) keep track of stack depth.
-
-   It is very important that sizeof(header) agree with malloc
-   alignment chunk size.  The following default should work okay.  */
-
-#  ifndef      ALIGN_SIZE
-#   define ALIGN_SIZE  sizeof(double)
-#  endif
-
-typedef union hdr
-{
-  char align[ALIGN_SIZE];      /* To force sizeof(header).  */
-  struct
-    {
-      union hdr *next;         /* For chaining headers.  */
-      char *deep;              /* For stack depth measure.  */
-    } h;
-} header;
-
-static header *last_alloca_header = NULL;      /* -> last alloca header.  */
-
-/* Return a pointer to at least SIZE bytes of storage,
-   which will be automatically reclaimed upon exit from
-   the procedure that called alloca.  Originally, this space
-   was supposed to be taken from the current stack frame of the
-   caller, but that method cannot be made to work for some
-   implementations of C, for example under Gould's UTX/32.  */
-
-void *
-alloca (size_t size)
-{
-  auto char probe;             /* Probes stack depth: */
-  register char *depth = ADDRESS_FUNCTION (probe);
-
-#  if STACK_DIRECTION == 0
-  if (STACK_DIR == 0)          /* Unknown growth direction.  */
-    find_stack_direction ();
-#  endif
-
-  /* Reclaim garbage, defined as all alloca'd storage that
-     was allocated from deeper in the stack than currently.  */
-
-  {
-    register header *hp;       /* Traverses linked list.  */
-
-#  ifdef emacs
-    BLOCK_INPUT;
-#  endif
-
-    for (hp = last_alloca_header; hp != NULL;)
-      if ((STACK_DIR > 0 && hp->h.deep > depth)
-         || (STACK_DIR < 0 && hp->h.deep < depth))
-       {
-         register header *np = hp->h.next;
-
-         free (hp);            /* Collect garbage.  */
-
-         hp = np;              /* -> next header.  */
-       }
-      else
-       break;                  /* Rest are not deeper.  */
-
-    last_alloca_header = hp;   /* -> last valid storage.  */
-
-#  ifdef emacs
-    UNBLOCK_INPUT;
-#  endif
-  }
-
-  if (size == 0)
-    return NULL;               /* No allocation required.  */
-
-  /* Allocate combined header + user data storage.  */
-
-  {
-    /* Address of header.  */
-    register header *new;
-
-    size_t combined_size = sizeof (header) + size;
-    if (combined_size < sizeof (header))
-      memory_full ();
-
-    new = malloc (combined_size);
-
-    if (! new)
-      memory_full ();
-
-    new->h.next = last_alloca_header;
-    new->h.deep = depth;
-
-    last_alloca_header = new;
-
-    /* User storage begins just after header.  */
-
-    return (void *) (new + 1);
-  }
-}
-
-#  if defined (CRAY) && defined (CRAY_STACKSEG_END)
-
-#   ifdef DEBUG_I00AFUNC
-#    include <stdio.h>
-#   endif
-
-#   ifndef CRAY_STACK
-#    define CRAY_STACK
-#    ifndef CRAY2
-/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
-struct stack_control_header
-  {
-    long shgrow:32;            /* Number of times stack has grown.  */
-    long shaseg:32;            /* Size of increments to stack.  */
-    long shhwm:32;             /* High water mark of stack.  */
-    long shsize:32;            /* Current size of stack (all segments).  */
-  };
-
-/* The stack segment linkage control information occurs at
-   the high-address end of a stack segment.  (The stack
-   grows from low addresses to high addresses.)  The initial
-   part of the stack segment linkage control information is
-   0200 (octal) words.  This provides for register storage
-   for the routine which overflows the stack.  */
-
-struct stack_segment_linkage
-  {
-    long ss[0200];             /* 0200 overflow words.  */
-    long sssize:32;            /* Number of words in this segment.  */
-    long ssbase:32;            /* Offset to stack base.  */
-    long:32;
-    long sspseg:32;            /* Offset to linkage control of previous
-                                  segment of stack.  */
-    long:32;
-    long sstcpt:32;            /* Pointer to task common address block.  */
-    long sscsnm;               /* Private control structure number for
-                                  microtasking.  */
-    long ssusr1;               /* Reserved for user.  */
-    long ssusr2;               /* Reserved for user.  */
-    long sstpid;               /* Process ID for pid based multi-tasking.  */
-    long ssgvup;               /* Pointer to multitasking thread giveup.  */
-    long sscray[7];            /* Reserved for Cray Research.  */
-    long ssa0;
-    long ssa1;
-    long ssa2;
-    long ssa3;
-    long ssa4;
-    long ssa5;
-    long ssa6;
-    long ssa7;
-    long sss0;
-    long sss1;
-    long sss2;
-    long sss3;
-    long sss4;
-    long sss5;
-    long sss6;
-    long sss7;
-  };
-
-#    else /* CRAY2 */
-/* The following structure defines the vector of words
-   returned by the STKSTAT library routine.  */
-struct stk_stat
-  {
-    long now;                  /* Current total stack size.  */
-    long maxc;                 /* Amount of contiguous space which would
-                                  be required to satisfy the maximum
-                                  stack demand to date.  */
-    long high_water;           /* Stack high-water mark.  */
-    long overflows;            /* Number of stack overflow ($STKOFEN) calls.  
*/
-    long hits;                 /* Number of internal buffer hits.  */
-    long extends;              /* Number of block extensions.  */
-    long stko_mallocs;         /* Block allocations by $STKOFEN.  */
-    long underflows;           /* Number of stack underflow calls ($STKRETN).  
*/
-    long stko_free;            /* Number of deallocations by $STKRETN.  */
-    long stkm_free;            /* Number of deallocations by $STKMRET.  */
-    long segments;             /* Current number of stack segments.  */
-    long maxs;                 /* Maximum number of stack segments so far.  */
-    long pad_size;             /* Stack pad size.  */
-    long current_address;      /* Current stack segment address.  */
-    long current_size;         /* Current stack segment size.  This
-                                  number is actually corrupted by STKSTAT to
-                                  include the fifteen word trailer area.  */
-    long initial_address;      /* Address of initial segment.  */
-    long initial_size;         /* Size of initial segment.  */
-  };
-
-/* The following structure describes the data structure which trails
-   any stack segment.  I think that the description in 'asdef' is
-   out of date.  I only describe the parts that I am sure about.  */
-
-struct stk_trailer
-  {
-    long this_address;         /* Address of this block.  */
-    long this_size;            /* Size of this block (does not include
-                                  this trailer).  */
-    long unknown2;
-    long unknown3;
-    long link;                 /* Address of trailer block of previous
-                                  segment.  */
-    long unknown5;
-    long unknown6;
-    long unknown7;
-    long unknown8;
-    long unknown9;
-    long unknown10;
-    long unknown11;
-    long unknown12;
-    long unknown13;
-    long unknown14;
-  };
-
-#    endif /* CRAY2 */
-#   endif /* not CRAY_STACK */
-
-#   ifdef CRAY2
-/* Determine a "stack measure" for an arbitrary ADDRESS.
-   I doubt that "lint" will like this much.  */
-
-static long
-i00afunc (long *address)
-{
-  struct stk_stat status;
-  struct stk_trailer *trailer;
-  long *block, size;
-  long result = 0;
-
-  /* We want to iterate through all of the segments.  The first
-     step is to get the stack status structure.  We could do this
-     more quickly and more directly, perhaps, by referencing the
-     $LM00 common block, but I know that this works.  */
-
-  STKSTAT (&status);
-
-  /* Set up the iteration.  */
-
-  trailer = (struct stk_trailer *) (status.current_address
-                                   + status.current_size
-                                   - 15);
-
-  /* There must be at least one stack segment.  Therefore it is
-     a fatal error if "trailer" is null.  */
-
-  if (trailer == 0)
-    abort ();
-
-  /* Discard segments that do not contain our argument address.  */
-
-  while (trailer != 0)
-    {
-      block = (long *) trailer->this_address;
-      size = trailer->this_size;
-      if (block == 0 || size == 0)
-       abort ();
-      trailer = (struct stk_trailer *) trailer->link;
-      if ((block <= address) && (address < (block + size)))
-       break;
-    }
-
-  /* Set the result to the offset in this segment and add the sizes
-     of all predecessor segments.  */
-
-  result = address - block;
-
-  if (trailer == 0)
-    {
-      return result;
-    }
-
-  do
-    {
-      if (trailer->this_size <= 0)
-       abort ();
-      result += trailer->this_size;
-      trailer = (struct stk_trailer *) trailer->link;
-    }
-  while (trailer != 0);
-
-  /* We are done.  Note that if you present a bogus address (one
-     not in any segment), you will get a different number back, formed
-     from subtracting the address of the first block.  This is probably
-     not what you want.  */
-
-  return (result);
-}
-
-#   else /* not CRAY2 */
-/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
-   Determine the number of the cell within the stack,
-   given the address of the cell.  The purpose of this
-   routine is to linearize, in some sense, stack addresses
-   for alloca.  */
-
-static long
-i00afunc (long address)
-{
-  long stkl = 0;
-
-  long size, pseg, this_segment, stack;
-  long result = 0;
-
-  struct stack_segment_linkage *ssptr;
-
-  /* Register B67 contains the address of the end of the
-     current stack segment.  If you (as a subprogram) store
-     your registers on the stack and find that you are past
-     the contents of B67, you have overflowed the segment.
-
-     B67 also points to the stack segment linkage control
-     area, which is what we are really interested in.  */
-
-  stkl = CRAY_STACKSEG_END ();
-  ssptr = (struct stack_segment_linkage *) stkl;
-
-  /* If one subtracts 'size' from the end of the segment,
-     one has the address of the first word of the segment.
-
-     If this is not the first segment, 'pseg' will be
-     nonzero.  */
-
-  pseg = ssptr->sspseg;
-  size = ssptr->sssize;
-
-  this_segment = stkl - size;
-
-  /* It is possible that calling this routine itself caused
-     a stack overflow.  Discard stack segments which do not
-     contain the target address.  */
-
-  while (!(this_segment <= address && address <= stkl))
-    {
-#    ifdef DEBUG_I00AFUNC
-      fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
-#    endif
-      if (pseg == 0)
-       break;
-      stkl = stkl - pseg;
-      ssptr = (struct stack_segment_linkage *) stkl;
-      size = ssptr->sssize;
-      pseg = ssptr->sspseg;
-      this_segment = stkl - size;
-    }
-
-  result = address - this_segment;
-
-  /* If you subtract pseg from the current end of the stack,
-     you get the address of the previous stack segment's end.
-     This seems a little convoluted to me, but I'll bet you save
-     a cycle somewhere.  */
-
-  while (pseg != 0)
-    {
-#    ifdef DEBUG_I00AFUNC
-      fprintf (stderr, "%011o %011o\n", pseg, size);
-#    endif
-      stkl = stkl - pseg;
-      ssptr = (struct stack_segment_linkage *) stkl;
-      size = ssptr->sssize;
-      pseg = ssptr->sspseg;
-      result += size;
-    }
-  return (result);
-}
-
-#   endif /* not CRAY2 */
-#  endif /* CRAY */
-
-# endif /* no alloca */
-#endif /* not GCC version 2 */
diff --git a/lib/strftime.c b/lib/strftime.c
index b7b7c1f..ac011d4 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -50,14 +50,7 @@ extern char *tzname[];
 #define DO_MULTIBYTE (HAVE_MBLEN && ! MULTIBYTE_IS_FORMAT_SAFE)
 
 #if DO_MULTIBYTE
-# if HAVE_MBRLEN
-#  include <wchar.h>
-# else
-   /* Simulate mbrlen with mblen as best we can.  */
-#  define mbstate_t int
-#  define mbrlen(s, n, ps) mblen (s, n)
-#  define mbsinit(ps) (*(ps) == 0)
-# endif
+# include <wchar.h>
   static const mbstate_t mbstate_zero;
 #endif
 
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index f0b9b3b..d4b842a 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -35,6 +35,7 @@
 #endif
 
 /* mingw fails to declare _exit in <unistd.h>.  */
+/* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>.  */
 #include <stdlib.h>
 
 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
diff --git a/lib/wchar.in.h b/lib/wchar.in.h
index 2ba2d84..3425062 100644
--- a/lib/wchar.in.h
+++ b/lib/wchar.in.h
@@ -68,6 +68,197 @@ extern "C" {
 /* Define wint_t.  (Also done in wctype.in.h.)  */
 #if address@hidden@ && !defined wint_t
 # define wint_t int
+# ifndef WEOF
+#  define WEOF -1
+# endif
+#endif
+
+
+/* Override mbstate_t if it is too small.
+   On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
+   implementing mbrtowc for encodings like UTF-8.  */
+#if !(@HAVE_MBSINIT@ && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
+typedef int rpl_mbstate_t;
+# undef mbstate_t
+# define mbstate_t rpl_mbstate_t
+# define GNULIB_defined_mbstate_t 1
+#endif
+
+
+/* Convert a single-byte character to a wide character.  */
+#if @GNULIB_BTOWC@
+# if @REPLACE_BTOWC@
+#  undef btowc
+#  define btowc rpl_btowc
+# endif
+# if address@hidden@ || @REPLACE_BTOWC@
+extern wint_t btowc (int c);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef btowc
+# define btowc(c) \
+    (GL_LINK_WARNING ("btowc is unportable - " \
+                      "use gnulib module btowc for portability"), \
+     btowc (c))
+#endif
+
+
+/* Convert a wide character to a single-byte character.  */
+#if @GNULIB_WCTOB@
+# if @REPLACE_WCTOB@
+#  undef wctob
+#  define wctob rpl_wctob
+# endif
+# if (!defined wctob && address@hidden@) || @REPLACE_WCTOB@
+/* wctob is provided by gnulib, or wctob exists but is not declared.  */
+extern int wctob (wint_t wc);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef wctob
+# define wctob(w) \
+    (GL_LINK_WARNING ("wctob is unportable - " \
+                      "use gnulib module wctob for portability"), \
+     wctob (w))
+#endif
+
+
+/* Test whether *PS is in the initial state.  */
+#if @GNULIB_MBSINIT@
+# if @REPLACE_MBSINIT@
+#  undef mbsinit
+#  define mbsinit rpl_mbsinit
+# endif
+# if address@hidden@ || @REPLACE_MBSINIT@
+extern int mbsinit (const mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef mbsinit
+# define mbsinit(p) \
+    (GL_LINK_WARNING ("mbsinit is unportable - " \
+                      "use gnulib module mbsinit for portability"), \
+     mbsinit (p))
+#endif
+
+
+/* Convert a multibyte character to a wide character.  */
+#if @GNULIB_MBRTOWC@
+# if @REPLACE_MBRTOWC@
+#  undef mbrtowc
+#  define mbrtowc rpl_mbrtowc
+# endif
+# if address@hidden@ || @REPLACE_MBRTOWC@
+extern size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef mbrtowc
+# define mbrtowc(w,s,n,p) \
+    (GL_LINK_WARNING ("mbrtowc is unportable - " \
+                      "use gnulib module mbrtowc for portability"), \
+     mbrtowc (w, s, n, p))
+#endif
+
+
+/* Recognize a multibyte character.  */
+#if @GNULIB_MBRLEN@
+# if @REPLACE_MBRLEN@
+#  undef mbrlen
+#  define mbrlen rpl_mbrlen
+# endif
+# if address@hidden@ || @REPLACE_MBRLEN@
+extern size_t mbrlen (const char *s, size_t n, mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef mbrlen
+# define mbrlen(s,n,p) \
+    (GL_LINK_WARNING ("mbrlen is unportable - " \
+                      "use gnulib module mbrlen for portability"), \
+     mbrlen (s, n, p))
+#endif
+
+
+/* Convert a string to a wide string.  */
+#if @GNULIB_MBSRTOWCS@
+# if @REPLACE_MBSRTOWCS@
+#  undef mbsrtowcs
+#  define mbsrtowcs rpl_mbsrtowcs
+# endif
+# if address@hidden@ || @REPLACE_MBSRTOWCS@
+extern size_t mbsrtowcs (wchar_t *dest, const char **srcp, size_t len, 
mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef mbsrtowcs
+# define mbsrtowcs(d,s,l,p) \
+    (GL_LINK_WARNING ("mbsrtowcs is unportable - " \
+                      "use gnulib module mbsrtowcs for portability"), \
+     mbsrtowcs (d, s, l, p))
+#endif
+
+
+/* Convert a string to a wide string.  */
+#if @GNULIB_MBSNRTOWCS@
+# if @REPLACE_MBSNRTOWCS@
+#  undef mbsnrtowcs
+#  define mbsnrtowcs rpl_mbsnrtowcs
+# endif
+# if address@hidden@ || @REPLACE_MBSNRTOWCS@
+extern size_t mbsnrtowcs (wchar_t *dest, const char **srcp, size_t srclen, 
size_t len, mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef mbsnrtowcs
+# define mbsnrtowcs(d,s,n,l,p) \
+    (GL_LINK_WARNING ("mbsnrtowcs is unportable - " \
+                      "use gnulib module mbsnrtowcs for portability"), \
+     mbsnrtowcs (d, s, n, l, p))
+#endif
+
+
+/* Convert a wide character to a multibyte character.  */
+#if @GNULIB_WCRTOMB@
+# if @REPLACE_WCRTOMB@
+#  undef wcrtomb
+#  define wcrtomb rpl_wcrtomb
+# endif
+# if address@hidden@ || @REPLACE_WCRTOMB@
+extern size_t wcrtomb (char *s, wchar_t wc, mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef wcrtomb
+# define wcrtomb(s,w,p) \
+    (GL_LINK_WARNING ("wcrtomb is unportable - " \
+                      "use gnulib module wcrtomb for portability"), \
+     wcrtomb (s, w, p))
+#endif
+
+
+/* Convert a wide string to a string.  */
+#if @GNULIB_WCSRTOMBS@
+# if @REPLACE_WCSRTOMBS@
+#  undef wcsrtombs
+#  define wcsrtombs rpl_wcsrtombs
+# endif
+# if address@hidden@ || @REPLACE_WCSRTOMBS@
+extern size_t wcsrtombs (char *dest, const wchar_t **srcp, size_t len, 
mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef wcsrtombs
+# define wcsrtombs(d,s,l,p) \
+    (GL_LINK_WARNING ("wcsrtombs is unportable - " \
+                      "use gnulib module wcsrtombs for portability"), \
+     wcsrtombs (d, s, l, p))
+#endif
+
+
+/* Convert a wide string to a string.  */
+#if @GNULIB_WCSNRTOMBS@
+# if address@hidden@
+extern size_t wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, 
size_t len, mbstate_t *ps);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef wcsnrtombs
+# define wcsnrtombs(d,s,n,l,p) \
+    (GL_LINK_WARNING ("wcsnrtombs is unportable - " \
+                      "use gnulib module wcsnrtombs for portability"), \
+     wcsnrtombs (d, s, n, l, p))
 #endif
 
 
diff --git a/m4/alloca.m4 b/m4/alloca.m4
index 95f54a6..4b978e1 100644
--- a/m4/alloca.m4
+++ b/m4/alloca.m4
@@ -1,5 +1,5 @@
-# alloca.m4 serial 8
-dnl Copyright (C) 2002-2004, 2006, 2007 Free Software Foundation, Inc.
+# alloca.m4 serial 9
+dnl Copyright (C) 2002-2004, 2006, 2007, 2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -26,7 +26,7 @@ AC_DEFUN([gl_FUNC_ALLOCA],
     ])
     if test $gl_cv_rpl_alloca = yes; then
       dnl OK, alloca can be implemented through a compiler built-in.
-      AC_DEFINE([HAVE_ALLOCA], 1,
+      AC_DEFINE([HAVE_ALLOCA], [1],
         [Define to 1 if you have 'alloca' after including <alloca.h>,
          a header that may be supplied by this distribution.])
       ALLOCA_H=alloca.h
diff --git a/m4/codeset.m4 b/m4/codeset.m4
new file mode 100644
index 0000000..413217b
--- /dev/null
+++ b/m4/codeset.m4
@@ -0,0 +1,21 @@
+# codeset.m4 serial 4 (gettext-0.18)
+dnl Copyright (C) 2000-2002, 2006, 2008, 2009 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+AC_DEFUN([AM_LANGINFO_CODESET],
+[
+  AC_CACHE_CHECK([for nl_langinfo and CODESET], [am_cv_langinfo_codeset],
+    [AC_TRY_LINK([#include <langinfo.h>],
+      [char* cs = nl_langinfo(CODESET); return !cs;],
+      [am_cv_langinfo_codeset=yes],
+      [am_cv_langinfo_codeset=no])
+    ])
+  if test $am_cv_langinfo_codeset = yes; then
+    AC_DEFINE([HAVE_LANGINFO_CODESET], [1],
+      [Define if you have <langinfo.h> and nl_langinfo(CODESET).])
+  fi
+])
diff --git a/m4/extensions.m4 b/m4/extensions.m4
index 917af94..611fcfd 100644
--- a/m4/extensions.m4
+++ b/m4/extensions.m4
@@ -1,4 +1,4 @@
-# serial 5  -*- Autoconf -*-
+# serial 6  -*- Autoconf -*-
 # Enable extensions on systems that normally disable them.
 
 # Copyright (C) 2003, 2006-2008 Free Software Foundation, Inc.
@@ -24,6 +24,8 @@ AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS],
 [AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
 AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
 
+  AC_REQUIRE([AC_CANONICAL_HOST])
+
   AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=])
   if test "$MINIX" = yes; then
     AC_DEFINE([_POSIX_SOURCE], [1],
@@ -36,6 +38,16 @@ AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
       [Define to 1 if on MINIX.])
   fi
 
+  dnl HP-UX 11.11 defines mbstate_t only if _XOPEN_SOURCE is defined to 500,
+  dnl regardless of whether the flags -Ae or _D_HPUX_SOURCE=1 are already
+  dnl provided.
+  case "$host_os" in
+    hpux*)
+      AC_DEFINE([_XOPEN_SOURCE], [500],
+        [Define to 500 only on HP-UX.])
+      ;;
+  esac
+
   AH_VERBATIM([__EXTENSIONS__],
 [/* Enable extensions on AIX 3, Interix.  */
 #ifndef _ALL_SOURCE
diff --git a/m4/glibc21.m4 b/m4/glibc21.m4
new file mode 100644
index 0000000..93fbf47
--- /dev/null
+++ b/m4/glibc21.m4
@@ -0,0 +1,30 @@
+# glibc21.m4 serial 4
+dnl Copyright (C) 2000-2002, 2004, 2008 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# Test for the GNU C Library, version 2.1 or newer.
+# From Bruno Haible.
+
+AC_DEFUN([gl_GLIBC21],
+  [
+    AC_CACHE_CHECK([whether we are using the GNU C Library 2.1 or newer],
+      [ac_cv_gnu_library_2_1],
+      [AC_EGREP_CPP([Lucky GNU user],
+       [
+#include <features.h>
+#ifdef __GNU_LIBRARY__
+ #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) || (__GLIBC__ > 2)
+  Lucky GNU user
+ #endif
+#endif
+       ],
+       [ac_cv_gnu_library_2_1=yes],
+       [ac_cv_gnu_library_2_1=no])
+      ]
+    )
+    AC_SUBST([GLIBC21])
+    GLIBC21="$ac_cv_gnu_library_2_1"
+  ]
+)
diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4
index 9adbfa6..e04c285 100644
--- a/m4/gnulib-cache.m4
+++ b/m4/gnulib-cache.m4
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2008 Free Software Foundation, Inc.
+# Copyright (C) 2002-2009 Free Software Foundation, Inc.
 #
 # This file is free software, distributed under the terms of the GNU
 # General Public License.  As a special exception to the GNU General
@@ -15,12 +15,12 @@
 
 
 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 
--doc-base=doc --tests-base=tests --aux-dir=build-aux --lgpl --libtool 
--macro-prefix=gl alloca autobuild count-one-bits extensions full-read 
full-write strcase strftime
+#   gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 
--doc-base=doc --tests-base=tests --aux-dir=build-aux --lgpl --libtool 
--macro-prefix=gl alloca-opt autobuild count-one-bits extensions full-read 
full-write strcase strftime
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([])
 gl_MODULES([
-  alloca
+  alloca-opt
   autobuild
   count-one-bits
   extensions
diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index c73db14..5804eb9 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -1,5 +1,5 @@
-# gnulib-common.m4 serial 6
-dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
+# gnulib-common.m4 serial 7
+dnl Copyright (C) 2007-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -63,7 +63,7 @@ m4_ifdef([AC_PROG_MKDIR_P], [], [
 # works.
 # This definition can be removed once autoconf >= 2.62 can be assumed.
 AC_DEFUN([AC_C_RESTRICT],
-[AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
+[AC_CACHE_CHECK([for C/C++ restrict keyword], [ac_cv_c_restrict],
   [ac_cv_c_restrict=no
    # The order here caters to the fact that C++ does not require restrict.
    for ac_kw in __restrict __restrict__ _Restrict restrict; do
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4
index 10c8156..5e9ce99 100644
--- a/m4/gnulib-comp.m4
+++ b/m4/gnulib-comp.m4
@@ -1,5 +1,5 @@
 # DO NOT EDIT! GENERATED AUTOMATICALLY!
-# Copyright (C) 2002-2008 Free Software Foundation, Inc.
+# Copyright (C) 2002-2009 Free Software Foundation, Inc.
 #
 # This file is free software, distributed under the terms of the GNU
 # General Public License.  As a special exception to the GNU General
@@ -42,13 +42,18 @@ AC_DEFUN([gl_INIT],
   m4_pushdef([gl_LIBSOURCES_DIR], [])
   gl_COMMON
   gl_source_base='lib'
-changequote(,)dnl
-LTALLOCA=`echo "$ALLOCA" | sed 's/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'`
-changequote([, ])dnl
-AC_SUBST([LTALLOCA])
   gl_FUNC_ALLOCA
   gl_COUNT_ONE_BITS
   gl_INLINE
+  gl_LOCALCHARSET
+  
LOCALCHARSET_TESTS_ENVIRONMENT="CHARSETALIASDIR=\"\$(top_builddir)/$gl_source_base\""
+  AC_SUBST([LOCALCHARSET_TESTS_ENVIRONMENT])
+  gl_FUNC_MBRLEN
+  gl_WCHAR_MODULE_INDICATOR([mbrlen])
+  gl_FUNC_MBRTOWC
+  gl_WCHAR_MODULE_INDICATOR([mbrtowc])
+  gl_FUNC_MBSINIT
+  gl_WCHAR_MODULE_INDICATOR([mbsinit])
   gl_SAFE_READ
   gl_SAFE_WRITE
   gt_TYPE_SSIZE_T
@@ -191,19 +196,27 @@ AC_DEFUN([gltests_LIBSOURCES], [
 # gnulib-tool and may be removed by future gnulib-tool invocations.
 AC_DEFUN([gl_FILE_LIST], [
   build-aux/link-warning.h
-  lib/alloca.c
   lib/alloca.in.h
+  lib/config.charset
   lib/count-one-bits.h
   lib/full-read.c
   lib/full-read.h
   lib/full-write.c
   lib/full-write.h
+  lib/localcharset.c
+  lib/localcharset.h
+  lib/mbrlen.c
+  lib/mbrtowc.c
+  lib/mbsinit.c
+  lib/ref-add.sin
+  lib/ref-del.sin
   lib/safe-read.c
   lib/safe-read.h
   lib/safe-write.c
   lib/safe-write.h
   lib/stdbool.in.h
   lib/strcasecmp.c
+  lib/streq.h
   lib/strftime.c
   lib/strftime.h
   lib/strings.in.h
@@ -216,11 +229,20 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/write.c
   m4/alloca.m4
   m4/autobuild.m4
+  m4/codeset.m4
   m4/count-one-bits.m4
   m4/extensions.m4
+  m4/glibc21.m4
   m4/gnulib-common.m4
   m4/include_next.m4
   m4/inline.m4
+  m4/localcharset.m4
+  m4/locale-fr.m4
+  m4/locale-ja.m4
+  m4/locale-zh.m4
+  m4/mbrlen.m4
+  m4/mbrtowc.m4
+  m4/mbsinit.m4
   m4/mbstate_t.m4
   m4/safe-read.m4
   m4/safe-write.m4
diff --git a/m4/inline.m4 b/m4/inline.m4
index a07076c..cee5109 100644
--- a/m4/inline.m4
+++ b/m4/inline.m4
@@ -1,5 +1,5 @@
-# inline.m4 serial 3
-dnl Copyright (C) 2006 Free Software Foundation, Inc.
+# inline.m4 serial 4
+dnl Copyright (C) 2006, 2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -32,7 +32,7 @@ AC_DEFUN([gl_INLINE],
      fi
     ])
   if test $gl_cv_c_inline_effective = yes; then
-    AC_DEFINE([HAVE_INLINE], 1,
+    AC_DEFINE([HAVE_INLINE], [1],
       [Define to 1 if the compiler supports one of the keywords
        'inline', '__inline__', '__inline' and effectively inlines
        functions marked as such.])
diff --git a/m4/localcharset.m4 b/m4/localcharset.m4
new file mode 100644
index 0000000..e960104
--- /dev/null
+++ b/m4/localcharset.m4
@@ -0,0 +1,16 @@
+# localcharset.m4 serial 6
+dnl Copyright (C) 2002, 2004, 2006, 2009 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_LOCALCHARSET],
+[
+  dnl Prerequisites of lib/localcharset.c.
+  AC_REQUIRE([AM_LANGINFO_CODESET])
+  AC_CHECK_DECLS_ONCE([getc_unlocked])
+
+  dnl Prerequisites of the lib/Makefile.am snippet.
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_REQUIRE([gl_GLIBC21])
+])
diff --git a/m4/locale-fr.m4 b/m4/locale-fr.m4
new file mode 100644
index 0000000..e471839
--- /dev/null
+++ b/m4/locale-fr.m4
@@ -0,0 +1,204 @@
+# locale-fr.m4 serial 10
+dnl Copyright (C) 2003, 2005-2009 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+dnl Determine the name of a french locale with traditional encoding.
+AC_DEFUN([gt_LOCALE_FR],
+[
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_REQUIRE([AM_LANGINFO_CODESET])
+  AC_CACHE_CHECK([for a traditional french locale], [gt_cv_locale_fr], [
+    macosx=
+changequote(,)dnl
+    case "$host_os" in
+      darwin[56]*) ;;
+      darwin*) macosx=yes;;
+    esac
+changequote([,])dnl
+    if test -n "$macosx"; then
+      # On Darwin 7 (MacOS X), the libc supports some locales in non-UTF-8
+      # encodings, but the kernel does not support them. The documentation
+      # says:
+      #   "... all code that calls BSD system routines should ensure
+      #    that the const *char parameters of these routines are in UTF-8
+      #    encoding. All BSD system functions expect their string
+      #    parameters to be in UTF-8 encoding and nothing else."
+      # See the comments in config.charset. Therefore we bypass the test.
+      gt_cv_locale_fr=none
+    else
+      AC_LANG_CONFTEST([AC_LANG_SOURCE([
+changequote(,)dnl
+#include <locale.h>
+#include <time.h>
+#if HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+struct tm t;
+char buf[16];
+int main () {
+  /* Check whether the given locale name is recognized by the system.  */
+  if (setlocale (LC_ALL, "") == NULL) return 1;
+  /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
+     On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
+     is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
+     On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
+     succeeds but then nl_langinfo(CODESET) is "646". In this situation,
+     some unit tests fail.  */
+#if HAVE_LANGINFO_CODESET
+  {
+    const char *cs = nl_langinfo (CODESET);
+    if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0)
+      return 1;
+  }
+#endif
+#ifdef __CYGWIN__
+  /* On Cygwin, avoid locale names without encoding suffix, because the
+     locale_charset() function relies on the encoding suffix.  Note that
+     LC_ALL is set on the command line.  */
+  if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
+#endif
+  /* Check whether in the abbreviation of the second month, the second
+     character (should be U+00E9: LATIN SMALL LETTER E WITH ACUTE) is only
+     one byte long. This excludes the UTF-8 encoding.  */
+  t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
+  if (strftime (buf, sizeof (buf), "%b", &t) < 3 || buf[2] != 'v') return 1;
+  /* Check whether the decimal separator is a comma.
+     On NetBSD 3.0 in the fr_FR.ISO8859-1 locale, localeconv()->decimal_point
+     are nl_langinfo(RADIXCHAR) are both ".".  */
+  if (localeconv () ->decimal_point[0] != ',') return 1;
+  return 0;
+}
+changequote([,])dnl
+        ])])
+      if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
+        # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
+        # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
+        # configure script would override the LC_ALL setting. Likewise for
+        # LC_CTYPE, which is also set at the beginning of the configure script.
+        # Test for the usual locale name.
+        if (LC_ALL=fr_FR LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+          gt_cv_locale_fr=fr_FR
+        else
+          # Test for the locale name with explicit encoding suffix.
+          if (LC_ALL=fr_FR.ISO-8859-1 LC_TIME= LC_CTYPE= ./conftest; exit) 
2>/dev/null; then
+            gt_cv_locale_fr=fr_FR.ISO-8859-1
+          else
+            # Test for the AIX, OSF/1, FreeBSD, NetBSD, OpenBSD locale name.
+            if (LC_ALL=fr_FR.ISO8859-1 LC_TIME= LC_CTYPE= ./conftest; exit) 
2>/dev/null; then
+              gt_cv_locale_fr=fr_FR.ISO8859-1
+            else
+              # Test for the HP-UX locale name.
+              if (LC_ALL=fr_FR.iso88591 LC_TIME= LC_CTYPE= ./conftest; exit) 
2>/dev/null; then
+                gt_cv_locale_fr=fr_FR.iso88591
+              else
+                # Test for the Solaris 7 locale name.
+                if (LC_ALL=fr LC_TIME= LC_CTYPE= ./conftest; exit) 
2>/dev/null; then
+                  gt_cv_locale_fr=fr
+                else
+                  # None found.
+                  gt_cv_locale_fr=none
+                fi
+              fi
+            fi
+          fi
+        fi
+      fi
+      rm -fr conftest*
+    fi
+  ])
+  LOCALE_FR=$gt_cv_locale_fr
+  AC_SUBST([LOCALE_FR])
+])
+
+dnl Determine the name of a french locale with UTF-8 encoding.
+AC_DEFUN([gt_LOCALE_FR_UTF8],
+[
+  AC_REQUIRE([AM_LANGINFO_CODESET])
+  AC_CACHE_CHECK([for a french Unicode locale], [gt_cv_locale_fr_utf8], [
+    AC_LANG_CONFTEST([AC_LANG_SOURCE([
+changequote(,)dnl
+#include <locale.h>
+#include <time.h>
+#if HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+struct tm t;
+char buf[16];
+int main () {
+  /* On BeOS and Haiku, locales are not implemented in libc.  Rather, libintl
+     imitates locale dependent behaviour by looking at the environment
+     variables, and all locales use the UTF-8 encoding.  */
+#if !(defined __BEOS__ || defined __HAIKU__)
+  /* Check whether the given locale name is recognized by the system.  */
+  if (setlocale (LC_ALL, "") == NULL) return 1;
+  /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
+     On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
+     is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
+     On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
+     succeeds but then nl_langinfo(CODESET) is "646". In this situation,
+     some unit tests fail.  */
+# if HAVE_LANGINFO_CODESET
+  {
+    const char *cs = nl_langinfo (CODESET);
+    if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0)
+      return 1;
+  }
+# endif
+# ifdef __CYGWIN__
+  /* On Cygwin, avoid locale names without encoding suffix, because the
+     locale_charset() function relies on the encoding suffix.  Note that
+     LC_ALL is set on the command line.  */
+  if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
+# endif
+  /* Check whether in the abbreviation of the second month, the second
+     character (should be U+00E9: LATIN SMALL LETTER E WITH ACUTE) is
+     two bytes long, with UTF-8 encoding.  */
+  t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
+  if (strftime (buf, sizeof (buf), "%b", &t) < 4
+      || buf[1] != (char) 0xc3 || buf[2] != (char) 0xa9 || buf[3] != 'v')
+    return 1;
+#endif
+  /* Check whether the decimal separator is a comma.
+     On NetBSD 3.0 in the fr_FR.ISO8859-1 locale, localeconv()->decimal_point
+     are nl_langinfo(RADIXCHAR) are both ".".  */
+  if (localeconv () ->decimal_point[0] != ',') return 1;
+  return 0;
+}
+changequote([,])dnl
+      ])])
+    if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
+      # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
+      # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
+      # configure script would override the LC_ALL setting. Likewise for
+      # LC_CTYPE, which is also set at the beginning of the configure script.
+      # Test for the usual locale name.
+      if (LC_ALL=fr_FR LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+        gt_cv_locale_fr_utf8=fr_FR
+      else
+        # Test for the locale name with explicit encoding suffix.
+        if (LC_ALL=fr_FR.UTF-8 LC_TIME= LC_CTYPE= ./conftest; exit) 
2>/dev/null; then
+          gt_cv_locale_fr_utf8=fr_FR.UTF-8
+        else
+          # Test for the Solaris 7 locale name.
+          if (LC_ALL=fr.UTF-8 LC_TIME= LC_CTYPE= ./conftest; exit) 
2>/dev/null; then
+            gt_cv_locale_fr_utf8=fr.UTF-8
+          else
+            # None found.
+            gt_cv_locale_fr_utf8=none
+          fi
+        fi
+      fi
+    fi
+    rm -fr conftest*
+  ])
+  LOCALE_FR_UTF8=$gt_cv_locale_fr_utf8
+  AC_SUBST([LOCALE_FR_UTF8])
+])
diff --git a/m4/locale-ja.m4 b/m4/locale-ja.m4
new file mode 100644
index 0000000..c80c5af
--- /dev/null
+++ b/m4/locale-ja.m4
@@ -0,0 +1,126 @@
+# locale-ja.m4 serial 6
+dnl Copyright (C) 2003, 2005-2009 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+dnl Determine the name of a japanese locale with EUC-JP encoding.
+AC_DEFUN([gt_LOCALE_JA],
+[
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_REQUIRE([AM_LANGINFO_CODESET])
+  AC_CACHE_CHECK([for a traditional japanese locale], [gt_cv_locale_ja], [
+    macosx=
+changequote(,)dnl
+    case "$host_os" in
+      darwin[56]*) ;;
+      darwin*) macosx=yes;;
+    esac
+changequote([,])dnl
+    if test -n "$macosx"; then
+      # On Darwin 7 (MacOS X), the libc supports some locales in non-UTF-8
+      # encodings, but the kernel does not support them. The documentation
+      # says:
+      #   "... all code that calls BSD system routines should ensure
+      #    that the const *char parameters of these routines are in UTF-8
+      #    encoding. All BSD system functions expect their string
+      #    parameters to be in UTF-8 encoding and nothing else."
+      # See the comments in config.charset. Therefore we bypass the test.
+      gt_cv_locale_ja=none
+    else
+      AC_LANG_CONFTEST([AC_LANG_SOURCE([
+changequote(,)dnl
+#include <locale.h>
+#include <time.h>
+#if HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+struct tm t;
+char buf[16];
+int main ()
+{
+  const char *p;
+  /* Check whether the given locale name is recognized by the system.  */
+  if (setlocale (LC_ALL, "") == NULL) return 1;
+  /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
+     On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
+     is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
+     On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
+     succeeds but then nl_langinfo(CODESET) is "646". In this situation,
+     some unit tests fail.  */
+#if HAVE_LANGINFO_CODESET
+  {
+    const char *cs = nl_langinfo (CODESET);
+    if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0)
+      return 1;
+  }
+#endif
+#ifdef __CYGWIN__
+  /* On Cygwin, avoid locale names without encoding suffix, because the
+     locale_charset() function relies on the encoding suffix.  Note that
+     LC_ALL is set on the command line.  */
+  if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
+#endif
+  /* Check whether MB_CUR_MAX is > 1.  This excludes the dysfunctional locales
+     on Cygwin 1.5.x.  */
+  if (MB_CUR_MAX == 1)
+    return 1;
+  /* Check whether in a month name, no byte in the range 0x80..0x9F occurs.
+     This excludes the UTF-8 encoding.  */
+  t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
+  if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
+  for (p = buf; *p != '\0'; p++)
+    if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
+      return 1;
+  return 0;
+}
+changequote([,])dnl
+        ])])
+      if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
+        # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
+        # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
+        # configure script would override the LC_ALL setting. Likewise for
+        # LC_CTYPE, which is also set at the beginning of the configure script.
+        # Test for the AIX locale name.
+        if (LC_ALL=ja_JP LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+          gt_cv_locale_ja=ja_JP
+        else
+          # Test for the locale name with explicit encoding suffix.
+          if (LC_ALL=ja_JP.EUC-JP LC_TIME= LC_CTYPE= ./conftest; exit) 
2>/dev/null; then
+            gt_cv_locale_ja=ja_JP.EUC-JP
+          else
+            # Test for the HP-UX, OSF/1, NetBSD locale name.
+            if (LC_ALL=ja_JP.eucJP LC_TIME= LC_CTYPE= ./conftest; exit) 
2>/dev/null; then
+              gt_cv_locale_ja=ja_JP.eucJP
+            else
+              # Test for the IRIX, FreeBSD locale name.
+              if (LC_ALL=ja_JP.EUC LC_TIME= LC_CTYPE= ./conftest; exit) 
2>/dev/null; then
+                gt_cv_locale_ja=ja_JP.EUC
+              else
+                # Test for the Solaris 7 locale name.
+                if (LC_ALL=ja LC_TIME= LC_CTYPE= ./conftest; exit) 
2>/dev/null; then
+                  gt_cv_locale_ja=ja
+                else
+                  # Special test for NetBSD 1.6.
+                  if test -f /usr/share/locale/ja_JP.eucJP/LC_CTYPE; then
+                    gt_cv_locale_ja=ja_JP.eucJP
+                  else
+                    # None found.
+                    gt_cv_locale_ja=none
+                  fi
+                fi
+              fi
+            fi
+          fi
+        fi
+      fi
+      rm -fr conftest*
+    fi
+  ])
+  LOCALE_JA=$gt_cv_locale_ja
+  AC_SUBST([LOCALE_JA])
+])
diff --git a/m4/locale-zh.m4 b/m4/locale-zh.m4
new file mode 100644
index 0000000..ba7f9c5
--- /dev/null
+++ b/m4/locale-zh.m4
@@ -0,0 +1,111 @@
+# locale-zh.m4 serial 5
+dnl Copyright (C) 2003, 2005-2009 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+dnl Determine the name of a chinese locale with GB18030 encoding.
+AC_DEFUN([gt_LOCALE_ZH_CN],
+[
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_REQUIRE([AM_LANGINFO_CODESET])
+  AC_CACHE_CHECK([for a transitional chinese locale], [gt_cv_locale_zh_CN], [
+    macosx=
+changequote(,)dnl
+    case "$host_os" in
+      darwin[56]*) ;;
+      darwin*) macosx=yes;;
+    esac
+changequote([,])dnl
+    if test -n "$macosx"; then
+      # On Darwin 7 (MacOS X), the libc supports some locales in non-UTF-8
+      # encodings, but the kernel does not support them. The documentation
+      # says:
+      #   "... all code that calls BSD system routines should ensure
+      #    that the const *char parameters of these routines are in UTF-8
+      #    encoding. All BSD system functions expect their string
+      #    parameters to be in UTF-8 encoding and nothing else."
+      # See the comments in config.charset. Therefore we bypass the test.
+      gt_cv_locale_zh_CN=none
+    else
+      AC_LANG_CONFTEST([AC_LANG_SOURCE([
+changequote(,)dnl
+#include <locale.h>
+#include <stdlib.h>
+#include <time.h>
+#if HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+struct tm t;
+char buf[16];
+int main ()
+{
+  const char *p;
+  /* Check whether the given locale name is recognized by the system.  */
+  if (setlocale (LC_ALL, "") == NULL) return 1;
+  /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
+     On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
+     is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
+     On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
+     succeeds but then nl_langinfo(CODESET) is "646". In this situation,
+     some unit tests fail.  */
+#if HAVE_LANGINFO_CODESET
+  {
+    const char *cs = nl_langinfo (CODESET);
+    if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0)
+      return 1;
+  }
+#endif
+#ifdef __CYGWIN__
+  /* On Cygwin, avoid locale names without encoding suffix, because the
+     locale_charset() function relies on the encoding suffix.  Note that
+     LC_ALL is set on the command line.  */
+  if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
+#endif
+  /* Check whether in a month name, no byte in the range 0x80..0x9F occurs.
+     This excludes the UTF-8 encoding.  */
+  t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
+  if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
+  for (p = buf; *p != '\0'; p++)
+    if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
+      return 1;
+  /* Check whether a typical GB18030 multibyte sequence is recognized as a
+     single wide character.  This excludes the GB2312 and GBK encodings.  */
+  if (mblen ("\203\062\332\066", 5) != 4)
+    return 1;
+  return 0;
+}
+changequote([,])dnl
+        ])])
+      if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
+        # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
+        # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
+        # configure script would override the LC_ALL setting. Likewise for
+        # LC_CTYPE, which is also set at the beginning of the configure script.
+        # Test for the locale name without encoding suffix.
+        if (LC_ALL=zh_CN LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+          gt_cv_locale_zh_CN=zh_CN
+        else
+          # Test for the locale name with explicit encoding suffix.
+          if (LC_ALL=zh_CN.GB18030 LC_TIME= LC_CTYPE= ./conftest; exit) 
2>/dev/null; then
+            gt_cv_locale_zh_CN=zh_CN.GB18030
+          else
+            # None found.
+            gt_cv_locale_zh_CN=none
+          fi
+        fi
+      else
+        # If there was a link error, due to mblen(), the system is so old that
+        # it certainly doesn't have a chinese locale.
+        gt_cv_locale_zh_CN=none
+      fi
+      rm -fr conftest*
+    fi
+  ])
+  LOCALE_ZH_CN=$gt_cv_locale_zh_CN
+  AC_SUBST([LOCALE_ZH_CN])
+])
diff --git a/m4/mbrlen.m4 b/m4/mbrlen.m4
new file mode 100644
index 0000000..5623ed5
--- /dev/null
+++ b/m4/mbrlen.m4
@@ -0,0 +1,197 @@
+# mbrlen.m4 serial 2
+dnl Copyright (C) 2008 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_MBRLEN],
+[
+  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+
+  AC_REQUIRE([AC_TYPE_MBSTATE_T])
+  AC_REQUIRE([gl_FUNC_MBRTOWC])
+  AC_CHECK_FUNCS_ONCE([mbrlen])
+  if test $ac_cv_func_mbrlen = no; then
+    HAVE_MBRLEN=0
+  else
+    dnl Most bugs affecting the system's mbrtowc function also affect the
+    dnl mbrlen function. So override mbrlen whenever mbrtowc is overridden.
+    dnl We could also run the individual tests below; the results would be
+    dnl the same.
+    if test $REPLACE_MBRTOWC = 1; then
+      REPLACE_MBRLEN=1
+    fi
+  fi
+  if test $HAVE_MBRLEN = 0 || test $REPLACE_MBRLEN = 1; then
+    gl_REPLACE_WCHAR_H
+    AC_LIBOBJ([mbrlen])
+    gl_PREREQ_MBRLEN
+  fi
+])
+
+dnl Test whether mbrlen puts the state into non-initial state when parsing an
+dnl incomplete multibyte character.
+dnl Result is gl_cv_func_mbrlen_incomplete_state.
+
+AC_DEFUN([gl_MBRLEN_INCOMPLETE_STATE],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gt_LOCALE_JA])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether mbrlen handles incomplete characters],
+    [gl_cv_func_mbrlen_incomplete_state],
+    [
+      dnl Initial guess, used when cross-compiling or when no suitable locale
+      dnl is present.
+changequote(,)dnl
+      case "$host_os" in
+              # Guess no on AIX and OSF/1.
+        osf*) gl_cv_func_mbrlen_incomplete_state="guessing no" ;;
+              # Guess yes otherwise.
+        *)    gl_cv_func_mbrlen_incomplete_state="guessing yes" ;;
+      esac
+changequote([,])dnl
+      if test $LOCALE_JA != none; then
+        AC_TRY_RUN([
+#include <locale.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+  if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
+    {
+      const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
+      mbstate_t state;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
+        if (mbsinit (&state))
+          return 1;
+    }
+  return 0;
+}],
+          [gl_cv_func_mbrlen_incomplete_state=yes],
+          [gl_cv_func_mbrlen_incomplete_state=no],
+          [])
+      fi
+    ])
+])
+
+dnl Test whether mbrlen, when parsing the end of a multibyte character,
+dnl correctly returns the number of bytes that were needed to complete the
+dnl character (not the total number of bytes of the multibyte character).
+dnl Result is gl_cv_func_mbrlen_retval.
+
+AC_DEFUN([gl_MBRLEN_RETVAL],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gt_LOCALE_FR_UTF8])
+  AC_REQUIRE([gt_LOCALE_JA])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether mbrlen has a correct return value],
+    [gl_cv_func_mbrlen_retval],
+    [
+      dnl Initial guess, used when cross-compiling or when no suitable locale
+      dnl is present.
+changequote(,)dnl
+      case "$host_os" in
+                          # Guess no on HP-UX and Solaris.
+        hpux* | solaris*) gl_cv_func_mbrlen_retval="guessing no" ;;
+                          # Guess yes otherwise.
+        *)                gl_cv_func_mbrlen_retval="guessing yes" ;;
+      esac
+changequote([,])dnl
+      if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none; then
+        AC_TRY_RUN([
+#include <locale.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+  /* This fails on Solaris.  */
+  if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
+    {
+      char input[] = "B\303\274\303\237er"; /* "Büßer" */
+      mbstate_t state;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
+        {
+          input[1] = '\0';
+          if (mbrlen (input + 2, 5, &state) != 1)
+            return 1;
+        }
+    }
+  /* This fails on HP-UX 11.11.  */
+  if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
+    {
+      char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
+      mbstate_t state;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
+        {
+          input[1] = '\0';
+          if (mbrlen (input + 2, 5, &state) != 2)
+            return 1;
+        }
+    }
+  return 0;
+}],
+          [gl_cv_func_mbrlen_retval=yes],
+          [gl_cv_func_mbrlen_retval=no],
+          [])
+      fi
+    ])
+])
+
+dnl Test whether mbrlen, when parsing a NUL character, correctly returns 0.
+dnl Result is gl_cv_func_mbrlen_nul_retval.
+
+AC_DEFUN([gl_MBRLEN_NUL_RETVAL],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gt_LOCALE_ZH_CN])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether mbrlen returns 0 when parsing a NUL character],
+    [gl_cv_func_mbrlen_nul_retval],
+    [
+      dnl Initial guess, used when cross-compiling or when no suitable locale
+      dnl is present.
+changequote(,)dnl
+      case "$host_os" in
+                    # Guess no on Solaris 9.
+        solaris2.9) gl_cv_func_mbrlen_nul_retval="guessing no" ;;
+                    # Guess yes otherwise.
+        *)          gl_cv_func_mbrlen_nul_retval="guessing yes" ;;
+      esac
+changequote([,])dnl
+      if test $LOCALE_ZH_CN != none; then
+        AC_TRY_RUN([
+#include <locale.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+  /* This crashes on Solaris 9 inside __mbrtowc_dense_gb18030.  */
+  if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
+    {
+      mbstate_t state;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrlen ("", 1, &state) != 0)
+        return 1;
+    }
+  return 0;
+}],
+          [gl_cv_func_mbrlen_nul_retval=yes],
+          [gl_cv_func_mbrlen_nul_retval=no],
+          [])
+      fi
+    ])
+])
+
+# Prerequisites of lib/mbrlen.c.
+AC_DEFUN([gl_PREREQ_MBRLEN], [
+  :
+])
diff --git a/m4/mbrtowc.m4 b/m4/mbrtowc.m4
new file mode 100644
index 0000000..726497b
--- /dev/null
+++ b/m4/mbrtowc.m4
@@ -0,0 +1,325 @@
+# mbrtowc.m4 serial 13
+dnl Copyright (C) 2001-2002, 2004-2005, 2008, 2009 Free Software Foundation, 
Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_MBRTOWC],
+[
+  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+
+  AC_REQUIRE([AC_TYPE_MBSTATE_T])
+  gl_MBSTATE_T_BROKEN
+  if test $REPLACE_MBSTATE_T = 1; then
+    REPLACE_MBRTOWC=1
+  fi
+  AC_CHECK_FUNCS_ONCE([mbrtowc])
+  if test $ac_cv_func_mbrtowc = no; then
+    HAVE_MBRTOWC=0
+  fi
+  if test $HAVE_MBRTOWC != 0 && test $REPLACE_MBRTOWC != 1; then
+    gl_MBRTOWC_NULL_ARG
+    gl_MBRTOWC_RETVAL
+    gl_MBRTOWC_NUL_RETVAL
+    case "$gl_cv_func_mbrtowc_null_arg" in
+      *yes) ;;
+      *) AC_DEFINE([MBRTOWC_NULL_ARG_BUG], [1],
+           [Define if the mbrtowc function has the NULL string argument bug.])
+         REPLACE_MBRTOWC=1
+         ;;
+    esac
+    case "$gl_cv_func_mbrtowc_retval" in
+      *yes) ;;
+      *) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1],
+           [Define if the mbrtowc function returns a wrong return value.])
+         REPLACE_MBRTOWC=1
+         ;;
+    esac
+    case "$gl_cv_func_mbrtowc_nul_retval" in
+      *yes) ;;
+      *) AC_DEFINE([MBRTOWC_NUL_RETVAL_BUG], [1],
+           [Define if the mbrtowc function does not return 0 for a NUL 
character.])
+         REPLACE_MBRTOWC=1
+         ;;
+    esac
+  fi
+  if test $HAVE_MBRTOWC = 0 || test $REPLACE_MBRTOWC = 1; then
+    gl_REPLACE_WCHAR_H
+    AC_LIBOBJ([mbrtowc])
+    gl_PREREQ_MBRTOWC
+  fi
+])
+
+dnl Test whether mbsinit() and mbrtowc() need to be overridden in a way that
+dnl redefines the semantics of the given mbstate_t type.
+dnl Result is REPLACE_MBSTATE_T.
+dnl When this is set to 1, we replace both mbsinit() and mbrtowc(), in order to
+dnl avoid inconsistencies.
+
+AC_DEFUN([gl_MBSTATE_T_BROKEN],
+[
+  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+
+  AC_REQUIRE([AC_TYPE_MBSTATE_T])
+  AC_CHECK_FUNCS_ONCE([mbsinit])
+  AC_CHECK_FUNCS_ONCE([mbrtowc])
+  if test $ac_cv_func_mbsinit = yes && test $ac_cv_func_mbrtowc = yes; then
+    gl_MBRTOWC_INCOMPLETE_STATE
+    case "$gl_cv_func_mbrtowc_incomplete_state" in
+      *yes) REPLACE_MBSTATE_T=0 ;;
+      *)    REPLACE_MBSTATE_T=1 ;;
+    esac
+  else
+    REPLACE_MBSTATE_T=1
+  fi
+  if test $REPLACE_MBSTATE_T = 1; then
+    gl_REPLACE_WCHAR_H
+  fi
+])
+
+dnl Test whether mbrtowc puts the state into non-initial state when parsing an
+dnl incomplete multibyte character.
+dnl Result is gl_cv_func_mbrtowc_incomplete_state.
+
+AC_DEFUN([gl_MBRTOWC_INCOMPLETE_STATE],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gt_LOCALE_JA])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether mbrtowc handles incomplete characters],
+    [gl_cv_func_mbrtowc_incomplete_state],
+    [
+      dnl Initial guess, used when cross-compiling or when no suitable locale
+      dnl is present.
+changequote(,)dnl
+      case "$host_os" in
+              # Guess no on AIX and OSF/1.
+        osf*) gl_cv_func_mbrtowc_incomplete_state="guessing no" ;;
+              # Guess yes otherwise.
+        *)    gl_cv_func_mbrtowc_incomplete_state="guessing yes" ;;
+      esac
+changequote([,])dnl
+      if test $LOCALE_JA != none; then
+        AC_TRY_RUN([
+#include <locale.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+  if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
+    {
+      const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
+      mbstate_t state;
+      wchar_t wc;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
+        if (mbsinit (&state))
+          return 1;
+    }
+  return 0;
+}],
+          [gl_cv_func_mbrtowc_incomplete_state=yes],
+          [gl_cv_func_mbrtowc_incomplete_state=no],
+          [])
+      fi
+    ])
+])
+
+dnl Test whether mbrtowc supports a NULL string argument correctly.
+dnl Result is gl_cv_func_mbrtowc_null_arg.
+
+AC_DEFUN([gl_MBRTOWC_NULL_ARG],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gt_LOCALE_FR_UTF8])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether mbrtowc handles a NULL string argument],
+    [gl_cv_func_mbrtowc_null_arg],
+    [
+      dnl Initial guess, used when cross-compiling or when no suitable locale
+      dnl is present.
+changequote(,)dnl
+      case "$host_os" in
+              # Guess no on OSF/1.
+        osf*) gl_cv_func_mbrtowc_null_arg="guessing no" ;;
+              # Guess yes otherwise.
+        *)    gl_cv_func_mbrtowc_null_arg="guessing yes" ;;
+      esac
+changequote([,])dnl
+      if test $LOCALE_FR_UTF8 != none; then
+        AC_TRY_RUN([
+#include <locale.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+  if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
+    {
+      mbstate_t state;
+      wchar_t wc;
+      int ret;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      wc = (wchar_t) 0xBADFACE;
+      mbrtowc (&wc, NULL, 5, &state);
+      /* Check that wc was not modified.  */
+      if (wc != (wchar_t) 0xBADFACE)
+        return 1;
+    }
+  return 0;
+}], [gl_cv_func_mbrtowc_null_arg=yes], [gl_cv_func_mbrtowc_null_arg=no], [])
+      fi
+    ])
+])
+
+dnl Test whether mbrtowc, when parsing the end of a multibyte character,
+dnl correctly returns the number of bytes that were needed to complete the
+dnl character (not the total number of bytes of the multibyte character).
+dnl Result is gl_cv_func_mbrtowc_retval.
+
+AC_DEFUN([gl_MBRTOWC_RETVAL],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gt_LOCALE_FR_UTF8])
+  AC_REQUIRE([gt_LOCALE_JA])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether mbrtowc has a correct return value],
+    [gl_cv_func_mbrtowc_retval],
+    [
+      dnl Initial guess, used when cross-compiling or when no suitable locale
+      dnl is present.
+changequote(,)dnl
+      case "$host_os" in
+                          # Guess no on HP-UX and Solaris.
+        hpux* | solaris*) gl_cv_func_mbrtowc_retval="guessing no" ;;
+                          # Guess yes otherwise.
+        *)                gl_cv_func_mbrtowc_retval="guessing yes" ;;
+      esac
+changequote([,])dnl
+      if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none; then
+        AC_TRY_RUN([
+#include <locale.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+  /* This fails on Solaris.  */
+  if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
+    {
+      char input[] = "B\303\274\303\237er"; /* "Büßer" */
+      mbstate_t state;
+      wchar_t wc;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
+        {
+          input[1] = '\0';
+          if (mbrtowc (&wc, input + 2, 5, &state) != 1)
+            return 1;
+        }
+    }
+  /* This fails on HP-UX 11.11.  */
+  if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
+    {
+      char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
+      mbstate_t state;
+      wchar_t wc;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
+        {
+          input[1] = '\0';
+          if (mbrtowc (&wc, input + 2, 5, &state) != 2)
+            return 1;
+        }
+    }
+  return 0;
+}],
+          [gl_cv_func_mbrtowc_retval=yes],
+          [gl_cv_func_mbrtowc_retval=no],
+          [])
+      fi
+    ])
+])
+
+dnl Test whether mbrtowc, when parsing a NUL character, correctly returns 0.
+dnl Result is gl_cv_func_mbrtowc_nul_retval.
+
+AC_DEFUN([gl_MBRTOWC_NUL_RETVAL],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([gt_LOCALE_ZH_CN])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether mbrtowc returns 0 when parsing a NUL character],
+    [gl_cv_func_mbrtowc_nul_retval],
+    [
+      dnl Initial guess, used when cross-compiling or when no suitable locale
+      dnl is present.
+changequote(,)dnl
+      case "$host_os" in
+                    # Guess no on Solaris 9.
+        solaris2.9) gl_cv_func_mbrtowc_nul_retval="guessing no" ;;
+                    # Guess yes otherwise.
+        *)          gl_cv_func_mbrtowc_nul_retval="guessing yes" ;;
+      esac
+changequote([,])dnl
+      if test $LOCALE_ZH_CN != none; then
+        AC_TRY_RUN([
+#include <locale.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+  /* This fails on Solaris 9.  */
+  if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
+    {
+      mbstate_t state;
+      wchar_t wc;
+
+      memset (&state, '\0', sizeof (mbstate_t));
+      if (mbrtowc (&wc, "", 1, &state) != 0)
+        return 1;
+    }
+  return 0;
+}],
+          [gl_cv_func_mbrtowc_nul_retval=yes],
+          [gl_cv_func_mbrtowc_nul_retval=no],
+          [])
+      fi
+    ])
+])
+
+# Prerequisites of lib/mbrtowc.c.
+AC_DEFUN([gl_PREREQ_MBRTOWC], [
+  :
+])
+
+
+dnl From Paul Eggert
+
+dnl This override of an autoconf macro can be removed when autoconf 2.60 or
+dnl newer can be assumed everywhere.
+
+m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.60]),[-1],[
+AC_DEFUN([AC_FUNC_MBRTOWC],
+[
+  dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60.
+  AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared],
+    gl_cv_func_mbrtowc,
+    [AC_LINK_IFELSE(
+       [AC_LANG_PROGRAM(
+            [[#include <wchar.h>]],
+            [[wchar_t wc;
+              char const s[] = "";
+              size_t n = 1;
+              mbstate_t state;
+              return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])],
+       gl_cv_func_mbrtowc=yes,
+       gl_cv_func_mbrtowc=no)])
+  if test $gl_cv_func_mbrtowc = yes; then
+    AC_DEFINE([HAVE_MBRTOWC], [1],
+      [Define to 1 if mbrtowc and mbstate_t are properly declared.])
+  fi
+])
+])
diff --git a/m4/mbsinit.m4 b/m4/mbsinit.m4
new file mode 100644
index 0000000..03b055c
--- /dev/null
+++ b/m4/mbsinit.m4
@@ -0,0 +1,30 @@
+# mbsinit.m4 serial 3
+dnl Copyright (C) 2008 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_MBSINIT],
+[
+  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+
+  AC_REQUIRE([AC_TYPE_MBSTATE_T])
+  gl_MBSTATE_T_BROKEN
+  if test $REPLACE_MBSTATE_T = 1; then
+    REPLACE_MBSINIT=1
+  fi
+  AC_CHECK_FUNCS_ONCE([mbsinit])
+  if test $ac_cv_func_mbsinit = no; then
+    HAVE_MBSINIT=0
+  fi
+  if test $HAVE_MBSINIT = 0 || test $REPLACE_MBSINIT = 1; then
+    gl_REPLACE_WCHAR_H
+    AC_LIBOBJ([mbsinit])
+    gl_PREREQ_MBSINIT
+  fi
+])
+
+# Prerequisites of lib/mbsinit.c.
+AC_DEFUN([gl_PREREQ_MBSINIT], [
+  :
+])
diff --git a/m4/mbstate_t.m4 b/m4/mbstate_t.m4
index 0da32b6..d4ec6f0 100644
--- a/m4/mbstate_t.m4
+++ b/m4/mbstate_t.m4
@@ -1,5 +1,5 @@
-# mbstate_t.m4 serial 10
-dnl Copyright (C) 2000-2002, 2008 Free Software Foundation, Inc.
+# mbstate_t.m4 serial 12
+dnl Copyright (C) 2000-2002, 2008, 2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -13,7 +13,10 @@ dnl with or without modifications, as long as this notice is 
preserved.
 # AC_TYPE_MBSTATE_T
 # -----------------
 AC_DEFUN([AC_TYPE_MBSTATE_T],
-  [AC_CACHE_CHECK([for mbstate_t], ac_cv_type_mbstate_t,
+[
+   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) dnl for HP-UX 11.11
+
+   AC_CACHE_CHECK([for mbstate_t], [ac_cv_type_mbstate_t],
      [AC_COMPILE_IFELSE(
        [AC_LANG_PROGRAM(
           [AC_INCLUDES_DEFAULT[
@@ -22,9 +25,10 @@ AC_DEFUN([AC_TYPE_MBSTATE_T],
        [ac_cv_type_mbstate_t=yes],
        [ac_cv_type_mbstate_t=no])])
    if test $ac_cv_type_mbstate_t = yes; then
-     AC_DEFINE([HAVE_MBSTATE_T], 1,
+     AC_DEFINE([HAVE_MBSTATE_T], [1],
               [Define to 1 if <wchar.h> declares mbstate_t.])
    else
-     AC_DEFINE([mbstate_t], int,
+     AC_DEFINE([mbstate_t], [int],
               [Define to a type if <wchar.h> does not define.])
-   fi])
+   fi
+])
diff --git a/m4/stdbool.m4 b/m4/stdbool.m4
index 2204ecd..57c804a 100644
--- a/m4/stdbool.m4
+++ b/m4/stdbool.m4
@@ -1,6 +1,6 @@
 # Check for stdbool.h that conforms to C99.
 
-dnl Copyright (C) 2002-2006 Free Software Foundation, Inc.
+dnl Copyright (C) 2002-2006, 2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -111,5 +111,5 @@ AC_DEFUN([AC_HEADER_STDBOOL],
        [ac_cv_header_stdbool_h=no])])
    AC_CHECK_TYPES([_Bool])
    if test $ac_cv_header_stdbool_h = yes; then
-     AC_DEFINE(HAVE_STDBOOL_H, 1, [Define to 1 if stdbool.h conforms to C99.])
+     AC_DEFINE([HAVE_STDBOOL_H], [1], [Define to 1 if stdbool.h conforms to 
C99.])
    fi])
diff --git a/m4/strcase.m4 b/m4/strcase.m4
index 79c525c..0dfdb1a 100644
--- a/m4/strcase.m4
+++ b/m4/strcase.m4
@@ -1,5 +1,5 @@
-# strcase.m4 serial 9
-dnl Copyright (C) 2002, 2005-2008 Free Software Foundation, Inc.
+# strcase.m4 serial 10
+dnl Copyright (C) 2002, 2005-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -13,7 +13,7 @@ AC_DEFUN([gl_STRCASE],
 AC_DEFUN([gl_FUNC_STRCASECMP],
 [
   AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS])
-  AC_REPLACE_FUNCS(strcasecmp)
+  AC_REPLACE_FUNCS([strcasecmp])
   if test $ac_cv_func_strcasecmp = no; then
     HAVE_STRCASECMP=0
     gl_PREREQ_STRCASECMP
@@ -23,11 +23,11 @@ AC_DEFUN([gl_FUNC_STRCASECMP],
 AC_DEFUN([gl_FUNC_STRNCASECMP],
 [
   AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS])
-  AC_REPLACE_FUNCS(strncasecmp)
+  AC_REPLACE_FUNCS([strncasecmp])
   if test $ac_cv_func_strncasecmp = no; then
     gl_PREREQ_STRNCASECMP
   fi
-  AC_CHECK_DECLS(strncasecmp)
+  AC_CHECK_DECLS([strncasecmp])
   if test $ac_cv_have_decl_strncasecmp = no; then
     HAVE_DECL_STRNCASECMP=0
   fi
diff --git a/m4/strftime.m4 b/m4/strftime.m4
index 70b5378..156defb 100644
--- a/m4/strftime.m4
+++ b/m4/strftime.m4
@@ -1,7 +1,7 @@
-#serial 29
+# serial 30
 
 # Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-# 2006, 2007 Free Software Foundation, Inc.
+# 2006, 2007, 2009 Free Software Foundation, Inc.
 #
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -25,8 +25,8 @@ AC_DEFUN([gl_FUNC_STRFTIME],
  AC_REQUIRE([AC_TYPE_MBSTATE_T])
  AC_REQUIRE([gl_TM_GMTOFF])
 
- AC_CHECK_FUNCS_ONCE(mblen mbrlen mempcpy tzset)
- AC_CHECK_HEADERS_ONCE(wchar.h)
+ AC_CHECK_FUNCS_ONCE([mblen mbrlen mempcpy tzset])
+ AC_CHECK_HEADERS_ONCE([wchar.h])
 
  AC_DEFINE([my_strftime], [nstrftime],
    [Define to the name of the strftime replacement function.])
diff --git a/m4/tm_gmtoff.m4 b/m4/tm_gmtoff.m4
index cb0b3c8..911af0a 100644
--- a/m4/tm_gmtoff.m4
+++ b/m4/tm_gmtoff.m4
@@ -1,5 +1,5 @@
-# tm_gmtoff.m4 serial 2
-dnl Copyright (C) 2002 Free Software Foundation, Inc.
+# tm_gmtoff.m4 serial 3
+dnl Copyright (C) 2002, 2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is 
preserved.
 AC_DEFUN([gl_TM_GMTOFF],
 [
  AC_CHECK_MEMBER([struct tm.tm_gmtoff],
-                 [AC_DEFINE(HAVE_TM_GMTOFF, 1,
+                 [AC_DEFINE([HAVE_TM_GMTOFF], [1],
                             [Define if struct tm has the tm_gmtoff member.])],
                  ,
                  [#include <time.h>])
diff --git a/m4/wchar.m4 b/m4/wchar.m4
index 5c923fa..ba8ee6a 100644
--- a/m4/wchar.m4
+++ b/m4/wchar.m4
@@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is 
preserved.
 
 dnl Written by Eric Blake.
 
-# wchar.m4 serial 6
+# wchar.m4 serial 22
 
 AC_DEFUN([gl_WCHAR_H],
 [
@@ -61,9 +61,39 @@ AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
 
 AC_DEFUN([gl_WCHAR_H_DEFAULTS],
 [
-  GNULIB_WCWIDTH=0; AC_SUBST([GNULIB_WCWIDTH])
+  GNULIB_BTOWC=0;      AC_SUBST([GNULIB_BTOWC])
+  GNULIB_WCTOB=0;      AC_SUBST([GNULIB_WCTOB])
+  GNULIB_MBSINIT=0;    AC_SUBST([GNULIB_MBSINIT])
+  GNULIB_MBRTOWC=0;    AC_SUBST([GNULIB_MBRTOWC])
+  GNULIB_MBRLEN=0;     AC_SUBST([GNULIB_MBRLEN])
+  GNULIB_MBSRTOWCS=0;  AC_SUBST([GNULIB_MBSRTOWCS])
+  GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS])
+  GNULIB_WCRTOMB=0;    AC_SUBST([GNULIB_WCRTOMB])
+  GNULIB_WCSRTOMBS=0;  AC_SUBST([GNULIB_WCSRTOMBS])
+  GNULIB_WCSNRTOMBS=0; AC_SUBST([GNULIB_WCSNRTOMBS])
+  GNULIB_WCWIDTH=0;    AC_SUBST([GNULIB_WCWIDTH])
   dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_BTOWC=1;        AC_SUBST([HAVE_BTOWC])
+  HAVE_MBSINIT=1;      AC_SUBST([HAVE_MBSINIT])
+  HAVE_MBRTOWC=1;      AC_SUBST([HAVE_MBRTOWC])
+  HAVE_MBRLEN=1;       AC_SUBST([HAVE_MBRLEN])
+  HAVE_MBSRTOWCS=1;    AC_SUBST([HAVE_MBSRTOWCS])
+  HAVE_MBSNRTOWCS=1;   AC_SUBST([HAVE_MBSNRTOWCS])
+  HAVE_WCRTOMB=1;      AC_SUBST([HAVE_WCRTOMB])
+  HAVE_WCSRTOMBS=1;    AC_SUBST([HAVE_WCSRTOMBS])
+  HAVE_WCSNRTOMBS=1;   AC_SUBST([HAVE_WCSNRTOMBS])
+  HAVE_DECL_WCTOB=1;   AC_SUBST([HAVE_DECL_WCTOB])
   HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH])
+  REPLACE_MBSTATE_T=0; AC_SUBST([REPLACE_MBSTATE_T])
+  REPLACE_BTOWC=0;     AC_SUBST([REPLACE_BTOWC])
+  REPLACE_WCTOB=0;     AC_SUBST([REPLACE_WCTOB])
+  REPLACE_MBSINIT=0;   AC_SUBST([REPLACE_MBSINIT])
+  REPLACE_MBRTOWC=0;   AC_SUBST([REPLACE_MBRTOWC])
+  REPLACE_MBRLEN=0;    AC_SUBST([REPLACE_MBRLEN])
+  REPLACE_MBSRTOWCS=0; AC_SUBST([REPLACE_MBSRTOWCS])
+  REPLACE_MBSNRTOWCS=0;AC_SUBST([REPLACE_MBSNRTOWCS])
+  REPLACE_WCRTOMB=0;   AC_SUBST([REPLACE_WCRTOMB])
+  REPLACE_WCSRTOMBS=0; AC_SUBST([REPLACE_WCSRTOMBS])
   REPLACE_WCWIDTH=0;   AC_SUBST([REPLACE_WCWIDTH])
   WCHAR_H='';          AC_SUBST([WCHAR_H])
 ])
diff --git a/m4/wint_t.m4 b/m4/wint_t.m4
index af5ed93..47a4363 100644
--- a/m4/wint_t.m4
+++ b/m4/wint_t.m4
@@ -1,5 +1,5 @@
-# wint_t.m4 serial 2 (gettext-0.17)
-dnl Copyright (C) 2003, 2007 Free Software Foundation, Inc.
+# wint_t.m4 serial 4 (gettext-0.18)
+dnl Copyright (C) 2003, 2007-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -10,7 +10,7 @@ dnl Prerequisite: AC_PROG_CC
 
 AC_DEFUN([gt_TYPE_WINT_T],
 [
-  AC_CACHE_CHECK([for wint_t], gt_cv_c_wint_t,
+  AC_CACHE_CHECK([for wint_t], [gt_cv_c_wint_t],
     [AC_TRY_COMPILE([
 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
    <wchar.h>.
@@ -21,8 +21,8 @@ AC_DEFUN([gt_TYPE_WINT_T],
 #include <time.h>
 #include <wchar.h>
        wint_t foo = (wchar_t)'\0';], ,
-       gt_cv_c_wint_t=yes, gt_cv_c_wint_t=no)])
+       [gt_cv_c_wint_t=yes], [gt_cv_c_wint_t=no])])
   if test $gt_cv_c_wint_t = yes; then
-    AC_DEFINE(HAVE_WINT_T, 1, [Define if you have the 'wint_t' type.])
+    AC_DEFINE([HAVE_WINT_T], [1], [Define if you have the 'wint_t' type.])
   fi
 ])
-- 
1.6.0.4


reply via email to

[Prev in Thread] Current Thread [Next in Thread]