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 int check_int(char *p, unsigned int *val)
114 if (sscanf(p, "%u", val) == 1)
120 int check_strset(char *p, char *name)
122 return strncmp(p, name, strlen(name));
125 static struct fio_option *find_option(struct fio_option *options,
128 struct fio_option *o;
136 if (!strcmp(o->name, opt))
145 static int handle_option(struct fio_option *o, char *ptr, void *data)
147 unsigned int il, *ilp;
148 unsigned long long ull, *ullp;
149 unsigned long ul1, ul2, *ulp1, *ulp2;
151 int ret = 0, is_time = 0;
153 tmpbuf = malloc(4096);
157 fio_opt_str_fn *fn = o->cb;
162 case FIO_OPT_STR_VAL_TIME:
164 case FIO_OPT_STR_VAL: {
165 fio_opt_str_val_fn *fn = o->cb;
168 ret = check_str_time(ptr, &ull);
170 ret = check_str_bytes(ptr, &ull);
175 if (o->max_val && ull > o->max_val)
179 ret = fn(data, &ull);
181 ullp = td_var(data, o->off1);
186 case FIO_OPT_STR_STORE:
187 cp = td_var(data, o->off1);
190 case FIO_OPT_RANGE: {
193 p1 = strchr(ptr, '-');
203 if (!check_range_bytes(p1, &ul1) && !check_range_bytes(p2, &ul2)) {
205 ulp1 = td_var(data, o->off1);
206 ulp2 = td_var(data, o->off2);
219 fio_opt_int_fn *fn = o->cb;
221 ret = check_int(ptr, &il);
225 if (o->max_val && il > o->max_val)
231 ilp = td_var(data, o->off1);
236 case FIO_OPT_STR_SET: {
237 fio_opt_str_set_fn *fn = o->cb;
242 ilp = td_var(data, o->off1);
248 fprintf(stderr, "Bad option type %d\n", o->type);
256 int parse_option(const char *opt, struct fio_option *options, void *data)
258 struct fio_option *o = find_option(options, opt);
264 pre = strchr(tmp, '=');
270 o = find_option(options, pre);
272 o = find_option(options, tmp);
277 fprintf(stderr, "Bad option %s\n", tmp);
281 return handle_option(o, post, data);