source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: Cleanup, no functional change:  The struct roff_man used to be a
@ 2018-12-30  0:50 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2018-12-30  0:50 UTC (permalink / raw)
  To: source

Log Message:
-----------
Cleanup, no functional change:

The struct roff_man used to be a bad mixture of internal parser
state and public parsing results.  Move the public results to the
parsing result struct roff_meta, which is already public.  Move the
rest of struct roff_man to the parser-internal header roff_int.h.

Since the validators need access to the parser state, call them
from the top level parser during mparse_result() rather than from
the main programs, also reducing code duplication.

This keeps parser internal state out of thee main programs (five
in mandoc portable) and out of eight formatters.

Modified Files:
--------------
    mandoc:
        Makefile.depend
        cgi.c
        demandoc.c
        libman.h
        libmdoc.h
        main.c
        main.h
        man.c
        man_html.c
        man_macro.c
        man_term.c
        mandoc.3
        mandoc.c
        mandoc_headers.3
        mandoc_parse.h
        mandocd.c
        mandocdb.c
        mdoc.c
        mdoc.h
        mdoc_html.c
        mdoc_macro.c
        mdoc_man.c
        mdoc_markdown.c
        mdoc_state.c
        mdoc_term.c
        mdoc_validate.c
        read.c
        roff.c
        roff.h
        roff_int.h
        tree.c

Revision Data
-------------
Index: man.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/man.c,v
retrieving revision 1.181
retrieving revision 1.182
diff -Lman.c -Lman.c -u -p -r1.181 -r1.182
--- man.c
+++ man.c
@@ -372,7 +372,7 @@ void
 man_validate(struct roff_man *man)
 {
 
-	man->last = man->first;
+	man->last = man->meta.first;
 	man_node_validate(man);
 	man->flags &= ~MAN_LITERAL;
 }
Index: read.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/read.c,v
retrieving revision 1.208
retrieving revision 1.209
diff -Lread.c -Lread.c -u -p -r1.208 -r1.209
--- read.c
+++ read.c
@@ -47,7 +47,6 @@
 struct	mparse {
 	struct roff	 *roff; /* roff parser (!NULL) */
 	struct roff_man	 *man; /* man parser */
-	char		 *sodest; /* filename pointed to by .so */
 	struct buf	 *primary; /* buffer currently being parsed */
 	struct buf	 *secondary; /* copy of top level input */
 	struct buf	 *loop; /* open .while request line */
@@ -123,15 +122,15 @@ choose_parser(struct mparse *curp)
 	}
 
 	if (format == MPARSE_MDOC) {
-		curp->man->macroset = MACROSET_MDOC;
+		curp->man->meta.macroset = MACROSET_MDOC;
 		if (curp->man->mdocmac == NULL)
 			curp->man->mdocmac = roffhash_alloc(MDOC_Dd, MDOC_MAX);
 	} else {
-		curp->man->macroset = MACROSET_MAN;
+		curp->man->meta.macroset = MACROSET_MAN;
 		if (curp->man->manmac == NULL)
 			curp->man->manmac = roffhash_alloc(MAN_TH, MAN_MAX);
 	}
