#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <getopt.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <errno.h>
#include "closeout.h"
#include "error.h"
#include "progname.h"
#include "relocatable.h"
#include "basename.h"
#include "exit.h"
#include "xsetenv.h"
#define HAVE_SETLOCALE 1
#undef _LIBINTL_H
#include "libgnuintl.h"
#define _(str) gettext (str)
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 }
};
static void usage (int __status)
#if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2)
__attribute__ ((noreturn))
#endif
;
int
main (int argc, char *argv[])
{
int optchar;
const char *msgid;
const char *msgid_plural;
const char *count;
unsigned long n;
bool do_help = false;
bool do_version = false;
bool environ_changed = false;
const char *domain = getenv ("TEXTDOMAIN");
const char *domaindir = getenv ("TEXTDOMAINDIR");
set_program_name (argv[0]);
#ifdef HAVE_SETLOCALE
setlocale (LC_ALL, "");
#endif
bindtextdomain (PACKAGE, relocate (LOCALEDIR));
textdomain (PACKAGE);
atexit (close_stdout);
while ((optchar = getopt_long (argc, argv, "+d:hV", long_options, NULL))
!= EOF)
switch (optchar)
{
case '\0':
break;
case 'd':
domain = optarg;
break;
case 'h':
do_help = true;
break;
case 'V':
do_version = true;
break;
case '=':
{
char *separator = strchr (optarg, '=');
if (separator != NULL)
{
*separator = '\0';
xsetenv (optarg, separator + 1, 1);
environ_changed = true;
break;
}
}
default:
usage (EXIT_FAILURE);
}
#ifdef HAVE_SETLOCALE
if (environ_changed)
setlocale (LC_ALL, "");
#endif
if (do_version)
{
printf ("%s (GNU %s) %s\n", basename (program_name), PACKAGE, VERSION);
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-2003");
printf (_("Written by %s.\n"), "Ulrich Drepper");
exit (EXIT_SUCCESS);
}
if (do_help)
usage (EXIT_SUCCESS);
if (argc - optind <= 2)
error (EXIT_FAILURE, 0, _("missing arguments"));
msgid = argv[optind++];
msgid_plural = argv[optind++];
if (domain == NULL || domain[0] == '\0')
domain = NULL;
else
if (domaindir != NULL && domaindir[0] != '\0')
bindtextdomain (domain, domaindir);
while (optind < argc)
{
count = argv[optind++];
{
char *endp;
unsigned long tmp_val;
errno = 0;
tmp_val = strtoul (count, &endp, 10);
if (errno == 0 && count[0] != '\0' && endp[0] == '\0')
n = tmp_val;
else
n = 99;
}
if (domain == NULL)
fputs (n == 1 ? msgid : msgid_plural, stdout);
else
fputs (dngettext (domain, msgid, msgid_plural, n), stdout);
}
exit (EXIT_SUCCESS);
}
static void
usage (int status)
{
if (status != EXIT_SUCCESS)
fprintf (stderr, _("Try `%s --help' for more information.\n"),
program_name);
else
{
printf (_("\
Usage: %s [OPTION] MSGID MSGID-PLURAL COUNT...\n\
-d, --domain=TEXTDOMAIN retrieve translated message from TEXTDOMAIN\n\
-h, --help display this help and exit\n\
-V, --version display version information and exit\n\
MSGID MSGID-PLURAL translate MSGID (singular) / MSGID-PLURAL (plural)\n\
COUNT choose singular/plural form based on this value\n"),
program_name);
printf (_("\
\n\
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\
Standard search directory: %s\n"), LOCALEDIR);
fputs (_("Report bugs to <bug-gnu-gettext@gnu.org>.\n"), stdout);
}
exit (status);
}