annotate lib/argmatch.h @ 9364:559ef0e161fe

New module: xprintf * modules/xprintf, lib/xprintf.c, lib/xprintf.h: New files.
author Jim Meyering <meyering@redhat.com>
date Fri, 19 Oct 2007 17:09:37 +0200
parents bbbbbf4cd1c5
children e8d2c6fc33ad
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
6275
fd0ccce602e4 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
3 Copyright (C) 1990, 1998, 1999, 2001, 2002, 2004, 2005 Free Software
4934
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
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 6275
diff changeset
6 This program is free software: you can redistribute it and/or modify
1587
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
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 6275
diff changeset
8 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 6275
diff changeset
9 (at your option) any later version.
1587
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
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 6275
diff changeset
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
18
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
19 /* Written by David MacKenzie <djm@ai.mit.edu>
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
20 Modified by Akim Demaille <demaille@inf.enst.fr> */
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
21
1602
ef61182520b2 remove leading _ from _ARGMATCH_H_
Jim Meyering <jim@meyering.net>
parents: 1592
diff changeset
22 #ifndef ARGMATCH_H_
ef61182520b2 remove leading _ from _ARGMATCH_H_
Jim Meyering <jim@meyering.net>
parents: 1592
diff changeset
23 # define ARGMATCH_H_ 1
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
24
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
25 # include <stddef.h>
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
26
6275
fd0ccce602e4 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
27 # include "verify.h"
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
28
6275
fd0ccce602e4 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
29 # define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
30
1669
cfd4c2c2d1fe (ARRAY_CARDINALITY): Define.
Jim Meyering <jim@meyering.net>
parents: 1666
diff changeset
31 /* Assert there are as many real arguments as there are values
6275
fd0ccce602e4 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
32 (argument list ends with a NULL guard). */
1669
cfd4c2c2d1fe (ARRAY_CARDINALITY): Define.
Jim Meyering <jim@meyering.net>
parents: 1666
diff changeset
33
6275
fd0ccce602e4 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
34 # define ARGMATCH_VERIFY(Arglist, Vallist) \
fd0ccce602e4 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 5848
diff changeset
35 verify (ARRAY_CARDINALITY (Arglist) == ARRAY_CARDINALITY (Vallist) + 1)
1669
cfd4c2c2d1fe (ARRAY_CARDINALITY): Define.
Jim Meyering <jim@meyering.net>
parents: 1666
diff changeset
36
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
37 /* 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
38 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
39 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
40 to the same values in VALLIST). */
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
41
5154
2fc698626922 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4934
diff changeset
42 ptrdiff_t argmatch (char const *arg, char const *const *arglist,
2fc698626922 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4934
diff changeset
43 char const *vallist, size_t valsize);
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
44
1592
6ba864382953 fix typo
Jim Meyering <jim@meyering.net>
parents: 1591
diff changeset
45 # 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
46 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
47
1666
d055f19f4195 tweak comment
Jim Meyering <jim@meyering.net>
parents: 1665
diff changeset
48 /* xargmatch calls this function when it fails. This function should not
d055f19f4195 tweak comment
Jim Meyering <jim@meyering.net>
parents: 1665
diff changeset
49 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
50 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
51 typedef void (*argmatch_exit_fn) (void);
1647
af020f6709a9 s/argmatch_exit_failure/argmatch_die/
Jim Meyering <jim@meyering.net>
parents: 1645
diff changeset
52 extern argmatch_exit_fn argmatch_die;
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
53
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
54 /* 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
55
5154
2fc698626922 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4934
diff changeset
56 void argmatch_invalid (char const *context, char const *value,
2fc698626922 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4934
diff changeset
57 ptrdiff_t problem);
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
58
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
59 /* 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
60
1645
cb8655b1684e (XARGMATCH): Define to return a value once again.
Jim Meyering <jim@meyering.net>
parents: 1612
diff changeset
61 # 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
62 argmatch_invalid (Context, Value, Problem)
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
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
65
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
66 /* Report on stderr the list of possible arguments. */
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
67
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
68 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
69 char const *vallist, size_t valsize);
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
70
1591
fccafdb9ccd1 white space changes
Jim Meyering <jim@meyering.net>
parents: 1588
diff changeset
71 # 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
72 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
73
1587
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
1645
cb8655b1684e (XARGMATCH): Define to return a value once again.
Jim Meyering <jim@meyering.net>
parents: 1612
diff changeset
76 /* 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
77 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
78
5154
2fc698626922 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4934
diff changeset
79 ptrdiff_t __xargmatch_internal (char const *context,
2fc698626922 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4934
diff changeset
80 char const *arg, char const *const *arglist,
2fc698626922 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4934
diff changeset
81 char const *vallist, size_t valsize,
2fc698626922 Merge from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4934
diff changeset
82 argmatch_exit_fn exit_fn);
1645
cb8655b1684e (XARGMATCH): Define to return a value once again.
Jim Meyering <jim@meyering.net>
parents: 1612
diff changeset
83
cb8655b1684e (XARGMATCH): Define to return a value once again.
Jim Meyering <jim@meyering.net>
parents: 1612
diff changeset
84 /* Programmer friendly interface to __xargmatch_internal. */
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
85
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
86 # 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
87 ((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
88 (char const *) (Vallist), \
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
89 sizeof *(Vallist), \
4001
53129a4ff530 Remove case insensitive option matching.
Bruno Haible <bruno@clisp.org>
parents: 3999
diff changeset
90 argmatch_die)])
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
91
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
92 /* Convert a value into a corresponding argument. */
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
93
3981
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
94 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
95 char const *const *arglist,
ec69b8096cf8 Do not include <config.h> or <sys/types.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents: 3590
diff changeset
96 char const *vallist, size_t valsize);
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
97
1612
c538e58c8007 (XARGMATCH): Don't return a value; instead, modify a parameter.
Jim Meyering <jim@meyering.net>
parents: 1602
diff changeset
98 # 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
99 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
100 (char const *) (Vallist), sizeof *(Vallist))
1587
3f067a341196 lots of changes from Akim Demaille.
Jim Meyering <jim@meyering.net>
parents: 925
diff changeset
101
1602
ef61182520b2 remove leading _ from _ARGMATCH_H_
Jim Meyering <jim@meyering.net>
parents: 1592
diff changeset
102 #endif /* ARGMATCH_H_ */