Exemple #1
0
static void
pset(const char *buf, int pos, struct mparse *curp)
{
	int		 i;

	/*
	 * Try to intuit which kind of manual parser should be used.  If
	 * passed in by command-line (-man, -mdoc), then use that
	 * explicitly.  If passed as -mandoc, then try to guess from the
	 * line: either skip dot-lines, use -mdoc when finding `.Dt', or
	 * default to -man, which is more lenient.
	 *
	 * Separate out pmdoc/pman from mdoc/man: the first persists
	 * through all parsers, while the latter is used per-parse.
	 */

	if ('.' == buf[0] || '\'' == buf[0]) {
		for (i = 1; buf[i]; i++)
			if (' ' != buf[i] && '\t' != buf[i])
				break;
		if ('\0' == buf[i])
			return;
	}

	switch (curp->inttype) {
	case (MPARSE_MDOC):
		if (NULL == curp->pmdoc) 
			curp->pmdoc = mdoc_alloc(curp->roff, curp,
					curp->defos);
		assert(curp->pmdoc);
		curp->mdoc = curp->pmdoc;
		return;
	case (MPARSE_MAN):
		if (NULL == curp->pman) 
			curp->pman = man_alloc(curp->roff, curp);
		assert(curp->pman);
		curp->man = curp->pman;
		return;
	default:
		break;
	}

	if (pos >= 3 && 0 == memcmp(buf, ".Dd", 3))  {
		if (NULL == curp->pmdoc) 
			curp->pmdoc = mdoc_alloc(curp->roff, curp,
					curp->defos);
		assert(curp->pmdoc);
		curp->mdoc = curp->pmdoc;
		return;
	} 

	if (NULL == curp->pman) 
		curp->pman = man_alloc(curp->roff, curp);
	assert(curp->pman);
	curp->man = curp->pman;
}
Exemple #2
0
struct mparse *
mparse_alloc(int options, enum mandoclevel wlevel,
		mandocmsg mmsg, const char *defos)
{
	struct mparse	*curp;

	assert(wlevel <= MANDOCLEVEL_FATAL);

	curp = mandoc_calloc(1, sizeof(struct mparse));

	curp->options = options;
	curp->wlevel = wlevel;
	curp->mmsg = mmsg;
	curp->defos = defos;

	curp->roff = roff_alloc(curp, options);
	if (curp->options & MPARSE_MDOC)
		curp->pmdoc = mdoc_alloc(
		    curp->roff, curp, curp->defos,
		    curp->options & MPARSE_QUICK ? 1 : 0);
	if (curp->options & MPARSE_MAN)
		curp->pman = man_alloc(curp->roff, curp,
		    curp->options & MPARSE_QUICK ? 1 : 0);

	return(curp);
}