-	curp->man->first->tok = TOKEN_NONE;
+	curp->man->meta.first->tok = TOKEN_NONE;
 }
 
 /*
@@ -334,9 +333,9 @@ rerun:
 		case ROFF_IGN:
 			break;
 		case ROFF_CONT:
-			if (curp->man->macroset == MACROSET_NONE)
+			if (curp->man->meta.macroset == MACROSET_NONE)
 				choose_parser(curp);
-			if ((curp->man->macroset == MACROSET_MDOC ?
+			if ((curp->man->meta.macroset == MACROSET_MDOC ?
 			     mdoc_parseln(curp->man, curp->line, ln.buf, of) :
 			     man_parseln(curp->man, curp->line, ln.buf, of)
 			    ) == 2)
@@ -365,7 +364,8 @@ rerun:
 		case ROFF_SO:
 			if ( ! (curp->options & MPARSE_SO) &&
 			    (i >= blk.sz || blk.buf[i] == '\0')) {
-				curp->sodest = mandoc_strdup(ln.buf + of);
+				curp->man->meta.sodest =
+				    mandoc_strdup(ln.buf + of);
 				goto out;
 			}
 			if ((fd = mparse_open(curp, ln.buf + of)) != -1) {
@@ -526,9 +526,9 @@ read_whole_file(struct mparse *curp, int
 static void
 mparse_end(struct mparse *curp)
 {
-	if (curp->man->macroset == MACROSET_NONE)
-		curp->man->macroset = MACROSET_MAN;
-	if (curp->man->macroset == MACROSET_MDOC)
+	if (curp->man->meta.macroset == MACROSET_NONE)
+		curp->man->meta.macroset = MACROSET_MAN;
+	if (curp->man->meta.macroset == MACROSET_MDOC)
 		mdoc_endparse(curp->man);
 	else
 		man_endparse(curp->man);
@@ -651,15 +651,15 @@ mparse_alloc(int options, enum mandoc_os
 	curp->man = roff_man_alloc(curp->roff, curp->os_s,
 		curp->options & MPARSE_QUICK ? 1 : 0);
 	if (curp->options & MPARSE_MDOC) {
-		curp->man->macroset = MACROSET_MDOC;
+		curp->man->meta.macroset = MACROSET_MDOC;
 		if (curp->man->mdocmac == NULL)
 			curp->man->mdocmac = roffhash_alloc(MDOC_Dd, MDOC_MAX);
 	} else if (curp->options & MPARSE_MAN) {
-		curp->man->macroset = MACROSET_MAN;
+		curp->man->meta.macroset = MACROSET_MAN;
 		if (curp->man->manmac == NULL)
 			curp->man->manmac = roffhash_alloc(MAN_TH, MAN_MAX);
 	}
-	curp->man->first->tok = TOKEN_NONE;
+	curp->man->meta.first->tok = TOKEN_NONE;
 	curp->man->meta.os_e = os_e;
 	return curp;
 }
@@ -671,8 +671,6 @@ mparse_reset(struct mparse *curp)
 	roff_man_reset(curp->man);
 	free_buf_list(curp->secondary);
 	curp->secondary = NULL;
-	free(curp->sodest);
-	curp->sodest = NULL;
 	curp->gzip = 0;
 }
 
@@ -684,21 +682,19 @@ mparse_free(struct mparse *curp)
 	roff_man_free(curp->man);
 	roff_free(curp->roff);
 	free_buf_list(curp->secondary);
-	free(curp->sodest);
 	free(curp);
 }
 
-void
-mparse_result(struct mparse *curp, struct roff_man **man,
-	char **sodest)
+struct roff_meta *
+mparse_result(struct mparse *curp)
 {
-
-	if (sodest && NULL != (*sodest = curp->sodest)) {
-		*man = NULL;
-		return;
+	if (curp->options & MPARSE_VALIDATE) {
+		if (curp->man->meta.macroset == MACROSET_MDOC)
+			mdoc_validate(curp->man);
+		else
+			man_validate(curp->man);
 	}
-	if (man)
-		*man = curp->man;
+	return &curp->man->meta;
 }
 
 void
Index: man_html.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/man_html.c,v
retrieving revision 1.160
retrieving revision 1.161
diff -Lman_html.c -Lman_html.c -u -p -r1.160 -r1.161
--- man_html.c
+++ man_html.c
@@ -139,7 +139,7 @@ print_bvspace(struct html *h, const stru
 }
 
 void
-html_man(void *arg, const struct roff_man *man)
+html_man(void *arg, const struct roff_meta *man)
 {
 	struct html		*h;
 	struct roff_node	*n;
@@ -154,16 +154,16 @@ html_man(void *arg, const struct roff_ma
 		if (n->type == ROFFT_COMMENT)
 			print_gen_comment(h, n);
 		t = print_otag(h, TAG_HEAD, "");
-		print_man_head(&man->meta, h);
+		print_man_head(man, h);
 		print_tagq(h, t);
 		print_otag(h, TAG_BODY, "");
 	}
 
-	man_root_pre(&man->meta, h);
+	man_root_pre(man, h);
 	t = print_otag(h, TAG_DIV, "c", "manual-text");
-	print_man_nodelist(&man->meta, n, h);
+	print_man_nodelist(man, n, h);
 	print_tagq(h, t);
-	man_root_post(&man->meta, h);
+	man_root_post(man, h);
 	print_tagq(h, NULL);
 }
 
Index: Makefile.depend
===================================================================
RCS file: /home/cvs/mandoc/mandoc/Makefile.depend,v
retrieving revision 1.40
retrieving revision 1.41
diff -LMakefile.depend -LMakefile.depend -u -p -r1.40 -r1.41
--- Makefile.depend
+++ Makefile.depend
@@ -38,7 +38,7 @@ man_html.o: man_html.c config.h mandoc_a
 man_macro.o: man_macro.c config.h mandoc.h roff.h man.h libmandoc.h roff_int.h libman.h
 man_term.o: man_term.c config.h mandoc_aux.h roff.h man.h out.h term.h main.h
 man_validate.o: man_validate.c config.h mandoc_aux.h mandoc.h roff.h man.h libmandoc.h roff_int.h libman.h
-mandoc.o: mandoc.c config.h mandoc_aux.h mandoc.h roff.h libmandoc.h
+mandoc.o: mandoc.c config.h mandoc_aux.h mandoc.h roff.h libmandoc.h roff_int.h
 mandoc_aux.o: mandoc_aux.c config.h mandoc.h mandoc_aux.h
 mandoc_msg.o: mandoc_msg.c mandoc.h
 mandoc_ohash.o: mandoc_ohash.c mandoc_aux.h mandoc_ohash.h compat_ohash.h
@@ -53,7 +53,7 @@ mdoc_html.o: mdoc_html.c config.h mandoc
 mdoc_macro.o: mdoc_macro.c config.h mandoc.h roff.h mdoc.h libmandoc.h roff_int.h libmdoc.h
 mdoc_man.o: mdoc_man.c config.h mandoc_aux.h mandoc.h roff.h mdoc.h man.h out.h main.h
 mdoc_markdown.o: mdoc_markdown.c mandoc_aux.h mandoc.h roff.h mdoc.h main.h
-mdoc_state.o: mdoc_state.c mandoc.h roff.h mdoc.h libmandoc.h libmdoc.h
+mdoc_state.o: mdoc_state.c mandoc.h roff.h mdoc.h libmandoc.h roff_int.h libmdoc.h
 mdoc_term.o: mdoc_term.c config.h mandoc_aux.h roff.h mdoc.h out.h term.h tag.h main.h
 mdoc_validate.o: mdoc_validate.c config.h mandoc_aux.h mandoc.h mandoc_xr.h roff.h mdoc.h libmandoc.h roff_int.h libmdoc.h
 msec.o: msec.c config.h mandoc.h libmandoc.h msec.in
Index: demandoc.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/demandoc.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -Ldemandoc.c -Ldemandoc.c -u -p -r1.31 -r1.32
--- demandoc.c
+++ demandoc.c
@@ -79,7 +79,7 @@ main(int argc, char *argv[])
 	argv += optind;
 
 	mchars_alloc();
-	mp = mparse_alloc(MPARSE_SO, MANDOC_OS_OTHER, NULL);
+	mp = mparse_alloc(MPARSE_SO | MPARSE_VALIDATE, MANDOC_OS_OTHER, NULL);
 	assert(mp);
 
 	if (argc < 1)
@@ -109,24 +109,19 @@ usage(void)
 static void
 pmandoc(struct mparse *mp, int fd, const char *fn, int list)
 {
-	struct roff_man	*man;
+	struct roff_meta	*meta;
 	int		 line, col;
 
 	mparse_readfd(mp, fd, fn);
 	close(fd);
-	mparse_result(mp, &man, NULL);
+	meta = mparse_result(mp);
 	line = 1;
 	col = 0;
 
-	if (man == NULL)
-		return;
-	if (man->macroset == MACROSET_MDOC) {
-		mdoc_validate(man);
-		pmdoc(man->first->child, &line, &col, list);
-	} else {
-		man_validate(man);
-		pman(man->first->child, &line, &col, list);
-	}
+	if (meta->macroset == MACROSET_MDOC)
+		pmdoc(meta->first->child, &line, &col, list);
+	else
+		pman(meta->first->child, &line, &col, list);
 
 	if ( ! list)
 		putchar('\n');
Index: roff_int.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff_int.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -Lroff_int.h -Lroff_int.h -u -p -r1.11 -r1.12
--- roff_int.h
+++ roff_int.h
@@ -18,6 +18,50 @@
  * Parser internals shared by multiple parsers.
  */
 
+struct	ohash;
+struct	roff_node;
+struct	roff_meta;
+struct	roff;
+struct	mdoc_arg;
+
+enum	roff_next {
+	ROFF_NEXT_SIBLING = 0,
+	ROFF_NEXT_CHILD
+};
+
+struct	roff_man {
+	struct roff_meta  meta;    /* Public parse results. */
+	struct roff	 *roff;    /* Roff parser state data. */
+	struct ohash	 *mdocmac; /* Mdoc macro lookup table. */
+	struct ohash	 *manmac;  /* Man macro lookup table. */
+	const char	 *os_s;    /* Default operating system. */
+	struct roff_node *last;    /* The last node parsed. */
+	struct roff_node *last_es; /* The most recent Es node. */
+	int		  quick;   /* Abort parse early. */
+	int		  flags;   /* Parse flags. */
+#define	MDOC_LITERAL	 (1 << 1)  /* In a literal scope. */
+#define	MDOC_PBODY	 (1 << 2)  /* In the document body. */
+#define	MDOC_NEWLINE	 (1 << 3)  /* First macro/text in a line. */
+#define	MDOC_PHRASE	 (1 << 4)  /* In a Bl -column phrase. */
+#define	MDOC_PHRASELIT	 (1 << 5)  /* Literal within a phrase. */
+#define	MDOC_FREECOL	 (1 << 6)  /* `It' invocation should close. */
+#define	MDOC_SYNOPSIS	 (1 << 7)  /* SYNOPSIS-style formatting. */
+#define	MDOC_KEEP	 (1 << 8)  /* In a word keep. */
+#define	MDOC_SMOFF	 (1 << 9)  /* Spacing is off. */
+#define	MDOC_NODELIMC	 (1 << 10) /* Disable closing delimiter handling. */
+#define	MAN_ELINE	 (1 << 11) /* Next-line element scope. */
+#define	MAN_BLINE	 (1 << 12) /* Next-line block scope. */
+#define	MDOC_PHRASEQF	 (1 << 13) /* Quote first word encountered. */
+#define	MDOC_PHRASEQL	 (1 << 14) /* Quote last word of this phrase. */
+#define	MDOC_PHRASEQN	 (1 << 15) /* Quote first word of the next phrase. */
+#define	MAN_LITERAL	  MDOC_LITERAL
+#define	MAN_NEWLINE	  MDOC_NEWLINE
+	enum roff_sec	  lastsec; /* Last section seen. */
+	enum roff_sec	  lastnamed; /* Last standard section seen. */
+	enum roff_next	  next;    /* Where to put the next node. */
+};
+
+
 struct roff_node *roff_node_alloc(struct roff_man *, int, int,
 			enum roff_type, int);
 void		  roff_node_append(struct roff_man *, struct roff_node *);
