+static struct fio_option *get_option(const char *opt,
+ struct fio_option *options, char **post)
+{
+ struct fio_option *o;
+ char *ret;
+
+ ret = strchr(opt, '=');
+ if (ret) {
+ *post = ret;
+ *ret = '\0';
+ ret = (char *) opt;
+ (*post)++;
+ strip_blank_end(ret);
+ o = find_option(options, ret);
+ } else {
+ o = find_option(options, opt);
+ *post = NULL;
+ }
+
+ return o;
+}
+
+static int opt_cmp(const void *p1, const void *p2)
+{
+ struct fio_option *o1, *o2;
+ char *s1, *s2, *foo;
+ int prio1, prio2;
+
+ s1 = strdup(*((char **) p1));
+ s2 = strdup(*((char **) p2));
+
+ o1 = get_option(s1, fio_options, &foo);
+ o2 = get_option(s2, fio_options, &foo);
+
+ prio1 = prio2 = 0;
+ if (o1)
+ prio1 = o1->prio;
+ if (o2)
+ prio2 = o2->prio;
+
+ free(s1);
+ free(s2);
+ return prio2 - prio1;
+}
+
+void sort_options(char **opts, struct fio_option *options, int num_opts)
+{
+ fio_options = options;
+ qsort(opts, num_opts, sizeof(char *), opt_cmp);
+ fio_options = NULL;
+}
+