From: Bruno Haible Date: Wed, 17 Jan 2001 17:45:22 +0000 (+0000) Subject: Since gettext is doesn't translate any more in the C locale, we must use X-Git-Tag: v0.10.36~185 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7a991ef5dcd4db939e5a90957a431544d1864d8;p=thirdparty%2Fgettext.git Since gettext is doesn't translate any more in the C locale, we must use 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. --- diff --git a/ChangeLog b/ChangeLog index eecf24f99..025aacfec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2001-01-06 Bruno Haible + + * configure.in: Use AC_CHECK_HEADERS instead of AC_HAVE_HEADERS. + Call gt_SETLOCALE. + 2000-12-30 Bruno Haible * ltconfig, ltmain.sh: Update from libtool-1.3.5. diff --git a/configure.in b/configure.in index 0ee90f114..1d46931e3 100644 --- a/configure.in +++ b/configure.in @@ -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 diff --git a/m4/ChangeLog b/m4/ChangeLog index 172e13b5d..638ee25f3 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,8 @@ +2001-01-06 Bruno Haible + + * setlocale.m4: New file. + * Makefile.am (EXTRA_DIST): Add it. + 2001-01-06 Bruno Haible * gettext.m4 (AM_WITH_NLS): Look for GNU gettext in libc and libintl, diff --git a/m4/Makefile.am b/m4/Makefile.am index eb744a4bd..00f37f057 100644 --- a/m4/Makefile.am +++ b/m4/Makefile.am @@ -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 index 000000000..3b400ca62 --- /dev/null +++ b/m4/setlocale.m4 @@ -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 +#ifdef HAVE_LOCALE_H +#include +#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.]) +]) diff --git a/src/ChangeLog b/src/ChangeLog index 1e81e11ae..652b97199 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2001-01-06 Bruno Haible + + * 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 * Makefile.am (po-gram-gen.h): Don't use $^, not supported by the diff --git a/src/Makefile.am b/src/Makefile.am index 3ad74f50b..a896b67b3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 index 000000000..eed05a12d --- /dev/null +++ b/src/setlocale.c @@ -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 +#endif + +#ifdef HAVE_STDLIB_H +# include +#else +# ifdef HAVE_MALLOC_H +# include +# endif +extern char *getenv (); +#endif + +#ifdef HAVE_LOCALE_H +# include +#endif + +#ifdef HAVE_STRING_H +# include +#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; +} diff --git a/tests/ChangeLog b/tests/ChangeLog index 4ec18c29b..74660c7fe 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,16 @@ +2001-01-06 Bruno Haible + + 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 * plural-1-prg.c: Include config.h. Needed for C compilers lacking diff --git a/tests/Makefile.am b/tests/Makefile.am index 4c92482e2..a7f7d5c39 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 diff --git a/tests/gettext-1 b/tests/gettext-1 index 2e8b96778..34147a421 100755 --- a/tests/gettext-1 +++ b/tests/gettext-1 @@ -4,7 +4,7 @@ TEXTDOMAINDIR=.. LANGUAGE=tests -LC_ALL= +LC_ALL=en LC_MESSAGES= LANG= export TEXTDOMAINDIR LANGUAGE LC_ALL LC_MESSAGES LANG diff --git a/tests/gettext-2 b/tests/gettext-2 index 87f402292..5bde6ebe5 100755 --- a/tests/gettext-2 +++ b/tests/gettext-2 @@ -4,7 +4,7 @@ TEXTDOMAINDIR=.. LANGUAGE=tests -LC_ALL= +LC_ALL=en LC_MESSAGES= LANG= export TEXTDOMAINDIR LANGUAGE LC_ALL LC_MESSAGES LANG diff --git a/tests/msgfmt-1 b/tests/msgfmt-1 index 033843d9a..1d1643426 100755 --- a/tests/msgfmt-1 +++ b/tests/msgfmt-1 @@ -2,7 +2,7 @@ TEXTDOMAINDIR=.. LANGUAGE=tests -LC_ALL= +LC_ALL=en LC_MESSAGES= LANG= export TEXTDOMAINDIR LANGUAGE LC_ALL LC_MESSAGES LANG diff --git a/tests/msgfmt-2 b/tests/msgfmt-2 index 5acc2dbb3..7976fce3c 100755 --- a/tests/msgfmt-2 +++ b/tests/msgfmt-2 @@ -2,7 +2,7 @@ TEXTDOMAINDIR=.. LANGUAGE=tests -LC_ALL= +LC_ALL=en LC_MESSAGES= LANG= export TEXTDOMAINDIR LANGUAGE LC_ALL LC_MESSAGES LANG diff --git a/tests/plural-1 b/tests/plural-1 index 52a186e31..39c4f22d4 100644 --- a/tests/plural-1 +++ b/tests/plural-1 @@ -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 diff --git a/tests/plural-1-prg.c b/tests/plural-1-prg.c index 38e8f5b23..daaa580b7 100644 --- a/tests/plural-1-prg.c +++ b/tests/plural-1-prg.c @@ -7,6 +7,12 @@ #include #include +#ifdef HAVE_LOCALE_H +# include +#else +extern char *setlocale (); +#endif + /* Make sure we use the included libintl, not the system's one. */ #if 0 #include @@ -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);