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)
54 #define ISL_ARG_BOOL_ARG (1 << 1)
58 struct isl_arg_choice *choice;
59 unsigned default_value;
60 unsigned default_selected;
61 int (*set)(void *opt, unsigned val);
64 struct isl_arg_flags *flags;
65 unsigned default_value;
68 unsigned default_value;
69 int (*set)(void *opt, unsigned val);
73 long default_selected;
74 int (*set)(void *opt, long val);
77 unsigned long default_value;
80 const char *default_value;
83 struct isl_arg *child;
87 void (*print_version)(void);
96 #define ISL_ARG_ALIAS(l) { \
97 .type = isl_arg_alias, \
100 #define ISL_ARG_ARG(st,f,a,d) { \
101 .type = isl_arg_arg, \
102 .argument_name = a, \
103 .offset = offsetof(st, f), \
104 .u = { .str = { .default_value = d } } \
106 #define ISL_ARG_CHOICE(st,f,s,l,c,d,h) { \
107 .type = isl_arg_choice, \
110 .offset = offsetof(st, f), \
112 .u = { .choice = { .choice = c, .default_value = d, \
113 .default_selected = d, .set = NULL } } \
115 #define ISL_ARG_OPT_CHOICE(st,f,s,l,c,d,ds,h) { \
116 .type = isl_arg_choice, \
119 .offset = offsetof(st, f), \
121 .u = { .choice = { .choice = c, .default_value = d, \
122 .default_selected = ds, .set = NULL } } \
124 #define ISL_ARG_USER_OPT_CHOICE(st,f,s,l,c,setter,d,ds,h) { \
125 .type = isl_arg_choice, \
128 .offset = offsetof(st, f), \
130 .u = { .choice = { .choice = c, .default_value = d, \
131 .default_selected = ds, .set = setter } } \
133 #define _ISL_ARG_BOOL_F(o,s,l,setter,d,h,fl) { \
134 .type = isl_arg_bool, \
140 .u = { .b = { .default_value = d, .set = setter } } \
142 #define ISL_ARG_BOOL_F(st,f,s,l,d,h,fl) \
143 _ISL_ARG_BOOL_F(offsetof(st, f),s,l,NULL,d,h,fl)
144 #define ISL_ARG_BOOL(st,f,s,l,d,h) \
145 ISL_ARG_BOOL_F(st,f,s,l,d,h,0)
146 #define ISL_ARG_PHANTOM_BOOL_F(s,l,setter,h,fl) \
147 _ISL_ARG_BOOL_F(-1,s,l,setter,0,h,fl)
148 #define ISL_ARG_PHANTOM_BOOL(s,l,setter,h) \
149 ISL_ARG_PHANTOM_BOOL_F(s,l,setter,h,0)
150 #define ISL_ARG_LONG(st,f,s,lo,d,h) { \
151 .type = isl_arg_long, \
154 .offset = offsetof(st, f), \
156 .u = { .l = { .default_value = d, .default_selected = d, \
159 #define ISL_ARG_USER_LONG(st,f,s,lo,setter,d,h) { \
160 .type = isl_arg_long, \
163 .offset = offsetof(st, f), \
165 .u = { .l = { .default_value = d, .default_selected = d, \
168 #define ISL_ARG_OPT_LONG(st,f,s,lo,d,ds,h) { \
169 .type = isl_arg_long, \
172 .offset = offsetof(st, f), \
174 .u = { .l = { .default_value = d, .default_selected = ds, \
177 #define ISL_ARG_ULONG(st,f,s,l,d,h) { \
178 .type = isl_arg_ulong, \
181 .offset = offsetof(st, f), \
183 .u = { .ul = { .default_value = d } } \
185 #define ISL_ARG_STR(st,f,s,l,a,d,h) { \
186 .type = isl_arg_str, \
189 .argument_name = a, \
190 .offset = offsetof(st, f), \
192 .u = { .str = { .default_value = d } } \
194 #define ISL_ARG_CHILD(st,f,l,c,h) { \
195 .type = isl_arg_child, \
197 .offset = offsetof(st, f), \
199 .u = { .child = { .child = c, .size = sizeof(*((st *)NULL)->f) } }\
201 #define ISL_ARG_FLAGS(st,f,s,l,c,d,h) { \
202 .type = isl_arg_flags, \
205 .offset = offsetof(st, f), \
207 .u = { .flags = { .flags = c, .default_value = d } } \
209 #define ISL_ARG_USER(st,f,i,c) { \
210 .type = isl_arg_user, \
211 .offset = offsetof(st, f), \
212 .u = { .user = { .init = i, .clear = c} } \
214 #define ISL_ARG_VERSION(print) { \
215 .type = isl_arg_version, \
216 .u = { .version = { .print_version = print } } \
218 #define ISL_ARG_END { isl_arg_end }
220 #define ISL_ARG_ALL (1 << 0)
222 void isl_arg_set_defaults(struct isl_arg *arg, void *opt);
223 void isl_arg_free(struct isl_arg *arg, void *opt);
224 int isl_arg_parse(struct isl_arg *arg, int argc, char **argv, void *opt,
227 #define ISL_ARG_DECL(prefix,st,arg) \
228 extern struct isl_arg arg[]; \
229 st *prefix ## _new_with_defaults(); \
230 void prefix ## _free(st *opt); \
231 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags);
233 #define ISL_ARG_DEF(prefix,st,arg) \
234 st *prefix ## _new_with_defaults() \
236 st *opt = (st *)calloc(1, sizeof(st)); \
238 isl_arg_set_defaults(arg, opt); \
242 void prefix ## _free(st *opt) \
244 isl_arg_free(arg, opt); \
247 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags) \
249 return isl_arg_parse(arg, argc, argv, opt, flags); \
252 #if defined(__cplusplus)