Fix recursive dump of options
authorJens Axboe <jens.axboe@oracle.com>
Sat, 1 Mar 2008 14:12:14 +0000 (15:12 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Sat, 1 Mar 2008 14:12:14 +0000 (15:12 +0100)
If a child also had a child, we would miss it.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
parse.c

diff --git a/parse.c b/parse.c
index 3c203121711dcb9595bea3b1b6e517dad3d76abb..f9e0ebeedc3fd635ccbc8605122f37a795289678 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -579,10 +579,11 @@ static struct fio_option *find_child(struct fio_option *options,
        return NULL;
 }
 
        return NULL;
 }
 
-static void print_option(struct fio_option *o, struct fio_option *org,
-                        int level)
+static void __print_option(struct fio_option *o, struct fio_option *org,
+                          int level)
 {
        char name[256], *p;
 {
        char name[256], *p;
+       int depth;
 
        if (!o)
                return;
 
        if (!o)
                return;
@@ -590,13 +591,37 @@ static void print_option(struct fio_option *o, struct fio_option *org,
                org = o;
        
        p = name;
                org = o;
        
        p = name;
-       if (level)
-               p += sprintf(p, "%s", "    ");
+       depth = level;
+       while (depth--)
+               p += sprintf(p, "%s", "  ");
 
        sprintf(p, "%s", o->name);
 
        printf("%-24s: %s\n", name, o->help);
 
        sprintf(p, "%s", o->name);
 
        printf("%-24s: %s\n", name, o->help);
-       print_option(find_child(o, org), org, level + 1);
+}
+
+static void print_option(struct fio_option *o)
+{
+       struct fio_option *parent;
+       struct fio_option *__o;
+       unsigned int printed;
+       unsigned int level;
+
+       __print_option(o, NULL, 0);
+       parent = o;
+       level = 0;
+       do {
+               level++;
+               printed = 0;
+
+               while ((__o = find_child(o, parent)) != NULL) {
+                       __print_option(__o, o, level);
+                       o = __o;
+                       printed++;
+               }
+
+               parent = o;
+       } while (printed);
 }
 
 int show_cmd_help(struct fio_option *options, const char *name)
 }
 
 int show_cmd_help(struct fio_option *options, const char *name)
@@ -635,7 +660,7 @@ int show_cmd_help(struct fio_option *options, const char *name)
                                printf("%24s: %s\n", o->name, o->help);
                        if (show_all) {
                                if (!o->parent)
                                printf("%24s: %s\n", o->name, o->help);
                        if (show_all) {
                                if (!o->parent)
-                                       print_option(o, NULL, 0);
+                                       print_option(o);
                                continue;
                        }
                }
                                continue;
                        }
                }