@@ -35,6 +79,8 @@ void		  roff_node_delete(struct roff_man
 struct ohash	 *roffhash_alloc(enum roff_tok, enum roff_tok);
 enum roff_tok	  roffhash_find(struct ohash *, const char *, size_t);
 void		  roffhash_free(struct ohash *);
+
+void		  roff_validate(struct roff_man *);
 
 /*
  * Functions called from roff.c need to be declared here,
Index: mdoc_markdown.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_markdown.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -Lmdoc_markdown.c -Lmdoc_markdown.c -u -p -r1.29 -r1.30
--- mdoc_markdown.c
+++ mdoc_markdown.c
@@ -261,21 +261,21 @@ md_act(enum roff_tok tok)
 }
 
 void
-markdown_mdoc(void *arg, const struct roff_man *mdoc)
+markdown_mdoc(void *arg, const struct roff_meta *mdoc)
 {
 	outflags = MD_Sm;
-	md_word(mdoc->meta.title);
-	if (mdoc->meta.msec != NULL) {
+	md_word(mdoc->title);
+	if (mdoc->msec != NULL) {
 		outflags &= ~MD_spc;
 		md_word("(");
-		md_word(mdoc->meta.msec);
+		md_word(mdoc->msec);
 		md_word(")");
 	}
 	md_word("-");
-	md_word(mdoc->meta.vol);
-	if (mdoc->meta.arch != NULL) {
+	md_word(mdoc->vol);
+	if (mdoc->arch != NULL) {
 		md_word("(");
-		md_word(mdoc->meta.arch);
+		md_word(mdoc->arch);
 		md_word(")");
 	}
 	outflags |= MD_sp;
@@ -283,9 +283,9 @@ markdown_mdoc(void *arg, const struct ro
 	md_nodelist(mdoc->first->child);
 
 	outflags |= MD_sp;
-	md_word(mdoc->meta.os);
+	md_word(mdoc->os);
 	md_word("-");
-	md_word(mdoc->meta.date);
+	md_word(mdoc->date);
 	putchar('\n');
 }
 
Index: mandoc.3
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc.3,v
retrieving revision 1.43
retrieving revision 1.44
diff -Lmandoc.3 -Lmandoc.3 -u -p -r1.43 -r1.44
--- mandoc.3
+++ mandoc.3
@@ -21,8 +21,6 @@
 .Sh NAME
 .Nm mandoc ,
 .Nm deroff ,
-.Nm man_validate ,
-.Nm mdoc_validate ,
 .Nm mparse_alloc ,
 .Nm mparse_copy ,
 .Nm mparse_free ,
@@ -68,11 +66,9 @@
 .Fo mparse_reset
 .Fa "struct mparse *parse"
 .Fc
-.Ft void
+.Ft struct roff_meta *
 .Fo mparse_result
 .Fa "struct mparse *parse"
-.Fa "struct roff_man **man"
-.Fa "char **sodest"
 .Fc
 .In roff.h
 .Ft void
@@ -85,18 +81,10 @@
 .In mdoc.h
 .Vt extern const char * const * mdoc_argnames;
 .Vt extern const char * const * mdoc_macronames;
-.Ft void
-.Fo mdoc_validate
-.Fa "struct roff_man *mdoc"
-.Fc
 .In sys/types.h
 .In mandoc.h
 .In man.h
 .Vt extern const char * const * man_macronames;
-.Ft void
-.Fo man_validate
-.Fa "struct roff_man *man"
-.Fc
 .Sh DESCRIPTION
 The
 .Nm mandoc
@@ -137,27 +125,13 @@ close it with
 retrieve the syntax tree with
 .Fn mparse_result ;
 .It
-depending on whether the
-.Fa macroset
-member of the returned
-.Vt struct roff_man
-is
-.Dv MACROSET_MDOC
-or
-.Dv MACROSET_MAN ,
-validate it with
-.Fn mdoc_validate
-or
-.Fn man_validate ,
-respectively;
-.It
 if information about the validity of the input is needed, fetch it with
 .Fn mparse_updaterc ;
 .It
 iterate over parse nodes with starting from the
 .Fa first
 member of the returned
-.Vt struct roff_man ;
+.Vt struct roff_meta ;
 .It
 free all allocated memory with
 .Fn mparse_free
@@ -205,29 +179,11 @@ including text contained in its child no
 To be used on children of the
 .Fa first
 member of
-.Vt struct roff_man .
+.Vt struct roff_meta .
 When it is no longer needed, the pointer returned from
 .Fn deroff
 can be passed to
 .Xr free 3 .
-.It Fn man_validate
-Validate the
-.Dv MACROSET_MAN
-parse tree obtained with
-.Fn mparse_result .
-Declared in
-.In man.h ,
-implemented in
-.Pa man.c .
-.It Fn mdoc_validate
-Validate the
-.Dv MACROSET_MDOC
-parse tree obtained with
-.Fn mparse_result .
-Declared in
-.In mdoc.h ,
-implemented in
-.Pa mdoc.c .
 .It Fn mparse_alloc
 Allocate a parser.
 The arguments have the following effect:
@@ -249,8 +205,8 @@ file inclusion requests are always honou
 Otherwise, if the request is the only content in an input file,
 only the file name is remembered, to be returned in the
 .Fa sodest
-argument of
-.Fn mparse_result .
+field of
+.Vt struct roff_meta .
 .Pp
 When the
 .Dv MPARSE_QUICK
@@ -259,6 +215,14 @@ This is for example useful in
 .Xr makewhatis 8
 .Fl Q
 to quickly build minimal databases.
+.Pp
+When the
+.Dv MARSE_VALIDATE
+bit is set,
+.Fn mparse_result
+runs the validation functions before returning the syntax tree.
+This is almost always required, except in certain debugging scenarios,
+for example to dump unvalidated syntax trees.
 .It Ar os_e
 Operating system to check base system conventions for.
 If
@@ -347,7 +311,6 @@ implemented in
 .Pa read.c .
 .It Fn mparse_result
 Obtain the result of a parse.
-One of the two pointers will be filled in.
 Declared in
 .In mandoc.h ,
 implemented in
Index: libmdoc.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/libmdoc.h,v
retrieving revision 1.115
retrieving revision 1.116
diff -Llibmdoc.h -Llibmdoc.h -u -p -r1.115 -r1.116
--- libmdoc.h
+++ libmdoc.h
@@ -16,6 +16,10 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+struct	roff_node;
+struct	roff_man;
+struct	mdoc_arg;
+
 #define	MACRO_PROT_ARGS	struct roff_man *mdoc, \
 			enum roff_tok tok, \
 			int line, \
Index: mdoc_macro.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_macro.c,v
retrieving revision 1.228
retrieving revision 1.229
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.228 -r1.229
--- mdoc_macro.c
+++ mdoc_macro.c
@@ -233,7 +233,7 @@ mdoc_endparse(struct roff_man *mdoc)
 
 	/* Rewind to the first. */
 
-	rew_last(mdoc, mdoc->first);
+	rew_last(mdoc, mdoc->meta.first);
 	mdoc_state_reset(mdoc);
 }
 
Index: man_macro.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/man_macro.c,v
retrieving revision 1.137
retrieving revision 1.138
diff -Lman_macro.c -Lman_macro.c -u -p -r1.137 -r1.138
--- man_macro.c
+++ man_macro.c
@@ -446,7 +446,7 @@ void
 man_endparse(struct roff_man *man)
 {
 
-	man_unscope(man, man->first);
+	man_unscope(man, man->meta.first);
 	man->flags &= ~MAN_LITERAL;
 }
 
