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 {
47 enum isl_arg_type type;
49 const char *long_name;
50 const char *argument_name;
53 #define ISL_ARG_SINGLE_DASH (1 << 0)
57 struct isl_arg_choice *choice;
58 unsigned default_value;
59 unsigned default_selected;
60 int (*set)(void *opt, unsigned val);
63 struct isl_arg_flags *flags;
64 unsigned default_value;
67 unsigned default_value;
68 int (*set)(void *opt, unsigned val);
72 long default_selected;
73 int (*set)(void *opt, long val);
76 unsigned long default_value;
79 const char *default_value;
82 struct isl_arg *child;
86 void (*print_version)(void);
95 #define ISL_ARG_ALIAS(l) { \
96 .type = isl_arg_alias, \
99 #define ISL_ARG_ARG(st,f,a,d) { \
100 .type = isl_arg_arg, \
101 .argument_name = a, \
102 .offset = offsetof(st, f), \
103 .u = { .str = { .default_value = d } } \
105 #define ISL_ARG_CHOICE(st,f,s,l,c,d,h) { \
106 .type = isl_arg_choice, \
109 .offset = offsetof(st, f), \
111 .u = { .choice = { .choice = c, .default_value = d, \
112 .default_selected = d, .set = NULL } } \
114 #define ISL_ARG_OPT_CHOICE(st,f,s,l,c,d,ds,h) { \
115 .type = isl_arg_choice, \
118 .offset = offsetof(st, f), \
120 .u = { .choice = { .choice = c, .default_value = d, \
121 .default_selected = ds, .set = NULL } } \
123 #define ISL_ARG_USER_OPT_CHOICE(st,f,s,l,c,setter,d,ds,h) { \
124 .type = isl_arg_choice, \
127 .offset = offsetof(st, f), \
129 .u = { .choice = { .choice = c, .default_value = d, \
130 .default_selected = ds, .set = setter } } \
132 #define _ISL_ARG_BOOL_F(o,s,l,setter,d,h,fl) { \
133 .type = isl_arg_bool, \
139 .u = { .b = { .default_value = d, .set = setter } } \
141 #define ISL_ARG_BOOL_F(st,f,s,l,d,h,fl) \
142 _ISL_ARG_BOOL_F(offsetof(st, f),s,l,NULL,d,h,fl)
143 #define ISL_ARG_BOOL(st,f,s,l,d,h) \
144 ISL_ARG_BOOL_F(st,f,s,l,d,h,0)
145 #define ISL_ARG_PHANTOM_BOOL_F(s,l,setter,h,fl) \
146 _ISL_ARG_BOOL_F(-1,s,l,setter,0,h,fl)
147 #define ISL_ARG_PHANTOM_BOOL(s,l,setter,h) \
148 ISL_ARG_PHANTOM_BOOL_F(s,l,setter,h,0)
149 #define ISL_ARG_LONG(st,f,s,lo,d,h) { \
150 .type = isl_arg_long, \
153 .offset = offsetof(st, f), \
155 .u = { .l = { .default_value = d, .default_selected = d, \
158 #define ISL_ARG_USER_LONG(st,f,s,lo,setter,d,h) { \
159 .type = isl_arg_long, \
162 .offset = offsetof(st, f), \
164 .u = { .l = { .default_value = d, .default_selected = d, \
167 #define ISL_ARG_OPT_LONG(st,f,s,lo,d,ds,h) { \
168 .type = isl_arg_long, \
171 .offset = offsetof(st, f), \
173 .u = { .l = { .default_value = d, .default_selected = ds, \
176 #define ISL_ARG_ULONG(st,f,s,l,d,h) { \
177 .type = isl_arg_ulong, \
180 .offset = offsetof(st, f), \
182 .u = { .ul = { .default_value = d } } \
184 #define ISL_ARG_STR(st,f,s,l,a,d,h) { \
185 .type = isl_arg_str, \
188 .argument_name = a, \
189 .offset = offsetof(st, f), \
191 .u = { .str = { .default_value = d } } \
193 #define ISL_ARG_CHILD(st,f,l,c,h) { \
194 .type = isl_arg_child, \
196 .offset = offsetof(st, f), \
198 .u = { .child = { .child = c, .size = sizeof(*((st *)NULL)->f) } }\
200 #define ISL_ARG_FLAGS(st,f,s,l,c,d,h) { \
201 .type = isl_arg_flags, \
204 .offset = offsetof(st, f), \
206 .u = { .flags = { .flags = c, .default_value = d } } \
208 #define ISL_ARG_USER(st,f,i,c) { \
209 .type = isl_arg_user, \
210 .offset = offsetof(st, f), \
211 .u = { .user = { .init = i, .clear = c} } \
213 #define ISL_ARG_VERSION(print) { \
214 .type = isl_arg_version, \
215 .u = { .version = { .print_version = print } } \
217 #define ISL_ARG_END { isl_arg_end }
219 #define ISL_ARG_ALL (1 << 0)
221 void isl_arg_set_defaults(struct isl_arg *arg, void *opt);
222 void isl_arg_free(struct isl_arg *arg, void *opt);
223 int isl_arg_parse(struct isl_arg *arg, int argc, char **argv, void *opt,
226 #define ISL_ARG_DECL(prefix,st,arg) \
227 extern struct isl_arg arg[]; \
228 st *prefix ## _new_with_defaults(); \
229 void prefix ## _free(st *opt); \
230 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags);
232 #define ISL_ARG_DEF(prefix,st,arg) \
233 st *prefix ## _new_with_defaults() \
235 st *opt = (st *)calloc(1, sizeof(st)); \
237 isl_arg_set_defaults(arg, opt); \
241 void prefix ## _free(st *opt) \
243 isl_arg_free(arg, opt); \
246 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags) \
248 return isl_arg_parse(arg, argc, argv, opt, flags); \
251 #if defined(__cplusplus)