* Find the next token in the string, starting at offset *startp. * Returns the token type, with *startp pointing to the first char * and *lenp the length. */
| 1677 | * and *lenp the length. |
| 1678 | */ |
| 1679 | enum ng_parse_token |
| 1680 | ng_parse_get_token(const char *s, int *startp, int *lenp) |
| 1681 | { |
| 1682 | char *t; |
| 1683 | int i; |
| 1684 | |
| 1685 | while (isspace(s[*startp])) |
| 1686 | (*startp)++; |
| 1687 | switch (s[*startp]) { |
| 1688 | case '\0': |
| 1689 | *lenp = 0; |
| 1690 | return T_EOF; |
| 1691 | case '{': |
| 1692 | *lenp = 1; |
| 1693 | return T_LBRACE; |
| 1694 | case '}': |
| 1695 | *lenp = 1; |
| 1696 | return T_RBRACE; |
| 1697 | case '[': |
| 1698 | *lenp = 1; |
| 1699 | return T_LBRACKET; |
| 1700 | case ']': |
| 1701 | *lenp = 1; |
| 1702 | return T_RBRACKET; |
| 1703 | case '=': |
| 1704 | *lenp = 1; |
| 1705 | return T_EQUALS; |
| 1706 | case '"': |
| 1707 | if ((t = ng_get_string_token(s, startp, lenp, NULL)) == NULL) |
| 1708 | return T_ERROR; |
| 1709 | free(t, M_NETGRAPH_PARSE); |
| 1710 | return T_STRING; |
| 1711 | default: |
| 1712 | for (i = *startp + 1; s[i] != '\0' && !isspace(s[i]) |
| 1713 | && s[i] != '{' && s[i] != '}' && s[i] != '[' |
| 1714 | && s[i] != ']' && s[i] != '=' && s[i] != '"'; i++) |
| 1715 | ; |
| 1716 | *lenp = i - *startp; |
| 1717 | return T_WORD; |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | /* |
| 1722 | * Get a string token, which must be enclosed in double quotes. |
no test coverage detected