1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23: #ifndef ARGMATCH_H_
24: # define ARGMATCH_H_ 1
25:
26: # include <stddef.h>
27:
28: # include "verify.h"
29:
30: # define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
31:
32:
33:
34:
35: # define ARGMATCH_VERIFY(Arglist, Vallist) \
36: verify (ARRAY_CARDINALITY (Arglist) == ARRAY_CARDINALITY (Vallist) + 1)
37:
38:
39:
40:
41:
42:
43: ptrdiff_t argmatch (char const *arg, char const *const *arglist,
44: char const *vallist, size_t valsize);
45:
46: # define ARGMATCH(Arg, Arglist, Vallist) \
47: argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist))
48:
49:
50:
51:
52: typedef void (*argmatch_exit_fn) (void);
53: extern argmatch_exit_fn argmatch_die;
54:
55:
56:
57: void argmatch_invalid (char const *context, char const *value,
58: ptrdiff_t problem);
59:
60:
61:
62: # define invalid_arg(Context, Value, Problem) \
63: argmatch_invalid (Context, Value, Problem)
64:
65:
66:
67:
68:
69: void argmatch_valid (char const *const *arglist,
70: char const *vallist, size_t valsize);
71:
72: # define ARGMATCH_VALID(Arglist, Vallist) \
73: argmatch_valid (Arglist, (char const *) (Vallist), sizeof *(Vallist))
74:
75:
76:
77:
78:
79:
80: ptrdiff_t __xargmatch_internal (char const *context,
81: char const *arg, char const *const *arglist,
82: char const *vallist, size_t valsize,
83: argmatch_exit_fn exit_fn);
84:
85:
86:
87: # define XARGMATCH(Context, Arg, Arglist, Vallist) \
88: ((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
89: (char const *) (Vallist), \
90: sizeof *(Vallist), \
91: argmatch_die)])
92:
93:
94:
95: char const *argmatch_to_argument (char const *value,
96: char const *const *arglist,
97: char const *vallist, size_t valsize);
98:
99: # define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \
100: argmatch_to_argument (Value, Arglist, \
101: (char const *) (Vallist), sizeof *(Vallist))
102:
103: #endif