* match_token_relaxed takes a table and a string, returns the value associated * with the string for the best match. * * Returns: * value from @table for matched records * -1 for non-matched records * -2 if more than one records match @string. */
| 694 | * -2 if more than one records match @string. |
| 695 | */ |
| 696 | int |
| 697 | match_token_relaxed(struct _s_x *table, const char *string) |
| 698 | { |
| 699 | struct _s_x *pt, *m; |
| 700 | int i, c; |
| 701 | |
| 702 | i = strlen(string); |
| 703 | c = 0; |
| 704 | |
| 705 | for (pt = table ; i != 0 && pt->s != NULL ; pt++) { |
| 706 | if (strncmp(pt->s, string, i) != 0) |
| 707 | continue; |
| 708 | m = pt; |
| 709 | c++; |
| 710 | } |
| 711 | |
| 712 | if (c == 1) |
| 713 | return (m->x); |
| 714 | |
| 715 | return (c > 0 ? -2: -1); |
| 716 | } |
| 717 | |
| 718 | int |
| 719 | get_token(struct _s_x *table, const char *string, const char *errbase) |