* Obtain the token, value, and conf from the given trailer. * * separator_pos must not be 0, since the token cannot be an empty string. * * If separator_pos is -1, interpret the whole trailer as a token. */
| 656 | * If separator_pos is -1, interpret the whole trailer as a token. |
| 657 | */ |
| 658 | static void parse_trailer(struct strbuf *tok, struct strbuf *val, |
| 659 | const struct conf_info **conf, const char *trailer, |
| 660 | ssize_t separator_pos) |
| 661 | { |
| 662 | struct arg_item *item; |
| 663 | size_t tok_len; |
| 664 | struct list_head *pos; |
| 665 | |
| 666 | if (separator_pos != -1) { |
| 667 | strbuf_add(tok, trailer, separator_pos); |
| 668 | strbuf_trim(tok); |
| 669 | strbuf_addstr(val, trailer + separator_pos + 1); |
| 670 | strbuf_trim(val); |
| 671 | } else { |
| 672 | strbuf_addstr(tok, trailer); |
| 673 | strbuf_trim(tok); |
| 674 | } |
| 675 | |
| 676 | /* Lookup if the token matches something in the config */ |
| 677 | tok_len = token_len_without_separator(tok->buf, tok->len); |
| 678 | if (conf) |
| 679 | *conf = &default_conf_info; |
| 680 | list_for_each(pos, &conf_head) { |
| 681 | item = list_entry(pos, struct arg_item, list); |
| 682 | if (token_matches_item(tok->buf, item, tok_len)) { |
| 683 | char *tok_buf = strbuf_detach(tok, NULL); |
| 684 | if (conf) |
| 685 | *conf = &item->conf; |
| 686 | strbuf_addstr(tok, token_from_item(item, tok_buf)); |
| 687 | free(tok_buf); |
| 688 | break; |
| 689 | } |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | static struct trailer_item *add_trailer_item(struct list_head *head, char *tok, |
| 694 | char *val) |
no test coverage detected