#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__
{
/* 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. */