FreeBSD/contrib/mdocml/mdoc.c
/*
 * 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 roff_man *mdoc, int line, char *buf, int offs)
{
	struct roff_node *n;
	char		 *c, *ws, *end;
	assert(mdoc->last);
	n = 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, line, offs, &offs, 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, line, offs, &offs, buf);
		return 1;
	}
	ws = NULL;
	for (c = end = buf + offs; *c; c++) {
		switch (*c) {
		case ' ':
			if (NULL == ws)
				ws = c;
			continue;
		case '\t':
			if (NULL == ws)
				ws = c;
			if (MDOC_LITERAL & mdoc->flags)
				continue;
			break;
		case '\\':
			if (c[1])
				c++;
		default:
			ws = NULL;
			break;
		}
		end = c + 1;
	}
	*end = '\0';
	if (ws)
		mandoc_msg(MANDOCERR_SPACE_EOL, mdoc->parse,
		    line, (int)(ws-buf), NULL);
	if (buf[offs] == '\0' && ! (mdoc->flags & MDOC_LITERAL)) {
		mandoc_msg(MANDOCERR_FI_BLANK, mdoc->parse,
		    line, (int)(c - buf), NULL);
		roff_elem_alloc(mdoc, line, offs, MDOC_sp);
		mdoc->last->flags |= MDOC_VALID | MDOC_ENDED;
		mdoc->next = ROFF_NEXT_SIBLING;
		return 1;
	}
	roff_word_alloc(mdoc, line, offs, buf+offs);
	if (mdoc->flags & MDOC_LITERAL)
		return 1;
	assert(buf < end);
	if (mandoc_eos(buf+offs, (size_t)(end-buf-offs)))
		mdoc->last->flags |= MDOC_EOS;
	return 1;
}
static int mdoc_ptext ( struct roff_man * mdoc , int line , char * buf , int offs ) { struct roff_node * n ; char * c , * ws , * end ; assert ( mdoc -> last ) ; n = 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 , line , offs , & offs , 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 , line , offs , & offs , buf ) ; return 1 ; } ws = NULL ; for ( c = end = buf + offs ; * c ; c ++ ) { switch ( * c ) { case ' ' : if ( NULL == ws ) ws = c ; continue ; case ' \t ' : if ( NULL == ws ) ws = c ; if ( MDOC_LITERAL & mdoc -> flags ) continue ; break ; case ' \\ ' : if ( c [ 1 ] ) c ++ ; default : ws = NULL ; break ; } end = c + 1 ; } * end = ' \0 ' ; if ( ws ) mandoc_msg ( MANDOCERR_SPACE_EOL , mdoc -> parse , line , ( int ) ( ws - buf ) , NULL ) ; if ( buf [ offs ] == ' \0 ' && ! ( mdoc -> flags & MDOC_LITERAL ) ) { mandoc_msg ( MANDOCERR_FI_BLANK , mdoc -> parse , line , ( int ) ( c - buf ) , NULL ) ; roff_elem_alloc ( mdoc , line , offs , MDOC_sp ) ; mdoc -> last -> flags |= MDOC_VALID | MDOC_ENDED ; mdoc -> next = ROFF_NEXT_SIBLING ; return 1 ; } roff_word_alloc ( mdoc , line , offs , buf + offs ) ; if ( mdoc -> flags & MDOC_LITERAL ) return 1 ; assert ( buf < end ) ; if ( mandoc_eos ( buf + offs , ( size_t ) ( end - buf - offs ) ) ) mdoc -> 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 .
/*
	 * Divert directly to list processing if we're encountering a
	 * columnar ROFFT_BLOCK with or without a prior ROFFT_BLOCK entry
	 * (a ROFFT_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.
	 */