2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
16 #if defined(__cplusplus)
20 struct isl_arg_choice {
25 struct isl_arg_flags {
49 enum isl_arg_type type;
51 const char *long_name;
52 const char *argument_name;
55 #define ISL_ARG_SINGLE_DASH (1 << 0)
56 #define ISL_ARG_BOOL_ARG (1 << 1)
57 #define ISL_ARG_HIDDEN (1 << 2)
61 struct isl_arg_choice *choice;
62 unsigned default_value;
63 unsigned default_selected;
64 int (*set)(void *opt, unsigned val);
67 struct isl_arg_flags *flags;
68 unsigned default_value;
71 unsigned default_value;
72 int (*set)(void *opt, unsigned val);
79 long default_selected;
80 int (*set)(void *opt, long val);
83 unsigned long default_value;
86 const char *default_value;
89 struct isl_arg *child;
93 void (*print_version)(void);
102 #define ISL_ARG_ALIAS(l) { \
103 .type = isl_arg_alias, \
106 #define ISL_ARG_ARG(st,f,a,d) { \
107 .type = isl_arg_arg, \
108 .argument_name = a, \
109 .offset = offsetof(st, f), \
110 .u = { .str = { .default_value = d } } \
112 #define ISL_ARG_FOOTER(h) { \
113 .type = isl_arg_footer, \
116 #define ISL_ARG_CHOICE(st,f,s,l,c,d,h) { \
117 .type = isl_arg_choice, \
120 .offset = offsetof(st, f), \
122 .u = { .choice = { .choice = c, .default_value = d, \
123 .default_selected = d, .set = NULL } } \
125 #define ISL_ARG_OPT_CHOICE(st,f,s,l,c,d,ds,h) { \
126 .type = isl_arg_choice, \
129 .offset = offsetof(st, f), \
131 .u = { .choice = { .choice = c, .default_value = d, \
132 .default_selected = ds, .set = NULL } } \
134 #define ISL_ARG_USER_OPT_CHOICE(st,f,s,l,c,setter,d,ds,h) { \
135 .type = isl_arg_choice, \
138 .offset = offsetof(st, f), \
140 .u = { .choice = { .choice = c, .default_value = d, \
141 .default_selected = ds, .set = setter } } \
143 #define _ISL_ARG_BOOL_F(o,s,l,setter,d,h,fl) { \
144 .type = isl_arg_bool, \
150 .u = { .b = { .default_value = d, .set = setter } } \
152 #define ISL_ARG_BOOL_F(st,f,s,l,d,h,fl) \
153 _ISL_ARG_BOOL_F(offsetof(st, f),s,l,NULL,d,h,fl)
154 #define ISL_ARG_BOOL(st,f,s,l,d,h) \
155 ISL_ARG_BOOL_F(st,f,s,l,d,h,0)
156 #define ISL_ARG_PHANTOM_BOOL_F(s,l,setter,h,fl) \
157 _ISL_ARG_BOOL_F(-1,s,l,setter,0,h,fl)
158 #define ISL_ARG_PHANTOM_BOOL(s,l,setter,h) \
159 ISL_ARG_PHANTOM_BOOL_F(s,l,setter,h,0)
160 #define ISL_ARG_INT_F(st,f,s,l,a,d,h,fl) { \
161 .type = isl_arg_int, \
164 .argument_name = a, \
165 .offset = offsetof(st, f), \
168 .u = { .ul = { .default_value = d } } \
170 #define ISL_ARG_INT(st,f,s,l,a,d,h) \
171 ISL_ARG_INT_F(st,f,s,l,a,d,h,0)
172 #define ISL_ARG_LONG(st,f,s,lo,d,h) { \
173 .type = isl_arg_long, \
176 .offset = offsetof(st, f), \
178 .u = { .l = { .default_value = d, .default_selected = d, \
181 #define ISL_ARG_USER_LONG(st,f,s,lo,setter,d,h) { \
182 .type = isl_arg_long, \
185 .offset = offsetof(st, f), \
187 .u = { .l = { .default_value = d, .default_selected = d, \
190 #define ISL_ARG_OPT_LONG(st,f,s,lo,d,ds,h) { \
191 .type = isl_arg_long, \
194 .offset = offsetof(st, f), \
196 .u = { .l = { .default_value = d, .default_selected = ds, \
199 #define ISL_ARG_ULONG(st,f,s,l,d,h) { \
200 .type = isl_arg_ulong, \
203 .offset = offsetof(st, f), \
205 .u = { .ul = { .default_value = d } } \
207 #define ISL_ARG_STR_F(st,f,s,l,a,d,h,fl) { \
208 .type = isl_arg_str, \
211 .argument_name = a, \
212 .offset = offsetof(st, f), \
215 .u = { .str = { .default_value = d } } \
217 #define ISL_ARG_STR(st,f,s,l,a,d,h) \
218 ISL_ARG_STR_F(st,f,s,l,a,d,h,0)
219 #define _ISL_ARG_CHILD(o,sz,l,c,h,fl) { \
220 .type = isl_arg_child, \
225 .u = { .child = { .child = c, .size = sz } } \
227 #define ISL_ARG_CHILD(st,f,l,c,h) \
228 _ISL_ARG_CHILD(offsetof(st, f),sizeof(*((st *)NULL)->f),l,c,h,0)
229 #define ISL_ARG_GROUP_F(c,h,fl) \
230 _ISL_ARG_CHILD(-1,0,NULL,c,h,fl)
231 #define ISL_ARG_GROUP(c,h) \
232 ISL_ARG_GROUP_F(c,h,0)
233 #define ISL_ARG_FLAGS(st,f,s,l,c,d,h) { \
234 .type = isl_arg_flags, \
237 .offset = offsetof(st, f), \
239 .u = { .flags = { .flags = c, .default_value = d } } \
241 #define ISL_ARG_USER(st,f,i,c) { \
242 .type = isl_arg_user, \
243 .offset = offsetof(st, f), \
244 .u = { .user = { .init = i, .clear = c} } \
246 #define ISL_ARG_VERSION(print) { \
247 .type = isl_arg_version, \
248 .u = { .version = { .print_version = print } } \
250 #define ISL_ARG_END { isl_arg_end }
252 #define ISL_ARG_ALL (1 << 0)
254 void isl_arg_set_defaults(struct isl_arg *arg, void *opt);
255 void isl_arg_free(struct isl_arg *arg, void *opt);
256 int isl_arg_parse(struct isl_arg *arg, int argc, char **argv, void *opt,
259 #define ISL_ARG_DECL(prefix,st,arg) \
260 extern struct isl_arg arg[]; \
261 st *prefix ## _new_with_defaults(); \
262 void prefix ## _free(st *opt); \
263 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags);
265 #define ISL_ARG_DEF(prefix,st,arg) \
266 st *prefix ## _new_with_defaults() \
268 st *opt = (st *)calloc(1, sizeof(st)); \
270 isl_arg_set_defaults(arg, opt); \
274 void prefix ## _free(st *opt) \
276 isl_arg_free(arg, opt); \
279 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags) \
281 return isl_arg_parse(arg, argc, argv, opt, flags); \
284 #if defined(__cplusplus)