2 * This file contains the ini and command liner parser main.
14 static unsigned long get_mult_time(char c)
31 static unsigned long get_mult_bytes(char c)
42 return 1024 * 1024 * 1024;
49 * convert string into decimal value, noting any size suffix
51 static int str_to_decimal(char *p, unsigned long long *val, int kilo)
58 *val = strtoul(str, NULL, 10);
59 if (*val == ULONG_MAX && errno == ERANGE)
63 *val *= get_mult_bytes(str[len - 1]);
65 *val *= get_mult_time(str[len - 1]);
69 static int check_str_bytes(char *p, unsigned long long *val)
71 return str_to_decimal(p, val, 1);
74 static int check_str_time(char *p, unsigned long long *val)
76 return str_to_decimal(p, val, 0);
79 void strip_blank_front(char **p)
87 void strip_blank_end(char *p)
89 char *s = p + strlen(p) - 1;
91 while (isspace(*s) || iscntrl(*s))
97 static int check_range_bytes(char *str, unsigned long *val)
101 if (sscanf(str, "%lu%c", val, &suffix) == 2) {
102 *val *= get_mult_bytes(suffix);
106 if (sscanf(str, "%lu", val) == 1)
112 static int check_int(char *p, unsigned int *val)
114 if (sscanf(p, "%u", val) == 1)
120 static struct fio_option *find_option(struct fio_option *options,
123 struct fio_option *o = &options[0];
126 if (!strcmp(o->name, opt))
135 static int handle_option(struct fio_option *o, char *ptr, void *data)
137 unsigned int il, *ilp;
138 unsigned long long ull, *ullp;
139 unsigned long ul1, ul2, *ulp1, *ulp2;
141 int ret = 0, is_time = 0;
143 tmpbuf = malloc(4096);
147 fio_opt_str_fn *fn = o->cb;
152 case FIO_OPT_STR_VAL_TIME:
154 case FIO_OPT_STR_VAL: {
155 fio_opt_str_val_fn *fn = o->cb;
158 ret = check_str_time(ptr, &ull);
160 ret = check_str_bytes(ptr, &ull);
165 if (o->max_val && ull > o->max_val)
169 ret = fn(data, &ull);
171 ullp = td_var(data, o->off1);
176 case FIO_OPT_STR_STORE:
177 cp = td_var(data, o->off1);
180 case FIO_OPT_RANGE: {
183 p1 = strchr(ptr, '-');
193 if (!check_range_bytes(p1, &ul1) && !check_range_bytes(p2, &ul2)) {
195 ulp1 = td_var(data, o->off1);
196 ulp2 = td_var(data, o->off2);
209 fio_opt_int_fn *fn = o->cb;
211 ret = check_int(ptr, &il);
215 if (o->max_val && il > o->max_val)
221 ilp = td_var(data, o->off1);
226 case FIO_OPT_STR_SET: {
227 fio_opt_str_set_fn *fn = o->cb;
232 ilp = td_var(data, o->off1);
238 fprintf(stderr, "Bad option type %d\n", o->type);
246 int parse_option(const char *opt, struct fio_option *options, void *data)
248 struct fio_option *o = find_option(options, opt);
254 pre = strchr(tmp, '=');
260 o = find_option(options, pre);
262 o = find_option(options, tmp);
267 fprintf(stderr, "Bad option %s\n", tmp);
271 return handle_option(o, post, data);