]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Since gettext is doesn't translate any more in the C locale, we must use
authorBruno Haible <bruno@clisp.org>
Wed, 17 Jan 2001 17:45:22 +0000 (17:45 +0000)
committerBruno Haible <bruno@clisp.org>
Wed, 17 Jan 2001 17:45:22 +0000 (17:45 +0000)
setlocale() in the testsuite. But since SunOS 4 and other old systems have
no other locales than the C locale, we must implement a fake setlocale()
ourselves.

16 files changed:
ChangeLog
configure.in
m4/ChangeLog
m4/Makefile.am
m4/setlocale.m4 [new file with mode: 0644]
src/ChangeLog
src/Makefile.am
src/setlocale.c [new file with mode: 0644]
tests/ChangeLog
tests/Makefile.am
tests/gettext-1
tests/gettext-2
tests/msgfmt-1
tests/msgfmt-2
tests/plural-1
tests/plural-1-prg.c

index eecf24f9932430134de5530dadf3003007105ac9..025aacfecd59b6fbcc0e826aed423937c429d6fa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2001-01-06  Bruno Haible  <haible@clisp.cons.org>
+
+       * configure.in: Use AC_CHECK_HEADERS instead of AC_HAVE_HEADERS.
+       Call gt_SETLOCALE.
+
 2000-12-30  Bruno Haible  <haible@clisp.cons.org>
 
        * ltconfig, ltmain.sh: Update from libtool-1.3.5.
index 0ee90f1145ccc535032f5047be12637863642a6e..1d46931e3874ab54ddda8b2e3bf6ce5f15333616 100644 (file)
@@ -1,6 +1,6 @@
 dnl Process this file with autoconf to produce a configure script.
 AC_PREREQ(2.12)
-AC_REVISION($Revision: 1.5 $)
+AC_REVISION($Revision: 1.6 $)
 AC_INIT(src/msgfmt.c)
 AM_INIT_AUTOMAKE(gettext, 0.10.36)
 AM_CONFIG_HEADER(config.h)
@@ -22,7 +22,7 @@ dnl Checks for libraries.
 
 dnl Checks for header files.
 AC_HEADER_STDC
-AC_HAVE_HEADERS(limits.h malloc.h string.h unistd.h values.h)
+AC_CHECK_HEADERS(limits.h malloc.h string.h unistd.h values.h)
 
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
@@ -54,6 +54,8 @@ fi
 
 AM_FUNC_ERROR_AT_LINE
 
+gt_SETLOCALE
+
 dnl These are the only lines required to internationalize the package.
 dnl (OK, not quite, the AC_OUTPUT has also some parts.)
 AM_GNU_GETTEXT
index 172e13b5df94941ff1f5d9c9f817dbb8cde79e40..638ee25f3f83106b44f2cbff1d2c3d8c059dc0bb 100644 (file)
@@ -1,3 +1,8 @@
+2001-01-06  Bruno Haible  <haible@clisp.cons.org>
+
+       * setlocale.m4: New file.
+       * Makefile.am (EXTRA_DIST): Add it.
+
 2001-01-06  Bruno Haible  <haible@clisp.cons.org>
 
        * gettext.m4 (AM_WITH_NLS): Look for GNU gettext in libc and libintl,
index eb744a4bd9f3a1fd83a5becf7db3fdb84eec88dc..00f37f057752723041a67a8a22ec18991d2a2dd9 100644 (file)
@@ -8,4 +8,4 @@ aclocal_DATA = gettext.m4 isc-posix.m4 lcmessage.m4 progtest.m4
 #   |sed 's/@$/%/;s/@/ \\@/g' |tr @% '\012\012'
 EXTRA_DIST = README \
 c-bs-a.m4 codeset.m4 gettext.m4 iconv.m4 inttypes_h.m4 isc-posix.m4 \
