Fio 1.17.2
[fio.git] / parse.c
diff --git a/parse.c b/parse.c
index ace34a697d20af4ffcff9fd013898927f3dd550c..879a3aa3c5b190bf63b37dd4b7f90f2be2fd5f83 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -148,9 +148,19 @@ void strip_blank_front(char **p)
 
 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';
@@ -178,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;
 }
@@ -546,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;
@@ -579,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;
                        }
                }