Exemplo n.º 1
0
struct mparse *
mparse_alloc(int options, enum mandoclevel wlevel, mandocmsg mmsg,
    const char *defos)
{
	struct mparse	*curp;

	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);
	curp->man = roff_man_alloc( curp->roff, curp, curp->defos,
		curp->options & MPARSE_QUICK ? 1 : 0);
	if (curp->options & MPARSE_MDOC) {
		mdoc_hash_init();
		curp->man->macroset = MACROSET_MDOC;
	} else if (curp->options & MPARSE_MAN) {
		man_hash_init();
		curp->man->macroset = MACROSET_MAN;
	}
	curp->man->first->tok = TOKEN_NONE;
	return curp;
}
Exemplo n.º 2
0
static void
choose_parser(struct mparse *curp)
{
	char		*cp, *ep;
	int		 format;

	/*
	 * If neither command line arguments -mdoc or -man select
	 * a parser nor the roff parser found a .Dd or .TH macro
	 * yet, look ahead in the main input buffer.
	 */

	if ((format = roff_getformat(curp->roff)) == 0) {
		cp = curp->primary->buf;
		ep = cp + curp->primary->sz;
		while (cp < ep) {
			if (*cp == '.' || *cp == '\'') {
				cp++;
				if (cp[0] == 'D' && cp[1] == 'd') {
					format = MPARSE_MDOC;
					break;
				}
				if (cp[0] == 'T' && cp[1] == 'H') {
					format = MPARSE_MAN;
					break;
				}
			}
			cp = memchr(cp, '\n', ep - cp);
			if (cp == NULL)
				break;
			cp++;
		}
	}

	if (curp->man == NULL) {
		curp->man = roff_man_alloc(curp->roff, curp, curp->defos,
		    curp->options & MPARSE_QUICK ? 1 : 0);
		curp->man->macroset = MACROSET_MAN;
		curp->man->first->tok = TOKEN_NONE;
	}

	if (format == MPARSE_MDOC) {
		mdoc_hash_init();
		curp->man->macroset = MACROSET_MDOC;
		curp->man->first->tok = TOKEN_NONE;
	} else {
		man_hash_init();
		curp->man->macroset = MACROSET_MAN;
		curp->man->first->tok = TOKEN_NONE;
	}
}
Exemplo n.º 3
0
struct man *
man_alloc(struct roff *roff, struct mparse *parse)
{
	struct man	*p;

	p = mandoc_calloc(1, sizeof(struct man));

	man_hash_init();
	p->parse = parse;
	p->roff = roff;

	man_alloc1(p);
	return(p);
}