* argp/argp-help.c: Likewise.
	* argp/argp-parse.c: Likewise.
This commit is contained in:
Ulrich Drepper 1998-09-07 13:47:26 +00:00
parent cf9f9a1686
commit 94b78bb204
6 changed files with 183 additions and 158 deletions

View File

@ -19,6 +19,8 @@
* stdlib/strtol.c: Likewise.
* string/strcoll.c: Likewise.
* string/strxfrm.c: Likewise.
* argp/argp-help.c: Likewise.
* argp/argp-parse.c: Likewise.
1998-09-07 09:58 Ulrich Drepper <drepper@cygnus.com>

View File

@ -800,63 +800,65 @@ hol_append (struct hol *hol, struct hol *more)
/* Merge entries. */
if (more->num_entries > 0)
if (hol->num_entries == 0)
{
hol->num_entries = more->num_entries;
hol->entries = more->entries;
hol->short_options = more->short_options;
more->num_entries = 0; /* Mark MORE's fields as invalid. */
}
else
/* Append the entries in MORE to those in HOL, taking care to only add
non-shadowed SHORT_OPTIONS values. */
{
unsigned left;
char *so, *more_so;
struct hol_entry *e;
unsigned num_entries = hol->num_entries + more->num_entries;
struct hol_entry *entries =
malloc (num_entries * sizeof (struct hol_entry));
unsigned hol_so_len = strlen (hol->short_options);
char *short_options =
malloc (hol_so_len + strlen (more->short_options) + 1);
{
if (hol->num_entries == 0)
{
hol->num_entries = more->num_entries;
hol->entries = more->entries;
hol->short_options = more->short_options;
more->num_entries = 0; /* Mark MORE's fields as invalid. */
}
else
/* Append the entries in MORE to those in HOL, taking care to only add
non-shadowed SHORT_OPTIONS values. */
{
unsigned left;
char *so, *more_so;
struct hol_entry *e;
unsigned num_entries = hol->num_entries + more->num_entries;
struct hol_entry *entries =
malloc (num_entries * sizeof (struct hol_entry));
unsigned hol_so_len = strlen (hol->short_options);
char *short_options =
malloc (hol_so_len + strlen (more->short_options) + 1);
__mempcpy (__mempcpy (entries, hol->entries,
hol->num_entries * sizeof (struct hol_entry)),
more->entries,
more->num_entries * sizeof (struct hol_entry));
__mempcpy (__mempcpy (entries, hol->entries,
hol->num_entries * sizeof (struct hol_entry)),
more->entries,
more->num_entries * sizeof (struct hol_entry));
__mempcpy (short_options, hol->short_options, hol_so_len);
__mempcpy (short_options, hol->short_options, hol_so_len);
/* Fix up the short options pointers from HOL. */
for (e = entries, left = hol->num_entries; left > 0; e++, left--)
e->short_options += (short_options - hol->short_options);
for (e = entries, left = hol->num_entries; left > 0; e++, left--)
e->short_options += (short_options - hol->short_options);
/* Now add the short options from MORE, fixing up its entries too. */
so = short_options + hol_so_len;
more_so = more->short_options;
for (left = more->num_entries; left > 0; e++, left--)
{
int opts_left;
const struct argp_option *opt;
so = short_options + hol_so_len;
more_so = more->short_options;
for (left = more->num_entries; left > 0; e++, left--)
{
int opts_left;
const struct argp_option *opt;
e->short_options = so;
e->short_options = so;
for (opts_left = e->num, opt = e->opt; opts_left; opt++, opts_left--)
{
int ch = *more_so;
if (oshort (opt) && ch == opt->key)
/* The next short option in MORE_SO, CH, is from OPT. */
{
if (! find_char (ch, short_options,
short_options + hol_so_len))
/* The short option CH isn't shadowed by HOL's options,
so add it to the sum. */
*so++ = ch;
more_so++;
}
}
}
for (opts_left = e->num, opt = e->opt; opts_left; opt++, opts_left--)
{
int ch = *more_so;
if (oshort (opt) && ch == opt->key)
/* The next short option in MORE_SO, CH, is from OPT. */
{
if (! find_char (ch, short_options,
short_options + hol_so_len))
/* The short option CH isn't shadowed by HOL's options,
so add it to the sum. */
*so++ = ch;
more_so++;
}
}
}
}
*so = '\0';
@ -900,10 +902,14 @@ arg (const struct argp_option *real, const char *req_fmt, const char *opt_fmt,
const char *domain, argp_fmtstream_t stream)
{
if (real->arg)
if (real->flags & OPTION_ARG_OPTIONAL)
__argp_fmtstream_printf (stream, opt_fmt, dgettext (domain, real->arg));
else
__argp_fmtstream_printf (stream, req_fmt, dgettext (domain, real->arg));
{
if (real->flags & OPTION_ARG_OPTIONAL)
__argp_fmtstream_printf (stream, opt_fmt,
dgettext (domain, real->arg));
else
__argp_fmtstream_printf (stream, req_fmt,
dgettext (domain, real->arg));
}
}
/* Helper functions for hol_entry_help. */
@ -1245,16 +1251,18 @@ usage_long_opt (const struct argp_option *opt,
arg = real->arg;
if (! (flags & OPTION_NO_USAGE))
if (arg)
{
arg = dgettext (domain, arg);
if (flags & OPTION_ARG_OPTIONAL)
__argp_fmtstream_printf (stream, " [--%s[=%s]]", opt->name, arg);
else
__argp_fmtstream_printf (stream, " [--%s=%s]", opt->name, arg);
}
else
__argp_fmtstream_printf (stream, " [--%s]", opt->name);
{
if (arg)
{
arg = dgettext (domain, arg);
if (flags & OPTION_ARG_OPTIONAL)
__argp_fmtstream_printf (stream, " [--%s[=%s]]", opt->name, arg);
else
__argp_fmtstream_printf (stream, " [--%s=%s]", opt->name, arg);
}
else
__argp_fmtstream_printf (stream, " [--%s]", opt->name);
}
return 0;
}
@ -1385,16 +1393,18 @@ argp_args_usage (const struct argp *argp, const struct argp_state *state,
advance = !argp_args_usage ((child++)->argp, state, levels, advance, stream);
if (advance && multiple)
/* Need to increment our level. */
if (*nl)
/* There's more we can do here. */
{
(*our_level)++;
advance = 0; /* Our parent shouldn't advance also. */
}
else if (*our_level > 0)
/* We had multiple levels, but used them up; reset to zero. */
*our_level = 0;
{
/* Need to increment our level. */
if (*nl)
/* There's more we can do here. */
{
(*our_level)++;
advance = 0; /* Our parent shouldn't advance also. */
}
else if (*our_level > 0)
/* We had multiple levels, but used them up; reset to zero. */
*our_level = 0;
}
return !advance;
}

View File

@ -605,39 +605,43 @@ parser_finalize (struct parser *parser,
err = 0;
if (! err)
if (parser->state.next == parser->state.argc)
/* We successfully parsed all arguments! Call all the parsers again,
just a few more times... */
{
for (group = parser->groups;
group < parser->egroup && (!err || err==EBADKEY);
group++)
if (group->args_processed == 0)
err = group_parse (group, &parser->state, ARGP_KEY_NO_ARGS, 0);
for (group = parser->groups;
group < parser->egroup && (!err || err==EBADKEY);
group++)
err = group_parse (group, &parser->state, ARGP_KEY_END, 0);
{
if (parser->state.next == parser->state.argc)
/* We successfully parsed all arguments! Call all the parsers again,
just a few more times... */
{
for (group = parser->groups;
group < parser->egroup && (!err || err==EBADKEY);
group++)
if (group->args_processed == 0)
err = group_parse (group, &parser->state, ARGP_KEY_NO_ARGS, 0);
for (group = parser->groups;
group < parser->egroup && (!err || err==EBADKEY);
group++)
err = group_parse (group, &parser->state, ARGP_KEY_END, 0);
if (err == EBADKEY)
err = 0; /* Some parser didn't understand. */
if (err == EBADKEY)
err = 0; /* Some parser didn't understand. */
/* Tell the user that all arguments are parsed. */
if (end_index)
*end_index = parser->state.next;
}
else if (end_index)
/* Return any remaining arguments to the user. */
*end_index = parser->state.next;
else
/* No way to return the remaining arguments, they must be bogus. */
{
if (!(parser->state.flags & ARGP_NO_ERRS) && parser->state.err_stream)
fprintf (parser->state.err_stream,
dgettext (parser->argp->argp_domain,
"%s: Too many arguments\n"), parser->state.name);
err = EBADKEY;
}
/* Tell the user that all arguments are parsed. */
if (end_index)
*end_index = parser->state.next;
}
else if (end_index)
/* Return any remaining arguments to the user. */
*end_index = parser->state.next;
else
/* No way to return the remaining arguments, they must be bogus. */
{
if (!(parser->state.flags & ARGP_NO_ERRS)
&& parser->state.err_stream)
fprintf (parser->state.err_stream,
dgettext (parser->argp->argp_domain,
"%s: Too many arguments\n"),
parser->state.name);
err = EBADKEY;
}
}
/* Okay, we're all done, with either an error or success; call the parsers
to indicate which one. */
@ -849,20 +853,22 @@ parser_parse_next (struct parser *parser, int *arg_ebadkey)
opt = KEY_END;
if (opt == KEY_END)
/* We're past what getopt considers the options. */
if (parser->state.next >= parser->state.argc
|| (parser->state.flags & ARGP_NO_ARGS))
/* Indicate that we're done. */
{
*arg_ebadkey = 1;
return EBADKEY;
}
else
/* A non-option arg; simulate what getopt might have done. */
{
opt = KEY_ARG;
optarg = parser->state.argv[parser->state.next++];
}
{
/* We're past what getopt considers the options. */
if (parser->state.next >= parser->state.argc
|| (parser->state.flags & ARGP_NO_ARGS))
/* Indicate that we're done. */
{
*arg_ebadkey = 1;
return EBADKEY;
}
else
/* A non-option arg; simulate what getopt might have done. */
{
opt = KEY_ARG;
optarg = parser->state.argv[parser->state.next++];
}
}
if (opt == KEY_ARG)
/* A non-option argument; try each parser in turn. */

View File

@ -404,12 +404,14 @@ noconv:
hexadecimal digits. This is no error case. We return 0 and
ENDPTR points to the `x`. */
if (endptr != NULL)
if (save - nptr >= 2 && TOUPPER (save[-1]) == L_('X')
&& save[-2] == L_('0'))
*endptr = (STRING_TYPE *) &save[-1];
else
/* There was no number to convert. */
*endptr = (STRING_TYPE *) nptr;
{
if (save - nptr >= 2 && TOUPPER (save[-1]) == L_('X')
&& save[-2] == L_('0'))
*endptr = (STRING_TYPE *) &save[-1];
else
/* There was no number to convert. */
*endptr = (STRING_TYPE *) nptr;
}
return 0L;
}

View File

@ -172,32 +172,35 @@ STRCOLL (s1, s2, l)
/* We have to increment the index counters. */
if ((forward && ++s1idx >= s1run->data[pass].number)
|| (!forward && --s1idx < 0))
if (forward)
{
s1run = s1run->next;
s1idx = 0;
}
else
{
s1run = s1run->prev;
if (s1run != NULL)
s1idx = s1run->data[pass].number - 1;
}
{
if (forward)
{
s1run = s1run->next;
s1idx = 0;
}
else
{
s1run = s1run->prev;
if (s1run != NULL)
s1idx = s1run->data[pass].number - 1;
}
}
if ((forward && ++s2idx >= s2run->data[pass].number)
|| (!forward && --s2idx < 0))
if (forward)
{
s2run = s2run->next;
s2idx = 0;
}
else
{
s2run = s2run->prev;
if (s2run != NULL)
s2idx = s2run->data[pass].number - 1;
}
{
if (forward)
{
s2run = s2run->next;
s2idx = 0;
}
else
{
s2run = s2run->prev;
if (s2run != NULL)
s2idx = s2run->data[pass].number - 1;
}
}
}
if (s1run != s2run)

View File

@ -250,17 +250,19 @@ STRXFRM (STRING_TYPE *dest, const STRING_TYPE *src, size_t n, __locale_t l)
/* We have to increment the index counters. */
if ((forward && ++idx >= run->data[pass].number)
|| (!forward && --idx < 0))
if (forward)
{
run = run->next;
idx = 0;
}
else
{
run = run->prev;
if (run != NULL)
idx = run->data[pass].number - 1;
}
{
if (forward)
{
run = run->next;
idx = 0;
}
else
{
run = run->prev;
if (run != NULL)
idx = run->data[pass].number - 1;
}
}
}
/* Write marker for end of word. */