FreeBSD/contrib/mdocml/mdoc.c
/*
 * Parse a macro line, that is, a line beginning with the control
 * character.
 */
Parse a macro line, that is, a line beginning with the control
character.
Parse a macro line that is a line beginning with the control character .
static int
mdoc_pmacro(struct roff_man *mdoc, int ln, char *buf, int offs)
{
	struct roff_node *n;
	const char	 *cp;
	int		  tok;
	int		  i, sv;
	char		  mac[5];
	sv = offs;
	i = 0;
	while (i < 4 && strchr(" \t\\", buf[offs]) == NULL)
		mac[i++] = buf[offs++];
	mac[i] = '\0';
	tok = (i > 1 && i < 4) ? mdoc_hash_find(mac) : TOKEN_NONE;
	if (tok == TOKEN_NONE) {
		mandoc_msg(MANDOCERR_MACRO, mdoc->parse,
		    ln, sv, buf + sv - 1);
		return 1;
	}
	switch (buf[offs]) {
	case '\\':
		cp = buf + offs + 1;
		mandoc_escape(&cp, NULL, NULL);
		offs = cp - buf;
		break;
	case '\t':
		offs++;
		break;
	default:
		break;
	}
	while (buf[offs] && ' ' == buf[offs])
		offs++;
	if ('\0' == buf[offs] && ' ' == buf[offs - 1])
		mandoc_msg(MANDOCERR_SPACE_EOL, mdoc->parse,
		    ln, offs - 1, NULL);
	if (NULL == mdoc->last || MDOC_It == tok || MDOC_El == tok) {
		mdoc_macro(mdoc, tok, ln, sv, &offs, buf);
		return 1;
	}
	n = mdoc->last;
	assert(mdoc->last);
	if (n->tok == MDOC_Bl && n->type == ROFFT_BODY &&
	    n->end == ENDBODY_NOT && n->norm->Bl.type == LIST_column) {
		mdoc->flags |= MDOC_FREECOL;
		mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf);
		return 1;
	}
	if (n->tok == MDOC_It && n->type == ROFFT_BLOCK &&
	    NULL != n->parent &&
	    MDOC_Bl == n->parent->tok &&
	    LIST_column == n->parent->norm->Bl.type) {
		mdoc->flags |= MDOC_FREECOL;
		mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf);
		return 1;
	}
	mdoc_macro(mdoc, tok, ln, sv, &offs, buf);
	if (mdoc->quick && MDOC_Sh == tok &&
	    SEC_NAME != mdoc->last->sec)
		return 2;
	return 1;
}
static int mdoc_pmacro ( struct roff_man * mdoc , int ln , char * buf , int offs ) { struct roff_node * n ; const char * cp ; int tok ; int i , sv ; char mac [ 5 ] ; sv = offs ; i = 0 ; while ( i < 4 && strchr ( " \t \\ " , buf [ offs ] ) == NULL ) mac [ i ++ ] = buf [ offs ++ ] ; mac [ i ] = ' \0 ' ; tok = ( i > 1 && i < 4 ) ? mdoc_hash_find ( mac ) : TOKEN_NONE ; if ( tok == TOKEN_NONE ) { mandoc_msg ( MANDOCERR_MACRO , mdoc -> parse , ln , sv , buf + sv - 1 ) ; return 1 ; } switch ( buf [ offs ] ) { case ' \\ ' : cp = buf + offs + 1 ; mandoc_escape ( & cp , NULL , NULL ) ; offs = cp - buf ; break ; case ' \t ' : offs ++ ; break ; default : break ; } while ( buf [ offs ] && ' ' == buf [ offs ] ) offs ++ ; if ( ' \0 ' == buf [ offs ] && ' ' == buf [ offs - 1 ] ) mandoc_msg ( MANDOCERR_SPACE_EOL , mdoc -> parse , ln , offs - 1 , NULL ) ; if ( NULL == mdoc -> last || MDOC_It == tok || MDOC_El == tok ) { mdoc_macro ( mdoc , tok , ln , sv , & offs , buf ) ; return 1 ; } n = mdoc -> last ; assert ( mdoc -> last ) ; if ( n -> tok == MDOC_Bl && n -> type == ROFFT_BODY && n -> end == ENDBODY_NOT && n -> norm -> Bl . type == LIST_column ) { mdoc -> flags |= MDOC_FREECOL ; mdoc_macro ( mdoc , MDOC_It , ln , sv , & sv , buf ) ; return 1 ; } if ( n -> tok == MDOC_It && n -> type == ROFFT_BLOCK && NULL != n -> parent && MDOC_Bl == n -> parent -> tok && LIST_column == n -> parent -> norm -> Bl . type ) { mdoc -> flags |= MDOC_FREECOL ; mdoc_macro ( mdoc , MDOC_It , ln , sv , & sv , buf ) ; return 1 ; } mdoc_macro ( mdoc , tok , ln , sv , & offs , buf ) ; if ( mdoc -> quick && MDOC_Sh == tok && SEC_NAME != mdoc -> last -> sec ) return 2 ; return 1 ; }
Parse a macro line, that is, a line beginning with the control
 character.
Parse a macro line that is a line beginning with the control character .
/*
	 * Copy the first word into a nil-terminated buffer.
	 * Stop when a space, tab, escape, or eoln is encountered.
	 */ /* Skip a leading escape sequence or tab. */ /* Jump to the next non-whitespace word. */ /*
	 * Trailing whitespace.  Note that tabs are allowed to be passed
	 * into the parser as "text", so we only warn about spaces here.
	 */ /*
	 * If an initial macro or a list invocation, divert directly
	 * into macro processing.
	 */ /*
	 * If the first macro of a `Bl -column', open an `It' block
	 * context around the parsed macro.
	 */ /*
	 * If we're following a block-level `It' within a `Bl -column'
	 * context (perhaps opened in the above block or in ptext()),
	 * then open an `It' block context around the parsed macro.
	 */ /* Normal processing of a macro. */ /* In quick mode (for mandocdb), abort after the NAME section. */