MCPcopy Index your code
hub / github.com/F-Stack/f-stack / ng_get_string_token

Function ng_get_string_token

freebsd/netgraph/ng_parse.c:1725–1806  ·  view source on GitHub ↗

* Get a string token, which must be enclosed in double quotes. * The normal C backslash escapes are recognized. */

Source from the content-addressed store, hash-verified

1723 * The normal C backslash escapes are recognized.
1724 */
1725char *
1726ng_get_string_token(const char *s, int *startp, int *lenp, int *slenp)
1727{
1728 char *cbuf, *p;
1729 int start, off;
1730 int slen;
1731
1732 while (isspace(s[*startp]))
1733 (*startp)++;
1734 start = *startp;
1735 if (s[*startp] != '"')
1736 return (NULL);
1737 cbuf = malloc(strlen(s + start), M_NETGRAPH_PARSE, M_NOWAIT);
1738 if (cbuf == NULL)
1739 return (NULL);
1740 strcpy(cbuf, s + start + 1);
1741 for (slen = 0, off = 1, p = cbuf; *p != '\0'; slen++, off++, p++) {
1742 if (*p == '"') {
1743 *p = '\0';
1744 *lenp = off + 1;
1745 if (slenp != NULL)
1746 *slenp = slen;
1747 return (cbuf);
1748 } else if (p[0] == '\\' && p[1] != '\0') {
1749 int x, k;
1750 char *v;
1751
1752 strcpy(p, p + 1);
1753 v = p;
1754 switch (*p) {
1755 case 't':
1756 *v = '\t';
1757 off++;
1758 continue;
1759 case 'n':
1760 *v = '\n';
1761 off++;
1762 continue;
1763 case 'r':
1764 *v = '\r';
1765 off++;
1766 continue;
1767 case 'v':
1768 *v = '\v';
1769 off++;
1770 continue;
1771 case 'f':
1772 *v = '\f';
1773 off++;
1774 continue;
1775 case '"':
1776 *v = '"';
1777 off++;
1778 continue;
1779 case '0': case '1': case '2': case '3':
1780 case '4': case '5': case '6': case '7':
1781 for (x = k = 0;
1782 k < 3 && *v >= '0' && *v <= '7'; v++) {

Callers 6

ng_string_parseFunction · 0.85
ng_fixedstring_parseFunction · 0.85
ng_sizedstring_parseFunction · 0.85
ng_bytearray_parseFunction · 0.85
ng_parse_get_tokenFunction · 0.85

Calls 6

isspaceFunction · 0.85
mallocFunction · 0.85
isxdigitFunction · 0.85
isdigitFunction · 0.85
tolowerFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected