Polly 20.0.0git
arg.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 *
4 * Use of this software is governed by the MIT license
5 *
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8 */
9
10#ifndef ISL_ARG_H
11#define ISL_ARG_H
12
13#include <stddef.h>
14#include <stdlib.h>
15
16#if defined(__cplusplus)
17extern "C" {
18#endif
19
21 const char *name;
22 unsigned value;
23};
24
26 const char *name;
27 unsigned mask;
28 unsigned value;
29};
30
47};
48
49struct isl_args;
50
51struct isl_arg {
54 const char *long_name;
55 const char *argument_name;
56#define ISL_ARG_OFFSET_NONE ((size_t) -1)
57 size_t offset;
58 const char *help_msg;
59#define ISL_ARG_SINGLE_DASH (1 << 0)
60#define ISL_ARG_BOOL_ARG (1 << 1)
61#define ISL_ARG_HIDDEN (1 << 2)
62 unsigned flags;
63 union {
64 struct {
66 unsigned default_value;
68 int (*set)(void *opt, unsigned val);
70 struct {
72 unsigned default_value;
74 struct {
75 unsigned default_value;
76 int (*set)(void *opt, unsigned val);
77 } b;
78 struct {
80 } i;
81 struct {
84 int (*set)(void *opt, long val);
85 } l;
86 struct {
87 unsigned long default_value;
88 } ul;
89 struct {
90 const char *default_value;
91 } str;
92 struct {
93 size_t offset_n;
95 struct {
96 struct isl_args *child;
98 struct {
99 void (*print_version)(void);
101 struct {
102 int (*init)(void*);
103 void (*clear)(void*);
105 } u;
106};
107
108struct isl_args {
110 struct isl_arg *args;
111};
112
113#define ISL_ARGS_START(s,name) \
114 struct isl_arg name ## LIST[]; \
115 struct isl_args name = { sizeof(s), name ## LIST }; \
116 struct isl_arg name ## LIST[] = {
117#define ISL_ARGS_END \
118 { isl_arg_end } };
119
120#define ISL_ARG_ALIAS(l) { \
121 .type = isl_arg_alias, \
122 .long_name = l, \
123},
124#define ISL_ARG_ARG(st,f,a,d) { \
125 .type = isl_arg_arg, \
126 .argument_name = a, \
127 .offset = offsetof(st, f), \
128 .u = { .str = { .default_value = d } } \
129},
130#define ISL_ARG_FOOTER(h) { \
131 .type = isl_arg_footer, \
132 .help_msg = h, \
133},
134#define ISL_ARG_CHOICE(st,f,s,l,c,d,h) { \
135 .type = isl_arg_choice, \
136 .short_name = s, \
137 .long_name = l, \
138 .offset = offsetof(st, f), \
139 .help_msg = h, \
140 .u = { .choice = { .choice = c, .default_value = d, \
141 .default_selected = d, .set = NULL } } \
142},
143#define ISL_ARG_OPT_CHOICE(st,f,s,l,c,d,ds,h) { \
144 .type = isl_arg_choice, \
145 .short_name = s, \
146 .long_name = l, \
147 .offset = offsetof(st, f), \
148 .help_msg = h, \
149 .u = { .choice = { .choice = c, .default_value = d, \
150 .default_selected = ds, .set = NULL } } \
151},
152#define ISL_ARG_PHANTOM_USER_CHOICE_F(s,l,c,setter,d,h,fl) { \
153 .type = isl_arg_choice, \
154 .short_name = s, \
155 .long_name = l, \
156 .offset = ISL_ARG_OFFSET_NONE, \
157 .help_msg = h, \
158 .flags = fl, \
159 .u = { .choice = { .choice = c, .default_value = d, \
160 .default_selected = d, .set = setter } } \
161},
162#define ISL_ARG_USER_OPT_CHOICE(st,f,s,l,c,setter,d,ds,h) { \
163 .type = isl_arg_choice, \
164 .short_name = s, \
165 .long_name = l, \
166 .offset = offsetof(st, f), \
167 .help_msg = h, \
168 .u = { .choice = { .choice = c, .default_value = d, \
169 .default_selected = ds, .set = setter } } \
170},
171#define _ISL_ARG_BOOL_F(o,s,l,setter,d,h,fl) { \
172 .type = isl_arg_bool, \
173 .short_name = s, \
174 .long_name = l, \
175 .offset = o, \
176 .help_msg = h, \
177 .flags = fl, \
178 .u = { .b = { .default_value = d, .set = setter } } \
179},
180#define ISL_ARG_BOOL_F(st,f,s,l,d,h,fl) \
181 _ISL_ARG_BOOL_F(offsetof(st, f),s,l,NULL,d,h,fl)
182#define ISL_ARG_BOOL(st,f,s,l,d,h) \
183 ISL_ARG_BOOL_F(st,f,s,l,d,h,0)
184#define ISL_ARG_PHANTOM_BOOL_F(s,l,setter,h,fl) \
185 _ISL_ARG_BOOL_F(ISL_ARG_OFFSET_NONE,s,l,setter,0,h,fl)
186#define ISL_ARG_PHANTOM_BOOL(s,l,setter,h) \
187 ISL_ARG_PHANTOM_BOOL_F(s,l,setter,h,0)
188#define ISL_ARG_INT_F(st,f,s,l,a,d,h,fl) { \
189 .type = isl_arg_int, \
190 .short_name = s, \
191 .long_name = l, \
192 .argument_name = a, \
193 .offset = offsetof(st, f), \
194 .help_msg = h, \
195 .flags = fl, \
196 .u = { .i = { .default_value = d } } \
197},
198#define ISL_ARG_INT(st,f,s,l,a,d,h) \
199 ISL_ARG_INT_F(st,f,s,l,a,d,h,0)
200#define ISL_ARG_LONG(st,f,s,lo,d,h) { \
201 .type = isl_arg_long, \
202 .short_name = s, \
203 .long_name = lo, \
204 .offset = offsetof(st, f), \
205 .help_msg = h, \
206 .u = { .l = { .default_value = d, .default_selected = d, \
207 .set = NULL } } \
208},
209#define ISL_ARG_USER_LONG(st,f,s,lo,setter,d,h) { \
210 .type = isl_arg_long, \
211 .short_name = s, \
212 .long_name = lo, \
213 .offset = offsetof(st, f), \
214 .help_msg = h, \
215 .u = { .l = { .default_value = d, .default_selected = d, \
216 .set = setter } } \
217},
218#define ISL_ARG_OPT_LONG(st,f,s,lo,d,ds,h) { \
219 .type = isl_arg_long, \
220 .short_name = s, \
221 .long_name = lo, \
222 .offset = offsetof(st, f), \
223 .help_msg = h, \
224 .u = { .l = { .default_value = d, .default_selected = ds, \
225 .set = NULL } } \
226},
227#define ISL_ARG_ULONG(st,f,s,l,d,h) { \
228 .type = isl_arg_ulong, \
229 .short_name = s, \
230 .long_name = l, \
231 .offset = offsetof(st, f), \
232 .help_msg = h, \
233 .u = { .ul = { .default_value = d } } \
234},
235#define ISL_ARG_STR_F(st,f,s,l,a,d,h,fl) { \
236 .type = isl_arg_str, \
237 .short_name = s, \
238 .long_name = l, \
239 .argument_name = a, \
240 .offset = offsetof(st, f), \
241 .help_msg = h, \
242 .flags = fl, \
243 .u = { .str = { .default_value = d } } \
244},
245#define ISL_ARG_STR(st,f,s,l,a,d,h) \
246 ISL_ARG_STR_F(st,f,s,l,a,d,h,0)
247#define ISL_ARG_STR_LIST(st,f_n,f_l,s,l,a,h) { \
248 .type = isl_arg_str_list, \
249 .short_name = s, \
250 .long_name = l, \
251 .argument_name = a, \
252 .offset = offsetof(st, f_l), \
253 .help_msg = h, \
254 .u = { .str_list = { .offset_n = offsetof(st, f_n) } } \
255},
256#define _ISL_ARG_CHILD(o,l,c,h,fl) { \
257 .type = isl_arg_child, \
258 .long_name = l, \
259 .offset = o, \
260 .help_msg = h, \
261 .flags = fl, \
262 .u = { .child = { .child = c } } \
263},
264#define ISL_ARG_CHILD(st,f,l,c,h) \
265 _ISL_ARG_CHILD(offsetof(st, f),l,c,h,0)
266#define ISL_ARG_GROUP_F(l,c,h,fl) \
267 _ISL_ARG_CHILD(ISL_ARG_OFFSET_NONE,l,c,h,fl)
268#define ISL_ARG_GROUP(l,c,h) \
269 ISL_ARG_GROUP_F(l,c,h,0)
270#define ISL_ARG_FLAGS(st,f,s,l,c,d,h) { \
271 .type = isl_arg_flags, \
272 .short_name = s, \
273 .long_name = l, \
274 .offset = offsetof(st, f), \
275 .help_msg = h, \
276 .u = { .flags = { .flags = c, .default_value = d } } \
277},
278#define ISL_ARG_USER(st,f,i,c) { \
279 .type = isl_arg_user, \
280 .offset = offsetof(st, f), \
281 .u = { .user = { .init = i, .clear = c} } \
282},
283#define ISL_ARG_VERSION(print) { \
284 .type = isl_arg_version, \
285 .u = { .version = { .print_version = print } } \
286},
287
288#define ISL_ARG_ALL (1 << 0)
289#define ISL_ARG_SKIP_HELP (1 << 1)
290
291void isl_args_set_defaults(struct isl_args *args, void *opt);
292void isl_args_free(struct isl_args *args, void *opt);
293int isl_args_parse(struct isl_args *args, int argc, char **argv, void *opt,
294 unsigned flags);
295
296#define ISL_ARG_DECL(prefix,st,args) \
297extern struct isl_args args; \
298st *prefix ## _new_with_defaults(void); \
299void prefix ## _free(st *opt); \
300int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags);
301
302#define ISL_ARG_DEF(prefix,st,args) \
303st *prefix ## _new_with_defaults() \
304{ \
305 st *opt = (st *)calloc(1, sizeof(st)); \
306 if (opt) \
307 isl_args_set_defaults(&(args), opt); \
308 return opt; \
309} \
310 \
311void prefix ## _free(st *opt) \
312{ \
313 isl_args_free(&(args), opt); \
314} \
315 \
316int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags) \
317{ \
318 return isl_args_parse(&(args), argc, argv, opt, flags); \
319}
320
321#if defined(__cplusplus)
322}
323#endif
324
325#endif
void isl_args_set_defaults(struct isl_args *args, void *opt)
Definition: isl_arg.c:91
void isl_args_free(struct isl_args *args, void *opt)
Definition: isl_arg.c:199
int isl_args_parse(struct isl_args *args, int argc, char **argv, void *opt, unsigned flags)
Definition: isl_arg.c:1256
isl_arg_type
Definition: arg.h:31
@ isl_arg_user
Definition: arg.h:41
@ isl_arg_bool
Definition: arg.h:35
@ isl_arg_child
Definition: arg.h:36
@ isl_arg_footer
Definition: arg.h:39
@ isl_arg_long
Definition: arg.h:42
@ isl_arg_version
Definition: arg.h:46
@ isl_arg_alias
Definition: arg.h:33
@ isl_arg_arg
Definition: arg.h:34
@ isl_arg_ulong
Definition: arg.h:43
@ isl_arg_str_list
Definition: arg.h:45
@ isl_arg_end
Definition: arg.h:32
@ isl_arg_str
Definition: arg.h:44
@ isl_arg_int
Definition: arg.h:40
__isl_export __isl_give ISL_HMAP __isl_take ISL_KEY __isl_take ISL_VAL * val
Definition: hmap.h:32
static void print_version(void)
Definition: isl_options.c:105
const char * set
Definition: isl_test.c:1356
const char * name
Definition: arg.h:21
unsigned value
Definition: arg.h:22
unsigned value
Definition: arg.h:28
const char * name
Definition: arg.h:26
unsigned mask
Definition: arg.h:27
Definition: arg.h:51
struct isl_arg::@0::@4 i
const char * default_value
Definition: arg.h:90
int(* set)(void *opt, unsigned val)
Definition: arg.h:68
int(* init)(void *)
Definition: arg.h:102
unsigned default_selected
Definition: arg.h:67
struct isl_arg::@0::@6 ul
long default_value
Definition: arg.h:82
size_t offset
Definition: arg.h:57
struct isl_arg::@0::@7 str
unsigned default_value
Definition: arg.h:66
const char * argument_name
Definition: arg.h:55
enum isl_arg_type type
Definition: arg.h:52
union isl_arg::@0 u
const char * long_name
Definition: arg.h:54
unsigned long default_value
Definition: arg.h:87
char short_name
Definition: arg.h:53
size_t offset_n
Definition: arg.h:93
int default_value
Definition: arg.h:79
struct isl_arg::@0::@11 user
struct isl_arg::@0::@3 b
struct isl_arg_choice * choice
Definition: arg.h:65
unsigned flags
Definition: arg.h:62
struct isl_arg::@0::@10 version
struct isl_arg_flags * flags
Definition: arg.h:71
void(* clear)(void *)
Definition: arg.h:103
struct isl_args * child
Definition: arg.h:96
long default_selected
Definition: arg.h:83
struct isl_arg::@0::@5 l
const char * help_msg
Definition: arg.h:58
struct isl_arg::@0::@8 str_list
Definition: arg.h:108
struct isl_arg * args
Definition: arg.h:110
size_t options_size
Definition: arg.h:109