1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-01 10:06:57 +03:00
1998-03-06 12:42  Ulrich Drepper  <drepper@cygnus.com>

	* argp/argp.h (struct argp): Add new field domain.
	* argp/argp-help.c: Change all gettext calls to dgettext and use
	domain field from appropriate argp in call.
	* argp/argp-parse.c: Likewise.
This commit is contained in:
Ulrich Drepper
1998-03-06 12:45:08 +00:00
parent ac16e90592
commit 9184d3db10
4 changed files with 84 additions and 52 deletions

View File

@ -1,3 +1,10 @@
1998-03-06 12:42 Ulrich Drepper <drepper@cygnus.com>
* argp/argp.h (struct argp): Add new field domain.
* argp/argp-help.c: Change all gettext calls to dgettext and use
domain field from appropriate argp in call.
* argp/argp-parse.c: Likewise.
1998-03-06 11:35 Ulrich Drepper <drepper@cygnus.com> 1998-03-06 11:35 Ulrich Drepper <drepper@cygnus.com>
* posix/wordexp-test.c: Change testsuite so that it can run even * posix/wordexp-test.c: Change testsuite so that it can run even

View File

@ -1,5 +1,5 @@
/* Hierarchial argument parsing help output /* Hierarchial argument parsing help output
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Written by Miles Bader <miles@gnu.ai.mit.edu>. Written by Miles Bader <miles@gnu.ai.mit.edu>.
@ -35,9 +35,8 @@
When compiling libc, the _ macro is predefined. */ When compiling libc, the _ macro is predefined. */
#ifdef HAVE_LIBINTL_H #ifdef HAVE_LIBINTL_H
# include <libintl.h> # include <libintl.h>
# define _(msgid) gettext (msgid)
#else #else
# define _(msgid) (msgid) # define dgettext(domain, msgid) (msgid)
# define gettext(msgid) (msgid) # define gettext(msgid) (msgid)
#endif #endif
#endif #endif
@ -180,7 +179,8 @@ fill_in_uparams (const struct argp_state *state)
{ {
if (unspec && !un->is_bool) if (unspec && !un->is_bool)
__argp_failure (state, 0, 0, __argp_failure (state, 0, 0,
_("%.*s: ARGP_HELP_FMT parameter requires a value"), dgettext (state->root_argp->argp_domain, "\
%.*s: ARGP_HELP_FMT parameter requires a value"),
(int) var_len, var); (int) var_len, var);
else else
*(int *)((char *)&uparams + un->uparams_offs) = val; *(int *)((char *)&uparams + un->uparams_offs) = val;
@ -188,7 +188,8 @@ fill_in_uparams (const struct argp_state *state)
} }
if (! un->name) if (! un->name)
__argp_failure (state, 0, 0, __argp_failure (state, 0, 0,
_("%.*s: Unknown ARGP_HELP_FMT parameter"), dgettext (state->root_argp->argp_domain, "\
%.*s: Unknown ARGP_HELP_FMT parameter"),
(int) var_len, var); (int) var_len, var);
var = arg; var = arg;
@ -198,7 +199,8 @@ fill_in_uparams (const struct argp_state *state)
else if (*var) else if (*var)
{ {
__argp_failure (state, 0, 0, __argp_failure (state, 0, 0,
_("Garbage in ARGP_HELP_FMT: %s"), var); dgettext (state->root_argp->argp_domain,
"Garbage in ARGP_HELP_FMT: %s"), var);
break; break;
} }
} }
@ -492,8 +494,8 @@ static inline int
hol_entry_short_iterate (const struct hol_entry *entry, hol_entry_short_iterate (const struct hol_entry *entry,
int (*func)(const struct argp_option *opt, int (*func)(const struct argp_option *opt,
const struct argp_option *real, const struct argp_option *real,
void *cookie), const char *domain, void *cookie),
void *cookie) const char *domain, void *cookie)
{ {
unsigned nopts; unsigned nopts;
int val = 0; int val = 0;
@ -506,7 +508,7 @@ hol_entry_short_iterate (const struct hol_entry *entry,
if (!oalias (opt)) if (!oalias (opt))
real = opt; real = opt;
if (ovisible (opt)) if (ovisible (opt))
val = (*func)(opt, real, cookie); val = (*func)(opt, real, domain, cookie);
so++; so++;
} }
@ -517,8 +519,8 @@ static inline int
hol_entry_long_iterate (const struct hol_entry *entry, hol_entry_long_iterate (const struct hol_entry *entry,
int (*func)(const struct argp_option *opt, int (*func)(const struct argp_option *opt,
const struct argp_option *real, const struct argp_option *real,
void *cookie), const char *domain, void *cookie),
void *cookie) const char *domain, void *cookie)
{ {
unsigned nopts; unsigned nopts;
int val = 0; int val = 0;
@ -530,7 +532,7 @@ hol_entry_long_iterate (const struct hol_entry *entry,
if (!oalias (opt)) if (!oalias (opt))
real = opt; real = opt;
if (ovisible (opt)) if (ovisible (opt))
val = (*func)(opt, real, cookie); val = (*func)(opt, real, domain, cookie);
} }
return val; return val;
@ -539,7 +541,7 @@ hol_entry_long_iterate (const struct hol_entry *entry,
/* Iterator that returns true for the first short option. */ /* Iterator that returns true for the first short option. */
static inline int static inline int
until_short (const struct argp_option *opt, const struct argp_option *real, until_short (const struct argp_option *opt, const struct argp_option *real,
void *cookie) const char *domain, void *cookie)
{ {
return oshort (opt) ? opt->key : 0; return oshort (opt) ? opt->key : 0;
} }
@ -548,7 +550,8 @@ until_short (const struct argp_option *opt, const struct argp_option *real,
static char static char
hol_entry_first_short (const struct hol_entry *entry) hol_entry_first_short (const struct hol_entry *entry)
{ {
return hol_entry_short_iterate (entry, until_short, 0); return hol_entry_short_iterate (entry, until_short,
entry->argp->argp_domain, 0);
} }
/* Returns the first valid long option in ENTRY, or 0 if there is none. */ /* Returns the first valid long option in ENTRY, or 0 if there is none. */
@ -672,7 +675,8 @@ canon_doc_option (const char **name)
/* Order ENTRY1 & ENTRY2 by the order which they should appear in a help /* Order ENTRY1 & ENTRY2 by the order which they should appear in a help
listing. */ listing. */
static int static int
hol_entry_cmp (const struct hol_entry *entry1, const struct hol_entry *entry2) hol_entry_cmp (const struct hol_entry *entry1,
const struct hol_entry *entry2)
{ {
/* The group numbers by which the entries should be ordered; if either is /* The group numbers by which the entries should be ordered; if either is
in a cluster, then this is just the group within the cluster. */ in a cluster, then this is just the group within the cluster. */
@ -867,13 +871,13 @@ space (argp_fmtstream_t stream, size_t ensure)
optional argument. */ optional argument. */
static void static void
arg (const struct argp_option *real, const char *req_fmt, const char *opt_fmt, arg (const struct argp_option *real, const char *req_fmt, const char *opt_fmt,
argp_fmtstream_t stream) const char *domain, argp_fmtstream_t stream)
{ {
if (real->arg) if (real->arg)
if (real->flags & OPTION_ARG_OPTIONAL) if (real->flags & OPTION_ARG_OPTIONAL)
__argp_fmtstream_printf (stream, opt_fmt, gettext (real->arg)); __argp_fmtstream_printf (stream, opt_fmt, dgettext (domain, real->arg));
else else
__argp_fmtstream_printf (stream, req_fmt, gettext (real->arg)); __argp_fmtstream_printf (stream, req_fmt, dgettext (domain, real->arg));
} }
/* Helper functions for hol_entry_help. */ /* Helper functions for hol_entry_help. */
@ -934,7 +938,7 @@ static void
print_header (const char *str, const struct argp *argp, print_header (const char *str, const struct argp *argp,
struct pentry_state *pest) struct pentry_state *pest)
{ {
const char *tstr = gettext (str); const char *tstr = dgettext (argp->argp_domain, str);
const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_HEADER, argp, pest->state); const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_HEADER, argp, pest->state);
if (fstr) if (fstr)
@ -1032,7 +1036,7 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state,
__argp_fmtstream_putc (stream, '-'); __argp_fmtstream_putc (stream, '-');
__argp_fmtstream_putc (stream, *so); __argp_fmtstream_putc (stream, *so);
if (!have_long_opt || uparams.dup_args) if (!have_long_opt || uparams.dup_args)
arg (real, " %s", "[%s]", stream); arg (real, " %s", "[%s]", state->root_argp->argp_domain, stream);
else if (real->arg) else if (real->arg)
hhstate->suppressed_dup_arg = 1; hhstate->suppressed_dup_arg = 1;
} }
@ -1051,7 +1055,9 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state,
/* Calling gettext here isn't quite right, since sorting will /* Calling gettext here isn't quite right, since sorting will
have been done on the original; but documentation options have been done on the original; but documentation options
should be pretty rare anyway... */ should be pretty rare anyway... */
__argp_fmtstream_puts (stream, gettext (opt->name)); __argp_fmtstream_puts (stream,
dgettext (state->root_argp->argp_domain,
opt->name));
} }
} }
else else
@ -1066,7 +1072,8 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state,
comma (uparams.long_opt_col, &pest); comma (uparams.long_opt_col, &pest);
__argp_fmtstream_printf (stream, "--%s", opt->name); __argp_fmtstream_printf (stream, "--%s", opt->name);
if (first_long_opt || uparams.dup_args) if (first_long_opt || uparams.dup_args)
arg (real, "=%s", "[=%s]", stream); arg (real, "=%s", "[=%s]", state->root_argp->argp_domain,
stream);
else if (real->arg) else if (real->arg)
hhstate->suppressed_dup_arg = 1; hhstate->suppressed_dup_arg = 1;
} }
@ -1085,7 +1092,8 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state,
goto cleanup; /* Just return, after cleaning up. */ goto cleanup; /* Just return, after cleaning up. */
else else
{ {
const char *tstr = real->doc ? gettext (real->doc) : 0; const char *tstr = real->doc ? dgettext (state->root_argp->argp_domain,
real->doc) : 0;
const char *fstr = filter_doc (tstr, real->key, entry->argp, state); const char *fstr = filter_doc (tstr, real->key, entry->argp, state);
if (fstr && *fstr) if (fstr && *fstr)
{ {
@ -1132,7 +1140,7 @@ hol_help (struct hol *hol, const struct argp_state *state,
if (hhstate.suppressed_dup_arg && uparams.dup_args_note) if (hhstate.suppressed_dup_arg && uparams.dup_args_note)
{ {
const char *tstr = _("\ const char *tstr = dgettext (state->root_argp->argp_domain, "\
Mandatory or optional arguments to long options are also mandatory or \ Mandatory or optional arguments to long options are also mandatory or \
optional for any corresponding short options."); optional for any corresponding short options.");
const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_DUP_ARGS_NOTE, const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_DUP_ARGS_NOTE,
@ -1155,7 +1163,7 @@ optional for any corresponding short options.");
static int static int
add_argless_short_opt (const struct argp_option *opt, add_argless_short_opt (const struct argp_option *opt,
const struct argp_option *real, const struct argp_option *real,
void *cookie) const char *domain, void *cookie)
{ {
char **snao_end = cookie; char **snao_end = cookie;
if (!(opt->arg || real->arg) if (!(opt->arg || real->arg)
@ -1169,7 +1177,7 @@ add_argless_short_opt (const struct argp_option *opt,
static int static int
usage_argful_short_opt (const struct argp_option *opt, usage_argful_short_opt (const struct argp_option *opt,
const struct argp_option *real, const struct argp_option *real,
void *cookie) const char *domain, void *cookie)
{ {
argp_fmtstream_t stream = cookie; argp_fmtstream_t stream = cookie;
const char *arg = opt->arg; const char *arg = opt->arg;
@ -1180,7 +1188,7 @@ usage_argful_short_opt (const struct argp_option *opt,
if (arg && !(flags & OPTION_NO_USAGE)) if (arg && !(flags & OPTION_NO_USAGE))
{ {
arg = gettext (arg); arg = dgettext (domain, arg);
if (flags & OPTION_ARG_OPTIONAL) if (flags & OPTION_ARG_OPTIONAL)
__argp_fmtstream_printf (stream, " [-%c[%s]]", opt->key, arg); __argp_fmtstream_printf (stream, " [-%c[%s]]", opt->key, arg);
@ -1201,7 +1209,7 @@ usage_argful_short_opt (const struct argp_option *opt,
static int static int
usage_long_opt (const struct argp_option *opt, usage_long_opt (const struct argp_option *opt,
const struct argp_option *real, const struct argp_option *real,
void *cookie) const char *domain, void *cookie)
{ {
argp_fmtstream_t stream = cookie; argp_fmtstream_t stream = cookie;
const char *arg = opt->arg; const char *arg = opt->arg;
@ -1213,7 +1221,7 @@ usage_long_opt (const struct argp_option *opt,
if (! (flags & OPTION_NO_USAGE)) if (! (flags & OPTION_NO_USAGE))
if (arg) if (arg)
{ {
arg = gettext (arg); arg = dgettext (domain, arg);
if (flags & OPTION_ARG_OPTIONAL) if (flags & OPTION_ARG_OPTIONAL)
__argp_fmtstream_printf (stream, " [--%s[=%s]]", opt->name, arg); __argp_fmtstream_printf (stream, " [--%s[=%s]]", opt->name, arg);
else else
@ -1240,7 +1248,8 @@ hol_usage (struct hol *hol, argp_fmtstream_t stream)
for (entry = hol->entries, nentries = hol->num_entries for (entry = hol->entries, nentries = hol->num_entries
; nentries > 0 ; nentries > 0
; entry++, nentries--) ; entry++, nentries--)
hol_entry_short_iterate (entry, add_argless_short_opt, &snao_end); hol_entry_short_iterate (entry, add_argless_short_opt,
entry->argp->argp_domain, &snao_end);
if (snao_end > short_no_arg_opts) if (snao_end > short_no_arg_opts)
{ {
*snao_end++ = 0; *snao_end++ = 0;
@ -1251,13 +1260,15 @@ hol_usage (struct hol *hol, argp_fmtstream_t stream)
for (entry = hol->entries, nentries = hol->num_entries for (entry = hol->entries, nentries = hol->num_entries
; nentries > 0 ; nentries > 0
; entry++, nentries--) ; entry++, nentries--)
hol_entry_short_iterate (entry, usage_argful_short_opt, stream); hol_entry_short_iterate (entry, usage_argful_short_opt,
entry->argp->argp_domain, stream);
/* Finally, a list of long options (whew!). */ /* Finally, a list of long options (whew!). */
for (entry = hol->entries, nentries = hol->num_entries for (entry = hol->entries, nentries = hol->num_entries
; nentries > 0 ; nentries > 0
; entry++, nentries--) ; entry++, nentries--)
hol_entry_long_iterate (entry, usage_long_opt, stream); hol_entry_long_iterate (entry, usage_long_opt,
entry->argp->argp_domain, stream);
} }
} }
@ -1314,7 +1325,7 @@ argp_args_usage (const struct argp *argp, const struct argp_state *state,
char *our_level = *levels; char *our_level = *levels;
int multiple = 0; int multiple = 0;
const struct argp_child *child = argp->children; const struct argp_child *child = argp->children;
const char *tdoc = gettext (argp->args_doc), *nl = 0; const char *tdoc = dgettext (argp->argp_domain, argp->args_doc), *nl = 0;
const char *fdoc = filter_doc (tdoc, ARGP_KEY_HELP_ARGS_DOC, argp, state); const char *fdoc = filter_doc (tdoc, ARGP_KEY_HELP_ARGS_DOC, argp, state);
if (fdoc) if (fdoc)
@ -1379,7 +1390,7 @@ argp_doc (const struct argp *argp, const struct argp_state *state,
void *input = 0; void *input = 0;
int anything = 0; int anything = 0;
size_t inp_text_limit = 0; size_t inp_text_limit = 0;
const char *doc = gettext (argp->doc); const char *doc = dgettext (argp->argp_domain, argp->doc);
const struct argp_child *child = argp->children; const struct argp_child *child = argp->children;
if (doc) if (doc)
@ -1503,8 +1514,13 @@ _help (const struct argp *argp, const struct argp_state *state, FILE *stream,
int old_wm = __argp_fmtstream_set_wmargin (fs, uparams.usage_indent); int old_wm = __argp_fmtstream_set_wmargin (fs, uparams.usage_indent);
char *levels = pattern_levels; char *levels = pattern_levels;
if (first_pattern)
__argp_fmtstream_printf (fs, "%s %s", __argp_fmtstream_printf (fs, "%s %s",
_(first_pattern ? "Usage:" : " or: "), dgettext (argp->argp_domain, "Usage:"),
name);
else
__argp_fmtstream_printf (fs, "%s %s",
dgettext (argp->argp_domain, " or: "),
name); name);
/* We set the lmargin as well as the wmargin, because hol_usage /* We set the lmargin as well as the wmargin, because hol_usage
@ -1515,7 +1531,8 @@ _help (const struct argp *argp, const struct argp_state *state, FILE *stream,
/* Just show where the options go. */ /* Just show where the options go. */
{ {
if (hol->num_entries > 0) if (hol->num_entries > 0)
__argp_fmtstream_puts (fs, _(" [OPTION...]")); __argp_fmtstream_puts (fs, dgettext (argp->argp_domain,
" [OPTION...]"));
} }
else else
/* Actually print the options. */ /* Actually print the options. */
@ -1542,7 +1559,7 @@ _help (const struct argp *argp, const struct argp_state *state, FILE *stream,
if (flags & ARGP_HELP_SEE) if (flags & ARGP_HELP_SEE)
{ {
__argp_fmtstream_printf (fs, _("\ __argp_fmtstream_printf (fs, dgettext (argp->argp_domain, "\
Try `%s --help' or `%s --usage' for more information.\n"), Try `%s --help' or `%s --usage' for more information.\n"),
name, name); name, name);
anything = 1; anything = 1;
@ -1569,7 +1586,8 @@ Try `%s --help' or `%s --usage' for more information.\n"),
{ {
if (anything) if (anything)
__argp_fmtstream_putc (fs, '\n'); __argp_fmtstream_putc (fs, '\n');
__argp_fmtstream_printf (fs, _("Report bugs to %s.\n"), __argp_fmtstream_printf (fs, dgettext (argp->argp_domain,
"Report bugs to %s.\n"),
argp_program_bug_address); argp_program_bug_address);
anything = 1; anything = 1;
} }

View File

@ -1,5 +1,5 @@
/* Hierarchial argument parsing, layered over getopt /* Hierarchial argument parsing, layered over getopt
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Written by Miles Bader <miles@gnu.ai.mit.edu>. Written by Miles Bader <miles@gnu.ai.mit.edu>.
@ -33,9 +33,8 @@
When compiling libc, the _ macro is predefined. */ When compiling libc, the _ macro is predefined. */
#ifdef HAVE_LIBINTL_H #ifdef HAVE_LIBINTL_H
# include <libintl.h> # include <libintl.h>
# define _(msgid) gettext (msgid)
#else #else
# define _(msgid) (msgid) # define dgettext(domain, msgid) (msgid)
# define gettext(msgid) (msgid) # define gettext(msgid) (msgid)
#endif #endif
#define N_(msgid) (msgid) #define N_(msgid) (msgid)
@ -161,7 +160,8 @@ argp_version_parser (int key, char *arg, struct argp_state *state)
else if (argp_program_version) else if (argp_program_version)
fprintf (state->out_stream, "%s\n", argp_program_version); fprintf (state->out_stream, "%s\n", argp_program_version);
else else
__argp_error (state, _("(PROGRAM ERROR) No version known!?")); __argp_error (state, dgettext (state->root_argp->argp_domain,
"(PROGRAM ERROR) No version known!?"));
if (! (state->flags & ARGP_NO_EXIT)) if (! (state->flags & ARGP_NO_EXIT))
exit (0); exit (0);
break; break;
@ -634,7 +634,8 @@ parser_finalize (struct parser *parser,
{ {
if (!(parser->state.flags & ARGP_NO_ERRS) && parser->state.err_stream) if (!(parser->state.flags & ARGP_NO_ERRS) && parser->state.err_stream)
fprintf (parser->state.err_stream, fprintf (parser->state.err_stream,
_("%s: Too many arguments\n"), parser->state.name); dgettext (parser->argp->argp_domain,
"%s: Too many arguments\n"), parser->state.name);
err = EBADKEY; err = EBADKEY;
} }
@ -775,7 +776,8 @@ parser_parse_opt (struct parser *parser, int opt, char *val)
static const char bad_key_err[] = static const char bad_key_err[] =
N_("(PROGRAM ERROR) Option should have been recognized!?"); N_("(PROGRAM ERROR) Option should have been recognized!?");
if (group_key == 0) if (group_key == 0)
__argp_error (&parser->state, "-%c: %s", opt, _(bad_key_err)); __argp_error (&parser->state, "-%c: %s", opt,
dgettext (parser->argp->argp_domain, bad_key_err));
else else
{ {
struct option *long_opt = parser->long_opts; struct option *long_opt = parser->long_opts;
@ -783,7 +785,7 @@ parser_parse_opt (struct parser *parser, int opt, char *val)
long_opt++; long_opt++;
__argp_error (&parser->state, "--%s: %s", __argp_error (&parser->state, "--%s: %s",
long_opt->name ? long_opt->name : "???", long_opt->name ? long_opt->name : "???",
_(bad_key_err)); dgettext (parser->argp->argp_domain, bad_key_err));
} }
} }

View File

@ -1,5 +1,5 @@
/* Hierarchial argument parsing, layered over getopt. /* Hierarchial argument parsing, layered over getopt.
Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Written by Miles Bader <miles@gnu.ai.mit.edu>. Written by Miles Bader <miles@gnu.ai.mit.edu>.
@ -238,6 +238,11 @@ struct argp
that should be done by the filter function. INPUT is either the input that should be done by the filter function. INPUT is either the input
supplied to argp_parse, or NULL, if argp_help was called directly. */ supplied to argp_parse, or NULL, if argp_help was called directly. */
char *(*help_filter)(int __key, __const char *__text, void *__input); char *(*help_filter)(int __key, __const char *__text, void *__input);
/* If non-zero the strings used in the argp library are translated using
the domain described by this string. Otherwise the currently installed
default domain is used. */
const char *argp_domain;
}; };
/* Possible KEY arguments to a help filter function. */ /* Possible KEY arguments to a help filter function. */