Blame lib/argmatch.h

Packit Service fdd496
/* argmatch.h -- definitions and prototypes for argmatch.c
Packit Service fdd496
Packit Service fdd496
   Copyright (C) 1990, 1998-1999, 2001-2002, 2004-2005, 2009-2017 Free Software
Packit Service fdd496
   Foundation, Inc.
Packit Service fdd496
Packit Service fdd496
   This program is free software: you can redistribute it and/or modify
Packit Service fdd496
   it under the terms of the GNU General Public License as published by
Packit Service fdd496
   the Free Software Foundation; either version 3 of the License, or
Packit Service fdd496
   (at your option) any later version.
Packit Service fdd496
Packit Service fdd496
   This program is distributed in the hope that it will be useful,
Packit Service fdd496
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fdd496
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service fdd496
   GNU General Public License for more details.
Packit Service fdd496
Packit Service fdd496
   You should have received a copy of the GNU General Public License
Packit Service fdd496
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Service fdd496
Packit Service fdd496
/* Written by David MacKenzie <djm@ai.mit.edu>
Packit Service fdd496
   Modified by Akim Demaille <demaille@inf.enst.fr> */
Packit Service fdd496
Packit Service fdd496
#ifndef ARGMATCH_H_
Packit Service fdd496
# define ARGMATCH_H_ 1
Packit Service fdd496
Packit Service fdd496
# include <stddef.h>
Packit Service fdd496
Packit Service fdd496
# include "verify.h"
Packit Service fdd496
Packit Service fdd496
#ifdef  __cplusplus
Packit Service fdd496
extern "C" {
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
Packit Service fdd496
Packit Service fdd496
/* Assert there are as many real arguments as there are values
Packit Service fdd496
   (argument list ends with a NULL guard).  */
Packit Service fdd496
Packit Service fdd496
# define ARGMATCH_VERIFY(Arglist, Vallist) \
Packit Service fdd496
    verify (ARRAY_CARDINALITY (Arglist) == ARRAY_CARDINALITY (Vallist) + 1)
Packit Service fdd496
Packit Service fdd496
/* Return the index of the element of ARGLIST (NULL terminated) that
Packit Service fdd496
   matches with ARG.  If VALLIST is not NULL, then use it to resolve
Packit Service fdd496
   false ambiguities (i.e., different matches of ARG but corresponding
Packit Service fdd496
   to the same values in VALLIST).  */
Packit Service fdd496
Packit Service fdd496
ptrdiff_t argmatch (char const *arg, char const *const *arglist,
Packit Service fdd496
                    char const *vallist, size_t valsize) _GL_ATTRIBUTE_PURE;
Packit Service fdd496
Packit Service fdd496
# define ARGMATCH(Arg, Arglist, Vallist) \
Packit Service fdd496
  argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist))
Packit Service fdd496
Packit Service fdd496
/* xargmatch calls this function when it fails.  This function should not
Packit Service fdd496
   return.  By default, this is a function that calls ARGMATCH_DIE which
Packit Service fdd496
   in turn defaults to 'exit (exit_failure)'.  */
Packit Service fdd496
typedef void (*argmatch_exit_fn) (void);
Packit Service fdd496
extern argmatch_exit_fn argmatch_die;
Packit Service fdd496
Packit Service fdd496
/* Report on stderr why argmatch failed.  Report correct values. */
Packit Service fdd496
Packit Service fdd496
void argmatch_invalid (char const *context, char const *value,
Packit Service fdd496
                       ptrdiff_t problem);
Packit Service fdd496
Packit Service fdd496
/* Left for compatibility with the old name invalid_arg */
Packit Service fdd496
Packit Service fdd496
# define invalid_arg(Context, Value, Problem) \
Packit Service fdd496
  argmatch_invalid (Context, Value, Problem)
Packit Service fdd496
Packit Service fdd496
Packit Service fdd496
Packit Service fdd496
/* Report on stderr the list of possible arguments.  */
Packit Service fdd496
Packit Service fdd496
void argmatch_valid (char const *const *arglist,
Packit Service fdd496
                     char const *vallist, size_t valsize);
Packit Service fdd496
Packit Service fdd496
# define ARGMATCH_VALID(Arglist, Vallist) \
Packit Service fdd496
  argmatch_valid (Arglist, (char const *) (Vallist), sizeof *(Vallist))
Packit Service fdd496
Packit Service fdd496
Packit Service fdd496
Packit Service fdd496
/* Same as argmatch, but upon failure, report an explanation of the
Packit Service fdd496
   failure, and exit using the function EXIT_FN. */
Packit Service fdd496
Packit Service fdd496
ptrdiff_t __xargmatch_internal (char const *context,
Packit Service fdd496
                                char const *arg, char const *const *arglist,
Packit Service fdd496
                                char const *vallist, size_t valsize,
Packit Service fdd496
                                argmatch_exit_fn exit_fn);
Packit Service fdd496
Packit Service fdd496
/* Programmer friendly interface to __xargmatch_internal. */
Packit Service fdd496
Packit Service fdd496
# define XARGMATCH(Context, Arg, Arglist, Vallist)              \
Packit Service fdd496
  ((Vallist) [__xargmatch_internal (Context, Arg, Arglist,      \
Packit Service fdd496
                                    (char const *) (Vallist),   \
Packit Service fdd496
                                    sizeof *(Vallist),          \
Packit Service fdd496
                                    argmatch_die)])
Packit Service fdd496
Packit Service fdd496
/* Convert a value into a corresponding argument. */
Packit Service fdd496
Packit Service fdd496
char const *argmatch_to_argument (char const *value,
Packit Service fdd496
                                  char const *const *arglist,
Packit Service fdd496
                                  char const *vallist, size_t valsize)
Packit Service fdd496
  _GL_ATTRIBUTE_PURE;
Packit Service fdd496
Packit Service fdd496
# define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist)                  \
Packit Service fdd496
  argmatch_to_argument (Value, Arglist,                                 \
Packit Service fdd496
                        (char const *) (Vallist), sizeof *(Vallist))
Packit Service fdd496
Packit Service fdd496
#ifdef  __cplusplus
Packit Service fdd496
}
Packit Service fdd496
#endif
Packit Service fdd496
Packit Service fdd496
#endif /* ARGMATCH_H_ */