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
;
54 struct isl_arg_choice
*choice
;
55 unsigned default_value
;
56 unsigned default_selected
;
59 struct isl_arg_flags
*flags
;
60 unsigned default_value
;
63 unsigned default_value
;
67 long default_selected
;
68 int (*set
)(void *opt
, long val
);
71 unsigned long default_value
;
74 const char *default_value
;
77 struct isl_arg
*child
;
81 void (*print_version
)(void);
90 #define ISL_ARG_ARG(st,f,a,d) { \
91 .type = isl_arg_arg, \
93 .offset = offsetof(st, f), \
94 .u = { .str = { .default_value = d } } \
96 #define ISL_ARG_CHOICE(st,f,s,l,c,d,h) { \
97 .type = isl_arg_choice, \
100 .offset = offsetof(st, f), \
102 .u = { .choice = { .choice = c, .default_value = d, \
103 .default_selected = d } } \
105 #define ISL_ARG_OPT_CHOICE(st,f,s,l,c,d,ds,h) { \
106 .type = isl_arg_choice, \
109 .offset = offsetof(st, f), \
111 .u = { .choice = { .choice = c, .default_value = d, \
112 .default_selected = ds } } \
114 #define ISL_ARG_BOOL(st,f,s,l,d,h) { \
115 .type = isl_arg_bool, \
118 .offset = offsetof(st, f), \
120 .u = { .b = { .default_value = d } } \
122 #define ISL_ARG_LONG(st,f,s,lo,d,h) { \
123 .type = isl_arg_long, \
126 .offset = offsetof(st, f), \
128 .u = { .l = { .default_value = d, .default_selected = d, \
131 #define ISL_ARG_USER_LONG(st,f,s,lo,setter,d,h) { \
132 .type = isl_arg_long, \
135 .offset = offsetof(st, f), \
137 .u = { .l = { .default_value = d, .default_selected = d, \
140 #define ISL_ARG_OPT_LONG(st,f,s,lo,d,ds,h) { \
141 .type = isl_arg_long, \
144 .offset = offsetof(st, f), \
146 .u = { .l = { .default_value = d, .default_selected = ds, \
149 #define ISL_ARG_ULONG(st,f,s,l,d,h) { \
150 .type = isl_arg_ulong, \
153 .offset = offsetof(st, f), \
155 .u = { .ul = { .default_value = d } } \
157 #define ISL_ARG_STR(st,f,s,l,a,d,h) { \
158 .type = isl_arg_str, \
161 .argument_name = a, \
162 .offset = offsetof(st, f), \
164 .u = { .str = { .default_value = d } } \
166 #define ISL_ARG_CHILD(st,f,l,c,h) { \
167 .type = isl_arg_child, \
169 .offset = offsetof(st, f), \
171 .u = { .child = { .child = c, .size = sizeof(*((st *)NULL)->f) } }\
173 #define ISL_ARG_FLAGS(st,f,s,l,c,d,h) { \
174 .type = isl_arg_flags, \
177 .offset = offsetof(st, f), \
179 .u = { .flags = { .flags = c, .default_value = d } } \
181 #define ISL_ARG_USER(st,f,i,c) { \
182 .type = isl_arg_user, \
183 .offset = offsetof(st, f), \
184 .u = { .user = { .init = i, .clear = c} } \
186 #define ISL_ARG_VERSION(print) { \
187 .type = isl_arg_version, \
188 .u = { .version = { .print_version = print } } \
190 #define ISL_ARG_END { isl_arg_end }
192 #define ISL_ARG_ALL (1 << 0)
194 void isl_arg_set_defaults(struct isl_arg
*arg
, void *opt
);
195 void isl_arg_free(struct isl_arg
*arg
, void *opt
);
196 int isl_arg_parse(struct isl_arg
*arg
, int argc
, char **argv
, void *opt
,
199 #define ISL_ARG_DECL(prefix,st,arg) \
200 extern struct isl_arg arg[]; \
201 st *prefix ## _new_with_defaults(); \
202 void prefix ## _free(st *opt); \
203 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags);
205 #define ISL_ARG_DEF(prefix,st,arg) \
206 st *prefix ## _new_with_defaults() \
208 st *opt = (st *)calloc(1, sizeof(st)); \
210 isl_arg_set_defaults(arg, opt); \
214 void prefix ## _free(st *opt) \
216 isl_arg_free(arg, opt); \
219 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags) \
221 return isl_arg_parse(arg, argc, argv, opt, flags); \
224 #if defined(__cplusplus)