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 {
51 enum isl_arg_type type;
53 const char *long_name;
54 const char *argument_name;
57 #define ISL_ARG_SINGLE_DASH (1 << 0)
58 #define ISL_ARG_BOOL_ARG (1 << 1)
59 #define ISL_ARG_HIDDEN (1 << 2)
63 struct isl_arg_choice *choice;
64 unsigned default_value;
65 unsigned default_selected;
66 int (*set)(void *opt, unsigned val);
69 struct isl_arg_flags *flags;
70 unsigned default_value;
73 unsigned default_value;
74 int (*set)(void *opt, unsigned val);
81 long default_selected;
82 int (*set)(void *opt, long val);
85 unsigned long default_value;
88 const char *default_value;
91 struct isl_args *child;
94 void (*print_version)(void);
105 struct isl_arg *args;
108 #define ISL_ARGS_START(s,name) \
109 struct isl_arg name ## LIST[]; \
110 struct isl_args name = { sizeof(s), name ## LIST }; \
111 struct isl_arg name ## LIST[] = {
112 #define ISL_ARGS_END \
115 #define ISL_ARG_ALIAS(l) { \
116 .type = isl_arg_alias, \
119 #define ISL_ARG_ARG(st,f,a,d) { \
120 .type = isl_arg_arg, \
121 .argument_name = a, \
122 .offset = offsetof(st, f), \
123 .u = { .str = { .default_value = d } } \
125 #define ISL_ARG_FOOTER(h) { \
126 .type = isl_arg_footer, \
129 #define ISL_ARG_CHOICE(st,f,s,l,c,d,h) { \
130 .type = isl_arg_choice, \
133 .offset = offsetof(st, f), \
135 .u = { .choice = { .choice = c, .default_value = d, \
136 .default_selected = d, .set = NULL } } \
138 #define ISL_ARG_OPT_CHOICE(st,f,s,l,c,d,ds,h) { \
139 .type = isl_arg_choice, \
142 .offset = offsetof(st, f), \
144 .u = { .choice = { .choice = c, .default_value = d, \
145 .default_selected = ds, .set = NULL } } \
147 #define ISL_ARG_USER_OPT_CHOICE(st,f,s,l,c,setter,d,ds,h) { \
148 .type = isl_arg_choice, \
151 .offset = offsetof(st, f), \
153 .u = { .choice = { .choice = c, .default_value = d, \
154 .default_selected = ds, .set = setter } } \
156 #define _ISL_ARG_BOOL_F(o,s,l,setter,d,h,fl) { \
157 .type = isl_arg_bool, \
163 .u = { .b = { .default_value = d, .set = setter } } \
165 #define ISL_ARG_BOOL_F(st,f,s,l,d,h,fl) \
166 _ISL_ARG_BOOL_F(offsetof(st, f),s,l,NULL,d,h,fl)
167 #define ISL_ARG_BOOL(st,f,s,l,d,h) \
168 ISL_ARG_BOOL_F(st,f,s,l,d,h,0)
169 #define ISL_ARG_PHANTOM_BOOL_F(s,l,setter,h,fl) \
170 _ISL_ARG_BOOL_F(-1,s,l,setter,0,h,fl)
171 #define ISL_ARG_PHANTOM_BOOL(s,l,setter,h) \
172 ISL_ARG_PHANTOM_BOOL_F(s,l,setter,h,0)
173 #define ISL_ARG_INT_F(st,f,s,l,a,d,h,fl) { \
174 .type = isl_arg_int, \
177 .argument_name = a, \
178 .offset = offsetof(st, f), \
181 .u = { .ul = { .default_value = d } } \
183 #define ISL_ARG_INT(st,f,s,l,a,d,h) \
184 ISL_ARG_INT_F(st,f,s,l,a,d,h,0)
185 #define ISL_ARG_LONG(st,f,s,lo,d,h) { \
186 .type = isl_arg_long, \
189 .offset = offsetof(st, f), \
191 .u = { .l = { .default_value = d, .default_selected = d, \
194 #define ISL_ARG_USER_LONG(st,f,s,lo,setter,d,h) { \
195 .type = isl_arg_long, \
198 .offset = offsetof(st, f), \
200 .u = { .l = { .default_value = d, .default_selected = d, \
203 #define ISL_ARG_OPT_LONG(st,f,s,lo,d,ds,h) { \
204 .type = isl_arg_long, \
207 .offset = offsetof(st, f), \
209 .u = { .l = { .default_value = d, .default_selected = ds, \
212 #define ISL_ARG_ULONG(st,f,s,l,d,h) { \
213 .type = isl_arg_ulong, \
216 .offset = offsetof(st, f), \
218 .u = { .ul = { .default_value = d } } \
220 #define ISL_ARG_STR_F(st,f,s,l,a,d,h,fl) { \
221 .type = isl_arg_str, \
224 .argument_name = a, \
225 .offset = offsetof(st, f), \
228 .u = { .str = { .default_value = d } } \
230 #define ISL_ARG_STR(st,f,s,l,a,d,h) \
231 ISL_ARG_STR_F(st,f,s,l,a,d,h,0)
232 #define _ISL_ARG_CHILD(o,l,c,h,fl) { \
233 .type = isl_arg_child, \
238 .u = { .child = { .child = c } } \
240 #define ISL_ARG_CHILD(st,f,l,c,h) \
241 _ISL_ARG_CHILD(offsetof(st, f),l,c,h,0)
242 #define ISL_ARG_GROUP_F(c,h,fl) \
243 _ISL_ARG_CHILD(-1,NULL,c,h,fl)
244 #define ISL_ARG_GROUP(c,h) \
245 ISL_ARG_GROUP_F(c,h,0)
246 #define ISL_ARG_FLAGS(st,f,s,l,c,d,h) { \
247 .type = isl_arg_flags, \
250 .offset = offsetof(st, f), \
252 .u = { .flags = { .flags = c, .default_value = d } } \
254 #define ISL_ARG_USER(st,f,i,c) { \
255 .type = isl_arg_user, \
256 .offset = offsetof(st, f), \
257 .u = { .user = { .init = i, .clear = c} } \
259 #define ISL_ARG_VERSION(print) { \
260 .type = isl_arg_version, \
261 .u = { .version = { .print_version = print } } \
264 #define ISL_ARG_ALL (1 << 0)
266 void isl_args_set_defaults(struct isl_args *args, void *opt);
267 void isl_args_free(struct isl_args *args, void *opt);
268 int isl_args_parse(struct isl_args *args, int argc, char **argv, void *opt,
271 #define ISL_ARG_DECL(prefix,st,args) \
272 extern struct isl_args args; \
273 st *prefix ## _new_with_defaults(void); \
274 void prefix ## _free(st *opt); \
275 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags);
277 #define ISL_ARG_DEF(prefix,st,args) \
278 st *prefix ## _new_with_defaults() \
280 st *opt = (st *)calloc(1, sizeof(st)); \
282 isl_args_set_defaults(&(args), opt); \
286 void prefix ## _free(st *opt) \
288 isl_args_free(&(args), opt); \
291 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags) \
293 return isl_args_parse(&(args), argc, argv, opt, flags); \
296 #if defined(__cplusplus)