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(st,f,s,l,a,d,h) { \
208 .type = isl_arg_str, \
211 .argument_name = a, \
212 .offset = offsetof(st, f), \
214 .u = { .str = { .default_value = d } } \
216 #define _ISL_ARG_CHILD(o,sz,l,c,h,fl) { \
217 .type = isl_arg_child, \
222 .u = { .child = { .child = c, .size = sz } } \
224 #define ISL_ARG_CHILD(st,f,l,c,h) \
225 _ISL_ARG_CHILD(offsetof(st, f),sizeof(*((st *)NULL)->f),l,c,h,0)
226 #define ISL_ARG_GROUP_F(c,h,fl) \
227 _ISL_ARG_CHILD(-1,0,NULL,c,h,fl)
228 #define ISL_ARG_GROUP(c,h) \
229 ISL_ARG_GROUP_F(c,h,0)
230 #define ISL_ARG_FLAGS(st,f,s,l,c,d,h) { \
231 .type = isl_arg_flags, \
234 .offset = offsetof(st, f), \
236 .u = { .flags = { .flags = c, .default_value = d } } \
238 #define ISL_ARG_USER(st,f,i,c) { \
239 .type = isl_arg_user, \
240 .offset = offsetof(st, f), \
241 .u = { .user = { .init = i, .clear = c} } \
243 #define ISL_ARG_VERSION(print) { \
244 .type = isl_arg_version, \
245 .u = { .version = { .print_version = print } } \
247 #define ISL_ARG_END { isl_arg_end }
249 #define ISL_ARG_ALL (1 << 0)
251 void isl_arg_set_defaults(struct isl_arg
*arg
, void *opt
);
252 void isl_arg_free(struct isl_arg
*arg
, void *opt
);
253 int isl_arg_parse(struct isl_arg
*arg
, int argc
, char **argv
, void *opt
,
256 #define ISL_ARG_DECL(prefix,st,arg) \
257 extern struct isl_arg arg[]; \
258 st *prefix ## _new_with_defaults(); \
259 void prefix ## _free(st *opt); \
260 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags);
262 #define ISL_ARG_DEF(prefix,st,arg) \
263 st *prefix ## _new_with_defaults() \
265 st *opt = (st *)calloc(1, sizeof(st)); \
267 isl_arg_set_defaults(arg, opt); \
271 void prefix ## _free(st *opt) \
273 isl_arg_free(arg, opt); \
276 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags) \
278 return isl_arg_parse(arg, argc, argv, opt, flags); \
281 #if defined(__cplusplus)