annotate lib/argmatch.h @ 5848:a48fb0e98c8c

*** empty log message ***
author Paul Eggert <eggert@cs.ucla.edu>
date Sat, 14 May 2005 06:03:57 +0000
parents 2fc698626922
children fd0ccce602e4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1588
a6a81f3170d0 remove trailing blanks
Jim Meyering <jim@meyering.net>
parents: 1587
diff changeset
1 /* argmatch.h -- definitions and prototypes for argmatch.c
4934
0ffd1692e066 Exit-status fixes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4001
diff changeset
2
0ffd1692e066 Exit-status fixes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4001
diff changeset
3 Copyright (C) 1990, 1998, 1999, 2001, 2002, 2004 Free Software
0ffd1692e066 Exit-status fixes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4001
diff changeset
4 Foundation, Inc.
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
5
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
6 This program is free software; you can redistribute it and/or modify
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
7 it under the terms of the GNU General Public License as published by
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
9 any later version.
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
10
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
11 This program is distributed in the hope that it will be useful,
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
14 GNU General Public License for more details.
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
15
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
16 You should have received a copy of the GNU General Public License
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
17 along with this program; if not, write to the Free Software Foundation,
5848
a48fb0e98c8c *** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents: 5154
diff changeset
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
19
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
20 /* Written by David MacKenzie <djm@ai.mit.edu>
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
21 Modified by Akim Demaille <demaille@inf.enst.fr> */
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
22
1602
ef61182520b2 remove leading _ from _ARGMATCH_H_
Jim Meyering <jim@meyering.net>
parents: 1592
diff changeset
23 #ifndef ARGMATCH_H_
ef61182520b2 remove leading _ from _ARGMATCH_H_
Jim Meyering <jim@meyering.net>
parents: 1592
diff changeset
24 # define ARGMATCH_H_ 1
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
25
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
26 # include <stddef.h>
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
27
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
28 # define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
29
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
30 # define ARGMATCH_CONSTRAINT(Arglist, Vallist) \
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
31 (ARRAY_CARDINALITY (Arglist) == ARRAY_CARDINALITY (Vallist) + 1)
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
32
1669
cfd4c2c2d1fe (ARRAY_CARDINALITY): Define.
Jim Meyering <jim@meyering.net>
parents: 1666
diff changeset
33 /* Assert there are as many real arguments as there are values
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
34 (argument list ends with a NULL guard). ARGMATCH_VERIFY is
3999
1ad61bc49b25 Comment tweak.
Bruno Haible <bruno@clisp.org>
parents: 3981
diff changeset
35 preferred, since it is guaranteed to be checked at compile-time.
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
36 ARGMATCH_ASSERT is for backward compatibility only. */
1669
cfd4c2c2d1fe (ARRAY_CARDINALITY): Define.
Jim Meyering <jim@meyering.net>
parents: 1666
diff changeset
37
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
38 # define ARGMATCH_VERIFY(Arglist, Vallist) \
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
39 struct argmatch_verify \
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
40 { \
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
41 char argmatch_verify[ARGMATCH_CONSTRAINT(Arglist, Vallist) ? 1 : -1]; \
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
42 }
1669
cfd4c2c2d1fe (ARRAY_CARDINALITY): Define.
Jim Meyering <jim@meyering.net>
parents: 1666
diff changeset
43
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
44 # define ARGMATCH_ASSERT(Arglist, Vallist) \
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
45 assert (ARGMATCH_CONSTRAINT (Arglist, Vallist))
1669
cfd4c2c2d1fe (ARRAY_CARDINALITY): Define.
Jim Meyering <jim@meyering.net>
parents: 1666
diff changeset
46
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
47 /* Return the index of the element of ARGLIST (NULL terminated) that
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
48 matches with ARG. If VALLIST is not NULL, then use it to resolve
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
49 false ambiguities (i.e., different matches of ARG but corresponding
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
50 to the same values in VALLIST). */
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
51
5154
2fc698626922 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4934
diff changeset
52 ptrdiff_t argmatch (char const *arg, char const *const *arglist,
2fc698626922 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4934
diff changeset
53 char const *vallist, size_t valsize);
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
54
1592
6ba864382953 fix typo
Jim Meyering <jim@meyering.net>
parents: 1591
diff changeset
55 # define ARGMATCH(Arg, Arglist, Vallist) \
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
56 argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist))
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
57
1666
d055f19f4195 tweak comment
Jim Meyering <jim@meyering.net>
parents: 1665
diff changeset
58 /* xargmatch calls this function when it fails. This function should not
d055f19f4195 tweak comment
Jim Meyering <jim@meyering.net>
parents: 1665
diff changeset
59 return. By default, this is a function that calls ARGMATCH_DIE which
4934
0ffd1692e066 Exit-status fixes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4001
diff changeset
60 in turn defaults to `exit (exit_failure)'. */
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
61 typedef void (*argmatch_exit_fn) (void);
1647
af020f6709a9 s/argmatch_exit_failure/argmatch_die/
Jim Meyering <jim@meyering.net>
parents: 1645
diff changeset
62 extern argmatch_exit_fn argmatch_die;
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
63
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
64 /* Report on stderr why argmatch failed. Report correct values. */
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
65
5154
2fc698626922 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4934
diff changeset
66 void argmatch_invalid (char const *context, char const *value,
2fc698626922 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4934
diff changeset
67 ptrdiff_t problem);
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
68
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
69 /* Left for compatibility with the old name invalid_arg */
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
70
1645
cb8655b1684e (XARGMATCH): Define to return a value once again.
Jim Meyering <jim@meyering.net>
parents: 1612
diff changeset
71 # define invalid_arg(Context, Value, Problem) \
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
72 argmatch_invalid (Context, Value, Problem)
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
73
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
74
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
75
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
76 /* Report on stderr the list of possible arguments. */
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
77
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
78 void argmatch_valid (char const *const *arglist,
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
79 char const *vallist, size_t valsize);
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
80
1591
fccafdb9ccd1 white space changes
Jim Meyering <jim@meyering.net>
parents: 1588
diff changeset
81 # define ARGMATCH_VALID(Arglist, Vallist) \
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
82 argmatch_valid (Arglist, (char const *) (Vallist), sizeof *(Vallist))
1645
cb8655b1684e (XARGMATCH): Define to return a value once again.
Jim Meyering <jim@meyering.net>
parents: 1612
diff changeset
83
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
84
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
85
1645
cb8655b1684e (XARGMATCH): Define to return a value once again.
Jim Meyering <jim@meyering.net>
parents: 1612
diff changeset
86 /* Same as argmatch, but upon failure, reports a explanation on the
cb8655b1684e (XARGMATCH): Define to return a value once again.
Jim Meyering <jim@meyering.net>
parents: 1612
diff changeset
87 failure, and exits using the function EXIT_FN. */
cb8655b1684e (XARGMATCH): Define to return a value once again.
Jim Meyering <jim@meyering.net>
parents: 1612
diff changeset
88
5154
2fc698626922 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4934
diff changeset
89 ptrdiff_t __xargmatch_internal (char const *context,
2fc698626922 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4934
diff changeset
90 char const *arg, char const *const *arglist,
2fc698626922 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4934
diff changeset
91 char const *vallist, size_t valsize,
2fc698626922 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4934
diff changeset
92 argmatch_exit_fn exit_fn);
1645
cb8655b1684e (XARGMATCH): Define to return a value once again.
Jim Meyering <jim@meyering.net>
parents: 1612
diff changeset
93
cb8655b1684e (XARGMATCH): Define to return a value once again.
Jim Meyering <jim@meyering.net>
parents: 1612
diff changeset
94 /* Programmer friendly interface to __xargmatch_internal. */
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
95
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
96 # define XARGMATCH(Context, Arg, Arglist, Vallist) \
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
97 ((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
98 (char const *) (Vallist), \
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
99 sizeof *(Vallist), \
4001
53129a4ff530 Remove case insensitive option matching.
Bruno Haible <bruno@clisp.org>
parents: 3999
diff changeset
100 argmatch_die)])
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
101
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
102 /* Convert a value into a corresponding argument. */
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
103
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
104 char const *argmatch_to_argument (char const *value,
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
105 char const *const *arglist,
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
106 char const *vallist, size_t valsize);
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
107
1612
c538e58c8007 (XARGMATCH): Don't return a value; instead, modify a parameter.
Jim Meyering <jim@meyering.net>
parents: 1602
diff changeset
108 # define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
109 argmatch_to_argument (Value, Arglist, \
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
110 (char const *) (Vallist), sizeof *(Vallist))
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
111
1602
ef61182520b2 remove leading _ from _ARGMATCH_H_
Jim Meyering <jim@meyering.net>
parents: 1592
diff changeset
112 #endif /* ARGMATCH_H_ */