]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Change the tests to be less verbose on Solaris and HP-UX.
authorBruno Haible <bruno@clisp.org>
Mon, 7 Jan 2002 17:50:01 +0000 (17:50 +0000)
committerBruno Haible <bruno@clisp.org>
Sun, 21 Jun 2009 22:36:25 +0000 (00:36 +0200)
17 files changed:
src/ChangeLog
src/gettext.c
tests/ChangeLog
tests/gettext-1
tests/gettext-2
tests/lang-c
tests/lang-c++
tests/lang-objc
tests/msgcmp-2
tests/msgfmt-1
tests/msgfmt-2
tests/msgmerge-2
tests/plural-1
tests/plural-1-prg.c
tests/plural-2
tests/tstgettext.c
tests/tstngettext.c

index 7b1387699f39a4202d46bdf38898aacaf90ec5f0..2fa84e52f685614f7cc999e3ae91e5f57dd3b179 100644 (file)
@@ -1,3 +1,7 @@
+2002-01-05  Bruno Haible  <bruno@clisp.org>
+
+       * gettext.c: TESTS version is now separate.
+
 2002-01-05  Bruno Haible  <bruno@clisp.org>
 
        * x-java.l (extract_java): Avoid "uninitialized variable" warnings.
index 29b7dbb7456e591312bd7df16fa48e58d2931352..9e75a941b7605cd27b610a15a236efc5504b2f55 100644 (file)
@@ -1,5 +1,5 @@
 /* gettext - retrieve text string from message catalog and print it.
-   Copyright (C) 1995-1997, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1995-1997, 2000-2002 Free Software Foundation, Inc.
    Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, May 1995.
 
    This program is free software; you can redistribute it and/or modify
 #include "xmalloc.h"
 #include "exit.h"
 
-#ifdef TESTS
-# 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"
-#else
-# include "gettext.h"
-#endif
+#include "gettext.h"
 
 #define _(str) gettext (str)
 
index b122aef18b97cc17ab5d14636c06a76aed6d2a6d..d5c13664395402cca696b2a3f6ccf370fa5c7ee8 100644 (file)
@@ -1,3 +1,35 @@
+2002-01-05  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        * msgfilter-2: Skip the test if 'sed' adds extraneous newlines.
index 604ab64bc81ec6c20bf73021655a8675232fa592..37d72b889cfdcc864cec253e1e4fcf2f7a3174af 100755 (executable)
@@ -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"
index 548237a61d9cdfb597f8a965d751373efede92f5..9961f583c494cb8a2c57984fffc588aca09ae06c 100755 (executable)
@@ -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"
index 8593bfb912c838f3b54acc3a3639cdcdb1f20e28..5196e960436d6cc5175799888e871ed7e208e811 100755 (executable)
@@ -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;;
index ebe4a09c8cd1d159900129dec17ddc160e48c251..e74f00ebf71451b3a3b7ff4cc9cef8dd1da91c4d 100755 (executable)
@@ -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;;
index 586397835547d798ac2e2b26108af0e9120830fd..3e5d296d372c9ab68786c1dfa755ad2942f51950 100755 (executable)
@@ -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;;
index 096f75a111c7b7dff0f4ea02a15f1ff9023891cd..14be05d5039bfaa874561efe9a6a5395344d4921 100755 (executable)
@@ -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 <<EOF > 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"
index ef30ccbce73cde9410cbb3f6b0859028bf3d9959..3566d16bf26f68fd4ff12328eacd2dc4aee7e108 100755 (executable)
@@ -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"
index e03e034027f1e758c5d22df54300c57c879901e7..f567aad029dd3395ba28f8e653759584e0e6d223 100755 (executable)
@@ -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
index a47a95dc0103eb691270ff2b14b2198906360b1f..d3bd69e3243ff6e850b019d6544b2ca341940b5e 100755 (executable)
@@ -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 <<EOF > 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
 
index 355e748aba81fddc3dc3596f4953a01aa20655a9..23537f2d7e6215b59c2815a3b6a48c13710e74b7 100644 (file)
@@ -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
index e7bc5013d645adb6b76602d2c2a51c16cec7f4f4..9642c1767cbc2ebf3bf54ad51f95fccfa1d7e9a8 100644 (file)
@@ -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");
index c474f1384c05f0e71074b76102e20a5e5d45cc64..09b7cf390495c95657956e3424002bf80cabbbbf 100755 (executable)
@@ -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
index 98cd74dc683a63b795dee7b430bddab70f7a8bed..732cc269d21179bfe067b40ff74f27e4e39857c6 100644 (file)
@@ -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 <drepper@gnu.ai.mit.edu>, 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 <config.h>
+#endif
+
+#include <getopt.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <locale.h>
+
+#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 <bug-gnu-gettext@gnu.org>.\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;
+}
index 49ceea708cfcdb38f76a124ae3c7a9d067dbc428..6a2770cb2d05bb73c3f9d55d0cb23e4ca7faa500 100644 (file)
@@ -20,6 +20,7 @@
 #endif
 
 #include <getopt.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <locale.h>
@@ -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)
     {