Fio 1.17.1
[fio.git] / parse.c
diff --git a/parse.c b/parse.c
index 4d8e95db7fbe88b84a45c7bb215b1b7f3db47223..879a3aa3c5b190bf63b37dd4b7f90f2be2fd5f83 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -142,13 +142,25 @@ void strip_blank_front(char **p)
 
        while (isspace(*s))
                s++;
+
+       *p = s;
 }
 
 void strip_blank_end(char *p)
 {
-       char *s = p + strlen(p) - 1;
-
-       while (isspace(*s) || iscntrl(*s))
+       char *s;
+
+       s = strchr(p, ';');
+       if (s)
+               *s = '\0';
+       s = strchr(p, '#');
+       if (s)
+               *s = '\0';
+       if (s)
+               p = s;
+
+       s = p + strlen(p);
+       while ((isspace(*s) || iscntrl(*s)) && (s > p))
                s--;
 
        *(s + 1) = '\0';
@@ -176,8 +188,13 @@ static int check_int(const char *p, int *val)
 {
        if (!strlen(p))
                return 1;
-       if (sscanf(p, "%u", val) == 1)
-               return 0;
+       if (strstr(p, "0x") || strstr(p, "0X")) {
+               if (sscanf(p, "%x", val) == 1)
+                       return 0;
+       } else {
+               if (sscanf(p, "%u", val) == 1)
+                       return 0;
+       }
 
        return 1;
 }
@@ -450,9 +467,9 @@ int parse_option(const char *opt, struct fio_option *options, void *data)
 {
        struct fio_option *o;
        char *pre, *post;
-       char tmp[64];
+       char *tmp;
 
-       strncpy(tmp, opt, sizeof(tmp) - 1);
+       tmp = strdup(opt);
 
        pre = strchr(tmp, '=');
        if (pre) {
@@ -468,13 +485,17 @@ int parse_option(const char *opt, struct fio_option *options, void *data)
 
        if (!o) {
                fprintf(stderr, "Bad option %s\n", tmp);
+               free(tmp);
                return 1;
        }
 
-       if (!handle_option(o, post, data))
+       if (!handle_option(o, post, data)) {
+               free(tmp);
                return 0;
+       }
 
        fprintf(stderr, "fio: failed parsing %s\n", opt);
+       free(tmp);
        return 1;
 }
 
@@ -540,6 +561,38 @@ static void show_option_help(struct fio_option *o)
        show_option_values(o);
 }
 
+static struct fio_option *find_child(struct fio_option *options,
+                                    struct fio_option *o)
+{
+       struct fio_option *__o;
+
+       for (__o = options + 1; __o->name; __o++)
+               if (__o->parent && !strcmp(__o->parent, o->name))
+                       return __o;
+
+       return NULL;
+}
+
+static void print_option(struct fio_option *o, struct fio_option *org,
+                        int level)
+{
+       char name[256], *p;
+
+       if (!o)
+               return;
+       if (!org)
+               org = o;
+       
+       p = name;
+       if (level)
+               p += sprintf(p, "%s", "    ");
+
+       sprintf(p, "%s", o->name);
+
+       printf("%-24s: %s\n", name, o->help);
+       print_option(find_child(o, org), org, level + 1);
+}
+
 int show_cmd_help(struct fio_option *options, const char *name)
 {
        struct fio_option *o, *closest;
@@ -573,9 +626,10 @@ int show_cmd_help(struct fio_option *options, const char *name)
                if (show_all || match) {
                        found = 1;
                        if (match)
-                               printf("%20s: %s\n", o->name, o->help);
+                               printf("%24s: %s\n", o->name, o->help);
                        if (show_all) {
-                               printf("%-20s: %s\n", o->name, o->help);
+                               if (!o->parent)
+                                       print_option(o, NULL, 0);
                                continue;
                        }
                }
@@ -625,6 +679,8 @@ void options_init(struct fio_option *options)
                        o->minval = 0;
                        o->maxval = 1;
                }
+               if (o->type == FIO_OPT_STR_SET && o->def)
+                       fprintf(stderr, "Option %s: string set option with default will always be true\n", o->name);
                if (!o->cb && !o->off1)
                        fprintf(stderr, "Option %s: neither cb nor offset given\n", o->name);
                if (o->type == FIO_OPT_STR || o->type == FIO_OPT_STR_STORE)