| | 557 | | static int get_cmd_options(char **data, int ignore_unknown, |
| | 558 | | const char *cmd, GHashTable *options) |
| | 559 | | { |
| | 560 | | COMMAND_REC *rec; |
| | 561 | | char *option, *arg, **optlist; |
| | 562 | | int pos; |
| | 563 | | |
| | 564 | | |
| | 565 | | rec = cmd == NULL ? NULL : command_find(cmd);
|
| true | 566 | | optlist = rec == NULL ? NULL : rec->options;
|
| | 567 | | |
| | 568 | | option = NULL; pos = -1;
|
| | 569 | | for (;;) { |
| | 570 | | if (**data == '-') { |
| optlist <= 4095 | 571 | | if (option != NULL && *optlist[pos] == '+') {
|
| | 572 | | |
| | 573 | | *data = optlist[pos] + 1; |
| | 574 | | return CMDERR_OPTION_ARG_MISSING; |
| | 575 | | } |
| | 576 | | |
| | 577 | | (*data)++; |
| | 578 | | if (**data == '-' && (*data)[1] == ' ') { |
| | 579 | | |
| | 580 | | |
| | 581 | | (*data)++; |
| | 582 | | while (**data == ' ') (*data)++; |
| | 583 | | break; |
| | 584 | | } |
| | 585 | | |
| | 586 | | if (**data == '\0') |
| | 587 | | option = "-"; |
| | 588 | | else if (**data != ' ') |
| | 589 | | option = cmd_get_param(data); |
| | 590 | | else { |
| | 591 | | option = "-"; |
| | 592 | | (*data)++; |
| | 593 | | } |
| | 594 | | |
| | 595 | | |
| | 596 | | pos = optlist == NULL ? -1 :
|
| | 597 | | option_find(optlist, option); |
| | 598 | | |
| | 599 | | if (pos == -1 && optlist != NULL &&
|
| | 600 | | is_numeric(option, '\0')) { |
| | 601 | | |
| | 602 | | pos = option_find(optlist, "#"); |
| | 603 | | if (pos != -1) { |
| | 604 | | g_hash_table_insert(options, "#", |
| | 605 | | option); |
| | 606 | | pos = -3; |
| | 607 | | } |
| | 608 | | } |
| | 609 | | |
| | 610 | | if (pos == -1 && !ignore_unknown) { |
| | 611 | | |
| | 612 | | *data = option; |
| | 613 | | return CMDERR_OPTION_UNKNOWN; |
| | 614 | | } |
| | 615 | | if (pos == -2 && !ignore_unknown) { |
| | 616 | | |
| | 617 | | *data = option; |
| | 618 | | return CMDERR_OPTION_AMBIGUOUS; |
| | 619 | | } |
| | 620 | | if (pos >= 0) { |
| | 621 | | |
| | 622 | | |
| | 623 | | option = optlist[pos] + |
| | 624 | | iscmdtype(*optlist[pos]);
|
| | 625 | | } |
| | 626 | | if (options != NULL && pos != -3)
|
| | 627 | | g_hash_table_insert(options, option, ""); |
| | 628 | | |
| | 629 | | if (pos < 0 || !iscmdtype(*optlist[pos]) ||
|
| | 630 | | *optlist[pos] == '!') |
| | 631 | | option = NULL;
|
| | 632 | | |
| | 633 | | while (**data == ' ') (*data)++; |
| | 634 | | continue; |
| | 635 | | } |
| | 636 | | |
| | 637 | | if (option == NULL)
|
| | 638 | | break; |
| | 639 | | |
| | 640 | | if (*optlist[pos] == '@' && !is_numeric(*data, ' ')) |
| | 641 | | break; |
| | 642 | | |
| | 643 | | |
| | 644 | | arg = cmd_get_quoted_param(data); |
| | 645 | | if (options != NULL) {
|
| | 646 | | g_hash_table_remove(options, option); |
| | 647 | | g_hash_table_insert(options, option, arg); |
| | 648 | | } |
| | 649 | | option = NULL;
|
| | 650 | | |
| | 651 | | while (**data == ' ') (*data)++; |