parse: get rid of raw option offsets
[fio.git] / goptions.c
index b78accdaf3a141a7258680994cfe4f0b73f608a0..33183682d97f7eb3f2ab0887ffe6cea575245e24 100644 (file)
@@ -885,33 +885,60 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o,
                unsigned long long *ullp = NULL;
                struct gopt_int *i;
 
-               if (o->off1)
-                       ullp = td_var(to, o->off1);
+               if (o->off1) {
+                       if (o->prof_opts)
+                               ullp = td_var(o->prof_opts, o->off1);
+                       else
+                               ullp = td_var(to, o->off1);
+               }
 
                i = container_of(gopt, struct gopt_int, gopt);
                if (ullp)
                        gopt_int_set_val(i, *ullp);
                break;
                }
-       case FIO_OPT_INT: {
-               unsigned int *ip = NULL;
-               struct gopt_int *i;
+       case FIO_OPT_INT:
+               if (o->posval[0].ival) {
+                       unsigned int *ip = NULL;
+                       struct gopt_combo *c;
 
-               if (o->off1)
-                       ip = td_var(to, o->off1);
+                       if (o->off1) {
+                               if (o->prof_opts)
+                                       ip = td_var(o->prof_opts, o->off1);
+                               else
+                                       ip = td_var(to, o->off1);
+                       }
 
-               i = container_of(gopt, struct gopt_int, gopt);
-               if (ip)
-                       gopt_int_set_val(i, *ip);
-               break;
+                       c = container_of(gopt, struct gopt_combo, gopt);
+                       if (ip)
+                               gopt_combo_int_set_val(c, *ip);
+               } else {
+                       unsigned int *ip = NULL;
+                       struct gopt_int *i;
+
+                       if (o->off1) {
+                               if (o->prof_opts)
+                                       ip = td_var(o->prof_opts, o->off1);
+                               else
+                                       ip = td_var(to, o->off1);
+                       }
+
+                       i = container_of(gopt, struct gopt_int, gopt);
+                       if (ip)
+                               gopt_int_set_val(i, *ip);
                }
+               break;
        case FIO_OPT_STR_SET:
        case FIO_OPT_BOOL: {
                unsigned int *ip = NULL;
                struct gopt_bool *b;
 
-               if (o->off1)
-                       ip = td_var(to, o->off1);
+               if (o->off1) {
+                       if (o->prof_opts)
+                               ip = td_var(o->prof_opts, o->off1);
+                       else
+                               ip = td_var(to, o->off1);
+               }
 
                b = container_of(gopt, struct gopt_bool, gopt);
                if (ip)
@@ -923,8 +950,12 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o,
                        unsigned int *ip = NULL;
                        struct gopt_combo *c;
 
-                       if (o->off1)
-                               ip = td_var(to, o->off1);
+                       if (o->off1) {
+                               if (o->prof_opts)
+                                       ip = td_var(o->prof_opts, o->off1);
+                               else
+                                       ip = td_var(to, o->off1);
+                       }
 
                        c = container_of(gopt, struct gopt_combo, gopt);
                        if (ip)
@@ -934,7 +965,12 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o,
                        char *text = NULL;
 
                        if (o->off1) {
-                               char **p = td_var(to, o->off1);
+                               char **p;
+
+                               if (o->prof_opts)
+                                       p = td_var(o->prof_opts, o->off1);
+                               else
+                                       p = td_var(to, o->off1);
 
                                text = *p;
                        }
@@ -950,7 +986,13 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o,
                char *text = NULL;
 
                if (o->off1) {
-                       char **p = td_var(to, o->off1);
+                       char **p;
+
+                       if (o->prof_opts)
+                               p = td_var(o->prof_opts, o->off1);
+                       else
+                               p = td_var(to, o->off1);
+
                        text = *p;
                }
 
@@ -972,10 +1014,19 @@ static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o,
                break;
        case FIO_OPT_RANGE: {
                struct gopt_range *r;
-               unsigned int *ip[4] = { td_var(to, o->off1),
-                                       td_var(to, o->off2),
-                                       td_var(to, o->off3),
-                                       td_var(to, o->off4) };
+               unsigned int *ip[4];
+
+               if (o->prof_opts) {
+                       ip[0] = td_var(o->prof_opts, o->off1);
+                       ip[1] = td_var(o->prof_opts, o->off2);
+                       ip[2] = td_var(o->prof_opts, o->off3);
+                       ip[3] = td_var(o->prof_opts, o->off4);
+               } else {
+                       ip[0] = td_var(to, o->off1);
+                       ip[1] = td_var(to, o->off2);
+                       ip[2] = td_var(to, o->off3);
+                       ip[3] = td_var(to, o->off4);
+               }
 
                r = container_of(gopt, struct gopt_range, gopt);
                gopt_int_range_set_val(r, *ip);
@@ -1002,8 +1053,12 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox,
        case FIO_OPT_STR_VAL: {
                unsigned long long *ullp = NULL;
 
-               if (o->off1)
-                       ullp = td_var(to, o->off1);
+               if (o->off1) {
+                       if (o->prof_opts)
+                               ullp = td_var(o->prof_opts, o->off1);
+                       else
+                               ullp = td_var(to, o->off1);
+               }
 
                go = gopt_new_str_val(gjv, o, ullp, opt_index);
                break;
@@ -1011,27 +1066,51 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox,
        case FIO_OPT_STR_VAL_TIME: {
                unsigned long long *ullp = NULL;
 
-               if (o->off1)
-                       ullp = td_var(to, o->off1);
+               if (o->off1) {
+                       if (o->prof_opts)
+                               ullp = td_var(o->prof_opts, o->off1);
+                       else
+                               ullp = td_var(to, o->off1);
+               }
 
                go = gopt_new_ullong(gjv, o, ullp, opt_index);
                break;
                }
-       case FIO_OPT_INT: {
-               unsigned int *ip = NULL;
+       case FIO_OPT_INT:
+               if (o->posval[0].ival) {
+                       unsigned int *ip = NULL;
 
-               if (o->off1)
-                       ip = td_var(to, o->off1);
+                       if (o->off1) {
+                               if (o->prof_opts)
+                                       ip = td_var(o->prof_opts, o->off1);
+                               else
+                                       ip = td_var(to, o->off1);
+                       }
 
-               go = gopt_new_int(gjv, o, ip, opt_index);
-               break;
+                       go = gopt_new_combo_int(gjv, o, ip, opt_index);
+               } else {
+                       unsigned int *ip = NULL;
+
+                       if (o->off1) {
+                               if (o->prof_opts)
+                                       ip = td_var(o->prof_opts, o->off1);
+                               else
+                                       ip = td_var(to, o->off1);
+                       }
+
+                       go = gopt_new_int(gjv, o, ip, opt_index);
                }
+               break;
        case FIO_OPT_STR_SET:
        case FIO_OPT_BOOL: {
                unsigned int *ip = NULL;
 
-               if (o->off1)
-                       ip = td_var(to, o->off1);
+               if (o->off1) {
+                       if (o->prof_opts)
+                               ip = td_var(o->prof_opts, o->off1);
+                       else
+                               ip = td_var(to, o->off1);
+               }
 
                go = gopt_new_bool(gjv, o, ip, opt_index);
                break;
@@ -1040,8 +1119,12 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox,
                if (o->posval[0].ival) {
                        unsigned int *ip = NULL;
 
-                       if (o->off1)
-                               ip = td_var(to, o->off1);
+                       if (o->off1) {
+                               if (o->prof_opts)
+                                       ip = td_var(o->prof_opts, o->off1);
+                               else
+                                       ip = td_var(to, o->off1);
+                       }
 
                        go = gopt_new_combo_int(gjv, o, ip, opt_index);
                } else {
@@ -1055,7 +1138,13 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox,
                char *text = NULL;
 
                if (o->off1) {
-                       char **p = td_var(to, o->off1);
+                       char **p;
+
+                       if (o->prof_opts)
+                               p = td_var(o->prof_opts, o->off1);
+                       else
+                               p = td_var(to, o->off1);
+
                        text = *p;
                }
 
@@ -1071,10 +1160,19 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox,
                go = gopt_new_str_multi(gjv, o, opt_index);
                break;
        case FIO_OPT_RANGE: {
-               unsigned int *ip[4] = { td_var(to, o->off1),
-                                       td_var(to, o->off2),
-                                       td_var(to, o->off3),
-                                       td_var(to, o->off4) };
+               unsigned int *ip[4];
+
+               if (o->prof_opts) {
+                       ip[0] = td_var(o->prof_opts, o->off1);
+                       ip[1] = td_var(o->prof_opts, o->off2);
+                       ip[2] = td_var(o->prof_opts, o->off3);
+                       ip[3] = td_var(o->prof_opts, o->off4);
+               } else {
+                       ip[0] = td_var(to, o->off1);
+                       ip[1] = td_var(to, o->off2);
+                       ip[2] = td_var(to, o->off3);
+                       ip[3] = td_var(to, o->off4);
+               }
 
                go = gopt_new_int_range(gjv, o, ip, opt_index);
                break;
@@ -1184,12 +1282,17 @@ static void gopt_handle_str_multi_changed(struct gopt_job_view *gjv,
                                          struct gopt_str_multi *m,
                                          struct fio_option *o)
 {
-       unsigned int *ip = td_var(gjv->o, o->off1);
        struct value_pair *vp;
+       unsigned int *ip;
        gboolean set;
        guint val = 0;
        int i;
 
+       if (o->prof_opts)
+               ip = td_var(o->prof_opts, o->off1);
+       else
+               ip = td_var(gjv->o, o->off1);
+
        i = 0;
        vp = &o->posval[0];
        while (vp->ival) {
@@ -1214,13 +1317,22 @@ static void gopt_handle_range_changed(struct gopt_job_view *gjv,
                                      struct gopt_range *r,
                                      struct fio_option *o)
 {
-       unsigned int *ip[4] = { td_var(gjv->o, o->off1),
-                               td_var(gjv->o, o->off2),
-                               td_var(gjv->o, o->off3),
-                               td_var(gjv->o, o->off4) };
+       unsigned int *ip[4];
        gint val;
        int i;
 
+       if (o->prof_opts) {
+               ip[0] = td_var(o->prof_opts, o->off1);
+               ip[1] = td_var(o->prof_opts, o->off2);
+               ip[2] = td_var(o->prof_opts, o->off3);
+               ip[3] = td_var(o->prof_opts, o->off4);
+       } else {
+               ip[0] = td_var(gjv->o, o->off1);
+               ip[1] = td_var(gjv->o, o->off2);
+               ip[2] = td_var(gjv->o, o->off3);
+               ip[3] = td_var(gjv->o, o->off4);
+       }
+
        for (i = 0; i < GOPT_RANGE_SPIN; i++) {
                val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[i]));
                *ip[i] = val;
@@ -1231,10 +1343,15 @@ static void gopt_handle_str_val_changed(struct gopt_job_view *gjv,
                                        struct gopt_str_val *s,
                                        struct fio_option *o)
 {
-       unsigned long long *ullp = td_var(gjv->o, o->off1);
+       unsigned long long *ullp;
        GtkAdjustment *adj;
        gint index;
 
+       if (o->prof_opts)
+               ullp = td_var(o->prof_opts, o->off1);
+       else
+               ullp = td_var(gjv->o, o->off1);
+
        if (!ullp)
                return;
 
@@ -1255,7 +1372,12 @@ static void gopt_handle_str_val_changed(struct gopt_job_view *gjv,
 static void gopt_handle_str_changed(struct gopt_job_view *gjv,
                                    struct gopt_str *s, struct fio_option *o)
 {
-       char **p = td_var(gjv->o, o->off1);
+       char **p;
+
+       if (o->prof_opts)
+               p = td_var(o->prof_opts, o->off1);
+       else
+               p = td_var(gjv->o, o->off1);
 
        if (*p)
                free(*p);
@@ -1266,9 +1388,14 @@ static void gopt_handle_str_changed(struct gopt_job_view *gjv,
 static void gopt_handle_bool_changed(struct gopt_job_view *gjv,
                                     struct gopt_bool *b, struct fio_option *o)
 {
-       unsigned int *ip = td_var(gjv->o, o->off1);
+       unsigned int *ip;
        gboolean set;
 
+       if (o->prof_opts)
+               ip = td_var(o->prof_opts, o->off1);
+       else
+               ip = td_var(gjv->o, o->off1);
+
        set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check));
        *ip = set;
 }
@@ -1276,10 +1403,15 @@ static void gopt_handle_bool_changed(struct gopt_job_view *gjv,
 static void gopt_handle_int_changed(struct gopt_job_view *gjv,
                                    struct gopt_int *i, struct fio_option *o)
 {
-       unsigned int *ip = td_var(gjv->o, o->off1);
        GtkAdjustment *adj;
+       unsigned int *ip;
        guint val;
 
+       if (o->prof_opts)
+               ip = td_var(o->prof_opts, o->off1);
+       else
+               ip = td_var(gjv->o, o->off1);
+
        adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(i->spin));
        val = gtk_adjustment_get_value(adj);
        *ip = val;
@@ -1289,7 +1421,12 @@ static void gopt_handle_combo_str_changed(struct gopt_job_view *gjv,
                                          struct gopt_combo *c,
                                          struct fio_option *o)
 {
-       char **p = td_var(gjv->o, o->off1);
+       char **p;
+
+       if (o->prof_opts)
+               p = td_var(o->prof_opts, o->off1);
+       else
+               p = td_var(gjv->o, o->off1);
 
        if (*p)
                free(*p);
@@ -1301,9 +1438,14 @@ static void gopt_handle_combo_int_changed(struct gopt_job_view *gjv,
                                          struct gopt_combo *c,
                                          struct fio_option *o)
 {
-       unsigned int *ip = td_var(gjv->o, o->off1);
+       unsigned int *ip;
        gint index;
 
+       if (o->prof_opts)
+               ip = td_var(o->prof_opts, o->off1);
+       else
+               ip = td_var(gjv->o, o->off1);
+
        index = gtk_combo_box_get_active(GTK_COMBO_BOX(c->combo));
        *ip = o->posval[index].oval;
 }
@@ -1371,8 +1513,8 @@ static void gopt_handle_changed(struct gopt *gopt)
                break;
                }
        default:
-               log_err("gfio: bad option type %s/%d\n", gopt->opt_type);
-               return;
+               log_err("gfio: bad option type%d\n", gopt->opt_type);
+               break;
        }
 }