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 {
46 enum isl_arg_type type;
48 const char *long_name;
49 const char *argument_name;
55 struct isl_arg_choice *choice;
56 unsigned default_value;
57 unsigned default_selected;
58 int (*set)(void *opt, unsigned val);
61 struct isl_arg_flags *flags;
62 unsigned default_value;
65 unsigned default_value;
66 int (*set)(void *opt, unsigned val);
70 long default_selected;
71 int (*set)(void *opt, long val);
74 unsigned long default_value;
77 const char *default_value;
80 struct isl_arg *child;
84 void (*print_version)(void);
93 #define ISL_ARG_ARG(st,f,a,d) { \
94 .type = isl_arg_arg, \
96 .offset = offsetof(st, f), \
97 .u = { .str = { .default_value = d } } \
99 #define ISL_ARG_CHOICE(st,f,s,l,c,d,h) { \
100 .type = isl_arg_choice, \
103 .offset = offsetof(st, f), \
105 .u = { .choice = { .choice = c, .default_value = d, \
106 .default_selected = d, .set = NULL } } \
108 #define ISL_ARG_OPT_CHOICE(st,f,s,l,c,d,ds,h) { \
109 .type = isl_arg_choice, \
112 .offset = offsetof(st, f), \
114 .u = { .choice = { .choice = c, .default_value = d, \
115 .default_selected = ds, .set = NULL } } \
117 #define ISL_ARG_USER_OPT_CHOICE(st,f,s,l,c,setter,d,ds,h) { \
118 .type = isl_arg_choice, \
121 .offset = offsetof(st, f), \
123 .u = { .choice = { .choice = c, .default_value = d, \
124 .default_selected = ds, .set = setter } } \
126 #define _ISL_ARG_BOOL_F(o,s,l,setter,d,h,fl) { \
127 .type = isl_arg_bool, \
133 .u = { .b = { .default_value = d, .set = setter } } \
135 #define ISL_ARG_BOOL_F(st,f,s,l,d,h,fl) \
136 _ISL_ARG_BOOL_F(offsetof(st, f),s,l,NULL,d,h,fl)
137 #define ISL_ARG_BOOL(st,f,s,l,d,h) \
138 ISL_ARG_BOOL_F(st,f,s,l,d,h,0)
139 #define ISL_ARG_PHANTOM_BOOL_F(s,l,setter,h,fl) \
140 _ISL_ARG_BOOL_F(-1,s,l,setter,0,h,fl)
141 #define ISL_ARG_PHANTOM_BOOL(s,l,setter,h) \
142 ISL_ARG_PHANTOM_BOOL_F(s,l,setter,h,0)
143 #define ISL_ARG_LONG(st,f,s,lo,d,h) { \
144 .type = isl_arg_long, \
147 .offset = offsetof(st, f), \
149 .u = { .l = { .default_value = d, .default_selected = d, \
152 #define ISL_ARG_USER_LONG(st,f,s,lo,setter,d,h) { \
153 .type = isl_arg_long, \
156 .offset = offsetof(st, f), \
158 .u = { .l = { .default_value = d, .default_selected = d, \
161 #define ISL_ARG_OPT_LONG(st,f,s,lo,d,ds,h) { \
162 .type = isl_arg_long, \
165 .offset = offsetof(st, f), \
167 .u = { .l = { .default_value = d, .default_selected = ds, \
170 #define ISL_ARG_ULONG(st,f,s,l,d,h) { \
171 .type = isl_arg_ulong, \
174 .offset = offsetof(st, f), \
176 .u = { .ul = { .default_value = d } } \
178 #define ISL_ARG_STR(st,f,s,l,a,d,h) { \
179 .type = isl_arg_str, \
182 .argument_name = a, \
183 .offset = offsetof(st, f), \
185 .u = { .str = { .default_value = d } } \
187 #define ISL_ARG_CHILD(st,f,l,c,h) { \
188 .type = isl_arg_child, \
190 .offset = offsetof(st, f), \
192 .u = { .child = { .child = c, .size = sizeof(*((st *)NULL)->f) } }\
194 #define ISL_ARG_FLAGS(st,f,s,l,c,d,h) { \
195 .type = isl_arg_flags, \
198 .offset = offsetof(st, f), \
200 .u = { .flags = { .flags = c, .default_value = d } } \
202 #define ISL_ARG_USER(st,f,i,c) { \
203 .type = isl_arg_user, \
204 .offset = offsetof(st, f), \
205 .u = { .user = { .init = i, .clear = c} } \
207 #define ISL_ARG_VERSION(print) { \
208 .type = isl_arg_version, \
209 .u = { .version = { .print_version = print } } \
211 #define ISL_ARG_END { isl_arg_end }
213 #define ISL_ARG_ALL (1 << 0)
215 void isl_arg_set_defaults(struct isl_arg *arg, void *opt);
216 void isl_arg_free(struct isl_arg *arg, void *opt);
217 int isl_arg_parse(struct isl_arg *arg, int argc, char **argv, void *opt,
220 #define ISL_ARG_DECL(prefix,st,arg) \
221 extern struct isl_arg arg[]; \
222 st *prefix ## _new_with_defaults(); \
223 void prefix ## _free(st *opt); \
224 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags);
226 #define ISL_ARG_DEF(prefix,st,arg) \
227 st *prefix ## _new_with_defaults() \
229 st *opt = (st *)calloc(1, sizeof(st)); \
231 isl_arg_set_defaults(arg, opt); \
235 void prefix ## _free(st *opt) \
237 isl_arg_free(arg, opt); \
240 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags) \
242 return isl_arg_parse(arg, argc, argv, opt, flags); \
245 #if defined(__cplusplus)