isl_basic_map_free: return NULL
[platform/upstream/isl.git] / include / isl / arg.h
index d34a111..07ee44c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2008-2009 Katholieke Universiteit Leuven
  *
- * Use of this software is governed by the GNU LGPLv2.1 license
+ * Use of this software is governed by the MIT license
  *
  * Written by Sven Verdoolaege, K.U.Leuven, Departement
  * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
@@ -36,14 +36,18 @@ enum isl_arg_type {
        isl_arg_child,
        isl_arg_choice,
        isl_arg_flags,
+       isl_arg_footer,
        isl_arg_int,
        isl_arg_user,
        isl_arg_long,
        isl_arg_ulong,
        isl_arg_str,
+       isl_arg_str_list,
        isl_arg_version
 };
 
+struct isl_args;
+
 struct isl_arg {
        enum isl_arg_type        type;
        char                     short_name;
@@ -85,8 +89,10 @@ struct isl_arg {
                const char              *default_value;
        } str;
        struct {
-               struct isl_arg          *child;
-               size_t                   size;
+               size_t                   offset_n;
+       } str_list;
+       struct {
+               struct isl_args         *child;
        } child;
        struct {
                void (*print_version)(void);
@@ -98,6 +104,18 @@ struct isl_arg {
        } u;
 };
 
+struct isl_args {
+       size_t                   options_size;
+       struct isl_arg          *args;
+};
+
+#define ISL_ARGS_START(s,name)                                         \
+       struct isl_arg name ## LIST[];                                  \
+       struct isl_args name = { sizeof(s), name ## LIST };             \
+       struct isl_arg name ## LIST[] = {
+#define ISL_ARGS_END                                                   \
+       { isl_arg_end } };
+
 #define ISL_ARG_ALIAS(l)       {                                       \
        .type = isl_arg_alias,                                          \
        .long_name = l,                                                 \
@@ -108,6 +126,10 @@ struct isl_arg {
        .offset = offsetof(st, f),                                      \
        .u = { .str = { .default_value = d } }                          \
 },
+#define ISL_ARG_FOOTER(h)      {                                       \
+       .type = isl_arg_footer,                                         \
+       .help_msg = h,                                                  \
+},
 #define ISL_ARG_CHOICE(st,f,s,l,c,d,h) {                               \
        .type = isl_arg_choice,                                         \
        .short_name = s,                                                \
@@ -199,22 +221,41 @@ struct isl_arg {
        .help_msg = h,                                                  \
        .u = { .ul = { .default_value = d } }                           \
 },
-#define ISL_ARG_STR(st,f,s,l,a,d,h)    {                               \
+#define ISL_ARG_STR_F(st,f,s,l,a,d,h,fl)       {                       \
        .type = isl_arg_str,                                            \
        .short_name = s,                                                \
        .long_name = l,                                                 \
        .argument_name = a,                                             \
        .offset = offsetof(st, f),                                      \
        .help_msg = h,                                                  \
+       .flags = fl,                                                    \
        .u = { .str = { .default_value = d } }                          \
 },
-#define ISL_ARG_CHILD(st,f,l,c,h)      {                               \
+#define ISL_ARG_STR(st,f,s,l,a,d,h)                                    \
+       ISL_ARG_STR_F(st,f,s,l,a,d,h,0)
+#define ISL_ARG_STR_LIST(st,f_n,f_l,s,l,a,h)   {                       \
+       .type = isl_arg_str_list,                                       \
+       .short_name = s,                                                \
+       .long_name = l,                                                 \
+       .argument_name = a,                                             \
+       .offset = offsetof(st, f_l),                                    \
+       .help_msg = h,                                                  \
+       .u = { .str_list = { .offset_n = offsetof(st, f_n) } }          \
+},
+#define _ISL_ARG_CHILD(o,l,c,h,fl)     {                               \
        .type = isl_arg_child,                                          \
        .long_name = l,                                                 \
-       .offset = offsetof(st, f),                                      \
+       .offset = o,                                                    \
        .help_msg = h,                                                  \
-       .u = { .child = { .child = c, .size = sizeof(*((st *)NULL)->f) } }\
+       .flags = fl,                                                    \
+       .u = { .child = { .child = c } }                                \
 },
+#define ISL_ARG_CHILD(st,f,l,c,h)                                      \
+       _ISL_ARG_CHILD(offsetof(st, f),l,c,h,0)
+#define ISL_ARG_GROUP_F(c,h,fl)                                                \
+       _ISL_ARG_CHILD(-1,NULL,c,h,fl)
+#define ISL_ARG_GROUP(c,h)                                             \
+       ISL_ARG_GROUP_F(c,h,0)
 #define ISL_ARG_FLAGS(st,f,s,l,c,d,h)  {                               \
        .type = isl_arg_flags,                                          \
        .short_name = s,                                                \
@@ -232,38 +273,38 @@ struct isl_arg {
        .type = isl_arg_version,                                        \
        .u = { .version = { .print_version = print } }                  \
 },
-#define ISL_ARG_END    { isl_arg_end }
 
-#define ISL_ARG_ALL    (1 << 0)
+#define ISL_ARG_ALL            (1 << 0)
+#define ISL_ARG_SKIP_HELP      (1 << 1)
 
-void isl_arg_set_defaults(struct isl_arg *arg, void *opt);
-void isl_arg_free(struct isl_arg *arg, void *opt);
-int isl_arg_parse(struct isl_arg *arg, int argc, char **argv, void *opt,
+void isl_args_set_defaults(struct isl_args *args, void *opt);
+void isl_args_free(struct isl_args *args, void *opt);
+int isl_args_parse(struct isl_args *args, int argc, char **argv, void *opt,
        unsigned flags);
 
-#define ISL_ARG_DECL(prefix,st,arg                                   \
-extern struct isl_arg arg[];                                           \
-st *prefix ## _new_with_defaults();                                    \
+#define ISL_ARG_DECL(prefix,st,args)                                   \
+extern struct isl_args args;                                           \
+st *prefix ## _new_with_defaults(void);                                        \
 void prefix ## _free(st *opt);                                         \
 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags);
 
-#define ISL_ARG_DEF(prefix,st,arg                                    \
+#define ISL_ARG_DEF(prefix,st,args)                                    \
 st *prefix ## _new_with_defaults()                                     \
 {                                                                      \
        st *opt = (st *)calloc(1, sizeof(st));                          \
        if (opt)                                                        \
-               isl_arg_set_defaults(arg, opt);                         \
+               isl_args_set_defaults(&(args), opt);                    \
        return opt;                                                     \
 }                                                                      \
                                                                        \
 void prefix ## _free(st *opt)                                          \
 {                                                                      \
-       isl_arg_free(arg, opt);                                         \
+       isl_args_free(&(args), opt);                                    \
 }                                                                      \
                                                                        \
 int prefix ## _parse(st *opt, int argc, char **argv, unsigned flags)   \
 {                                                                      \
-       return isl_arg_parse(arg, argc, argv, opt, flags);              \
+       return isl_args_parse(&(args), argc, argv, opt, flags);         \
 }
 
 #if defined(__cplusplus)