contrib/mdocml/mdoc.c
static int
mdoc_ptext(struct mdoc *m, int line, char *buf, int offs)
{
	char		 *c, *ws, *end;
	struct mdoc_node *n;

	/* No text before an initial macro. */

	if (SEC_NONE == m->lastnamed) {
		mdoc_pmsg(m, line, offs, MANDOCERR_NOTEXT);
		return(1);
	}

	assert(m->last);
	n = m->last;

	/*
	 * Divert directly to list processing if we're encountering a
	 * columnar MDOC_BLOCK with or without a prior MDOC_BLOCK entry
	 * (a MDOC_BODY means it's already open, in which case we should
	 * process within its context in the normal way).
	 */

	if (MDOC_Bl == n->tok && MDOC_BODY == n->type &&
			LIST_column == n->norm->Bl.type) {
		/* `Bl' is open without any children. */
		m->flags |= MDOC_FREECOL;
		return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf));
	}

	if (MDOC_It == n->tok && MDOC_BLOCK == n->type &&
			NULL != n->parent &&
			MDOC_Bl == n->parent->tok &&
			LIST_column == n->parent->norm->Bl.type) {
		/* `Bl' has block-level `It' children. */
		m->flags |= MDOC_FREECOL;
		return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf));
	}

	/*
	 * Search for the beginning of unescaped trailing whitespace (ws)
	 * and for the first character not to be output (end).
	 */

	/* FIXME: replace with strcspn(). */
	ws = NULL;
	for (c = end = buf + offs; *c; c++) {
		switch (*c) {
		case '-':
			if (mandoc_hyph(buf + offs, c))
				*c = ASCII_HYPH;
			ws = NULL;
			break;
		case ' ':
			if (NULL == ws)
				ws = c;
			continue;
		case '\t':
			/*
			 * Always warn about trailing tabs,
			 * even outside literal context,
			 * where they should be put on the next line.
			 */
			if (NULL == ws)
				ws = c;
			/*
			 * Strip trailing tabs in literal context only;
			 * outside, they affect the next line.
			 */
			if (MDOC_LITERAL & m->flags)
				continue;
			break;
		case '\\':
			/* Skip the escaped character, too, if any. */
			if (c[1])
				c++;
			/* FALLTHROUGH */
		default:
			ws = NULL;
			break;
		}
		end = c + 1;
	}
	*end = '\0';

	if (ws)
		mdoc_pmsg(m, line, (int)(ws-buf), MANDOCERR_EOLNSPACE);

	if ('\0' == buf[offs] && ! (MDOC_LITERAL & m->flags)) {
		mdoc_pmsg(m, line, (int)(c-buf), MANDOCERR_NOBLANKLN);

		/*
		 * Insert a `sp' in the case of a blank line.  Technically,
		 * blank lines aren't allowed, but enough manuals assume this
		 * behaviour that we want to work around it.
		 */
		if ( ! mdoc_elem_alloc(m, line, offs, MDOC_sp, NULL))
			return(0);

		m->next = MDOC_NEXT_SIBLING;
		return(1);
	}

	if ( ! mdoc_word_alloc(m, line, offs, buf+offs))
		return(0);

	if (MDOC_LITERAL & m->flags)
		return(1);

	/*
	 * End-of-sentence check.  If the last character is an unescaped
	 * EOS character, then flag the node as being the end of a
	 * sentence.  The front-end will know how to interpret this.
	 */

	assert(buf < end);

	if (mandoc_eos(buf+offs, (size_t)(end-buf-offs), 0))
		m->last->flags |= MDOC_EOS;

	return(1);
}
/*
 * Parse free-form text, that is, a line that does not begin with the
 * control character.
 */