-lcmessage.m4 progtest.m4 uintmax_t.m4 ulonglong.m4
+lcmessage.m4 progtest.m4 setlocale.m4 uintmax_t.m4 ulonglong.m4
diff --git a/m4/setlocale.m4 b/m4/setlocale.m4
new file mode 100644 (file)
index 0000000..3b400ca
--- /dev/null
@@ -0,0 +1,26 @@
+#serial 1
+
+# Check for setlocale declaration.
+
+AC_DEFUN(gt_SETLOCALE,[
+AC_CHECK_HEADERS([locale.h])
+AC_MSG_CHECKING([for setlocale declaration])
+AC_CACHE_VAL(gt_cv_proto_setlocale, [
+AC_TRY_COMPILE([
+#include <stdlib.h>
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+#if defined(__STDC__) || defined(__cplusplus)
+char* setlocale (int category, char* locale);
+#else
+char* setlocale();
+#endif
+], [], gt_cv_proto_setlocale_arg1="", gt_cv_proto_setlocale_arg1="const")
+gt_cv_proto_setlocale="extern char* setlocale (int, $gt_cv_proto_setlocale_arg1 char*);"])
+gt_cv_proto_setlocale=`echo "[$]gt_cv_proto_setlocale" | tr -s ' ' | sed -e 's/( /(/'`
+AC_MSG_RESULT([$]{ac_t:-
+         }[$]gt_cv_proto_setlocale)
+AC_DEFINE_UNQUOTED(SETLOCALE_CONST,$gt_cv_proto_setlocale_arg1,
+  [Define as const if the declaration of setlocale() needs const.])
+])
index 1e81e11ae43d52920f0ded2332228b609cffe40d..652b9719902998096bbbf61899200b2d4422eeb4 100644 (file)
@@ -1,3 +1,11 @@
+2001-01-06  Bruno Haible  <haible@clisp.cons.org>
+
+       * setlocale.c: New file.
+       * Makefile.am (EXTRA_PROGRAMS): New variable.
+       (all-local): New target.
+       (CLEANFILES): New variable.
+       (tstgettext_SOURCES): New variable.
+
 2001-01-05  Bruno Haible  <haible@clisp.cons.org>
 
        * Makefile.am (po-gram-gen.h): Don't use $^, not supported by the
index 3ad74f50b41b03ab5d469c31f50c0d544f4c0bf9..a896b67b375b8baa5c375839fcd1eb3782b8c9b9 100644 (file)
@@ -39,8 +39,13 @@ LDADD = ../lib/libnlsut.a @INTLLIBS@ ../intl/libintl.$la
 SED = sed
 YACC = @YACC@ -d
 
-# Source dependecies.
+EXTRA_PROGRAMS = tstgettext
+all-local: $(EXTRA_PROGRAMS)
+CLEANFILES = $(EXTRA_PROGRAMS)
+
+# Source dependencies.
 gettext_SOURCES = gettextp.c
+tstgettext_SOURCES = gettextp.c setlocale.c
 msgcmp_SOURCES = message.c msgcmp.c open-po.c po-gram-gen.y po-hash-gen.y \
 po-lex.c po.c str-list.c dir-list.c
 msgfmt_SOURCES = msgfmt.c open-po.c po-gram-gen.y po-hash-gen.y po-lex.c po.c \