Index: roff.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff.h,v
retrieving revision 1.65
retrieving revision 1.66
diff -Lroff.h -Lroff.h -u -p -r1.65 -r1.66
--- roff.h
+++ roff.h
@@ -21,6 +21,8 @@
 struct	ohash;
 struct	mdoc_arg;
 union	mdoc_data;
+struct	tbl_span;
+struct	eqn_box;
 
 enum	roff_macroset {
 	MACROSET_NONE = 0,
@@ -478,11 +480,6 @@ enum	roff_tok {
 	MAN_MAX
 };
 
-enum	roff_next {
-	ROFF_NEXT_SIBLING = 0,
-	ROFF_NEXT_CHILD
-};
-
 /*
  * Indicates that a BODY's formatting has ended, but
  * the scope is still open.  Used for badly nested blocks.
@@ -534,6 +531,7 @@ struct	roff_node {
 };
 
 struct	roff_meta {
+	struct roff_node *first;   /* The first node parsed. */
 	char		 *msec;    /* Manual section, usually a digit. */
 	char		 *vol;     /* Manual volume title. */
 	char		 *os;      /* Operating system. */
@@ -541,47 +539,14 @@ struct	roff_meta {
 	char		 *title;   /* Manual title, usually CAPS. */
 	char		 *name;    /* Leading manual name. */
 	char		 *date;    /* Normalized date. */
+	char		 *sodest;  /* .so target file name or NULL. */
 	int		  hasbody; /* Document is not empty. */
 	int		  rcsids;  /* Bits indexed by enum mandoc_os. */
 	enum mandoc_os	  os_e;    /* Operating system. */
-};
-
-struct	roff_man {
-	struct roff_meta  meta;    /* Document meta-data. */
-	struct roff	 *roff;    /* Roff parser state data. */
-	struct ohash	 *mdocmac; /* Mdoc macro lookup table. */
-	struct ohash	 *manmac;  /* Man macro lookup table. */
-	const char	 *os_s;    /* Default operating system. */
-	struct roff_node *first;   /* The first node parsed. */
-	struct roff_node *last;    /* The last node parsed. */
-	struct roff_node *last_es; /* The most recent Es node. */
-	int		  quick;   /* Abort parse early. */
-	int		  flags;   /* Parse flags. */
-#define	MDOC_LITERAL	 (1 << 1)  /* In a literal scope. */
-#define	MDOC_PBODY	 (1 << 2)  /* In the document body. */
-#define	MDOC_NEWLINE	 (1 << 3)  /* First macro/text in a line. */
-#define	MDOC_PHRASE	 (1 << 4)  /* In a Bl -column phrase. */
-#define	MDOC_PHRASELIT	 (1 << 5)  /* Literal within a phrase. */
-#define	MDOC_FREECOL	 (1 << 6)  /* `It' invocation should close. */
-#define	MDOC_SYNOPSIS	 (1 << 7)  /* SYNOPSIS-style formatting. */
-#define	MDOC_KEEP	 (1 << 8)  /* In a word keep. */
-#define	MDOC_SMOFF	 (1 << 9)  /* Spacing is off. */
-#define	MDOC_NODELIMC	 (1 << 10) /* Disable closing delimiter handling. */
-#define	MAN_ELINE	 (1 << 11) /* Next-line element scope. */
-#define	MAN_BLINE	 (1 << 12) /* Next-line block scope. */
-#define	MDOC_PHRASEQF	 (1 << 13) /* Quote first word encountered. */
-#define	MDOC_PHRASEQL	 (1 << 14) /* Quote last word of this phrase. */
-#define	MDOC_PHRASEQN	 (1 << 15) /* Quote first word of the next phrase. */
-#define	MAN_LITERAL	  MDOC_LITERAL
-#define	MAN_NEWLINE	  MDOC_NEWLINE
 	enum roff_macroset macroset; /* Kind of high-level macros used. */
-	enum roff_sec	  lastsec; /* Last section seen. */
-	enum roff_sec	  lastnamed; /* Last standard section seen. */
-	enum roff_next	  next;    /* Where to put the next node. */
 };
 
 extern	const char *const *roff_name;
 
 
 void		 deroff(char **, const struct roff_node *);
-void		 roff_validate(struct roff_man *);
Index: mandoc_parse.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc_parse.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lmandoc_parse.h -Lmandoc_parse.h -u -p -r1.3 -r1.4
--- mandoc_parse.h
+++ mandoc_parse.h
@@ -28,10 +28,11 @@
 #define	MPARSE_QUICK	(1 << 3)  /* abort the parse early */
 #define	MPARSE_UTF8	(1 << 4)  /* accept UTF-8 input */
 #define	MPARSE_LATIN1	(1 << 5)  /* accept ISO-LATIN-1 input */
+#define	MPARSE_VALIDATE	(1 << 6)  /* call validation functions */
 
 
+struct	roff_meta;
 struct	mparse;
-struct	roff_man;
 
 struct mparse	 *mparse_alloc(int, enum mandoc_os, const char *);
 void		  mparse_copy(const struct mparse *);
@@ -39,5 +40,4 @@ void		  mparse_free(struct mparse *);
 int		  mparse_open(struct mparse *, const char *);
 void		  mparse_readfd(struct mparse *, int, const char *);
 void		  mparse_reset(struct mparse *);
-void		  mparse_result(struct mparse *,
-			struct roff_man **, char **);
+struct roff_meta *mparse_result(struct mparse *);
Index: mandoc_headers.3
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc_headers.3,v
retrieving revision 1.29
retrieving revision 1.30
diff -Lmandoc_headers.3 -Lmandoc_headers.3 -u -p -r1.29 -r1.30
--- mandoc_headers.3
+++ mandoc_headers.3
@@ -115,7 +115,6 @@ Provides
 .Vt enum mandoc_os ,
 .Vt enum mdoc_endbody ,
 .Vt enum roff_macroset ,
-.Vt enum roff_next ,
 .Vt enum roff_sec ,
 .Vt enum roff_tok ,
 .Vt enum roff_type ,
@@ -124,21 +123,25 @@ Provides
 .Vt struct roff_node ,
 the constant array
 .Va roff_name
-and the functions
-.Fn deroff
-and
-.Fn roff_validate .
+and the function
+.Fn deroff .
 .Pp
 Uses pointers to the types
 .Vt struct ohash
 from
-.Pa mandoc_ohash.h
-and
+.Pa mandoc_ohash.h ,
 .Vt struct mdoc_arg
 and
 .Vt union mdoc_data
 from
-.Pa mdoc.h
+.Pa mdoc.h ,
+.Vt struct tbl_span
+from
+.Pa tbl.h ,
+and
+.Vt struct eqn_box
+from
+.Pa eqn.h
 as opaque struct members.
 .It Qq Pa tbl.h
 Data structures for the
@@ -183,10 +186,9 @@ and in the main parser, but not in forma
 Requires
 .Pa mandoc.h
 for
-.Vt enum mandocerr ,
-.Vt enum mandoclevel ,
+.Vt enum mandocerr
 and
-.Fn mandocmsg ,
+.Vt enum mandoclevel
 and
 .Pa roff.h
 for
@@ -198,7 +200,7 @@ from
 .Pa read.c
 for function prototypes.
 Uses
-.Vt struct roff_man
+.Vt struct roff_meta
 from
 .Pa roff.h
 as an opaque type for function prototypes.
@@ -246,11 +248,15 @@ and the functions
 described in
 .Xr mandoc 3 .
 .Pp
-Uses the type
-.Vt struct roff_man
+Uses the types
+.Vt struct roff_node
 from
 .Pa roff.h
-as an opaque type for function prototypes.
+and
+.Vt struct roff_man
+from
+.Pa roff_int.h
+as opaque types for function prototypes.
 .Pp
 When this header is included, the same file should not include
 internals of different parsers.
@@ -312,13 +318,17 @@ for
 and
 .Vt enum roff_tok .
 .Pp
-Provides functions named
+Provides
+.Vt enum roff_next ,
+.Vt struct roff_man ,
+functions named
 .Fn roff_*
 to handle roff nodes,
 .Fn roffhash_alloc ,
 .Fn roffhash_find ,
-and
 .Fn roffhash_free ,
+and
+.Fn roff_validate ,
 and the two special functions
 .Fn man_breakscope
 and
@@ -327,11 +337,17 @@ because the latter two are needed by
 .Qq Pa roff.c .
 .Pp
 Uses the types
-.Vt struct roff_man
-and
+.Vt struct ohash
+from
+.Pa mandoc_ohash.h ,
 .Vt struct roff_node
+and
+.Vt struct roff_meta
 from
-.Pa roff.h
+.Pa roff.h ,
+.Vt struct roff
+from
+.Pa roff.c ,
 and
 .Vt struct mdoc_arg
 from
@@ -354,11 +370,12 @@ and many functions internal to the
 parser.
 .Pp
 Uses the types
-.Vt struct roff_man
-and
 .Vt struct roff_node
 from
-.Pa roff.h
+.Pa roff.h ,
+.Vt struct roff_man
+from
+.Pa roff_int.h ,
 and
 .Vt struct mdoc_arg
 from
@@ -380,11 +397,13 @@ and some functions internal to the
 parser.
 .Pp
 Uses the types
-.Vt struct roff_man
-and
 .Vt struct roff_node
 from
 .Pa roff.h
+and
+.Vt struct roff_man
+from
+.Pa roff_int.h
 as opaque types for function prototypes.
 .Pp
 When this header is included, the same file should not include
@@ -610,7 +629,7 @@ functionality mentioned in
 Provides the top level steering functions for all formatters.
 .Pp
 Uses the type
-.Vt struct roff_man
+.Vt struct roff_meta
 from
 .Pa roff.h
 as an opaque type for function prototypes.
Index: mdoc.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc.c,v
retrieving revision 1.271
retrieving revision 1.272
diff -Lmdoc.c -Lmdoc.c -u -p -r1.271 -r1.272
--- mdoc.c
+++ mdoc.c
@@ -433,7 +433,7 @@ void
 mdoc_validate(struct roff_man *mdoc)
 {
 
-	mdoc->last = mdoc->first;
+	mdoc->last = mdoc->meta.first;
 	mdoc_node_validate(mdoc);
 	mdoc_state_reset(mdoc);
 }
Index: mdoc_validate.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_validate.c,v
retrieving revision 1.365
retrieving revision 1.366
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.365 -r1.366
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -1952,7 +1952,7 @@ post_root(POST_ARGS)
 		while (*arch != NULL && strcmp(*arch, mdoc->meta.arch))
 			arch++;
 		if (*arch == NULL) {
-			n = mdoc->first->child;
+			n = mdoc->meta.first->child;
 			while (n->tok != MDOC_Dt ||
 			    n->child == NULL ||
 			    n->child->next == NULL ||
@@ -1968,7 +1968,7 @@ post_root(POST_ARGS)
 
 	/* Check that we begin with a proper `Sh'. */
 
-	n = mdoc->first->child;
+	n = mdoc->meta.first->child;
 	while (n != NULL &&
 	    (n->type == ROFFT_COMMENT ||
 	     (n->tok >= MDOC_Dd &&
Index: mdoc_man.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_man.c,v
retrieving revision 1.130
retrieving revision 1.131
diff -Lmdoc_man.c -Lmdoc_man.c -u -p -r1.130 -r1.131
--- mdoc_man.c
+++ mdoc_man.c
@@ -602,7 +602,7 @@ print_count(int *count)
 }
 
 void
-man_mdoc(void *arg, const struct roff_man *mdoc)
+man_mdoc(void *arg, const struct roff_meta *mdoc)
 {
 	struct roff_node *n;
 
@@ -615,9 +615,8 @@ man_mdoc(void *arg, const struct roff_ma
 	}
 
 	printf(".TH \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n",
-	    mdoc->meta.title,
-	    (mdoc->meta.msec == NULL ? "" : mdoc->meta.msec),
-	    mdoc->meta.date, mdoc->meta.os, mdoc->meta.vol);
+	    mdoc->title, (mdoc->msec == NULL ? "" : mdoc->msec),
+	    mdoc->date, mdoc->os, mdoc->vol);
 
 	/* Disable hyphenation and if nroff, disable justification. */
 	printf(".nh\n.if n .ad l");
@@ -629,7 +628,7 @@ man_mdoc(void *arg, const struct roff_ma
 		*fontqueue.tail = 'R';
 	}
 	for (; n != NULL; n = n->next)
-		print_node(&mdoc->meta, n);
+		print_node(mdoc, n);
 	putchar('\n');
 }
 
Index: cgi.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/cgi.c,v
retrieving revision 1.163
retrieving revision 1.164
diff -Lcgi.c -Lcgi.c -u -p -r1.163 -r1.164
--- cgi.c
+++ cgi.c
@@ -849,7 +849,7 @@ resp_format(const struct req *req, const
 {
 	struct manoutput conf;
 	struct mparse	*mp;
-	struct roff_man	*man;
+	struct roff_meta *meta;
 	void		*vp;
 	int		 fd;
 	int		 usepath;
@@ -860,10 +860,11 @@ resp_format(const struct req *req, const
 	}
 
 	mchars_alloc();
-	mp = mparse_alloc(MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1,
-	    MANDOC_OS_OTHER, req->q.manpath);
+	mp = mparse_alloc(MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1 |
+	    MPARSE_VALIDATE, MANDOC_OS_OTHER, req->q.manpath);
 	mparse_readfd(mp, fd, file);
 	close(fd);
+	meta = mparse_result(mp);
 
 	memset(&conf, 0, sizeof(conf));
 	conf.fragment = 1;
@@ -874,24 +875,11 @@ resp_format(const struct req *req, const
 	    scriptname, *scriptname == '\0' ? "" : "/",
 	    usepath ? req->q.manpath : "", usepath ? "/" : "");
 
-	mparse_result(mp, &man, NULL);
-	if (man == NULL) {
-		warnx("fatal mandoc error: %s/%s", req->q.manpath, file);
-		pg_error_internal();
-		mparse_free(mp);
-		mchars_free();
-		return;
-	}
-
 	vp = html_alloc(&conf);
-
-	if (man->macroset == MACROSET_MDOC) {
-		mdoc_validate(man);
-		html_mdoc(vp, man);
-	} else {
-		man_validate(man);
-		html_man(vp, man);
-	}
+	if (meta->macroset == MACROSET_MDOC)
+		html_mdoc(vp, meta);
+	else
+		html_man(vp, meta);
 
 	html_free(vp);
 	mparse_free(mp);
Index: man_term.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/man_term.c,v
retrieving revision 1.222
retrieving revision 1.223
diff -Lman_term.c -Lman_term.c -u -p -r1.222 -r1.223
--- man_term.c
+++ man_term.c
@@ -147,7 +147,7 @@ man_term_act(enum roff_tok tok)
 }
 
 void
-terminal_man(void *arg, const struct roff_man *man)
+terminal_man(void *arg, const struct roff_meta *man)
 {
 	struct termp		*p;
 	struct roff_node	*n;
@@ -176,18 +176,17 @@ terminal_man(void *arg, const struct rof
 			    !strcmp(n->child->child->string, "SYNOPSIS")) {
 				if (n->child->next->child != NULL)
 					print_man_nodelist(p, &mt,
-					    n->child->next->child,
-					    &man->meta);
+					    n->child->next->child, man);
 				term_newln(p);
 				break;
 			}
 			n = n->next;
 		}
 	} else {
-		term_begin(p, print_man_head, print_man_foot, &man->meta);
+		term_begin(p, print_man_head, print_man_foot, man);
 		p->flags |= TERMP_NOSPACE;
 		if (n != NULL)
-			print_man_nodelist(p, &mt, n, &man->meta);
+			print_man_nodelist(p, &mt, n, man);
 		term_end(p);
 	}
 	p->defindent = save_defindent;
Index: mdoc.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc.h,v
retrieving revision 1.145
retrieving revision 1.146
diff -Lmdoc.h -Lmdoc.h -u -p -r1.145 -r1.146
--- mdoc.h
+++ mdoc.h
@@ -16,6 +16,9 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+struct	roff_node;
+struct	roff_man;
+
 enum	mdocargt {
 	MDOC_Split, /* -split */
 	MDOC_Nosplit, /* -nospli */
Index: roff.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff.c,v
retrieving revision 1.355
retrieving revision 1.356
diff -Lroff.c -Lroff.c -u -p -r1.355 -r1.356
--- roff.c
+++ roff.c
@@ -807,9 +807,8 @@ roff_alloc(int options)
 static void
 roff_man_free1(struct roff_man *man)
 {
-
-	if (man->first != NULL)
-		roff_node_delete(man, man->first);
+	if (man->meta.first != NULL)
+		roff_node_delete(man, man->meta.first);
 	free(man->meta.msec);
 	free(man->meta.vol);
 	free(man->meta.os);
@@ -817,19 +816,19 @@ roff_man_free1(struct roff_man *man)
 	free(man->meta.title);
 	free(man->meta.name);
 	free(man->meta.date);
+	free(man->meta.sodest);
 }
 
 static void
 roff_man_alloc1(struct roff_man *man)
 {
-
 	memset(&man->meta, 0, sizeof(man->meta));
-	man->first = mandoc_calloc(1, sizeof(*man->first));
-	man->first->type = ROFFT_ROOT;
-	man->last = man->first;
+	man->meta.first = mandoc_calloc(1, sizeof(*man->meta.first));
+	man->meta.first->type = ROFFT_ROOT;
+	man->last = man->meta.first;
 	man->last_es = NULL;
 	man->flags = 0;
-	man->macroset = MACROSET_NONE;
+	man->meta.macroset = MACROSET_NONE;
 	man->lastsec = man->lastnamed = SEC_NONE;
 	man->next = ROFF_NEXT_CHILD;
 }
@@ -837,7 +836,6 @@ roff_man_alloc1(struct roff_man *man)
 void
 roff_man_reset(struct roff_man *man)
 {
-
 	roff_man_free1(man);
 	roff_man_alloc1(man);
 }
@@ -845,7 +843,6 @@ roff_man_reset(struct roff_man *man)
 void
 roff_man_free(struct roff_man *man)
 {
-
 	roff_man_free1(man);
 	free(man);
 }
@@ -1020,7 +1017,7 @@ roff_addtbl(struct roff_man *man, int li
 	struct roff_node	*n;
 	struct tbl_span		*span;
 
-	if (man->macroset == MACROSET_MAN)
+	if (man->meta.macroset == MACROSET_MAN)
 		man_breakscope(man, ROFF_TS);
 	while ((span = tbl_span(tbl)) != NULL) {
 		n = roff_node_alloc(man, line, 0, ROFFT_TBL, TOKEN_NONE);
@@ -1064,8 +1061,8 @@ roff_node_unlink(struct roff_man *man, s
 			man->next = ROFF_NEXT_SIBLING;
 		}
 	}
-	if (man->first == n)
-		man->first = NULL;
+	if (man->meta.first == n)
+		man->meta.first = NULL;
 }
 
 void
@@ -3281,7 +3278,7 @@ roff_EQ(ROFF_ARGS)
 {
 	struct roff_node	*n;
 
-	if (r->man->macroset == MACROSET_MAN)
+	if (r->man->meta.macroset == MACROSET_MAN)
 		man_breakscope(r->man, ROFF_EQ);
 	n = roff_node_alloc(r->man, ln, ppos, ROFFT_EQN, TOKEN_NONE);
 	if (ln > r->man->last->line)
@@ -4021,7 +4018,7 @@ roff_getstrn(struct roff *r, const char 
 			break;
 		}
 	}
-	if (r->man->macroset != MACROSET_MAN) {
+	if (r->man->meta.macroset != MACROSET_MAN) {
 		for (tok = MDOC_Dd; tok < MDOC_MAX; tok++) {
 			if (strncmp(name, roff_name[tok], len) != 0 ||
 			    roff_name[tok][len] != '\0')
@@ -4035,7 +4032,7 @@ roff_getstrn(struct roff *r, const char 
 			}
 		}
 	}
-	if (r->man->macroset != MACROSET_MDOC) {
+	if (r->man->meta.macroset != MACROSET_MDOC) {
 		for (tok = MAN_TH; tok < MAN_MAX; tok++) {
 			if (strncmp(name, roff_name[tok], len) != 0 ||
 			    roff_name[tok][len] != '\0')
Index: mdoc_html.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_html.c,v
retrieving revision 1.320
retrieving revision 1.321
diff -Lmdoc_html.c -Lmdoc_html.c -u -p -r1.320 -r1.321
--- mdoc_html.c
+++ mdoc_html.c
@@ -283,7 +283,7 @@ synopsis_pre(struct html *h, const struc
 }
 
 void
-html_mdoc(void *arg, const struct roff_man *mdoc)
+html_mdoc(void *arg, const struct roff_meta *mdoc)
 {
 	struct html		*h;
 	struct roff_node	*n;
@@ -298,16 +298,16 @@ html_mdoc(void *arg, const struct roff_m
 		if (n->type == ROFFT_COMMENT)
 			print_gen_comment(h, n);
 		t = print_otag(h, TAG_HEAD, "");
-		print_mdoc_head(&mdoc->meta, h);
+		print_mdoc_head(mdoc, h);
 		print_tagq(h, t);
 		print_otag(h, TAG_BODY, "");
 	}
 
-	mdoc_root_pre(&mdoc->meta, h);
+	mdoc_root_pre(mdoc, h);
 	t = print_otag(h, TAG_DIV, "c", "manual-text");
-	print_mdoc_nodelist(&mdoc->meta, n, h);
+	print_mdoc_nodelist(mdoc, n, h);
 	print_tagq(h, t);
-	mdoc_root_post(&mdoc->meta, h);
+	mdoc_root_post(mdoc, h);
 	print_tagq(h, NULL);
 }
 
Index: mdoc_term.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_term.c,v
retrieving revision 1.370
retrieving revision 1.371
diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.370 -r1.371
--- mdoc_term.c
+++ mdoc_term.c
@@ -251,7 +251,7 @@ static	int	 fn_prio;
 
 
 void
-terminal_mdoc(void *arg, const struct roff_man *mdoc)
+terminal_mdoc(void *arg, const struct roff_meta *mdoc)
 {
 	struct roff_node	*n;
 	struct termp		*p;
@@ -269,8 +269,7 @@ terminal_mdoc(void *arg, const struct ro
 			if (n->tok == MDOC_Sh && n->sec == SEC_SYNOPSIS) {
 				if (n->child->next->child != NULL)
 					print_mdoc_nodelist(p, NULL,
-					    &mdoc->meta,
-					    n->child->next->child);
+					    mdoc, n->child->next->child);
 				term_newln(p);
 				break;
 			}
@@ -280,8 +279,7 @@ terminal_mdoc(void *arg, const struct ro
 		save_defindent = p->defindent;
 		if (p->defindent == 0)
 			p->defindent = 5;
-		term_begin(p, print_mdoc_head, print_mdoc_foot,
-		    &mdoc->meta);
+		term_begin(p, print_mdoc_head, print_mdoc_foot, mdoc);
 		while (n != NULL &&
 		    (n->type == ROFFT_COMMENT ||
 		     n->flags & NODE_NOPRT))
@@ -289,7 +287,7 @@ terminal_mdoc(void *arg, const struct ro
 		if (n != NULL) {
 			if (n->tok != MDOC_Sh)
 				term_vspace(p);
-			print_mdoc_nodelist(p, NULL, &mdoc->meta, n);
+			print_mdoc_nodelist(p, NULL, mdoc, n);
 		}
 		term_end(p);
 		p->defindent = save_defindent;
Index: mandoc.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc.c,v
retrieving revision 1.113
retrieving revision 1.114
diff -Lmandoc.c -Lmandoc.c -u -p -r1.113 -r1.114
--- mandoc.c
+++ mandoc.c
@@ -32,6 +32,7 @@
 #include "mandoc.h"
 #include "roff.h"
 #include "libmandoc.h"
+#include "roff_int.h"
 
 static	int	 a2time(time_t *, const char *, const char *);
 static	char	*time2a(time_t);
@@ -563,7 +564,7 @@ mandoc_normdate(struct roff_man *man, ch
 		mandoc_msg(MANDOCERR_DATE_BAD, ln, pos, "%s", in);
 	else if (t > time(NULL) + 86400)
 		mandoc_msg(MANDOCERR_DATE_FUTURE, ln, pos, "%s", in);
-	else if (man->macroset == MACROSET_MDOC)
+	else if (man->meta.macroset == MACROSET_MDOC)
 		mandoc_msg(MANDOCERR_DATE_LEGACY, ln, pos, "Dd %s", in);
 
 	/* Use any non-mdoc(7) date verbatim. */
Index: main.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/main.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -Lmain.h -Lmain.h -u -p -r1.28 -r1.29
--- main.h
+++ main.h
@@ -16,7 +16,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-struct	roff_man;
+struct	roff_meta;
 struct	manoutput;
 
 /*
@@ -27,14 +27,14 @@ struct	manoutput;
  */
 
 void		 *html_alloc(const struct manoutput *);
-void		  html_mdoc(void *, const struct roff_man *);
-void		  html_man(void *, const struct roff_man *);
+void		  html_mdoc(void *, const struct roff_meta *);
+void		  html_man(void *, const struct roff_meta *);
 void		  html_free(void *);
 
-void		  tree_mdoc(void *, const struct roff_man *);
-void		  tree_man(void *, const struct roff_man *);
+void		  tree_mdoc(void *, const struct roff_meta *);
+void		  tree_man(void *, const struct roff_meta *);
 
-void		  man_mdoc(void *, const struct roff_man *);
+void		  man_mdoc(void *, const struct roff_meta *);
 
 void		 *locale_alloc(const struct manoutput *);
 void		 *utf8_alloc(const struct manoutput *);
@@ -45,8 +45,8 @@ void		 *pdf_alloc(const struct manoutput
 void		 *ps_alloc(const struct manoutput *);
 void		  pspdf_free(void *);
 
-void		  terminal_mdoc(void *, const struct roff_man *);
-void		  terminal_man(void *, const struct roff_man *);
+void		  terminal_mdoc(void *, const struct roff_meta *);
+void		  terminal_man(void *, const struct roff_meta *);
 void		  terminal_sepline(void *);
 
-void		  markdown_mdoc(void *, const struct roff_man *);
+void		  markdown_mdoc(void *, const struct roff_meta *);
Index: mdoc_state.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_state.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -Lmdoc_state.c -Lmdoc_state.c -u -p -r1.11 -r1.12
--- mdoc_state.c
+++ mdoc_state.c
@@ -25,6 +25,7 @@
 #include "roff.h"
 #include "mdoc.h"
 #include "libmandoc.h"
+#include "roff_int.h"
 #include "libmdoc.h"
 
 #define STATE_ARGS  struct roff_man *mdoc, struct roff_node *n
Index: libman.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/libman.h,v
retrieving revision 1.83
retrieving revision 1.84
diff -Llibman.h -Llibman.h -u -p -r1.83 -r1.84
--- libman.h
+++ libman.h
@@ -16,6 +16,9 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+struct	roff_node;
+struct	roff_man;
+
 #define	MACRO_PROT_ARGS	  struct roff_man *man, \
 			  enum roff_tok tok, \
 			  int line, \
Index: main.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/main.c,v
retrieving revision 1.314
retrieving revision 1.315
diff -Lmain.c -Lmain.c -u -p -r1.314 -r1.315
--- main.c
+++ main.c
@@ -308,6 +308,9 @@ main(int argc, char *argv[])
 		}
 	}
 
+	if (curp.outtype != OUTT_TREE || !curp.outopts->noval)
+		options |= MPARSE_VALIDATE;
+
 	if (outmode == OUTMODE_FLN ||
 	    outmode == OUTMODE_LST ||
 	    !isatty(STDOUT_FILENO))
@@ -801,7 +804,7 @@ fs_search(const struct mansearch *cfg, c
 static void
 parse(struct curparse *curp, int fd, const char *file)
 {
-	struct roff_man	 *man;
+	struct roff_meta *meta;
 
 	/* Begin by parsing the file itself. */
 
@@ -823,49 +826,43 @@ parse(struct curparse *curp, int fd, con
 	if (curp->outdata == NULL)
 		outdata_alloc(curp);
 
-	mparse_result(curp->mp, &man, NULL);
+	mandoc_xr_reset();
+	meta = mparse_result(curp->mp);
 
 	/* Execute the out device, if it exists. */
 
-	if (man == NULL)
-		return;
-	mandoc_xr_reset();
-	if (man->macroset == MACROSET_MDOC) {
-		if (curp->outtype != OUTT_TREE || !curp->outopts->noval)
-			mdoc_validate(man);
+	if (meta->macroset == MACROSET_MDOC) {
 		switch (curp->outtype) {
 		case OUTT_HTML:
-			html_mdoc(curp->outdata, man);
+			html_mdoc(curp->outdata, meta);
 			break;
 		case OUTT_TREE:
-			tree_mdoc(curp->outdata, man);
+			tree_mdoc(curp->outdata, meta);
 			break;
 		case OUTT_MAN:
-			man_mdoc(curp->outdata, man);
+			man_mdoc(curp->outdata, meta);
 			break;
 		case OUTT_PDF:
 		case OUTT_ASCII:
 		case OUTT_UTF8:
 		case OUTT_LOCALE:
 		case OUTT_PS:
-			terminal_mdoc(curp->outdata, man);
+			terminal_mdoc(curp->outdata, meta);
 			break;
 		case OUTT_MARKDOWN:
-			markdown_mdoc(curp->outdata, man);
+			markdown_mdoc(curp->outdata, meta);
 			break;
 		default:
 			break;
 		}
 	}
-	if (man->macroset == MACROSET_MAN) {
-		if (curp->outtype != OUTT_TREE || !curp->outopts->noval)
-			man_validate(man);
+	if (meta->macroset == MACROSET_MAN) {
 		switch (curp->outtype) {
 		case OUTT_HTML:
-			html_man(curp->outdata, man);
+			html_man(curp->outdata, meta);
 			break;
 		case OUTT_TREE:
-			tree_man(curp->outdata, man);
+			tree_man(curp->outdata, meta);
 			break;
 		case OUTT_MAN:
 			mparse_copy(curp->mp);
@@ -875,7 +872,7 @@ parse(struct curparse *curp, int fd, con
 		case OUTT_UTF8:
 		case OUTT_LOCALE:
 		case OUTT_PS:
-			terminal_man(curp->outdata, man);
+			terminal_man(curp->outdata, meta);
 			break;
 		default:
 			break;
Index: tree.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/tree.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -Ltree.c -Ltree.c -u -p -r1.82 -r1.83
--- tree.c
+++ tree.c
@@ -41,18 +41,18 @@ static	void	print_span(const struct tbl_
 
 
 void
-tree_mdoc(void *arg, const struct roff_man *mdoc)
+tree_mdoc(void *arg, const struct roff_meta *mdoc)
 {
-	print_meta(&mdoc->meta);
+	print_meta(mdoc);
 	putchar('\n');
 	print_mdoc(mdoc->first->child, 0);
 }
 
 void
-tree_man(void *arg, const struct roff_man *man)
+tree_man(void *arg, const struct roff_meta *man)
 {
-	print_meta(&man->meta);
-	if (man->meta.hasbody == 0)
+	print_meta(man);
+	if (man->hasbody == 0)
 		puts("body  = empty");
 	putchar('\n');
 	print_man(man->first->child, 0);
Index: mandocd.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandocd.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -Lmandocd.c -Lmandocd.c -u -p -r1.8 -r1.9
--- mandocd.c
+++ mandocd.c
@@ -244,35 +244,29 @@ main(int argc, char *argv[])
 static void
 process(struct mparse *parser, enum outt outtype, void *formatter)
 {
-	struct roff_man	 *man;
+	struct roff_meta *meta;
 
 	mparse_readfd(parser, STDIN_FILENO, "<unixfd>");
-	mparse_result(parser, &man, NULL);
-
-	if (man == NULL)
-		return;
-
-	if (man->macroset == MACROSET_MDOC) {
-		mdoc_validate(man);
+	meta = mparse_result(parser);
+	if (meta->macroset == MACROSET_MDOC) {
 		switch (outtype) {
 		case OUTT_ASCII:
 		case OUTT_UTF8:
-			terminal_mdoc(formatter, man);
+			terminal_mdoc(formatter, meta);
 			break;
 		case OUTT_HTML:
-			html_mdoc(formatter, man);
+			html_mdoc(formatter, meta);
 			break;
 		}
 	}
-	if (man->macroset == MACROSET_MAN) {
-		man_validate(man);
+	if (meta->macroset == MACROSET_MAN) {
 		switch (outtype) {
 		case OUTT_ASCII:
 		case OUTT_UTF8:
-			terminal_man(formatter, man);
+			terminal_man(formatter, meta);
 			break;
 		case OUTT_HTML:
-			html_man(formatter, man);
+			html_man(formatter, meta);
 			break;
 		}
 	}
Index: mandocdb.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandocdb.c,v
retrieving revision 1.261
retrieving revision 1.262
diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.261 -r1.262
--- mandocdb.c
+++ mandocdb.c
@@ -347,6 +347,7 @@ mandocdb(int argc, char *argv[])
 		goto usage; \
 	} while (/*CONSTCOND*/0)
 
+	mparse_options = MPARSE_VALIDATE;
 	path_arg = NULL;
 	op = OP_DEFAULT;
 
@@ -1115,8 +1116,7 @@ mpages_merge(struct dba *dba, struct mpa
 {
 	struct mpage		*mpage, *mpage_dest;
 	struct mlink		*mlink, *mlink_dest;
-	struct roff_man		*man;
-	char			*sodest;
+	struct roff_meta	*meta;
 	char			*cp;
 	int			 fd;
 
@@ -1129,8 +1129,7 @@ mpages_merge(struct dba *dba, struct mpa
 		mandoc_ohash_init(&names, 4, offsetof(struct str, key));
 		mandoc_ohash_init(&strings, 6, offsetof(struct str, key));
 		mparse_reset(mp);
-		man = NULL;
-		sodest = NULL;
+		meta = NULL;
 
 		if ((fd = mparse_open(mp, mlink->file)) == -1) {
 			say(mlink->file, "&open");
@@ -1145,14 +1144,14 @@ mpages_merge(struct dba *dba, struct mpa
 			mparse_readfd(mp, fd, mlink->file);
 			close(fd);
 			fd = -1;
-			mparse_result(mp, &man, &sodest);
+			meta = mparse_result(mp);
 		}
 
-		if (sodest != NULL) {
+		if (meta != NULL && meta->sodest != NULL) {
 			mlink_dest = ohash_find(&mlinks,
-			    ohash_qlookup(&mlinks, sodest));
+			    ohash_qlookup(&mlinks, meta->sodest));
 			if (mlink_dest == NULL) {
-				mandoc_asprintf(&cp, "%s.gz", sodest);
+				mandoc_asprintf(&cp, "%s.gz", meta->sodest);
 				mlink_dest = ohash_find(&mlinks,
 				    ohash_qlookup(&mlinks, cp));
 				free(cp);
@@ -1189,39 +1188,36 @@ mpages_merge(struct dba *dba, struct mpa
 				mpage->mlinks = NULL;
 			}
 			goto nextpage;
-		} else if (man != NULL && man->macroset == MACROSET_MDOC) {
-			mdoc_validate(man);
+		} else if (meta != NULL && meta->macroset == MACROSET_MDOC) {
 			mpage->form = FORM_SRC;
-			mpage->sec = man->meta.msec;
+			mpage->sec = meta->msec;
 			mpage->sec = mandoc_strdup(
 			    mpage->sec == NULL ? "" : mpage->sec);
-			mpage->arch = man->meta.arch;
+			mpage->arch = meta->arch;
 			mpage->arch = mandoc_strdup(
 			    mpage->arch == NULL ? "" : mpage->arch);
-			mpage->title = mandoc_strdup(man->meta.title);
-		} else if (man != NULL && man->macroset == MACROSET_MAN) {
-			man_validate(man);
-			if (*man->meta.msec != '\0' ||
-			    *man->meta.title != '\0') {
+			mpage->title = mandoc_strdup(meta->title);
+		} else if (meta != NULL && meta->macroset == MACROSET_MAN) {
+			if (*meta->msec != '\0' || *meta->title != '\0') {
 				mpage->form = FORM_SRC;
-				mpage->sec = mandoc_strdup(man->meta.msec);
+				mpage->sec = mandoc_strdup(meta->msec);
 				mpage->arch = mandoc_strdup(mlink->arch);
-				mpage->title = mandoc_strdup(man->meta.title);
+				mpage->title = mandoc_strdup(meta->title);
 			} else
-				man = NULL;
+				meta = NULL;
 		}
 
 		assert(mpage->desc == NULL);
-		if (man == NULL) {
+		if (meta == NULL) {
 			mpage->form = FORM_CAT;
 			mpage->sec = mandoc_strdup(mlink->dsec);
 			mpage->arch = mandoc_strdup(mlink->arch);
 			mpage->title = mandoc_strdup(mlink->name);
 			parse_cat(mpage, fd);
-		} else if (man->macroset == MACROSET_MDOC)
-			parse_mdoc(mpage, &man->meta, man->first);
+		} else if (meta->macroset == MACROSET_MDOC)
+			parse_mdoc(mpage, meta, meta->first);
 		else
-			parse_man(mpage, &man->meta, man->first);
+			parse_man(mpage, meta, meta->first);
 		if (mpage->desc == NULL) {
 			mpage->desc = mandoc_strdup(mlink->name);
 			if (warnings)
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-12-30  0:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-30  0:50 mandoc: Cleanup, no functional change: The struct roff_man used to be a schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).