mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 17:23:02 +00:00
Sync with gnulib.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/* argmatch.c -- find a match for a string in an array
|
/* argmatch.c -- find a match for a string in an array
|
||||||
Copyright (C) 1990, 1998, 1999, 2001 Free Software Foundation, Inc.
|
Copyright (C) 1990, 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -18,28 +18,23 @@
|
|||||||
/* Written by David MacKenzie <djm@ai.mit.edu>
|
/* Written by David MacKenzie <djm@ai.mit.edu>
|
||||||
Modified by Akim Demaille <demaille@inf.enst.fr> */
|
Modified by Akim Demaille <demaille@inf.enst.fr> */
|
||||||
|
|
||||||
|
#if HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "argmatch.h"
|
#include "argmatch.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#ifdef STDC_HEADERS
|
#include <stdlib.h>
|
||||||
# include <stdlib.h>
|
#include <string.h>
|
||||||
# include <string.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAVE_LOCALE_H
|
#include "gettext.h"
|
||||||
# include <locale.h>
|
#define _(msgid) gettext (msgid)
|
||||||
#endif
|
|
||||||
|
|
||||||
#if ENABLE_NLS
|
|
||||||
# include <libintl.h>
|
|
||||||
# define _(Text) gettext (Text)
|
|
||||||
#else
|
|
||||||
# define _(Text) Text
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "quotearg.h"
|
#include "quotearg.h"
|
||||||
#include "quote.h"
|
#include "quote.h"
|
||||||
|
#include "unlocked-io.h"
|
||||||
|
|
||||||
/* When reporting an invalid argument, show nonprinting characters
|
/* When reporting an invalid argument, show nonprinting characters
|
||||||
by using the quoting style ARGMATCH_QUOTING_STYLE. Do not use
|
by using the quoting style ARGMATCH_QUOTING_STYLE. Do not use
|
||||||
@@ -48,14 +43,6 @@
|
|||||||
# define ARGMATCH_QUOTING_STYLE locale_quoting_style
|
# define ARGMATCH_QUOTING_STYLE locale_quoting_style
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The following test is to work around the gross typo in
|
|
||||||
systems like Sony NEWS-OS Release 4.0C, whereby EXIT_FAILURE
|
|
||||||
is defined to 0, not 1. */
|
|
||||||
#if !EXIT_FAILURE
|
|
||||||
# undef EXIT_FAILURE
|
|
||||||
# define EXIT_FAILURE 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Non failing version of argmatch call this function after failing. */
|
/* Non failing version of argmatch call this function after failing. */
|
||||||
#ifndef ARGMATCH_DIE
|
#ifndef ARGMATCH_DIE
|
||||||
# define ARGMATCH_DIE exit (EXIT_FAILURE)
|
# define ARGMATCH_DIE exit (EXIT_FAILURE)
|
||||||
|
|||||||
100
lib/argmatch.h
100
lib/argmatch.h
@@ -21,29 +21,24 @@
|
|||||||
#ifndef ARGMATCH_H_
|
#ifndef ARGMATCH_H_
|
||||||
# define ARGMATCH_H_ 1
|
# define ARGMATCH_H_ 1
|
||||||
|
|
||||||
# if HAVE_CONFIG_H
|
# include <stddef.h>
|
||||||
# include <config.h>
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# include <sys/types.h>
|
# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
|
||||||
|
|
||||||
# ifndef PARAMS
|
|
||||||
# if PROTOTYPES || (defined (__STDC__) && __STDC__)
|
|
||||||
# define PARAMS(args) args
|
|
||||||
# else
|
|
||||||
# define PARAMS(args) ()
|
|
||||||
# endif /* GCC. */
|
|
||||||
# endif /* Not PARAMS. */
|
|
||||||
|
|
||||||
/* Assert there are as many real arguments as there are values
|
|
||||||
(argument list ends with a NULL guard). There is no execution
|
|
||||||
cost, since it will be statically evalauted to `assert (0)' or
|
|
||||||
`assert (1)'. Unfortunately there is no -Wassert-0. */
|
|
||||||
|
|
||||||
# define ARRAY_CARDINALITY(Array) (sizeof ((Array)) / sizeof (*(Array)))
|
|
||||||
|
|
||||||
# define ARGMATCH_CONSTRAINT(Arglist, Vallist) \
|
# define ARGMATCH_CONSTRAINT(Arglist, Vallist) \
|
||||||
(ARRAY_CARDINALITY ((Arglist)) == ARRAY_CARDINALITY ((Vallist)) + 1)
|
(ARRAY_CARDINALITY (Arglist) == ARRAY_CARDINALITY (Vallist) + 1)
|
||||||
|
|
||||||
|
/* Assert there are as many real arguments as there are values
|
||||||
|
(argument list ends with a NULL guard). ARGMATCH_VERIFY is
|
||||||
|
preferred, since it is guaranteed to be chedk at compile-time.
|
||||||
|
ARGMATCH_ASSERT is for backward compatibility only. */
|
||||||
|
|
||||||
|
# define ARGMATCH_VERIFY(Arglist, Vallist) \
|
||||||
|
struct argmatch_verify \
|
||||||
|
{ \
|
||||||
|
char argmatch_verify[ARGMATCH_CONSTRAINT(Arglist, Vallist) ? 1 : -1]; \
|
||||||
|
}
|
||||||
|
|
||||||
# define ARGMATCH_ASSERT(Arglist, Vallist) \
|
# define ARGMATCH_ASSERT(Arglist, Vallist) \
|
||||||
assert (ARGMATCH_CONSTRAINT (Arglist, Vallist))
|
assert (ARGMATCH_CONSTRAINT (Arglist, Vallist))
|
||||||
|
|
||||||
@@ -52,79 +47,74 @@
|
|||||||
false ambiguities (i.e., different matches of ARG but corresponding
|
false ambiguities (i.e., different matches of ARG but corresponding
|
||||||
to the same values in VALLIST). */
|
to the same values in VALLIST). */
|
||||||
|
|
||||||
int argmatch
|
int argmatch (char const *arg, char const *const *arglist,
|
||||||
PARAMS ((const char *arg, const char *const *arglist,
|
char const *vallist, size_t valsize);
|
||||||
const char *vallist, size_t valsize));
|
int argcasematch (char const *arg, char const *const *arglist,
|
||||||
int argcasematch
|
char const *vallist, size_t valsize);
|
||||||
PARAMS ((const char *arg, const char *const *arglist,
|
|
||||||
const char *vallist, size_t valsize));
|
|
||||||
|
|
||||||
# define ARGMATCH(Arg, Arglist, Vallist) \
|
# define ARGMATCH(Arg, Arglist, Vallist) \
|
||||||
argmatch ((Arg), (Arglist), (const char *) (Vallist), sizeof (*(Vallist)))
|
argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist))
|
||||||
|
|
||||||
# define ARGCASEMATCH(Arg, Arglist, Vallist) \
|
# define ARGCASEMATCH(Arg, Arglist, Vallist) \
|
||||||
argcasematch ((Arg), (Arglist), (const char *) (Vallist), sizeof (*(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)'. */
|
||||||
typedef void (*argmatch_exit_fn) PARAMS ((void));
|
typedef void (*argmatch_exit_fn) (void);
|
||||||
extern argmatch_exit_fn argmatch_die;
|
extern argmatch_exit_fn argmatch_die;
|
||||||
|
|
||||||
/* Report on stderr why argmatch failed. Report correct values. */
|
/* Report on stderr why argmatch failed. Report correct values. */
|
||||||
|
|
||||||
void argmatch_invalid
|
void argmatch_invalid (char const *context, char const *value, int problem);
|
||||||
PARAMS ((const char *context, const char *value, int problem));
|
|
||||||
|
|
||||||
/* Left for compatibility with the old name invalid_arg */
|
/* Left for compatibility with the old name invalid_arg */
|
||||||
|
|
||||||
# define invalid_arg(Context, Value, Problem) \
|
# define invalid_arg(Context, Value, Problem) \
|
||||||
argmatch_invalid ((Context), (Value), (Problem))
|
argmatch_invalid (Context, Value, Problem)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Report on stderr the list of possible arguments. */
|
/* Report on stderr the list of possible arguments. */
|
||||||
|
|
||||||
void argmatch_valid
|
void argmatch_valid (char const *const *arglist,
|
||||||
PARAMS ((const char *const *arglist,
|
char const *vallist, size_t valsize);
|
||||||
const char *vallist, size_t valsize));
|
|
||||||
|
|
||||||
# define ARGMATCH_VALID(Arglist, Vallist) \
|
# define ARGMATCH_VALID(Arglist, Vallist) \
|
||||||
argmatch_valid (Arglist, (const char *) Vallist, sizeof (*(Vallist)))
|
argmatch_valid (Arglist, (char const *) (Vallist), sizeof *(Vallist))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Same as argmatch, but upon failure, reports a explanation on the
|
/* Same as argmatch, but upon failure, reports a explanation on the
|
||||||
failure, and exits using the function EXIT_FN. */
|
failure, and exits using the function EXIT_FN. */
|
||||||
|
|
||||||
int __xargmatch_internal
|
int __xargmatch_internal (char const *context,
|
||||||
PARAMS ((const char *context,
|
char const *arg, char const *const *arglist,
|
||||||
const char *arg, const char *const *arglist,
|
char const *vallist, size_t valsize,
|
||||||
const char *vallist, size_t valsize,
|
int case_sensitive, argmatch_exit_fn exit_fn);
|
||||||
int case_sensitive, argmatch_exit_fn exit_fn));
|
|
||||||
|
|
||||||
/* Programmer friendly interface to __xargmatch_internal. */
|
/* Programmer friendly interface to __xargmatch_internal. */
|
||||||
|
|
||||||
# define XARGMATCH(Context, Arg, Arglist, Vallist) \
|
# define XARGMATCH(Context, Arg, Arglist, Vallist) \
|
||||||
(Vallist [__xargmatch_internal ((Context), (Arg), (Arglist), \
|
((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
|
||||||
(const char *) (Vallist), \
|
(char const *) (Vallist), \
|
||||||
sizeof (*(Vallist)), \
|
sizeof *(Vallist), \
|
||||||
1, argmatch_die)])
|
1, argmatch_die)])
|
||||||
|
|
||||||
# define XARGCASEMATCH(Context, Arg, Arglist, Vallist) \
|
# define XARGCASEMATCH(Context, Arg, Arglist, Vallist) \
|
||||||
(Vallist [__xargmatch_internal ((Context), (Arg), (Arglist), \
|
((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
|
||||||
(const char *) (Vallist), \
|
(char const *) (Vallist), \
|
||||||
sizeof (*(Vallist)), \
|
sizeof *(Vallist), \
|
||||||
0, argmatch_die)])
|
0, argmatch_die)])
|
||||||
|
|
||||||
/* Convert a value into a corresponding argument. */
|
/* Convert a value into a corresponding argument. */
|
||||||
|
|
||||||
const char *argmatch_to_argument
|
char const *argmatch_to_argument (char const *value,
|
||||||
PARAMS ((char const *value, const char *const *arglist,
|
char const *const *arglist,
|
||||||
const char *vallist, size_t valsize));
|
char const *vallist, size_t valsize);
|
||||||
|
|
||||||
# define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \
|
# define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \
|
||||||
argmatch_to_argument ((Value), (Arglist), \
|
argmatch_to_argument (Value, Arglist, \
|
||||||
(const char *) (Vallist), sizeof (*(Vallist)))
|
(char const *) (Vallist), sizeof *(Vallist))
|
||||||
|
|
||||||
#endif /* ARGMATCH_H_ */
|
#endif /* ARGMATCH_H_ */
|
||||||
|
|||||||
Reference in New Issue
Block a user