+#include "debug.h"
+#include "options.h"
+
+static struct fio_option *fio_options;
+extern unsigned int fio_get_kb_base(void *);
+
+static int vp_cmp(const void *p1, const void *p2)
+{
+ const struct value_pair *vp1 = p1;
+ const struct value_pair *vp2 = p2;
+
+ return strlen(vp2->ival) - strlen(vp1->ival);
+}
+
+static void posval_sort(struct fio_option *o, struct value_pair *vpmap)
+{
+ const struct value_pair *vp;
+ int entries;
+
+ memset(vpmap, 0, PARSE_MAX_VP * sizeof(struct value_pair));
+
+ for (entries = 0; entries < PARSE_MAX_VP; entries++) {
+ vp = &o->posval[entries];
+ if (!vp->ival || vp->ival[0] == '\0')
+ break;
+
+ memcpy(&vpmap[entries], vp, sizeof(*vp));
+ }
+
+ qsort(vpmap, entries, sizeof(struct value_pair), vp_cmp);
+}
+
+static void show_option_range(struct fio_option *o,
+ int (*logger)(const char *format, ...))
+{
+ if (o->type == FIO_OPT_FLOAT_LIST){
+ if (isnan(o->minfp) && isnan(o->maxfp))
+ return;
+
+ logger("%20s: min=%f", "range", o->minfp);
+ if (!isnan(o->maxfp))
+ logger(", max=%f", o->maxfp);
+ logger("\n");
+ } else {
+ if (!o->minval && !o->maxval)
+ return;
+
+ logger("%20s: min=%d", "range", o->minval);
+ if (o->maxval)
+ logger(", max=%d", o->maxval);
+ logger("\n");
+ }
+}
+
+static void show_option_values(struct fio_option *o)
+{
+ int i;
+
+ for (i = 0; i < PARSE_MAX_VP; i++) {
+ const struct value_pair *vp = &o->posval[i];
+
+ if (!vp->ival)
+ continue;
+
+ log_info("%20s: %-10s", i == 0 ? "valid values" : "", vp->ival);
+ if (vp->help)
+ log_info(" %s", vp->help);
+ log_info("\n");
+ }
+
+ if (i)
+ log_info("\n");
+}
+
+static void show_option_help(struct fio_option *o, int is_err)
+{
+ const char *typehelp[] = {
+ "invalid",
+ "string (opt=bla)",
+ "string (opt=bla)",
+ "string with possible k/m/g postfix (opt=4k)",
+ "string with time postfix (opt=10s)",
+ "string (opt=bla)",
+ "string with dual range (opt=1k-4k,4k-8k)",
+ "integer value (opt=100)",
+ "boolean value (opt=1)",
+ "list of floating point values separated by ':' (opt=5.9:7.8)",
+ "no argument (opt)",
+ "deprecated",
+ };
+ int (*logger)(const char *format, ...);
+
+ if (is_err)
+ logger = log_err;
+ else
+ logger = log_info;
+
+ if (o->alias)
+ logger("%20s: %s\n", "alias", o->alias);
+
+ logger("%20s: %s\n", "type", typehelp[o->type]);
+ logger("%20s: %s\n", "default", o->def ? o->def : "no default");
+ if (o->prof_name)
+ logger("%20s: only for profile '%s'\n", "valid", o->prof_name);
+ show_option_range(o, logger);
+ show_option_values(o);
+}