diff --git a/src/setlocale.c b/src/setlocale.c
new file mode 100644 (file)
index 0000000..eed05a1
--- /dev/null
@@ -0,0 +1,192 @@
+/* Fake setlocale - platform independent, for testing purposes.
+   Copyright (C) 2001 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#else
+# ifdef HAVE_MALLOC_H
+#  include <malloc.h>
+# endif
+extern char *getenv ();
+#endif
+
+#ifdef HAVE_LOCALE_H
+# include <locale.h>
+#endif
+
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+/* Return string representation of locale CATEGORY.  */
+static const char *
+category_to_name (category)
+     int category;
+{
+  const char *retval;
+
+  switch (category)
+  {
+#ifdef LC_COLLATE
+  case LC_COLLATE:
+    retval = "LC_COLLATE";
+    break;
+#endif
+#ifdef LC_CTYPE
+  case LC_CTYPE:
+    retval = "LC_CTYPE";
+    break;
+#endif
+#ifdef LC_MONETARY
+  case LC_MONETARY:
+    retval = "LC_MONETARY";
+    break;
+#endif
+#ifdef LC_NUMERIC
+  case LC_NUMERIC:
+    retval = "LC_NUMERIC";
+    break;
+#endif
+#ifdef LC_TIME
+  case LC_TIME:
+    retval = "LC_TIME";
+    break;
+#endif
+#ifdef LC_MESSAGES
+  case LC_MESSAGES:
+    retval = "LC_MESSAGES";
+    break;
+#endif
+#ifdef LC_RESPONSE
+  case LC_RESPONSE:
+    retval = "LC_RESPONSE";
+    break;
+#endif
+#ifdef LC_ALL
+  case LC_ALL:
+    /* This might not make sense but is perhaps better than any other
+       value.  */
+    retval = "LC_ALL";
+    break;
+#endif
+  default:
+    /* If you have a better idea for a default value let me know.  */
+    retval = "LC_XXX";
+  }
+
+  return retval;
+}
+
+/* An implementation of setlocale that always succeeds, but doesn't
+   actually change the behaviour of locale dependent functions.
+   Assumes setenv()/putenv() is not called.  */
+char *
+setlocale (category, locale)
+     int category;
+     SETLOCALE_CONST char *locale;
+{
+  char *retval;
+  static char C_string[] = "C";
+  static char *current_locale = C_string;
+#ifdef HAVE_LOCALE_H
+  struct list
+  {
+    int category;
+    char *current_locale;
+    struct list *next;
+  };
+  static struct list *facets = NULL;
+  struct list *facetp;
+
+  if (locale != NULL)
+    {
+      char *copy;
+
+      copy = (char *) malloc (strlen (locale) + 1);
+      strcpy (copy, locale);
+
+      if (category == LC_ALL)
+       {
+         while ((facetp = facets) != NULL)
+           {
+             facets = facetp->next;
+             free (facetp->current_locale);
+             free (facetp);
+           }
+         if (current_locale != C_string)
+           free (current_locale);
+         current_locale = copy;
+       }
+      else
+       {
+         for (facetp = facets; facetp != NULL; facetp = facetp->next)
+           if (category == facetp->category)
+             {
+               free (facetp->current_locale);
+               facetp->current_locale = copy;
+               break;
+             }
+         if (facetp == NULL)
+           {
+             facetp = (struct list *) malloc (sizeof (struct list));
+             facetp->category = category;
+             facetp->current_locale = copy;
+             facetp->next = facets;
+             facets = facetp;
+           }
+       }
+    }
+
+  retval = current_locale;
+  for (facetp = facets; facetp != NULL; facetp = facetp->next)
+    if (category == facetp->category)
+      {
+       retval = facetp->current_locale;
+       break;
+      }
+#else
+  if (locale != NULL)
+    {
+      if (current_locale != C_string)
+       free (current_locale);
+      current_locale = (char *) malloc (strlen (locale) + 1);
+      strcpy (current_locale, locale);
+    }
+
+  retval = current_locale;
+#endif
+
+  if (retval[0] == '\0')
+    {
+      retval = getenv ("LC_ALL");
+      if (retval == NULL || retval[0] == '\0')
+       {
+         retval = getenv (category_to_name (category));
+         if (retval == NULL || retval[0] == '\0')
+           {
+             retval = getenv ("LANG");
+             if (retval == NULL || retval[0] == '\0')
+               retval = "C";
+           }
+       }
+    }
+  return retval;
+}
index 4ec18c29b4fb890e0ef8206c89a7032c625de9ee..74660c7fe6eb07255be075c1e7f3ccb1230734d3 100644 (file)
@@ -1,3 +1,16 @@
+2001-01-06  Bruno Haible  <haible@clisp.cons.org>
+
+       Translations are now disabled in C locale.
+       * Makefile.am (TESTS_ENVIRONMENT): Use tstgettext for $GETTEXT.
+       (cake_LDADD): Add ../src/setlocale.o.
+       * gettext-1: Set LC_ALL to a nonempty value.
+       * gettext-2: Likewise.
+       * msgfmt-1: Likewise.
+       * msgfmt-2: Likewise.
+       * plural-1: Set LC_ALL, not LANGUAGE, to "fr".
+       * plural-1-prg.c: Include locale.h or declare setlocale.
+       (main): Call setlocale.
+
 2001-01-04  Bruno Haible  <haible@clisp.cons.org>
 
        * plural-1-prg.c: Include config.h. Needed for C compilers lacking
index 4c92482e24e57dc0aae0cbbd545c37af7edc57be..a7f7d5c3970162d562b5cf7949effe08006243f4 100644 (file)
@@ -29,7 +29,7 @@ EXTRA_DIST = $(TESTS) test.mo xg-test1.ok.po
 XGETTEXT = ../src/xgettext
 
 TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) PATH=../src:$$PATH \
