isl_options_parse: print help message
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 15 May 2010 14:40:46 +0000 (16:40 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 15 May 2010 17:26:39 +0000 (19:26 +0200)
bound.c
cat.c
include/isl_arg.h
isl_arg.c
isl_options.c
pip.c

diff --git a/bound.c b/bound.c
index 327705c..b32b65a 100644 (file)
--- a/bound.c
+++ b/bound.c
@@ -11,10 +11,10 @@ struct bound_options {
 };
 
 struct isl_arg bound_options_arg[] = {
-ISL_ARG_CHILD(struct bound_options, isl, "isl", isl_options_arg)
-ISL_ARG_BOOL(struct bound_options, verify, 'T', "verify", 0)
-ISL_ARG_BOOL(struct bound_options, print_all, 'A', "print-all", 0)
-ISL_ARG_BOOL(struct bound_options, continue_on_error, '\0', "continue-on-error", 0)
+ISL_ARG_CHILD(struct bound_options, isl, "isl", isl_options_arg, "isl options")
+ISL_ARG_BOOL(struct bound_options, verify, 'T', "verify", 0, NULL)
+ISL_ARG_BOOL(struct bound_options, print_all, 'A', "print-all", 0, NULL)
+ISL_ARG_BOOL(struct bound_options, continue_on_error, '\0', "continue-on-error", 0, NULL)
 ISL_ARG_END
 };
 
diff --git a/cat.c b/cat.c
index a737508..96722cc 100644 (file)
--- a/cat.c
+++ b/cat.c
@@ -14,9 +14,9 @@ struct cat_options {
 };
 
 struct isl_arg cat_options_arg[] = {
-ISL_ARG_CHILD(struct cat_options, isl, "isl", isl_options_arg)
+ISL_ARG_CHILD(struct cat_options, isl, "isl", isl_options_arg, "isl options")
 ISL_ARG_CHOICE(struct cat_options, format, 0, "format", \
-       cat_format,     ISL_FORMAT_ISL)
+       cat_format,     ISL_FORMAT_ISL, "output format")
 ISL_ARG_END
 };
 
index 86ff19e..75c9016 100644 (file)
@@ -34,6 +34,7 @@ struct isl_arg {
        char                     short_name;
        const char              *long_name;
        size_t                   offset;
+       const char              *help_msg;
        union {
        struct {
                struct isl_arg_choice   *choice;
@@ -49,24 +50,27 @@ struct isl_arg {
        } u;
 };
 
-#define ISL_ARG_CHOICE(st,f,s,l,c,d)   {                               \
+#define ISL_ARG_CHOICE(st,f,s,l,c,d,h) {                               \
        .type = isl_arg_choice,                                         \
        .short_name = s,                                                \
        .long_name = l,                                                 \
        .offset = offsetof(st, f),                                      \
+       .help_msg = h,                                                  \
        .u = { .choice = { .choice = c, .default_value = d } }          \
 },
-#define ISL_ARG_BOOL(st,f,s,l,d)       {                               \
+#define ISL_ARG_BOOL(st,f,s,l,d,h)     {                               \
        .type = isl_arg_bool,                                           \
        .short_name = s,                                                \
        .long_name = l,                                                 \
        .offset = offsetof(st, f),                                      \
+       .help_msg = h,                                                  \
        .u = { .b = { .default_value = d } }                            \
 },
-#define ISL_ARG_CHILD(st,f,l,c)                {                               \
+#define ISL_ARG_CHILD(st,f,l,c,h)      {                               \
        .type = isl_arg_child,                                          \
        .long_name = l,                                                 \
        .offset = offsetof(st, f),                                      \
+       .help_msg = h,                                                  \
        .u = { .child = { .child = c, .size = sizeof(*((st *)NULL)->f) } }\
 },
 #define ISL_ARG_END    { isl_arg_end }
index f7237e4..71c987d 100644 (file)
--- a/isl_arg.c
+++ b/isl_arg.c
@@ -53,36 +53,127 @@ void isl_arg_set_defaults(struct isl_arg *arg, void *opt)
        }
 }
 
-static void print_arg_help(struct isl_arg *decl, const char *prefix)
+static int print_arg_help(struct isl_arg *decl, const char *prefix)
 {
+       int len = 0;
+
        if (decl->short_name)
                printf("  -%c, --", decl->short_name);
        else
                printf("      --");
-       if (prefix)
+       len += 8;
+
+       if (prefix) {
                printf("%s-", prefix);
+               len += strlen(prefix) + 1;
+       }
        printf("%s", decl->long_name);
+       len += strlen(decl->long_name);
+
+       return len;
+}
+
+const void *isl_memrchr(const void *s, int c, size_t n)
+{
+       const char *p = s;
+       while (n-- > 0)
+               if (p[n] == c)
+                       return s + n;
+       return NULL;
+}
+
+static int print_help_msg(struct isl_arg *decl, int pos)
+{
+       int len;
+       const char *s;
+
+       if (!decl->help_msg)
+               return pos;
+
+       if (pos >= 29)
+               printf("\n%30s", "");
+       else
+               printf("%*s", 30 - pos, "");
+
+       s = decl->help_msg;
+       len = strlen(s);
+       while (len > 45) {
+               const char *space = isl_memrchr(s, ' ', 45);
+               int l;
+
+               if (!space)
+                       space = strchr(s + 45, ' ');
+               if (!space)
+                       break;
+               l = space - s;
+               printf("%.*s", l, s);
+               s = space + 1;
+               len -= l + 1;
+               printf("\n%30s", "");
+       }
+
+       printf("%s", s);
+       return len;
+}
+
+static void print_default_choice(struct isl_arg *decl, int pos)
+{
+       int i;
+       const char *default_prefix = "[default: ";
+       const char *default_suffix = "]";
+       const char *s = "none";
+       int len = strlen(default_prefix) + strlen(s) + strlen(default_suffix);
+
+       for (i = 0; decl->u.choice.choice[i].name; ++i)
+               if (decl->u.choice.choice[i].value == decl->u.choice.default_value) {
+                       s = decl->u.choice.choice[i].name;
+                       break;
+               }
+
+       if (!decl->help_msg) {
+               if (pos >= 29)
+                       printf("\n%30s", "");
+               else
+                       printf("%*s", 30 - pos, "");
+               pos = 0;
+       }
+
+       if (pos && pos + len >= 48)
+               printf("\n%30s", "");
+       else
+               printf(" ");
+       printf("%s%s%s", default_prefix, s, default_suffix);
 }
 
 static void print_choice_help(struct isl_arg *decl, const char *prefix)
 {
        int i;
+       int pos;
 
-       print_arg_help(decl, prefix);
+       pos = print_arg_help(decl, prefix);
        printf("=");
+       pos++;
 
        for (i = 0; decl->u.choice.choice[i].name; ++i) {
-               if (i)
+               if (i) {
                        printf("|");
+                       pos++;
+               }
                printf("%s", decl->u.choice.choice[i].name);
+               pos += strlen(decl->u.choice.choice[i].name);
        }
 
+       pos = print_help_msg(decl, pos);
+       print_default_choice(decl, pos);
+
        printf("\n");
 }
 
 static void print_bool_help(struct isl_arg *decl, const char *prefix)
 {
-       print_arg_help(decl, prefix);
+       int pos;
+       pos = print_arg_help(decl, prefix);
+       print_help_msg(decl, pos);
        printf("\n");
 }
 
index 6047535..2f8f0b5 100644 (file)
@@ -59,18 +59,22 @@ struct isl_arg_choice isl_closure_choice[] = {
 
 struct isl_arg isl_options_arg[] = {
 ISL_ARG_CHOICE(struct isl_options, lp_solver, 0, "lp-solver", \
-       isl_lp_solver_choice,   ISL_LP_TAB)
+       isl_lp_solver_choice,   ISL_LP_TAB, "lp solver to use")
 ISL_ARG_CHOICE(struct isl_options, ilp_solver, 0, "ilp-solver", \
-       isl_ilp_solver_choice,  ISL_ILP_GBR)
+       isl_ilp_solver_choice,  ISL_ILP_GBR, "ilp solver to use")
 ISL_ARG_CHOICE(struct isl_options, pip, 0, "pip", \
-       isl_pip_solver_choice,  ISL_PIP_TAB)
+       isl_pip_solver_choice,  ISL_PIP_TAB, "pip solver to use")
 ISL_ARG_CHOICE(struct isl_options, context, 0, "context", \
-       isl_pip_context_choice, ISL_CONTEXT_GBR)
+       isl_pip_context_choice, ISL_CONTEXT_GBR,
+       "how to handle the pip context tableau")
 ISL_ARG_CHOICE(struct isl_options, gbr, 0, "gbr", \
-       isl_gbr_choice, ISL_GBR_ONCE)
+       isl_gbr_choice, ISL_GBR_ONCE,
+       "how often to use generalized basis reduction")
 ISL_ARG_CHOICE(struct isl_options, closure, 0, "closure", \
-       isl_closure_choice,     ISL_CLOSURE_ISL)
-ISL_ARG_BOOL(struct isl_options, gbr_only_first, 0, "gbr-only-first", 0)
+       isl_closure_choice,     ISL_CLOSURE_ISL,
+       "closure operation to use")
+ISL_ARG_BOOL(struct isl_options, gbr_only_first, 0, "gbr-only-first", 0,
+       "only perform basis reduction in first direction")
 ISL_ARG_END
 };
 
diff --git a/pip.c b/pip.c
index 916a2f4..c097b9d 100644 (file)
--- a/pip.c
+++ b/pip.c
@@ -40,8 +40,8 @@ struct pip_options {
 };
 
 struct isl_arg pip_options_arg[] = {
-ISL_ARG_CHILD(struct pip_options, isl, "isl", isl_options_arg)
-ISL_ARG_BOOL(struct pip_options, verify, 'T', "verify", 0)
+ISL_ARG_CHILD(struct pip_options, isl, "isl", isl_options_arg, "isl options")
+ISL_ARG_BOOL(struct pip_options, verify, 'T', "verify", 0, NULL)
 ISL_ARG_END
 };