1 /* argmatch.c -- find a match for a string in an array
2 Copyright (C) 1990, 1998 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /* Written by David MacKenzie <djm@ai.mit.edu>
19 Modified by Akim Demaille <demaille@inf.enst.fr> */
22 # define _ARGMATCH_H_ 1
28 # include <sys/types.h>
31 # if PROTOTYPES || (defined (__STDC__) && __STDC__)
32 # define PARAMS(args) args
34 # define PARAMS(args) ()
36 # endif /* Not PARAMS. */
38 /* Return the index of the element of ARGLIST (NULL terminated) that
39 matches with ARG. If VALLIST is not NULL, then use it to resolve
40 false ambiguities (i.e., different matches of ARG but corresponding
41 to the same values in VALLIST). */
44 PARAMS ((const char *arg, const char *const *arglist,
45 const char *vallist, size_t valsize));
47 PARAMS ((const char *arg, const char *const *arglist,
48 const char *vallist, size_t valsize));
50 # define ARGMATCH(ARG,ARGLIST,VALLIST) \
51 argmatch (ARG, ARGLIST, (const char *) VALLIST, sizeof (*VALLIST))
53 # define ARGCASEMATCH(ARG,ARGLIST,VALLIST) \
54 argcasematch (ARG, ARGLIST, (const char *) VALLIST, sizeof (*VALLIST))
58 /* Report on stderr why argmatch failed. Report correct values. */
61 PARAMS ((const char *kind, const char *value, int problem));
63 /* Left for compatibility with the old name invalid_arg */
65 # define invalid_arg(KIND,VALUE,PROBLEM) \
66 argmatch_invalid (KIND, VALUE, PROBLEM)
70 /* Report on stderr the list of possible arguments. */
73 PARAMS ((const char *const *arglist,
74 const char *vallist, size_t valsize));
76 # define ARGMATCH_VALID(ARGLIST,VALLIST) \
77 valid_args (ARGLIST, (const char *) VALLIST, sizeof (*VALLIST))
80 /* Returns matches, or, upon error, report explanatory message and
83 int __xargmatch_internal
84 PARAMS ((const char *kind,
85 const char *arg, const char *const *arglist,
86 const char *vallist, size_t valsize,
89 # define XARGMATCH(KIND,ARG,ARGLIST,VALLIST) \
90 VALLIST [__xargmatch_internal (KIND, ARG, ARGLIST, \
91 (const char *) VALLIST, sizeof (*VALLIST), 1)]
93 # define XARGCASEMATCH(KIND,ARG,ARGLIST,VALLIST) \
94 VALLIST [__xargmatch_internal (KIND, ARG, ARGLIST, \
95 (const char *) VALLIST, sizeof (*VALLIST), 0)]
99 /* Convert a value into a corresponding argument. */
101 const char * argmatch_to_argument
102 PARAMS ((char * value, const char *const *arglist,
103 const char *vallist, size_t valsize));
105 # define ARGMATCH_TO_ARGUMENT(VALUE,ARGLIST,VALLIST) \
106 argmatch_to_argument ((char *) &VALUE, ARGLIST, \
107 (const char *) VALLIST, sizeof (*VALLIST))
109 #endif /* _ARGMATCH_H_ */