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 {
52 enum isl_arg_type type;
54 const char *long_name;
55 const char *argument_name;
58 #define ISL_ARG_SINGLE_DASH (1 << 0)
59 #define ISL_ARG_BOOL_ARG (1 << 1)
60 #define ISL_ARG_HIDDEN (1 << 2)
64 struct isl_arg_choice *choice;
65 unsigned default_value;
66 unsigned default_selected;
67 int (*set)(void *opt, unsigned val);
70 struct isl_arg_flags *flags;
71 unsigned default_value;
74 unsigned default_value;
75 int (*set)(void *opt, unsigned val);
82 long default_selected;
83 int (*set)(void *opt, long val);
86 unsigned long default_value;
89 const char *default_value;
95 struct isl_args *child;
98 void (*print_version)(void);
102 void (*clear)(void*);
109 struct isl_arg *args;
112 #define ISL_ARGS_START(s,name) \
113 struct isl_arg name ## LIST[]; \
114 struct isl_args name = { sizeof(s), name ## LIST }; \
115 struct isl_arg name ## LIST[] = {
116 #define ISL_ARGS_END \
119 #define ISL_ARG_ALIAS(l) { \
120 .type = isl_arg_alias, \
123 #define ISL_ARG_ARG(st,f,a,d) { \
124 .type = isl_arg_arg, \
125 .argument_name = a, \
126 .offset = offsetof(st, f), \
127 .u = { .str = { .default_value = d } } \
129 #define ISL_ARG_FOOTER(h) { \
130 .type = isl_arg_footer, \
133 #define ISL_ARG_CHOICE(st,f,s,l,c,d,h) { \
134 .type = isl_arg_choice, \
137 .offset = offsetof(st, f), \
139 .u = { .choice = { .choice = c, .default_value = d, \
140 .default_selected = d, .set = NULL } } \
142 #define ISL_ARG_OPT_CHOICE(st,f,s,l,c,d,ds,h) { \
143 .type = isl_arg_choice, \
146 .offset = offsetof(st, f), \
148 .u = { .choice = { .choice = c, .default_value = d, \
149 .default_selected = ds, .set = NULL } } \
151 #define ISL_ARG_USER_OPT_CHOICE(st,f,s,l,c,setter,d,ds,h) { \
152 .type = isl_arg_choice, \
155 .offset = offsetof(st, f), \
157 .u = { .choice = { .choice = c, .default_value = d, \
158 .default_selected = ds, .set = setter } } \
160 #define _ISL_ARG_BOOL_F(o,s,l,setter,d,h,fl) { \
161 .type = isl_arg_bool, \
167 .u = { .b = { .default_value = d, .set = setter } } \
169 #define ISL_ARG_BOOL_F(st,f,s,l,d,h,fl) \
170 _ISL_ARG_BOOL_F(offsetof(st, f),s,l,NULL,d,h,fl)
171 #define ISL_ARG_BOOL(st,f,s,l,d,h) \
172 ISL_ARG_BOOL_F(st,f,s,l,d,h,0)
173 #define ISL_ARG_PHANTOM_BOOL_F(s,l,setter,h,fl) \
174 _ISL_ARG_BOOL_F(-1,s,l,setter,0,h,fl)
175 #define ISL_ARG_PHANTOM_BOOL(s,l,setter,h) \
176 ISL_ARG_PHANTOM_BOOL_F(s,l,setter,h,0)
177 #define ISL_ARG_INT_F(st,f,s,l,a,d,h,fl) { \
178 .type = isl_arg_int, \
181 .argument_name = a, \
182 .offset = offsetof(st, f), \
185 .u = { .ul = { .default_value = d } } \
187 #define ISL_ARG_INT(st,f,s,l,a,d,h) \
188 ISL_ARG_INT_F(st,f,s,l,a,d,h,0)
189 #define ISL_ARG_LONG(st,f,s,lo,d,h) { \
190 .type = isl_arg_long, \
193 .offset = offsetof(st, f), \
195 .u = { .l = { .default_value = d, .default_selected = d, \
198 #define ISL_ARG_USER_LONG(st,f,s,lo,setter,d,h) { \
199 .type = isl_arg_long, \
202 .offset = offsetof(st, f), \
204 .u = { .l = { .default_value = d, .default_selected = d, \
207 #define ISL_ARG_OPT_LONG(st,f,s,lo,d,ds,h) { \
208 .type = isl_arg_long, \
211 .offset = offsetof(st, f), \
213 .u = { .l = { .default_value = d, .default_selected = ds, \
216 #define ISL_ARG_ULONG(st,f,s,l,d,h) { \
217 .type = isl_arg_ulong, \
220 .offset = offsetof(st, f), \
222 .u = { .ul = { .default_value = d } } \
224 #define ISL_ARG_STR_F(st,f,s,l,a,d,h,fl) { \
225 .type = isl_arg_str, \
228 .argument_name = a, \
229 .offset = offsetof(st, f), \
232 .u = { .str = { .default_value = d } } \
234 #define ISL_ARG_STR(st,f,s,l,a,d,h) \
235 ISL_ARG_STR_F(st,f,s,l,a,d,h,0)
236 #define ISL_ARG_STR_LIST(st,f_n,f_l,s,l,a,h) { \
237 .type = isl_arg_str_list, \
240 .argument_name = a, \
241 .offset = offsetof(st, f_l), \
243 .u = { .str_list = { .offset_n = offsetof(st, f_n) } } \
245 #define _ISL_ARG_CHILD(o,l,c,h,fl) { \
246 .type = isl_arg_child, \
251 .u = { .child = { .child = c } } \
253 #define ISL_ARG_CHILD(st,f,l,c,h) \
254 _ISL_ARG_CHILD(offsetof(st, f),l,c,h,0)
255 #define ISL_ARG_GROUP_F(c,h,fl) \
256 _ISL_ARG_CHILD(-1,NULL,c,h,fl)
257 #define ISL_ARG_GROUP(c,h) \
258 ISL_ARG_GROUP_F(c,h,0)
259 #define ISL_ARG_FLAGS(st,f,s,l,c,d,h) { \
260 .type = isl_arg_flags, \
263 .offset = offsetof(st, f), \
265 .u = { .flags = { .flags = c, .default_value = d } } \
267 #define ISL_ARG_USER(st,f,i,c) { \
268 .type = isl_arg_user, \
269 .offset = offsetof(st, f), \
270 .u = { .user = { .init = i, .clear = c} } \
272 #define ISL_ARG_VERSION(print) { \
273 .type = isl_arg_version, \
274 .u = { .version = { .print_version = print } } \
277 #define ISL_ARG_ALL (1 << 0)
279 void isl_args_set_defaults(struct isl_args *args, void *opt);
280 void isl_args_free(struct isl_args *args, void *opt);
281 int isl_args_parse(struct isl_args *args, int argc, char **argv, void *opt,
284 #define ISL_ARG_DECL(prefix,st,args) \
285 extern struct isl_args args; \
286 st *prefix ## _new_with_defaults(void); \
287 void prefix ## _free(st *opt); \
288 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags);
290 #define ISL_ARG_DEF(prefix,st,args) \
291 st *prefix ## _new_with_defaults() \
293 st *opt = (st *)calloc(1, sizeof(st)); \
295 isl_args_set_defaults(&(args), opt); \
299 void prefix ## _free(st *opt) \
301 isl_args_free(&(args), opt); \
304 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags) \
306 return isl_args_parse(&(args), argc, argv, opt, flags); \
309 #if defined(__cplusplus)