Remember to free the file structure as well
[fio.git] / parse.c
diff --git a/parse.c b/parse.c
index 90874f1642c792917d4081b73362199337e627b3..f9e0ebeedc3fd635ccbc8605122f37a795289678 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -10,6 +10,7 @@
 #include <limits.h>
 
 #include "parse.h"
+#include "debug.h"
 
 static int vp_cmp(const void *p1, const void *p2)
 {
@@ -229,6 +230,9 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
        char **cp;
        int ret = 0, is_time = 0;
 
+       dprint(FD_PARSE, "__handle_option=%s, type=%d, ptr=%s\n", o->name,
+                                                       o->type, ptr);
+
        if (!ptr && o->type != FIO_OPT_STR_SET) {
                fprintf(stderr, "Option %s requires an argument\n", o->name);
                return 1;
@@ -414,6 +418,8 @@ static int handle_option(struct fio_option *o, const char *ptr, void *data)
        const char *ptr2 = NULL;
        int r1, r2;
 
+       dprint(FD_PARSE, "handle_option=%s, ptr=%s\n", o->name, ptr);
+
        /*
         * See if we have a second set of parameters, hidden after a comma.
         * Do this before parsing the first round, to check if we should
@@ -573,10 +579,11 @@ static struct fio_option *find_child(struct fio_option *options,
        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;
+       int depth;
 
        if (!o)
                return;
@@ -584,13 +591,37 @@ static void print_option(struct fio_option *o, struct fio_option *org,
                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);
-       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)
@@ -629,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)
-                                       print_option(o, NULL, 0);
+                                       print_option(o);
                                continue;
                        }
                }
@@ -661,6 +692,8 @@ void fill_default_options(void *data, struct fio_option *options)
 {
        struct fio_option *o;
 
+       dprint(FD_PARSE, "filling default options\n");
+
        for (o = &options[0]; o->name; o++)
                if (o->def)
                        handle_option(o, o->def, data);
@@ -674,6 +707,8 @@ void options_init(struct fio_option *options)
 {
        struct fio_option *o;
 
+       dprint(FD_PARSE, "init options\n");
+
        for (o = &options[0]; o->name; o++) {
                if (o->type == FIO_OPT_BOOL) {
                        o->minval = 0;