From 47340af0f07f3a5e66c1654b16acbb5bf64435cb Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 7 Jan 2002 17:50:01 +0000 Subject: Change the tests to be less verbose on Solaris and HP-UX. --- tests/ChangeLog | 32 ++++ tests/gettext-1 | 10 +- tests/gettext-2 | 10 +- tests/lang-c | 6 +- tests/lang-c++ | 6 +- tests/lang-objc | 6 +- tests/msgcmp-2 | 7 +- tests/msgfmt-1 | 10 +- tests/msgfmt-2 | 10 +- tests/msgmerge-2 | 7 +- tests/plural-1 | 12 +- tests/plural-1-prg.c | 4 +- tests/plural-2 | 4 +- tests/tstgettext.c | 406 ++++++++++++++++++++++++++++++++++++++++++++++++++- tests/tstngettext.c | 23 +++ 15 files changed, 484 insertions(+), 69 deletions(-) (limited to 'tests') diff --git a/tests/ChangeLog b/tests/ChangeLog index b122aef..d5c1366 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,5 +1,37 @@ 2002-01-05 Bruno Haible + Avoid setting LC_ALL for random shell and utility commands, including + libtool generated shell scripts. It generates extraneous output on + Solaris and HP-UX. + + * tstgettext.c: Copy code from ../src/gettext.c. Add --env option. + * gettext-1: Pass extra environment variables only to the tstgettext + program. Pass LC_ALL via --env option. No need to pass LC_MESSAGES and + LANG. + * gettext-2: Likewise. + * msgfmt-1: Likewise. + * msgfmt-2: Likewise. + + * tstngettext.c: Add --env option. + * plural-2: Pass extra environment variables only to the tstngettext + program. Pass LC_ALL via --env option. + + * plural-1-prg.c: Pass locale as first argument. + * plural-1: Pass extra environment variables only to the cake program. + Pass LC_ALL value to cake as an argument. + + * msgcmp-2: Pass extra environment variables only to the msgcmp + program. + + * msgmerge-2: Pass extra environment variables only to the msgmerge + program. + + * lang-c: Pass LC_ALL value to prog as an argument. + * lang-c++: Likewise. + * lang-objc: Likewise. + +2002-01-05 Bruno Haible + * msgfilter-2: Skip the test if 'sed' adds extraneous newlines. 2002-01-04 Bruno Haible diff --git a/tests/gettext-1 b/tests/gettext-1 index 604ab64..37d72b8 100755 --- a/tests/gettext-1 +++ b/tests/gettext-1 @@ -2,13 +2,6 @@ # One argument is required which is the path to the toplevel directory # of the distribution. -TEXTDOMAINDIR=.. -LANGUAGE=tests -LC_ALL=en -LC_MESSAGES= -LANG= -export TEXTDOMAINDIR LANGUAGE LC_ALL LC_MESSAGES LANG - tmpfiles="" trap 'rm -fr $tmpfiles' 1 2 3 15 @@ -19,7 +12,8 @@ cp $top_srcdir/tests/test.mo LC_MESSAGES tmpfiles="$tmpfiles gt-test1.out" : ${GETTEXT=gettext} -${GETTEXT} -e test 'SYS_(C)\n' > gt-test1.out +TEXTDOMAINDIR=.. LANGUAGE=tests \ +${GETTEXT} --env LC_ALL=en -e test 'SYS_(C)\n' > gt-test1.out # Create correct file. tmpfile="$tmpfiles gtmf-test1.ok" diff --git a/tests/gettext-2 b/tests/gettext-2 index 548237a..9961f58 100755 --- a/tests/gettext-2 +++ b/tests/gettext-2 @@ -2,13 +2,6 @@ # One argument is required which is the path to the toplevel directory # of the distribution. -TEXTDOMAINDIR=.. -LANGUAGE=tests -LC_ALL=en -LC_MESSAGES= -LANG= -export TEXTDOMAINDIR LANGUAGE LC_ALL LC_MESSAGES LANG - if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu. if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then @@ -31,7 +24,8 @@ cp $top_srcdir/tests/test.mo LC_MESSAGES tmpfiles="$tmpfiles gt-test2.out" : ${GETTEXT=gettext} -${GETTEXT} test 'error 3' > gt-test2.out +TEXTDOMAINDIR=.. LANGUAGE=tests \ +${GETTEXT} --env LC_ALL=en test 'error 3' > gt-test2.out # Create correct file. tmpfile="$tmpfiles gtmf-test2.ok" diff --git a/tests/lang-c b/tests/lang-c index 8593bfb..5196e96 100755 --- a/tests/lang-c +++ b/tests/lang-c @@ -19,9 +19,9 @@ int main (argc, argv) int argc; char *argv[]; { - int n = atoi (argv[1]); + int n = atoi (argv[2]); - if (setlocale (LC_ALL, "") == NULL) + if (setlocale (LC_ALL, argv[1]) == NULL) { fprintf (stderr, "Couldn't set locale.\n"); exit (77); @@ -118,7 +118,7 @@ cat <<\EOF > prog.ok EUR remplace FF. EOF -LANGUAGE= LC_ALL=fr_FR ./prog 2 > prog.out +LANGUAGE= ./prog fr_FR 2 > prog.out case $? in 0) ;; 77) echo "SKIP: lang-c"; rm -fr $tmpfiles; exit 77;; diff --git a/tests/lang-c++ b/tests/lang-c++ index ebe4a09..e74f00e 100755 --- a/tests/lang-c++ +++ b/tests/lang-c++ @@ -23,9 +23,9 @@ cat <<\EOF > prog.cc int main (int argc, char *argv[]) { - int n = atoi (argv[1]); + int n = atoi (argv[2]); - if (setlocale (LC_ALL, "") == NULL) + if (setlocale (LC_ALL, argv[1]) == NULL) { cerr << "Couldn't set locale." << endl; exit (77); @@ -119,7 +119,7 @@ cat <<\EOF > prog.ok EUR remplace FF. EOF -LANGUAGE= LC_ALL=fr_FR ./prog 2 > prog.out +LANGUAGE= ./prog fr_FR 2 > prog.out case $? in 0) ;; 77) echo "SKIP: lang-c++"; rm -fr $tmpfiles; exit 77;; diff --git a/tests/lang-objc b/tests/lang-objc index 5863978..3e5d296 100755 --- a/tests/lang-objc +++ b/tests/lang-objc @@ -33,9 +33,9 @@ int main (argc, argv) int argc; char *argv[]; { - int n = atoi (argv[1]); + int n = atoi (argv[2]); - if (setlocale (LC_ALL, "") == NULL) + if (setlocale (LC_ALL, argv[1]) == NULL) { fprintf (stderr, "Couldn't set locale.\n"); exit (77); @@ -132,7 +132,7 @@ cat <<\EOF > prog.ok EUR remplace FF. EOF -LANGUAGE= LC_ALL=fr_FR ./prog 2 > prog.out +LANGUAGE= ./prog fr_FR 2 > prog.out case $? in 0) ;; 77) echo "SKIP: lang-objc"; rm -fr $tmpfiles; exit 77;; diff --git a/tests/msgcmp-2 b/tests/msgcmp-2 index 096f75a..14be05d 100755 --- a/tests/msgcmp-2 +++ b/tests/msgcmp-2 @@ -5,12 +5,6 @@ tmpfiles="" trap 'rm -fr $tmpfiles' 1 2 3 15 -LANGUAGE= -LC_ALL= -LC_MESSAGES= -LANG= -export LANGUAGE LC_ALL LC_MESSAGES LANG - tmpfiles="$tmpfiles mc-test2.in1 mc-test2.in2" cat < mc-test2.in1 msgid "one" msgstr "first" @@ -27,6 +21,7 @@ EOF tmpfiles="$tmpfiles mc-test2.out" : ${MSGCMP=msgcmp} +LC_MESSAGES=C LC_ALL= \ ${MSGCMP} mc-test2.in1 mc-test2.in2 > mc-test2.out 2>&1 tmpfiles="$tmpfiles mc-test2.ok" diff --git a/tests/msgfmt-1 b/tests/msgfmt-1 index ef30ccb..3566d16 100755 --- a/tests/msgfmt-1 +++ b/tests/msgfmt-1 @@ -1,12 +1,5 @@ #! /bin/sh -TEXTDOMAINDIR=.. -LANGUAGE=tests -LC_ALL=en -LC_MESSAGES= -LANG= -export TEXTDOMAINDIR LANGUAGE LC_ALL LC_MESSAGES LANG - tmpfiles="" trap 'rm -fr $tmpfiles' 1 2 3 15 @@ -64,7 +57,8 @@ ${MSGFMT} modules.po -o LC_MESSAGES/gen.mo tmpfiles="$tmpfiles mf-test1.out" : ${GETTEXT=gettext} -${GETTEXT} gen 'SYS_(C) +TEXTDOMAINDIR=.. LANGUAGE=tests \ +${GETTEXT} --env LC_ALL=en gen 'SYS_(C) ' > mf-test1.out tmpfiles="$tmpfiles gtmf-test1.ok" diff --git a/tests/msgfmt-2 b/tests/msgfmt-2 index e03e034..f567aad 100755 --- a/tests/msgfmt-2 +++ b/tests/msgfmt-2 @@ -1,12 +1,5 @@ #! /bin/sh -TEXTDOMAINDIR=.. -LANGUAGE=tests -LC_ALL=en -LC_MESSAGES= -LANG= -export TEXTDOMAINDIR LANGUAGE LC_ALL LC_MESSAGES LANG - if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu. if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then @@ -76,7 +69,8 @@ ${MSGFMT} modules.po -o LC_MESSAGES/gen.mo tmpfiles="$tmpfiles mf-test2.out" : ${GETTEXT=gettext} -${GETTEXT} gen 'error 3' > mf-test2.out +TEXTDOMAINDIR=.. LANGUAGE=tests \ +${GETTEXT} --env LC_ALL=en gen 'error 3' > mf-test2.out tmpfiles="$tmpfiles gtmf-test2.ok" echo $ac_n "error 3 translation$ac_c" > gtmf-test2.ok diff --git a/tests/msgmerge-2 b/tests/msgmerge-2 index a47a95d..d3bd69e 100755 --- a/tests/msgmerge-2 +++ b/tests/msgmerge-2 @@ -3,12 +3,6 @@ tmpfiles="" trap 'rm -fr $tmpfiles' 1 2 3 15 -LANGUAGE= -LC_ALL= -LC_MESSAGES= -LANG= -export LANGUAGE LC_ALL LC_MESSAGES LANG - tmpfiles="$tmpfiles mm-test2.in1 mm-test2.in2" cat < mm-test2.in1 msgid "2" msgstr "2" @@ -24,6 +18,7 @@ EOF tmpfiles="$tmpfiles mm-test2.out" : ${MSGMERGE=msgmerge} +LC_MESSAGES=C LC_ALL= \ ${MSGMERGE} -q mm-test2.in1 mm-test2.in2 -o /dev/stdout \ 2> mm-test2.out diff --git a/tests/plural-1 b/tests/plural-1 index 355e748..23537f2 100644 --- a/tests/plural-1 +++ b/tests/plural-1 @@ -53,22 +53,16 @@ sed 1,2d < fr.po > fr.po.strip : ${DIFF=diff} ${DIFF} fr.po.strip fr.po.tmp || exit 1 -LANGUAGE= -LC_ALL=fr -LC_MESSAGES= -LANG= -export LANGUAGE LC_ALL LC_MESSAGES LANG - tmpfiles="$tmpfiles cake.ok cake.out" : ${DIFF=diff} echo 'un morceau de gateau' > cake.ok -./cake 1 > cake.out || exit 1 +LANGUAGE= ./cake fr 1 > cake.out || exit 1 ${DIFF} cake.ok cake.out || exit 1 echo '2 morceaux de gateau' > cake.ok -./cake 2 > cake.out || exit 1 +LANGUAGE= ./cake fr 2 > cake.out || exit 1 ${DIFF} cake.ok cake.out || exit 1 echo '10 morceaux de gateau' > cake.ok -./cake 10 > cake.out || exit 1 +LANGUAGE= ./cake fr 10 > cake.out || exit 1 ${DIFF} cake.ok cake.out || exit 1 rm -fr $tmpfiles diff --git a/tests/plural-1-prg.c b/tests/plural-1-prg.c index e7bc501..9642c17 100644 --- a/tests/plural-1-prg.c +++ b/tests/plural-1-prg.c @@ -19,9 +19,9 @@ int main (argc, argv) int argc; char *argv[]; { - int n = atoi (argv[1]); + int n = atoi (argv[2]); - if (setlocale (LC_ALL, "") == NULL) + if (setlocale (LC_ALL, argv[1]) == NULL) return 1; textdomain ("cake"); diff --git a/tests/plural-2 b/tests/plural-2 index c474f13..09b7cf3 100755 --- a/tests/plural-2 +++ b/tests/plural-2 @@ -60,8 +60,8 @@ msgstr[9] "9" EOF ${MSGFMT} -o ll/LC_MESSAGES/plural.mo ll.po || exit 1 (for i in '' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do - LANGUAGE= LC_ALL=ll TEXTDOMAIN=plural TEXTDOMAINDIR=. \ - $NGETTEXT X Y ${i}0 ${i}1 ${i}2 ${i}3 ${i}4 ${i}5 ${i}6 ${i}7 ${i}8 ${i}9 + LANGUAGE= TEXTDOMAIN=plural TEXTDOMAINDIR=. \ + $NGETTEXT --env LC_ALL=ll X Y ${i}0 ${i}1 ${i}2 ${i}3 ${i}4 ${i}5 ${i}6 ${i}7 ${i}8 ${i}9 done) > dataout test "$dataok" = `cat dataout` || { echo "Formula evaluation error for language $lang" 1>&2 diff --git a/tests/tstgettext.c b/tests/tstgettext.c index 98cd74d..732cc26 100644 --- a/tests/tstgettext.c +++ b/tests/tstgettext.c @@ -1,3 +1,403 @@ -/* A version of the gettext program that uses the included libintl. */ -#define TESTS -#include "../src/gettext.c" +/* gettext - retrieve text string from message catalog and print it. + Copyright (C) 1995-1997, 2000-2002 Free Software Foundation, Inc. + Written by Ulrich Drepper , May 1995. + + 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 + +#include +#include +#include +#include +#include +#include + +#include "error.h" +#include "basename.h" +#include "xmalloc.h" +#include "exit.h" +#include "xsetenv.h" + +#define HAVE_SETLOCALE 1 +/* Make sure we use the included libintl, not the system's one. */ +#define textdomain textdomain__ +#define bindtextdomain bindtextdomain__ +#define gettext gettext__ +#define dgettext dgettext__ +#undef _LIBINTL_H +#include "libgnuintl.h" + +#define _(str) gettext (str) + +/* If nonzero add newline after last string. This makes only sense in + the `echo' emulation mode. */ +int add_newline; +/* If nonzero expand escape sequences in strings before looking in the + message catalog. */ +int do_expand; + +/* Name the program is called with. */ +const char *program_name; + +/* Long options. */ +static const struct option long_options[] = +{ + { "domain", required_argument, NULL, 'd' }, + { "env", required_argument, NULL, '=' }, + { "help", no_argument, NULL, 'h' }, + { "shell-script", no_argument, NULL, 's' }, + { "version", no_argument, NULL, 'V' }, + { NULL, 0, NULL, 0 } +}; + +/* Prototypes for local functions. Needed to ensure compiler checking of + function argument counts despite of K&R C function definition syntax. */ +static void usage PARAMS ((int status)) +#if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) + __attribute__ ((noreturn)) +#endif +; +static const char *expand_escape PARAMS ((const char *str)); + +int +main (argc, argv) + int argc; + char *argv[]; +{ + int optchar; + const char *msgid; + + /* Default values for command line options. */ + int do_help = 0; + int do_shell = 0; + int do_version = 0; + bool environ_changed = false; + const char *domain = getenv ("TEXTDOMAIN"); + const char *domaindir = getenv ("TEXTDOMAINDIR"); + add_newline = 1; + do_expand = 0; + + /* Set program name for message texts. */ + program_name = argv[0]; + if (strncmp (program_name, "lt-", 3) == 0) + program_name += 3; + +#ifdef HAVE_SETLOCALE + /* Set locale via LC_ALL. */ + setlocale (LC_ALL, ""); +#endif + + /* Set the text message domain. */ + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + + /* Parse command line options. */ + while ((optchar = getopt_long (argc, argv, "+d:eEhnsV", long_options, NULL)) + != EOF) + switch (optchar) + { + case '\0': /* Long option. */ + break; + case 'd': + domain = optarg; + break; + case 'e': + do_expand = 1; + break; + case 'E': + /* Ignore. Just for compatibility. */ + break; + case 'h': + do_help = 1; + break; + case 'n': + add_newline = 0; + break; + case 's': + do_shell = 1; + break; + case 'V': + do_version = 1; + break; + case '=': + { + /* Undocumented option --env sets an environment variable. */ + char *separator = strchr (optarg, '='); + if (separator != NULL) + { + *separator = '\0'; + xsetenv (optarg, separator + 1, 1); + environ_changed = true; + break; + } + } + /*FALLTHROUGH*/ + default: + usage (EXIT_FAILURE); + } + +#ifdef HAVE_SETLOCALE + if (environ_changed) + /* Set locale again via LC_ALL. */ + setlocale (LC_ALL, ""); +#endif + + /* Version information is requested. */ + if (do_version) + { + printf ("%s (GNU %s) %s\n", basename (program_name), PACKAGE, VERSION); + /* xgettext: no-wrap */ + printf (_("Copyright (C) %s Free Software Foundation, Inc.\n\ +This is free software; see the source for copying conditions. There is NO\n\ +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ +"), + "1995-1997, 2000, 2001"); + printf (_("Written by %s.\n"), "Ulrich Drepper"); + exit (EXIT_SUCCESS); + } + + /* Help is requested. */ + if (do_help) + usage (EXIT_SUCCESS); + + /* We have two major modes: use following Uniforum spec and as + internationalized `echo' program. */ + if (do_shell == 0) + { + /* We have to write a single strings translation to stdout. */ + + /* Get arguments. */ + switch (argc - optind) + { + default: + error (EXIT_FAILURE, 0, _("too many arguments")); + + case 2: + domain = argv[optind++]; + /* FALLTHROUGH */ + + case 1: + break; + + case 0: + error (EXIT_FAILURE, 0, _("missing arguments")); + } + + msgid = argv[optind++]; + + /* Expand escape sequences if enabled. */ + if (do_expand) + msgid = expand_escape (msgid); + + /* If no domain name is given we don't translate. */ + if (domain == NULL || domain[0] == '\0') + { + fputs (msgid, stdout); + } + else + { + /* Bind domain to appropriate directory. */ + if (domaindir != NULL && domaindir[0] != '\0') + bindtextdomain (domain, domaindir); + + /* Write out the result. */ + fputs (dgettext (domain, msgid), stdout); + } + } + else + { + if (optind < argc) + { + /* If no domain name is given we print the original string. + We mark this assigning NULL to domain. */ + if (domain == NULL || domain[0] == '\0') + domain = NULL; + else + /* Bind domain to appropriate directory. */ + if (domaindir != NULL && domaindir[0] != '\0') + bindtextdomain (domain, domaindir); + + /* We have to simulate `echo'. All arguments are strings. */ + do + { + msgid = argv[optind++]; + + /* Expand escape sequences if enabled. */ + if (do_expand) + msgid = expand_escape (msgid); + + /* Write out the result. */ + fputs (domain == NULL ? msgid : dgettext (domain, msgid), + stdout); + + /* We separate the arguments by a single ' '. */ + if (optind < argc) + fputc (' ', stdout); + } + while (optind < argc); + } + + /* If not otherwise told: add trailing newline. */ + if (add_newline) + fputc ('\n', stdout); + } + + exit (EXIT_SUCCESS); +} + + +/* Display usage information and exit. */ +static void +usage (status) + int status; +{ + if (status != EXIT_SUCCESS) + fprintf (stderr, _("Try `%s --help' for more information.\n"), + program_name); + else + { + /* xgettext: no-wrap */ + printf (_("\ +Usage: %s [OPTION] [[TEXTDOMAIN] MSGID]\n\ +or: %s [OPTION] -s [MSGID]...\n\ +"), program_name, program_name); + printf ("\n"); + /* xgettext: no-wrap */ + printf (_("\ +Display native language translation of a textual message.\n")); + printf ("\n"); + /* xgettext: no-wrap */ + printf (_("\ + -d, --domain=TEXTDOMAIN retrieve translated messages from TEXTDOMAIN\n\ + -e enable expansion of some escape sequences\n\ + -E (ignored for compatibility)\n\ + -h, --help display this help and exit\n\ + -n suppress trailing newline\n\ + -V, --version display version information and exit\n\ + [TEXTDOMAIN] MSGID retrieve translated message corresponding\n\ + to MSGID from TEXTDOMAIN\n")); + printf ("\n"); + /* xgettext: no-wrap */ + printf (_("\ +If the TEXTDOMAIN parameter is not given, the domain is determined from the\n\ +environment variable TEXTDOMAIN. If the message catalog is not found in the\n\ +regular directory, another location can be specified with the environment\n\ +variable TEXTDOMAINDIR.\n\ +When used with the -s option the program behaves like the `echo' command.\n\ +But it does not simply copy its arguments to stdout. Instead those messages\n\ +found in the selected catalog are translated.\n\ +Standard search directory: %s\n"), + getenv ("IN_HELP2MAN") == NULL ? LOCALEDIR : "@localedir@"); + printf ("\n"); + fputs (_("Report bugs to .\n"), stdout); + } + + exit (status); +} + + +/* Expand some escape sequences found in the argument string. */ +static const char * +expand_escape (str) + const char *str; +{ + char *retval, *rp; + const char *cp = str; + + do + { + while (cp[0] != '\0' && cp[0] != '\\') + ++cp; + } + while (cp[0] != '\0' && cp[1] != '\0' + && strchr ("bcfnrt\\01234567", cp[1]) == NULL); + + if (cp[0] == '\0') + return str; + + retval = (char *) xmalloc (strlen (str)); + + rp = retval + (cp - str); + memcpy (retval, str, cp - str); + + do + { + switch (*++cp) + { + case 'b': /* backspace */ + *rp++ = '\b'; + ++cp; + break; + case 'c': /* suppress trailing newline */ + add_newline = 0; + ++cp; + break; + case 'f': /* form feed */ + *rp++ = '\f'; + ++cp; + break; + case 'n': /* new line */ + *rp++ = '\n'; + ++cp; + break; + case 'r': /* carriage return */ + *rp++ = '\r'; + ++cp; + break; + case 't': /* horizontal tab */ + *rp++ = '\t'; + ++cp; + break; + case '\\': + *rp = '\\'; + ++cp; + break; + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + { + int ch = *cp++ - '0'; + + if (*cp >= '0' && *cp <= '7') + { + ch *= 8; + ch += *cp++ - '0'; + + if (*cp >= '0' && *cp <= '7') + { + ch *= 8; + ch += *cp++ - '0'; + } + } + *rp = ch; + } + break; + default: + *rp = '\\'; + break; + } + + while (cp[0] != '\0' && cp[0] != '\\') + *rp++ = *cp++; + } + while (cp[0] != '\0'); + + /* Terminate string. */ + *rp = '\0'; + + return (const char *) retval; +} diff --git a/tests/tstngettext.c b/tests/tstngettext.c index 49ceea7..6a2770c 100644 --- a/tests/tstngettext.c +++ b/tests/tstngettext.c @@ -20,6 +20,7 @@ #endif #include +#include #include #include #include @@ -28,6 +29,7 @@ #include "error.h" #include "basename.h" #include "exit.h" +#include "xsetenv.h" #define HAVE_SETLOCALE 1 /* Make sure we use the included libintl, not the system's one. */ @@ -47,6 +49,7 @@ char *program_name; static const struct option long_options[] = { { "domain", required_argument, NULL, 'd' }, + { "env", required_argument, NULL, '=' }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 } @@ -73,6 +76,7 @@ main (argc, argv) /* Default values for command line options. */ int do_help = 0; int do_version = 0; + bool environ_changed = false; const char *domain = getenv ("TEXTDOMAIN"); const char *domaindir = getenv ("TEXTDOMAINDIR"); @@ -104,10 +108,29 @@ main (argc, argv) case 'V': do_version = 1; break; + case '=': + { + /* Undocumented option --env sets an environment variable. */ + char *separator = strchr (optarg, '='); + if (separator != NULL) + { + *separator = '\0'; + xsetenv (optarg, separator + 1, 1); + environ_changed = true; + break; + } + } + /*FALLTHROUGH*/ default: usage (EXIT_FAILURE); } +#ifdef HAVE_SETLOCALE + if (environ_changed) + /* Set locale again via LC_ALL. */ + setlocale (LC_ALL, ""); +#endif + /* Version information is requested. */ if (do_version) { -- cgit v1.1