Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file contains the ini and command liner parser main. |
| 3 | */ |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <unistd.h> |
| 7 | #include <ctype.h> |
| 8 | #include <string.h> |
| 9 | #include <errno.h> |
| 10 | #include <limits.h> |
| 11 | |
| 12 | #include "parse.h" |
| 13 | |
Jens Axboe | f085737 | 2007-03-19 13:15:23 +0100 | [diff] [blame] | 14 | static int vp_cmp(const void *p1, const void *p2) |
| 15 | { |
| 16 | const struct value_pair *vp1 = p1; |
| 17 | const struct value_pair *vp2 = p2; |
| 18 | |
| 19 | return strlen(vp2->ival) - strlen(vp1->ival); |
| 20 | } |
| 21 | |
| 22 | static void posval_sort(struct fio_option *o, struct value_pair *vpmap) |
| 23 | { |
| 24 | const struct value_pair *vp; |
| 25 | int entries; |
| 26 | |
| 27 | memset(vpmap, 0, PARSE_MAX_VP * sizeof(struct value_pair)); |
| 28 | |
| 29 | for (entries = 0; entries < PARSE_MAX_VP; entries++) { |
| 30 | vp = &o->posval[entries]; |
| 31 | if (!vp->ival || vp->ival[0] == '\0') |
| 32 | break; |
| 33 | |
| 34 | memcpy(&vpmap[entries], vp, sizeof(*vp)); |
| 35 | } |
| 36 | |
| 37 | qsort(vpmap, entries, sizeof(struct value_pair), vp_cmp); |
| 38 | } |
| 39 | |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 40 | static void show_option_range(struct fio_option *o) |
| 41 | { |
| 42 | if (!o->minval && !o->maxval) |
| 43 | return; |
| 44 | |
Jens Axboe | ec1aee0 | 2007-02-26 13:18:47 +0100 | [diff] [blame] | 45 | printf("%20s: min=%d, max=%d\n", "range", o->minval, o->maxval); |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static void show_option_values(struct fio_option *o) |
| 49 | { |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 50 | int i = 0; |
| 51 | |
| 52 | do { |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 53 | const struct value_pair *vp = &o->posval[i]; |
| 54 | |
| 55 | if (!vp->ival) |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 56 | break; |
| 57 | |
Jens Axboe | 7837213 | 2007-03-14 13:24:07 +0100 | [diff] [blame] | 58 | printf("%20s: %-10s", i == 0 ? "valid values" : "", vp->ival); |
| 59 | if (vp->help) |
| 60 | printf(" %s", vp->help); |
| 61 | printf("\n"); |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 62 | i++; |
| 63 | } while (i < PARSE_MAX_VP); |
| 64 | |
| 65 | if (i) |
| 66 | printf("\n"); |
| 67 | } |
| 68 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 69 | static unsigned long get_mult_time(char c) |
| 70 | { |
| 71 | switch (c) { |
| 72 | case 'm': |
| 73 | case 'M': |
| 74 | return 60; |
| 75 | case 'h': |
| 76 | case 'H': |
| 77 | return 60 * 60; |
| 78 | case 'd': |
| 79 | case 'D': |
| 80 | return 24 * 60 * 60; |
| 81 | default: |
| 82 | return 1; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | static unsigned long get_mult_bytes(char c) |
| 87 | { |
| 88 | switch (c) { |
| 89 | case 'k': |
| 90 | case 'K': |
| 91 | return 1024; |
| 92 | case 'm': |
| 93 | case 'M': |
| 94 | return 1024 * 1024; |
| 95 | case 'g': |
| 96 | case 'G': |
| 97 | return 1024 * 1024 * 1024; |
Jens Axboe | f3502ba | 2007-02-14 01:27:09 +0100 | [diff] [blame] | 98 | case 'e': |
| 99 | case 'E': |
| 100 | return 1024 * 1024 * 1024 * 1024UL; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 101 | default: |
| 102 | return 1; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /* |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 107 | * convert string into decimal value, noting any size suffix |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 108 | */ |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 109 | static int str_to_decimal(const char *str, long long *val, int kilo) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 110 | { |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 111 | int len; |
| 112 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 113 | len = strlen(str); |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 114 | if (!len) |
| 115 | return 1; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 116 | |
Jens Axboe | 675de85 | 2007-02-10 19:01:07 +0100 | [diff] [blame] | 117 | *val = strtoll(str, NULL, 10); |
Jens Axboe | cda866c | 2007-01-10 16:02:32 +0100 | [diff] [blame] | 118 | if (*val == LONG_MAX && errno == ERANGE) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 119 | return 1; |
| 120 | |
| 121 | if (kilo) |
| 122 | *val *= get_mult_bytes(str[len - 1]); |
| 123 | else |
| 124 | *val *= get_mult_time(str[len - 1]); |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 125 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 126 | return 0; |
| 127 | } |
| 128 | |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 129 | static int check_str_bytes(const char *p, long long *val) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 130 | { |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 131 | return str_to_decimal(p, val, 1); |
| 132 | } |
| 133 | |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 134 | static int check_str_time(const char *p, long long *val) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 135 | { |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 136 | return str_to_decimal(p, val, 0); |
| 137 | } |
| 138 | |
| 139 | void strip_blank_front(char **p) |
| 140 | { |
| 141 | char *s = *p; |
| 142 | |
| 143 | while (isspace(*s)) |
| 144 | s++; |
Jens Axboe | 4d651da | 2007-03-28 19:34:53 +0200 | [diff] [blame] | 145 | |
| 146 | *p = s; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | void strip_blank_end(char *p) |
| 150 | { |
Jens Axboe | 523bfad | 2007-04-04 11:04:06 +0200 | [diff] [blame] | 151 | char *s; |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 152 | |
Jens Axboe | 523bfad | 2007-04-04 11:04:06 +0200 | [diff] [blame] | 153 | s = strchr(p, ';'); |
| 154 | if (s) |
| 155 | *s = '\0'; |
| 156 | s = strchr(p, '#'); |
| 157 | if (s) |
| 158 | *s = '\0'; |
| 159 | if (s) |
| 160 | p = s; |
| 161 | |
Jens Axboe | 7f7e6e5 | 2007-07-19 14:50:05 +0200 | [diff] [blame] | 162 | s = p + strlen(p); |
| 163 | while ((isspace(*s) || iscntrl(*s)) && (s > p)) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 164 | s--; |
| 165 | |
| 166 | *(s + 1) = '\0'; |
| 167 | } |
| 168 | |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 169 | static int check_range_bytes(const char *str, long *val) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 170 | { |
| 171 | char suffix; |
| 172 | |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 173 | if (!strlen(str)) |
| 174 | return 1; |
| 175 | |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 176 | if (sscanf(str, "%lu%c", val, &suffix) == 2) { |
| 177 | *val *= get_mult_bytes(suffix); |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | if (sscanf(str, "%lu", val) == 1) |
| 182 | return 0; |
| 183 | |
| 184 | return 1; |
| 185 | } |
| 186 | |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 187 | static int check_int(const char *p, int *val) |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 188 | { |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 189 | if (!strlen(p)) |
| 190 | return 1; |
Jens Axboe | a61bdfd | 2007-07-30 09:07:04 +0200 | [diff] [blame] | 191 | if (strstr(p, "0x")) { |
| 192 | if (sscanf(p, "%x", val) == 1) |
| 193 | return 0; |
| 194 | } else { |
| 195 | if (sscanf(p, "%u", val) == 1) |
| 196 | return 0; |
| 197 | } |
Jens Axboe | cb2c86f | 2006-10-26 13:48:34 +0200 | [diff] [blame] | 198 | |
| 199 | return 1; |
| 200 | } |
| 201 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 202 | static struct fio_option *find_option(struct fio_option *options, |
| 203 | const char *opt) |
| 204 | { |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 205 | struct fio_option *o; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 206 | |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 207 | for (o = &options[0]; o->name; o++) { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 208 | if (!strcmp(o->name, opt)) |
| 209 | return o; |
Jens Axboe | 03b74b3 | 2007-01-11 11:04:31 +0100 | [diff] [blame] | 210 | else if (o->alias && !strcmp(o->alias, opt)) |
| 211 | return o; |
Jens Axboe | 33963c6 | 2006-10-27 11:33:01 +0200 | [diff] [blame] | 212 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 213 | |
| 214 | return NULL; |
| 215 | } |
| 216 | |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 217 | #define val_store(ptr, val, off, data) \ |
| 218 | do { \ |
| 219 | ptr = td_var((data), (off)); \ |
| 220 | *ptr = (val); \ |
| 221 | } while (0) |
| 222 | |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 223 | static int __handle_option(struct fio_option *o, const char *ptr, void *data, |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 224 | int first, int more) |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 225 | { |
Jens Axboe | 63f2937 | 2007-01-10 13:20:09 +0100 | [diff] [blame] | 226 | int il, *ilp; |
| 227 | long long ull, *ullp; |
| 228 | long ul1, ul2; |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 229 | char **cp; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 230 | int ret = 0, is_time = 0; |
| 231 | |
Jens Axboe | 08e26e3 | 2006-11-21 13:15:10 +0100 | [diff] [blame] | 232 | if (!ptr && o->type != FIO_OPT_STR_SET) { |
| 233 | fprintf(stderr, "Option %s requires an argument\n", o->name); |
| 234 | return 1; |
| 235 | } |
| 236 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 237 | switch (o->type) { |
| 238 | case FIO_OPT_STR: { |
| 239 | fio_opt_str_fn *fn = o->cb; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 240 | const struct value_pair *vp; |
Jens Axboe | f085737 | 2007-03-19 13:15:23 +0100 | [diff] [blame] | 241 | struct value_pair posval[PARSE_MAX_VP]; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 242 | int i; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 243 | |
Jens Axboe | f085737 | 2007-03-19 13:15:23 +0100 | [diff] [blame] | 244 | posval_sort(o, posval); |
| 245 | |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 246 | for (i = 0; i < PARSE_MAX_VP; i++) { |
Jens Axboe | f085737 | 2007-03-19 13:15:23 +0100 | [diff] [blame] | 247 | vp = &posval[i]; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 248 | if (!vp->ival || vp->ival[0] == '\0') |
| 249 | break; |
Jens Axboe | 6612a27 | 2007-03-13 08:54:06 +0100 | [diff] [blame] | 250 | ret = 1; |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 251 | if (!strncmp(vp->ival, ptr, strlen(vp->ival))) { |
| 252 | ret = 0; |
| 253 | if (!o->off1) |
| 254 | break; |
| 255 | val_store(ilp, vp->oval, o->off1, data); |
| 256 | break; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | if (ret) |
| 261 | show_option_values(o); |
| 262 | else if (fn) |
| 263 | ret = fn(data, ptr); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 264 | break; |
| 265 | } |
| 266 | case FIO_OPT_STR_VAL_TIME: |
| 267 | is_time = 1; |
Jens Axboe | 75e6f36 | 2006-11-03 08:17:09 +0100 | [diff] [blame] | 268 | case FIO_OPT_STR_VAL: |
| 269 | case FIO_OPT_STR_VAL_INT: { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 270 | fio_opt_str_val_fn *fn = o->cb; |
| 271 | |
| 272 | if (is_time) |
| 273 | ret = check_str_time(ptr, &ull); |
| 274 | else |
| 275 | ret = check_str_bytes(ptr, &ull); |
| 276 | |
| 277 | if (ret) |
| 278 | break; |
| 279 | |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 280 | if (o->maxval && ull > o->maxval) { |
| 281 | fprintf(stderr, "max value out of range: %lld (%d max)\n", ull, o->maxval); |
| 282 | return 1; |
| 283 | } |
| 284 | if (o->minval && ull < o->minval) { |
| 285 | fprintf(stderr, "min value out of range: %lld (%d min)\n", ull, o->minval); |
| 286 | return 1; |
| 287 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 288 | |
| 289 | if (fn) |
| 290 | ret = fn(data, &ull); |
| 291 | else { |
Jens Axboe | 75e6f36 | 2006-11-03 08:17:09 +0100 | [diff] [blame] | 292 | if (o->type == FIO_OPT_STR_VAL_INT) { |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 293 | if (first) |
| 294 | val_store(ilp, ull, o->off1, data); |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 295 | if (!more && o->off2) |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 296 | val_store(ilp, ull, o->off2, data); |
Jens Axboe | 75e6f36 | 2006-11-03 08:17:09 +0100 | [diff] [blame] | 297 | } else { |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 298 | if (first) |
| 299 | val_store(ullp, ull, o->off1, data); |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 300 | if (!more && o->off2) |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 301 | val_store(ullp, ull, o->off2, data); |
Jens Axboe | 75e6f36 | 2006-11-03 08:17:09 +0100 | [diff] [blame] | 302 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 303 | } |
| 304 | break; |
| 305 | } |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 306 | case FIO_OPT_STR_STORE: { |
| 307 | fio_opt_str_fn *fn = o->cb; |
| 308 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 309 | cp = td_var(data, o->off1); |
| 310 | *cp = strdup(ptr); |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 311 | if (fn) { |
| 312 | ret = fn(data, ptr); |
| 313 | if (ret) { |
| 314 | free(*cp); |
| 315 | *cp = NULL; |
| 316 | } |
| 317 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 318 | break; |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 319 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 320 | case FIO_OPT_RANGE: { |
Jens Axboe | b765a37 | 2006-10-27 15:00:16 +0200 | [diff] [blame] | 321 | char tmp[128]; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 322 | char *p1, *p2; |
| 323 | |
Jens Axboe | 0bbab0e | 2006-11-02 09:18:36 +0100 | [diff] [blame] | 324 | strncpy(tmp, ptr, sizeof(tmp) - 1); |
Jens Axboe | b765a37 | 2006-10-27 15:00:16 +0200 | [diff] [blame] | 325 | |
| 326 | p1 = strchr(tmp, '-'); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 327 | if (!p1) { |
Jens Axboe | 0c9baf9 | 2007-01-11 15:59:26 +0100 | [diff] [blame] | 328 | p1 = strchr(tmp, ':'); |
| 329 | if (!p1) { |
| 330 | ret = 1; |
| 331 | break; |
| 332 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | p2 = p1 + 1; |
| 336 | *p1 = '\0'; |
Jens Axboe | b765a37 | 2006-10-27 15:00:16 +0200 | [diff] [blame] | 337 | p1 = tmp; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 338 | |
| 339 | ret = 1; |
| 340 | if (!check_range_bytes(p1, &ul1) && !check_range_bytes(p2, &ul2)) { |
| 341 | ret = 0; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 342 | if (ul1 > ul2) { |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 343 | unsigned long foo = ul1; |
| 344 | |
| 345 | ul1 = ul2; |
| 346 | ul2 = foo; |
| 347 | } |
| 348 | |
| 349 | if (first) { |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 350 | val_store(ilp, ul1, o->off1, data); |
| 351 | val_store(ilp, ul2, o->off2, data); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 352 | } |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 353 | if (!more && o->off3 && o->off4) { |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 354 | val_store(ilp, ul1, o->off3, data); |
| 355 | val_store(ilp, ul2, o->off4, data); |
| 356 | } |
| 357 | } |
| 358 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 359 | break; |
| 360 | } |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 361 | case FIO_OPT_INT: |
| 362 | case FIO_OPT_BOOL: { |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 363 | fio_opt_int_fn *fn = o->cb; |
| 364 | |
| 365 | ret = check_int(ptr, &il); |
| 366 | if (ret) |
| 367 | break; |
| 368 | |
Jens Axboe | db8e016 | 2007-01-10 13:41:26 +0100 | [diff] [blame] | 369 | if (o->maxval && il > (int) o->maxval) { |
| 370 | fprintf(stderr, "max value out of range: %d (%d max)\n", il, o->maxval); |
| 371 | return 1; |
| 372 | } |
| 373 | if (o->minval && il < o->minval) { |
| 374 | fprintf(stderr, "min value out of range: %d (%d min)\n", il, o->minval); |
| 375 | return 1; |
| 376 | } |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 377 | |
Jens Axboe | 76a43db | 2007-01-11 13:24:44 +0100 | [diff] [blame] | 378 | if (o->neg) |
| 379 | il = !il; |
| 380 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 381 | if (fn) |
| 382 | ret = fn(data, &il); |
| 383 | else { |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 384 | if (first) |
| 385 | val_store(ilp, il, o->off1, data); |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 386 | if (!more && o->off2) |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 387 | val_store(ilp, il, o->off2, data); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 388 | } |
| 389 | break; |
| 390 | } |
| 391 | case FIO_OPT_STR_SET: { |
| 392 | fio_opt_str_set_fn *fn = o->cb; |
| 393 | |
| 394 | if (fn) |
| 395 | ret = fn(data); |
| 396 | else { |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 397 | if (first) |
| 398 | val_store(ilp, 1, o->off1, data); |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 399 | if (!more && o->off2) |
Jens Axboe | 17abbe8 | 2006-11-06 11:23:10 +0100 | [diff] [blame] | 400 | val_store(ilp, 1, o->off2, data); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 401 | } |
| 402 | break; |
| 403 | } |
| 404 | default: |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 405 | fprintf(stderr, "Bad option type %u\n", o->type); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 406 | ret = 1; |
| 407 | } |
| 408 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 409 | return ret; |
| 410 | } |
| 411 | |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 412 | static int handle_option(struct fio_option *o, const char *ptr, void *data) |
| 413 | { |
Jens Axboe | 92b586f | 2006-11-07 14:29:17 +0100 | [diff] [blame] | 414 | const char *ptr2 = NULL; |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 415 | int r1, r2; |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 416 | |
| 417 | /* |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 418 | * See if we have a second set of parameters, hidden after a comma. |
| 419 | * Do this before parsing the first round, to check if we should |
| 420 | * copy set 1 options to set 2. |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 421 | */ |
Joel Becker | ad231bc | 2007-03-01 08:22:42 +0100 | [diff] [blame] | 422 | if (ptr && |
| 423 | (o->type != FIO_OPT_STR_STORE) && |
| 424 | (o->type != FIO_OPT_STR)) { |
Jens Axboe | 92b586f | 2006-11-07 14:29:17 +0100 | [diff] [blame] | 425 | ptr2 = strchr(ptr, ','); |
Jens Axboe | 0c9baf9 | 2007-01-11 15:59:26 +0100 | [diff] [blame] | 426 | if (!ptr2) |
| 427 | ptr2 = strchr(ptr, ':'); |
Jens Axboe | b486f76 | 2007-03-15 09:15:12 +0100 | [diff] [blame] | 428 | if (!ptr2) |
| 429 | ptr2 = strchr(ptr, '-'); |
Jens Axboe | 0c9baf9 | 2007-01-11 15:59:26 +0100 | [diff] [blame] | 430 | } |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 431 | |
| 432 | /* |
| 433 | * Don't return early if parsing the first option fails - if |
| 434 | * we are doing multiple arguments, we can allow the first one |
| 435 | * being empty. |
| 436 | */ |
| 437 | r1 = __handle_option(o, ptr, data, 1, !!ptr2); |
| 438 | |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 439 | if (!ptr2) |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 440 | return r1; |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 441 | |
| 442 | ptr2++; |
Jens Axboe | 787f7e9 | 2006-11-06 13:26:29 +0100 | [diff] [blame] | 443 | r2 = __handle_option(o, ptr2, data, 0, 0); |
| 444 | |
| 445 | return r1 && r2; |
Jens Axboe | f90eff5 | 2006-11-06 11:08:21 +0100 | [diff] [blame] | 446 | } |
| 447 | |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 448 | int parse_cmd_option(const char *opt, const char *val, |
| 449 | struct fio_option *options, void *data) |
| 450 | { |
| 451 | struct fio_option *o; |
| 452 | |
| 453 | o = find_option(options, opt); |
| 454 | if (!o) { |
| 455 | fprintf(stderr, "Bad option %s\n", opt); |
| 456 | return 1; |
| 457 | } |
| 458 | |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 459 | if (!handle_option(o, val, data)) |
| 460 | return 0; |
| 461 | |
| 462 | fprintf(stderr, "fio: failed parsing %s=%s\n", opt, val); |
| 463 | return 1; |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 464 | } |
| 465 | |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 466 | int parse_option(const char *opt, struct fio_option *options, void *data) |
| 467 | { |
Jens Axboe | b469282 | 2006-10-27 13:43:22 +0200 | [diff] [blame] | 468 | struct fio_option *o; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 469 | char *pre, *post; |
Jens Axboe | 0401bca | 2007-03-29 11:00:43 +0200 | [diff] [blame] | 470 | char *tmp; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 471 | |
Jens Axboe | 0401bca | 2007-03-29 11:00:43 +0200 | [diff] [blame] | 472 | tmp = strdup(opt); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 473 | |
| 474 | pre = strchr(tmp, '='); |
| 475 | if (pre) { |
| 476 | post = pre; |
| 477 | *pre = '\0'; |
| 478 | pre = tmp; |
| 479 | post++; |
| 480 | o = find_option(options, pre); |
| 481 | } else { |
| 482 | o = find_option(options, tmp); |
| 483 | post = NULL; |
| 484 | } |
| 485 | |
| 486 | if (!o) { |
| 487 | fprintf(stderr, "Bad option %s\n", tmp); |
Jens Axboe | 0401bca | 2007-03-29 11:00:43 +0200 | [diff] [blame] | 488 | free(tmp); |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 489 | return 1; |
| 490 | } |
| 491 | |
Jens Axboe | 0401bca | 2007-03-29 11:00:43 +0200 | [diff] [blame] | 492 | if (!handle_option(o, post, data)) { |
| 493 | free(tmp); |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 494 | return 0; |
Jens Axboe | 0401bca | 2007-03-29 11:00:43 +0200 | [diff] [blame] | 495 | } |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 496 | |
| 497 | fprintf(stderr, "fio: failed parsing %s\n", opt); |
Jens Axboe | 0401bca | 2007-03-29 11:00:43 +0200 | [diff] [blame] | 498 | free(tmp); |
Jens Axboe | b1508cf | 2006-11-02 09:12:40 +0100 | [diff] [blame] | 499 | return 1; |
Jens Axboe | e1f3650 | 2006-10-27 10:54:08 +0200 | [diff] [blame] | 500 | } |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 501 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 502 | /* |
| 503 | * Option match, levenshtein distance. Handy for not quite remembering what |
| 504 | * the option name is. |
| 505 | */ |
| 506 | static int string_distance(const char *s1, const char *s2) |
| 507 | { |
| 508 | unsigned int s1_len = strlen(s1); |
| 509 | unsigned int s2_len = strlen(s2); |
| 510 | unsigned int *p, *q, *r; |
| 511 | unsigned int i, j; |
| 512 | |
| 513 | p = malloc(sizeof(unsigned int) * (s2_len + 1)); |
| 514 | q = malloc(sizeof(unsigned int) * (s2_len + 1)); |
| 515 | |
| 516 | p[0] = 0; |
| 517 | for (i = 1; i <= s2_len; i++) |
| 518 | p[i] = p[i - 1] + 1; |
| 519 | |
| 520 | for (i = 1; i <= s1_len; i++) { |
| 521 | q[0] = p[0] + 1; |
| 522 | for (j = 1; j <= s2_len; j++) { |
| 523 | unsigned int sub = p[j - 1]; |
| 524 | |
| 525 | if (s1[i - 1] != s2[j - 1]) |
| 526 | sub++; |
| 527 | |
| 528 | q[j] = min(p[j] + 1, min(q[j - 1] + 1, sub)); |
| 529 | } |
| 530 | r = p; |
| 531 | p = q; |
| 532 | q = r; |
| 533 | } |
| 534 | |
| 535 | i = p[s2_len]; |
| 536 | free(p); |
| 537 | free(q); |
| 538 | return i; |
| 539 | } |
| 540 | |
| 541 | static void show_option_help(struct fio_option *o) |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 542 | { |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 543 | const char *typehelp[] = { |
| 544 | "string (opt=bla)", |
| 545 | "string with possible k/m/g postfix (opt=4k)", |
| 546 | "string with range and postfix (opt=1k-4k)", |
| 547 | "string with time postfix (opt=10s)", |
| 548 | "string (opt=bla)", |
| 549 | "string with dual range (opt=1k-4k,4k-8k)", |
| 550 | "integer value (opt=100)", |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 551 | "boolean value (opt=1)", |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 552 | "no argument (opt)", |
| 553 | }; |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 554 | |
Jens Axboe | d2bb7fe | 2007-03-15 14:11:38 +0100 | [diff] [blame] | 555 | if (o->alias) |
| 556 | printf("%20s: %s\n", "alias", o->alias); |
| 557 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 558 | printf("%20s: %s\n", "type", typehelp[o->type]); |
| 559 | printf("%20s: %s\n", "default", o->def ? o->def : "no default"); |
| 560 | show_option_range(o); |
| 561 | show_option_values(o); |
| 562 | } |
| 563 | |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 564 | static struct fio_option *find_child(struct fio_option *options, |
| 565 | struct fio_option *o) |
| 566 | { |
| 567 | struct fio_option *__o; |
| 568 | |
Jens Axboe | ef9aff5 | 2007-07-31 22:56:53 +0200 | [diff] [blame^] | 569 | for (__o = &options[0]; __o->name; __o++) { |
| 570 | if (__o->parent && !strcmp(__o->parent, o->name) |
| 571 | && !__o->parent_seen) { |
| 572 | __o->parent_seen = 1; |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 573 | return __o; |
Jens Axboe | ef9aff5 | 2007-07-31 22:56:53 +0200 | [diff] [blame^] | 574 | } |
| 575 | } |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 576 | |
| 577 | return NULL; |
| 578 | } |
| 579 | |
| 580 | static void print_option(struct fio_option *options, struct fio_option *o, |
Jens Axboe | ef9aff5 | 2007-07-31 22:56:53 +0200 | [diff] [blame^] | 581 | struct fio_option *org, int level) |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 582 | { |
| 583 | char name[256], *p; |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 584 | |
| 585 | if (!o) |
| 586 | return; |
Jens Axboe | ef9aff5 | 2007-07-31 22:56:53 +0200 | [diff] [blame^] | 587 | if (!org) |
| 588 | org = o; |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 589 | |
| 590 | p = name; |
Jens Axboe | ef9aff5 | 2007-07-31 22:56:53 +0200 | [diff] [blame^] | 591 | if (level) |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 592 | p += sprintf(p, "%s", " "); |
| 593 | |
| 594 | sprintf(p, "%s", o->name); |
| 595 | |
| 596 | printf("%-24s: %s\n", name, o->help); |
Jens Axboe | ef9aff5 | 2007-07-31 22:56:53 +0200 | [diff] [blame^] | 597 | print_option(options, find_child(options, org), org, level + 1); |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 598 | } |
| 599 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 600 | int show_cmd_help(struct fio_option *options, const char *name) |
| 601 | { |
| 602 | struct fio_option *o, *closest; |
| 603 | unsigned int best_dist; |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 604 | int found = 0; |
Jens Axboe | 320beef | 2007-03-01 10:44:12 +0100 | [diff] [blame] | 605 | int show_all = 0; |
| 606 | |
| 607 | if (!name || !strcmp(name, "all")) |
| 608 | show_all = 1; |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 609 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 610 | closest = NULL; |
| 611 | best_dist = -1; |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 612 | for (o = &options[0]; o->name; o++) { |
Jens Axboe | 320beef | 2007-03-01 10:44:12 +0100 | [diff] [blame] | 613 | int match = 0; |
| 614 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 615 | if (name) { |
Jens Axboe | 7f9348f | 2007-03-15 14:09:28 +0100 | [diff] [blame] | 616 | if (!strcmp(name, o->name) || |
| 617 | (o->alias && !strcmp(name, o->alias))) |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 618 | match = 1; |
| 619 | else { |
| 620 | unsigned int dist; |
| 621 | |
| 622 | dist = string_distance(name, o->name); |
| 623 | if (dist < best_dist) { |
| 624 | best_dist = dist; |
| 625 | closest = o; |
| 626 | } |
| 627 | } |
| 628 | } |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 629 | |
| 630 | if (show_all || match) { |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 631 | found = 1; |
Jens Axboe | c167ded | 2007-03-14 13:02:53 +0100 | [diff] [blame] | 632 | if (match) |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 633 | printf("%24s: %s\n", o->name, o->help); |
Jens Axboe | c167ded | 2007-03-14 13:02:53 +0100 | [diff] [blame] | 634 | if (show_all) { |
Jens Axboe | afdf935 | 2007-07-31 16:14:34 +0200 | [diff] [blame] | 635 | if (!o->parent) |
Jens Axboe | ef9aff5 | 2007-07-31 22:56:53 +0200 | [diff] [blame^] | 636 | print_option(options, o, NULL, 0); |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 637 | continue; |
Jens Axboe | c167ded | 2007-03-14 13:02:53 +0100 | [diff] [blame] | 638 | } |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 639 | } |
| 640 | |
Jens Axboe | 70df2f1 | 2007-01-11 14:04:47 +0100 | [diff] [blame] | 641 | if (!match) |
| 642 | continue; |
| 643 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 644 | show_option_help(o); |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 645 | } |
| 646 | |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 647 | if (found) |
| 648 | return 0; |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 649 | |
Jens Axboe | 0e9f7fa | 2007-03-01 14:05:30 +0100 | [diff] [blame] | 650 | printf("No such command: %s", name); |
| 651 | if (closest) { |
| 652 | printf(" - showing closest match\n"); |
| 653 | printf("%20s: %s\n", closest->name, closest->help); |
| 654 | show_option_help(closest); |
| 655 | } else |
| 656 | printf("\n"); |
| 657 | |
Jens Axboe | 29fc6af | 2007-01-09 21:22:02 +0100 | [diff] [blame] | 658 | return 1; |
Jens Axboe | fd28ca4 | 2007-01-09 21:20:13 +0100 | [diff] [blame] | 659 | } |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 660 | |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 661 | /* |
| 662 | * Handle parsing of default parameters. |
| 663 | */ |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 664 | void fill_default_options(void *data, struct fio_option *options) |
| 665 | { |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 666 | struct fio_option *o; |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 667 | |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 668 | for (o = &options[0]; o->name; o++) |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 669 | if (o->def) |
| 670 | handle_option(o, o->def, data); |
Jens Axboe | ee73849 | 2007-01-10 11:23:16 +0100 | [diff] [blame] | 671 | } |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 672 | |
| 673 | /* |
| 674 | * Sanitize the options structure. For now it just sets min/max for bool |
Jens Axboe | 5b0a888 | 2007-01-11 14:40:27 +0100 | [diff] [blame] | 675 | * values and whether both callback and offsets are given. |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 676 | */ |
| 677 | void options_init(struct fio_option *options) |
| 678 | { |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 679 | struct fio_option *o; |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 680 | |
Jens Axboe | 4945ba1 | 2007-01-11 14:36:56 +0100 | [diff] [blame] | 681 | for (o = &options[0]; o->name; o++) { |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 682 | if (o->type == FIO_OPT_BOOL) { |
| 683 | o->minval = 0; |
| 684 | o->maxval = 1; |
| 685 | } |
Jens Axboe | 0f3e35e | 2007-03-20 14:28:34 +0100 | [diff] [blame] | 686 | if (o->type == FIO_OPT_STR_SET && o->def) |
| 687 | fprintf(stderr, "Option %s: string set option with default will always be true\n", o->name); |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 688 | if (!o->cb && !o->off1) |
| 689 | fprintf(stderr, "Option %s: neither cb nor offset given\n", o->name); |
Jens Axboe | af52b34 | 2007-03-13 10:07:47 +0100 | [diff] [blame] | 690 | if (o->type == FIO_OPT_STR || o->type == FIO_OPT_STR_STORE) |
Jens Axboe | b1ec1da | 2007-02-23 10:29:16 +0100 | [diff] [blame] | 691 | continue; |
Jens Axboe | 5b0a888 | 2007-01-11 14:40:27 +0100 | [diff] [blame] | 692 | if (o->cb && (o->off1 || o->off2 || o->off3 || o->off4)) |
| 693 | fprintf(stderr, "Option %s: both cb and offset given\n", o->name); |
Jens Axboe | 13335dd | 2007-01-10 13:14:02 +0100 | [diff] [blame] | 694 | } |
| 695 | } |