-                   GETTEXT=`echo gettext|sed '$(transform)'` \
+                   GETTEXT=tstgettext \
                    XGETTEXT=`echo xgettext|sed '$(transform)'` \
                    MSGFMT=`echo msgfmt|sed '$(transform)'` \
                    MSGCMP=`echo msgcmp|sed '$(transform)'` \
@@ -47,6 +47,6 @@ xg-test1.ok.po: $(top_srcdir)/src/xgettext.c $(top_srcdir)/src/msgfmt.c \
 INCLUDES = -I${top_srcdir}/intl
 EXTRA_PROGRAMS = cake
 cake_SOURCES = plural-1-prg.c
-cake_LDADD = ../intl/libintl.a
+cake_LDADD = ../src/setlocale.o ../intl/libintl.a
 all-local: cake
 CLEANFILES = cake
index 2e8b967785597afb08affc6449d1b50f46c5acbf..34147a421c179ec33e77d4e299e93bbec944df28 100755 (executable)
@@ -4,7 +4,7 @@
 
 TEXTDOMAINDIR=..
 LANGUAGE=tests
-LC_ALL=
+LC_ALL=en
 LC_MESSAGES=
 LANG=
 export TEXTDOMAINDIR LANGUAGE LC_ALL LC_MESSAGES LANG
index 87f402292bcee600e8d25aa62e0ce44dc8470d26..5bde6ebe5a1e26447da00feeac5d26ea9bfeae65 100755 (executable)
@@ -4,7 +4,7 @@
 
 TEXTDOMAINDIR=..
 LANGUAGE=tests
-LC_ALL=
+LC_ALL=en
 LC_MESSAGES=
 LANG=
 export TEXTDOMAINDIR LANGUAGE LC_ALL LC_MESSAGES LANG
index 033843d9a436580caf0bb2efe886f71e049ae8e2..1d1643426fd79d8e5ee31bf9d790c18ee92aafbc 100755 (executable)
@@ -2,7 +2,7 @@
 
 TEXTDOMAINDIR=..
 LANGUAGE=tests
-LC_ALL=
+LC_ALL=en
 LC_MESSAGES=
 LANG=
 export TEXTDOMAINDIR LANGUAGE LC_ALL LC_MESSAGES LANG
index 5acc2dbb3e1d9a5e0083757e48ca64b6fd744746..7976fce3caac8bec049ef26745105fa362af9bc7 100755 (executable)
@@ -2,7 +2,7 @@
 
 TEXTDOMAINDIR=..
 LANGUAGE=tests
-LC_ALL=
+LC_ALL=en
 LC_MESSAGES=
 LANG=
 export TEXTDOMAINDIR LANGUAGE LC_ALL LC_MESSAGES LANG
index 52a186e3190e3e0a97e93f45c82b8c673300925c..39c4f22d4d261d808bef2b97708a157e5ca75964 100644 (file)
@@ -51,8 +51,8 @@ sed 1d < fr.po > fr.po.strip
 : ${DIFF=diff}
 ${DIFF} fr.po.strip fr.po.tmp || exit 1
 
-LANGUAGE=fr
-LC_ALL=
+LANGUAGE=
+LC_ALL=fr
 LC_MESSAGES=
 LANG=
 export LANGUAGE LC_ALL LC_MESSAGES LANG
index 38e8f5b237c3ab40846a426c94b9a612ce4cc8f7..daaa580b72f0a0995116a9cfd076732f4901b19d 100644 (file)
@@ -7,6 +7,12 @@
 #include <stdlib.h>
 #include <stdio.h>
 
+#ifdef HAVE_LOCALE_H
+# include <locale.h>
+#else
+extern char *setlocale ();
+#endif
+
 /* Make sure we use the included libintl, not the system's one. */
 #if 0
 #include <libintl.h>
@@ -26,6 +32,10 @@ int main (argc, argv)
   char *argv[];
 {
   int n = atoi (argv[1]);
+
+  if (setlocale (LC_ALL, "") == NULL)
+    return 1;
+
   textdomain ("cake");
   bindtextdomain ("cake", ".");
   printf (ngettext ("a piece of cake", "%d pieces of cake", n), n);