Parse free-form text, that is, a line that does not begin with the
control character.
Parse free - form text that is a line that does not begin with the control character .
static int
mdoc_ptext(struct mdoc *m, int line, char *buf, int offs)
{
	char		 *c, *ws, *end;
	struct mdoc_node *n;
	if (SEC_NONE == m->lastnamed) {
		mdoc_pmsg(m, line, offs, MANDOCERR_NOTEXT);
		return(1);
	}
	assert(m->last);
	n = m->last;
	if (MDOC_Bl == n->tok && MDOC_BODY == n->type &&
			LIST_column == n->norm->Bl.type) {
		m->flags |= MDOC_FREECOL;
		return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf));
	}
	if (MDOC_It == n->tok && MDOC_BLOCK == n->type &&
			NULL != n->parent &&
			MDOC_Bl == n->parent->tok &&
			LIST_column == n->parent->norm->Bl.type) {
		m->flags |= MDOC_FREECOL;
		return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf));
	}
	ws = NULL;
	for (c = end = buf + offs; *c; c++) {
		switch (*c) {
		case '-':
			if (mandoc_hyph(buf + offs, c))
				*c = ASCII_HYPH;
			ws = NULL;
			break;
		case ' ':
			if (NULL == ws)
				ws = c;
			continue;
		case '\t':
			if (NULL == ws)
				ws = c;
			if (MDOC_LITERAL & m->flags)
				continue;
			break;
		case '\\':
			if (c[1])
				c++;
		default:
			ws = NULL;
			break;
		}
		end = c + 1;
	}
	*end = '\0';
	if (ws)
		mdoc_pmsg(m, line, (int)(ws-buf), MANDOCERR_EOLNSPACE);
	if ('\0' == buf[offs] && ! (MDOC_LITERAL & m->flags)) {
		mdoc_pmsg(m, line, (int)(c-buf), MANDOCERR_NOBLANKLN);
		if ( ! mdoc_elem_alloc(m, line, offs, MDOC_sp, NULL))
			return(0);
		m->next = MDOC_NEXT_SIBLING;
		return(1);
	}
	if ( ! mdoc_word_alloc(m, line, offs, buf+offs))
		return(0);
	if (MDOC_LITERAL & m->flags)
		return(1);
	assert(buf < end);
	if (mandoc_eos(buf+offs, (size_t)(end-buf-offs), 0))
		m->last->flags |= MDOC_EOS;
	return(1);
}
static int mdoc_ptext ( struct mdoc * m , int line , char * buf , int offs ) { char * c , * ws , * end ; struct mdoc_node * n ; if ( SEC_NONE == m -> lastnamed ) { mdoc_pmsg ( m , line , offs , MANDOCERR_NOTEXT ) ; return ( 1 ) ; } assert ( m -> last ) ; n = m -> last ; if ( MDOC_Bl == n -> tok && MDOC_BODY == n -> type && LIST_column == n -> norm -> Bl . type ) { m -> flags |= MDOC_FREECOL ; return ( mdoc_macro ( m , MDOC_It , line , offs , & offs , buf ) ) ; } if ( MDOC_It == n -> tok && MDOC_BLOCK == n -> type && NULL != n -> parent && MDOC_Bl == n -> parent -> tok && LIST_column == n -> parent -> norm -> Bl . type ) { m -> flags |= MDOC_FREECOL ; return ( mdoc_macro ( m , MDOC_It , line , offs , & offs , buf ) ) ; } ws = NULL ; for ( c = end = buf + offs ; * c ; c ++ ) { switch ( * c ) { case ' ' : if ( mandoc_hyph ( buf + offs , c ) ) * c = ASCII_HYPH ; ws = NULL ; break ; case ' ' : if ( NULL == ws ) ws = c ; continue ; case ' \t ' : if ( NULL == ws ) ws = c ; if ( MDOC_LITERAL & m -> flags ) continue ; break ; case ' \\ ' : if ( c [ 1 ] ) c ++ ; default : ws = NULL ; break ; } end = c + 1 ; } * end = ' \0 ' ; if ( ws ) mdoc_pmsg ( m , line , ( int ) ( ws - buf ) , MANDOCERR_EOLNSPACE ) ; if ( ' \0 ' == buf [ offs ] && ! ( MDOC_LITERAL & m -> flags ) ) { mdoc_pmsg ( m , line , ( int ) ( c - buf ) , MANDOCERR_NOBLANKLN ) ; if ( ! mdoc_elem_alloc ( m , line , offs , MDOC_sp , NULL ) ) return ( 0 ) ; m -> next = MDOC_NEXT_SIBLING ; return ( 1 ) ; } if ( ! mdoc_word_alloc ( m , line , offs , buf + offs ) ) return ( 0 ) ; if ( MDOC_LITERAL & m -> flags ) return ( 1 ) ; assert ( buf < end ) ; if ( mandoc_eos ( buf + offs , ( size_t ) ( end - buf - offs ) , 0 ) ) m -> last -> flags |= MDOC_EOS ; return ( 1 ) ; }
Parse free-form text, that is, a line that does not begin with the
 control character.
Parse free - form text that is a line that does not begin with the control character .
/* No text before an initial macro. */ /*
	 * Divert directly to list processing if we're encountering a
	 * columnar MDOC_BLOCK with or without a prior MDOC_BLOCK entry
	 * (a MDOC_BODY means it's already open, in which case we should
	 * process within its context in the normal way).
	 */ /* `Bl' is open without any children. */ /* `Bl' has block-level `It' children. */ /*
	 * Search for the beginning of unescaped trailing whitespace (ws)
	 * and for the first character not to be output (end).
	 */ /* FIXME: replace with strcspn(). */ /*
			 * Always warn about trailing tabs,
			 * even outside literal context,
			 * where they should be put on the next line.
			 */ /*
			 * Strip trailing tabs in literal context only;
			 * outside, they affect the next line.
			 */ /* Skip the escaped character, too, if any. */ /* FALLTHROUGH */ /*
		 * Insert a `sp' in the case of a blank line.  Technically,
		 * blank lines aren't allowed, but enough manuals assume this
		 * behaviour that we want to work around it.
		 */ /*
	 * End-of-sentence check.  If the last character is an unescaped
	 * EOS character, then flag the node as being the end of a
	 * sentence.  The front-end will know how to interpret this.
	 */