FreeBSD/contrib/mdocml/eqn.c
/*
 * Parse a token from the stream of text.
 * A token consists of one of the recognised eqn(7) strings.
 * Strings are separated by delimiting marks.
 * This returns EQN_TOK_EOF when there are no more tokens.
 * If the token is an unrecognised string literal, then it returns
 * EQN_TOK__MAX and sets the "p" pointer to an allocated, nil-terminated
 * string.
 * This must be later freed with free(3).
 */
Parse a token from the stream of text.
A token consists of one of the recognised eqn(7) strings.
Strings are separated by delimiting marks.
This returns EQN_TOK_EOF when there are no more tokens.
If the token is an unrecognised string literal, then it returns
EQN_TOK__MAX and sets the "p" pointer to an allocated, nil-terminated
string.
This must be later freed with free(3).
Parse a token from the stream of text . A token consists of one of the recognised eqn ( 7 ) strings . Strings are separated by delimiting marks . This returns EQN_TOK_EOF when there are no more tokens . If the token is an unrecognised string literal then it returns EQN_TOK__MAX and sets the " p " pointer to an allocated nil - terminated string . This must be later freed with free ( 3 ) .
static enum eqn_tok
eqn_tok_parse(struct eqn_node *ep, char **p)
{
	const char	*start;
	size_t		 i, sz;
	int		 quoted;
	if (NULL != p)
		*p = NULL;
	quoted = ep->data[ep->cur] == '"';
	if (NULL == (start = eqn_nexttok(ep, &sz)))
		return EQN_TOK_EOF;
	if (quoted) {
		if (p != NULL)
			*p = mandoc_strndup(start, sz);
		return EQN_TOK__MAX;
	}
	for (i = 0; i < EQN_TOK__MAX; i++) {
		if (NULL == eqn_toks[i])
			continue;
		if (STRNEQ(start, sz, eqn_toks[i], strlen(eqn_toks[i])))
			break;
	}
	if (i == EQN_TOK__MAX && NULL != p)
		*p = mandoc_strndup(start, sz);
	return i;
}
static enum eqn_tok eqn_tok_parse ( struct eqn_node * ep , char * * p ) { const char * start ; size_t i , sz ; int quoted ; if ( NULL != p ) * p = NULL ; quoted = ep -> data [ ep -> cur ] == ' ' ; if ( NULL == ( start = eqn_nexttok ( ep , & sz ) ) ) return EQN_TOK_EOF ; if ( quoted ) { if ( p != NULL ) * p = mandoc_strndup ( start , sz ) ; return EQN_TOK__MAX ; } for ( i = 0 ; i < EQN_TOK__MAX ; i ++ ) { if ( NULL == eqn_toks [ i ] ) continue ; if ( STRNEQ ( start , sz , eqn_toks [ i ] , strlen ( eqn_toks [ i ] ) ) ) break ; } if ( i == EQN_TOK__MAX && NULL != p ) * p = mandoc_strndup ( start , sz ) ; return i ; }
Parse a token from the stream of text.
Parse a token from the stream of text .