Rename headers from isl_header.h to isl/header.h
[platform/upstream/isl.git] / isl_arg.c
index a9529b5..c6ffa14 100644 (file)
--- a/isl_arg.c
+++ b/isl_arg.c
@@ -11,8 +11,8 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "isl_arg.h"
-#include <isl_ctx.h>
+#include <isl/arg.h>
+#include <isl/ctx.h>
 
 static void set_default_choice(struct isl_arg *arg, void *opt)
 {
@@ -207,20 +207,14 @@ static int print_help_msg(struct isl_arg *decl, int pos)
        return len;
 }
 
-static void print_default_choice(struct isl_arg *decl, int pos)
+static void print_default(struct isl_arg *decl, const char *def, int pos)
 {
        int i;
        const char *default_prefix = "[default: ";
        const char *default_suffix = "]";
-       const char *s = "none";
        int len;
 
-       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;
-               }
-       len = strlen(default_prefix) + strlen(s) + strlen(default_suffix);
+       len = strlen(default_prefix) + strlen(def) + strlen(default_suffix);
 
        if (!decl->help_msg) {
                if (pos >= 29)
@@ -234,7 +228,21 @@ static void print_default_choice(struct isl_arg *decl, int pos)
                else
                        printf(" ");
        }
-       printf("%s%s%s", default_prefix, s, default_suffix);
+       printf("%s%s%s", default_prefix, def, default_suffix);
+}
+
+static void print_default_choice(struct isl_arg *decl, int pos)
+{
+       int i;
+       const char *s = "none";
+
+       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;
+               }
+
+       print_default(decl, s, pos);
 }
 
 static void print_choice_help(struct isl_arg *decl, const char *prefix)
@@ -337,7 +345,8 @@ static void print_bool_help(struct isl_arg *decl, const char *prefix)
        int pos;
        int no = decl->u.b.default_value == 1;
        pos = print_arg_help(decl, prefix, no);
-       print_help_msg(decl, pos);
+       pos = print_help_msg(decl, pos);
+       print_default(decl, no ? "yes" : "no", pos);
        printf("\n");
 }
 
@@ -509,8 +518,11 @@ static int parse_choice_option(struct isl_arg *decl, char **arg,
                return 0;
 
        if (!has_argument && (!arg[1] || arg[1][0] == '-')) {
-               *(unsigned *)(((char *)opt) + decl->offset) =
-                       decl->u.choice.default_selected;
+               unsigned u = decl->u.choice.default_selected;
+               if (decl->u.choice.set)
+                       decl->u.choice.set(opt, u);
+               else
+                       *(unsigned *)(((char *)opt) + decl->offset) = u;
 
                return 1;
        }
@@ -519,11 +531,16 @@ static int parse_choice_option(struct isl_arg *decl, char **arg,
                choice = arg[1];
 
        for (i = 0; decl->u.choice.choice[i].name; ++i) {
+               unsigned u;
+
                if (strcmp(choice, decl->u.choice.choice[i].name))
                        continue;
 
-               *(unsigned *)(((char *)opt) + decl->offset) =
-                       decl->u.choice.choice[i].value;
+               u = decl->u.choice.choice[i].value;
+               if (decl->u.choice.set)
+                       decl->u.choice.set(opt, u);
+               else
+                       *(unsigned *)(((char *)opt) + decl->offset) = u;
 
                return has_argument ? 1 : 2;
        }
@@ -591,9 +608,22 @@ static int parse_bool_option(struct isl_arg *decl, const char *arg,
                return 1;
        }
 
-       if (strncmp(arg, "--no-", 5))
+       if (strncmp(arg, "--", 2))
+               return 0;
+       arg += 2;
+
+       if (prefix) {
+               size_t prefix_len = strlen(prefix);
+               if (strncmp(arg, prefix, prefix_len) == 0 &&
+                   arg[prefix_len] == '-') {
+                       arg += prefix_len + 1;
+                       prefix = NULL;
+               }
+       }
+
+       if (strncmp(arg, "no-", 3))
                return 0;
-       arg += 5;
+       arg += 3;
 
        if (prefix) {
                size_t prefix_len = strlen(prefix);