mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-21 18:23:03 +00:00
Sync with gnulib again.
This commit is contained in:
@@ -68,7 +68,6 @@ argmatch_exit_fn argmatch_die = __argmatch_die;
|
|||||||
null-terminated array ARGLIST, return the index in ARGLIST
|
null-terminated array ARGLIST, return the index in ARGLIST
|
||||||
of the matched element, else -1 if it does not match any element
|
of the matched element, else -1 if it does not match any element
|
||||||
or -2 if it is ambiguous (is a prefix of more than one element).
|
or -2 if it is ambiguous (is a prefix of more than one element).
|
||||||
If SENSITIVE, comparison is case sensitive.
|
|
||||||
|
|
||||||
If VALLIST is none null, use it to resolve ambiguities limited to
|
If VALLIST is none null, use it to resolve ambiguities limited to
|
||||||
synonyms, i.e., for
|
synonyms, i.e., for
|
||||||
@@ -76,10 +75,9 @@ argmatch_exit_fn argmatch_die = __argmatch_die;
|
|||||||
"no", "nope" -> 1
|
"no", "nope" -> 1
|
||||||
"y" is a valid argument, for `0', and "n" for `1'. */
|
"y" is a valid argument, for `0', and "n" for `1'. */
|
||||||
|
|
||||||
static int
|
int
|
||||||
__argmatch_internal (const char *arg, const char *const *arglist,
|
argmatch (const char *arg, const char *const *arglist,
|
||||||
const char *vallist, size_t valsize,
|
const char *vallist, size_t valsize)
|
||||||
int case_sensitive)
|
|
||||||
{
|
{
|
||||||
int i; /* Temporary index in ARGLIST. */
|
int i; /* Temporary index in ARGLIST. */
|
||||||
size_t arglen; /* Length of ARG. */
|
size_t arglen; /* Length of ARG. */
|
||||||
@@ -91,9 +89,7 @@ __argmatch_internal (const char *arg, const char *const *arglist,
|
|||||||
/* Test all elements for either exact match or abbreviated matches. */
|
/* Test all elements for either exact match or abbreviated matches. */
|
||||||
for (i = 0; arglist[i]; i++)
|
for (i = 0; arglist[i]; i++)
|
||||||
{
|
{
|
||||||
if (case_sensitive
|
if (!strncmp (arglist[i], arg, arglen))
|
||||||
? !strncmp (arglist[i], arg, arglen)
|
|
||||||
: !strncasecmp (arglist[i], arg, arglen))
|
|
||||||
{
|
{
|
||||||
if (strlen (arglist[i]) == arglen)
|
if (strlen (arglist[i]) == arglen)
|
||||||
/* Exact match found. */
|
/* Exact match found. */
|
||||||
@@ -121,22 +117,6 @@ __argmatch_internal (const char *arg, const char *const *arglist,
|
|||||||
return matchind;
|
return matchind;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* argmatch - case sensitive version */
|
|
||||||
int
|
|
||||||
argmatch (const char *arg, const char *const *arglist,
|
|
||||||
const char *vallist, size_t valsize)
|
|
||||||
{
|
|
||||||
return __argmatch_internal (arg, arglist, vallist, valsize, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* argcasematch - case insensitive version */
|
|
||||||
int
|
|
||||||
argcasematch (const char *arg, const char *const *arglist,
|
|
||||||
const char *vallist, size_t valsize)
|
|
||||||
{
|
|
||||||
return __argmatch_internal (arg, arglist, vallist, valsize, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Error reporting for argmatch.
|
/* Error reporting for argmatch.
|
||||||
CONTEXT is a description of the type of entity that was being matched.
|
CONTEXT is a description of the type of entity that was being matched.
|
||||||
VALUE is the invalid value that was given.
|
VALUE is the invalid value that was given.
|
||||||
@@ -191,12 +171,9 @@ int
|
|||||||
__xargmatch_internal (const char *context,
|
__xargmatch_internal (const char *context,
|
||||||
const char *arg, const char *const *arglist,
|
const char *arg, const char *const *arglist,
|
||||||
const char *vallist, size_t valsize,
|
const char *vallist, size_t valsize,
|
||||||
int case_sensitive,
|
|
||||||
argmatch_exit_fn exit_fn)
|
argmatch_exit_fn exit_fn)
|
||||||
{
|
{
|
||||||
int res = __argmatch_internal (arg, arglist,
|
int res = argmatch (arg, arglist, vallist, valsize);
|
||||||
vallist, valsize,
|
|
||||||
case_sensitive);
|
|
||||||
if (res >= 0)
|
if (res >= 0)
|
||||||
/* Success. */
|
/* Success. */
|
||||||
return res;
|
return res;
|
||||||
@@ -282,12 +259,12 @@ main (int argc, const char *const *argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((cp = getenv ("VERSION_CONTROL")))
|
if ((cp = getenv ("VERSION_CONTROL")))
|
||||||
backup_type = XARGCASEMATCH ("$VERSION_CONTROL", cp,
|
backup_type = XARGMATCH ("$VERSION_CONTROL", cp,
|
||||||
backup_args, backup_vals);
|
backup_args, backup_vals);
|
||||||
|
|
||||||
if (argc == 2)
|
if (argc == 2)
|
||||||
backup_type = XARGCASEMATCH (program_name, argv[1],
|
backup_type = XARGMATCH (program_name, argv[1],
|
||||||
backup_args, backup_vals);
|
backup_args, backup_vals);
|
||||||
|
|
||||||
printf ("The version control is `%s'\n",
|
printf ("The version control is `%s'\n",
|
||||||
ARGMATCH_TO_ARGUMENT (backup_type, backup_args, backup_vals));
|
ARGMATCH_TO_ARGUMENT (backup_type, backup_args, backup_vals));
|
||||||
|
|||||||
@@ -49,15 +49,10 @@
|
|||||||
|
|
||||||
int argmatch (char const *arg, char const *const *arglist,
|
int argmatch (char const *arg, char const *const *arglist,
|
||||||
char const *vallist, size_t valsize);
|
char const *vallist, size_t valsize);
|
||||||
int argcasematch (char const *arg, char const *const *arglist,
|
|
||||||
char const *vallist, size_t valsize);
|
|
||||||
|
|
||||||
# define ARGMATCH(Arg, Arglist, Vallist) \
|
# define ARGMATCH(Arg, Arglist, Vallist) \
|
||||||
argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist))
|
argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist))
|
||||||
|
|
||||||
# define ARGCASEMATCH(Arg, Arglist, Vallist) \
|
|
||||||
argcasematch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist))
|
|
||||||
|
|
||||||
/* xargmatch calls this function when it fails. This function should not
|
/* xargmatch calls this function when it fails. This function should not
|
||||||
return. By default, this is a function that calls ARGMATCH_DIE which
|
return. By default, this is a function that calls ARGMATCH_DIE which
|
||||||
in turn defaults to `exit (EXIT_FAILURE)'. */
|
in turn defaults to `exit (EXIT_FAILURE)'. */
|
||||||
@@ -91,7 +86,7 @@ void argmatch_valid (char const *const *arglist,
|
|||||||
int __xargmatch_internal (char const *context,
|
int __xargmatch_internal (char const *context,
|
||||||
char const *arg, char const *const *arglist,
|
char const *arg, char const *const *arglist,
|
||||||
char const *vallist, size_t valsize,
|
char const *vallist, size_t valsize,
|
||||||
int case_sensitive, argmatch_exit_fn exit_fn);
|
argmatch_exit_fn exit_fn);
|
||||||
|
|
||||||
/* Programmer friendly interface to __xargmatch_internal. */
|
/* Programmer friendly interface to __xargmatch_internal. */
|
||||||
|
|
||||||
@@ -99,13 +94,7 @@ int __xargmatch_internal (char const *context,
|
|||||||
((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
|
((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
|
||||||
(char const *) (Vallist), \
|
(char const *) (Vallist), \
|
||||||
sizeof *(Vallist), \
|
sizeof *(Vallist), \
|
||||||
1, argmatch_die)])
|
argmatch_die)])
|
||||||
|
|
||||||
# define XARGCASEMATCH(Context, Arg, Arglist, Vallist) \
|
|
||||||
((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
|
|
||||||
(char const *) (Vallist), \
|
|
||||||
sizeof *(Vallist), \
|
|
||||||
0, argmatch_die)])
|
|
||||||
|
|
||||||
/* Convert a value into a corresponding argument. */
|
/* Convert a value into a corresponding argument. */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user