| 376 | |
| 377 | #define ALLSTRLEN 64 |
| 378 | static int |
| 379 | fiboptlist_csv(const char *arg, struct fibl_head_t *flh) |
| 380 | { |
| 381 | struct fibl *fl; |
| 382 | char *str0, *str, *token, *endptr; |
| 383 | int fib, error; |
| 384 | |
| 385 | str0 = str = NULL; |
| 386 | if (strcmp("all", arg) == 0) { |
| 387 | str = calloc(1, ALLSTRLEN); |
| 388 | if (str == NULL) { |
| 389 | error = 1; |
| 390 | goto fiboptlist_csv_ret; |
| 391 | } |
| 392 | if (numfibs > 1) |
| 393 | snprintf(str, ALLSTRLEN - 1, "%d-%d", 0, numfibs - 1); |
| 394 | else |
| 395 | snprintf(str, ALLSTRLEN - 1, "%d", 0); |
| 396 | } else if (strcmp("default", arg) == 0) { |
| 397 | str0 = str = calloc(1, ALLSTRLEN); |
| 398 | if (str == NULL) { |
| 399 | error = 1; |
| 400 | goto fiboptlist_csv_ret; |
| 401 | } |
| 402 | snprintf(str, ALLSTRLEN - 1, "%d", defaultfib); |
| 403 | } else |
| 404 | str0 = str = strdup(arg); |
| 405 | |
| 406 | error = 0; |
| 407 | while ((token = strsep(&str, ",")) != NULL) { |
| 408 | if (*token != '-' && strchr(token, '-') != NULL) { |
| 409 | error = fiboptlist_range(token, flh); |
| 410 | if (error) |
| 411 | goto fiboptlist_csv_ret; |
| 412 | } else { |
| 413 | errno = 0; |
| 414 | fib = strtol(token, &endptr, 0); |
| 415 | if (errno == 0) { |
| 416 | if (*endptr != '\0' || |
| 417 | fib < 0 || |
| 418 | (numfibs != -1 && fib > numfibs - 1)) |
| 419 | errno = EINVAL; |
| 420 | } |
| 421 | if (errno) { |
| 422 | error = 1; |
| 423 | goto fiboptlist_csv_ret; |
| 424 | } |
| 425 | fl = calloc(1, sizeof(*fl)); |
| 426 | if (fl == NULL) { |
| 427 | error = 1; |
| 428 | goto fiboptlist_csv_ret; |
| 429 | } |
| 430 | fl->fl_num = fib; |
| 431 | TAILQ_INSERT_TAIL(flh, fl, fl_next); |
| 432 | } |
| 433 | } |
| 434 | fiboptlist_csv_ret: |
| 435 | if (str0 != NULL) |