From: Bruno Haible Date: Tue, 20 Mar 2001 15:05:11 +0000 (+0000) Subject: Fix a bug. Optimize a bit. X-Git-Tag: v0.10.36~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b151ec614232e144f51945f1b30497a104903df2;p=thirdparty%2Fgettext.git Fix a bug. Optimize a bit. --- diff --git a/src/gettext.c b/src/gettext.c index ae5859798..af5c2b03c 100644 --- a/src/gettext.c +++ b/src/gettext.c @@ -29,6 +29,7 @@ #include "system.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__ @@ -155,64 +156,75 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ { /* We have to write a single strings translation to stdout. */ - if (optind >= argc) - error (EXIT_FAILURE, 0, _("missing arguments")); - /* Get arguments. */ - msgid = argv[optind++]; - if (optind < argc) + switch (argc - optind) { - domain = msgid; - msgid = argv[optind++]; - - if (optind < argc) + default: error (EXIT_FAILURE, 0, _("too many arguments")); - } - /* If no domain name is given we print the original string. */ - if (domain == NULL || domain[0] == '\0') - { - fputs (msgid, stdout); - exit (EXIT_SUCCESS); + case 2: + domain = argv[optind++]; + /* FALLTHROUGH */ + + case 1: + break; + + case 0: + error (EXIT_FAILURE, 0, _("missing arguments")); } - /* Bind domain to appropriate directory. */ - if (domaindir != NULL && domaindir[0] != '\0') - bindtextdomain (domain, domaindir); + msgid = argv[optind++]; - /* Expand escape sequences is enabled. */ + /* Expand escape sequences if enabled. */ if (do_expand) msgid = expand_escape (msgid); - /* Write out the result. */ - fputs (dgettext (domain, msgid), stdout); - } - else - { - /* If no domain name is given we print the original string. - We mark this assigning NULL to domain. */ + /* If no domain name is given we don't translate. */ if (domain == NULL || domain[0] == '\0') - domain = NULL; + { + fputs (msgid, stdout); + } else - /* Bind domain to appropriate directory. */ - if (domaindir != NULL && domaindir[0] != '\0') - bindtextdomain (domain, domaindir); - - /* We have to simulate `echo'. All arguments are strings. */ - while (optind < argc) { - msgid = argv[optind++]; - - /* Expand escape sequences is enabled. */ - if (do_expand) - msgid = expand_escape (msgid); + /* Bind domain to appropriate directory. */ + if (domaindir != NULL && domaindir[0] != '\0') + bindtextdomain (domain, domaindir); /* Write out the result. */ - fputs (domain == NULL ? msgid : dgettext (domain, msgid), stdout); - - /* We separate the arguments by a single ' '. */ - if (optind < argc) - fputc (' ', stdout); + 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. */