aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2018-12-30 00:49:54 +0000
committerIngo Schwarze <schwarze@openbsd.org>2018-12-30 00:49:54 +0000
commit68183e3516ca405d803db497157cd8246b9b8bad (patch)
treed88411ec1f7435c594c8afcfc4b99cca3a0d5bdf
parentb4f47224dd1036f4d89f641195a444eea00a55e8 (diff)
downloadmandoc-68183e3516ca405d803db497157cd8246b9b8bad.tar.gz
mandoc-68183e3516ca405d803db497157cd8246b9b8bad.tar.zst
mandoc-68183e3516ca405d803db497157cd8246b9b8bad.zip
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.
-rw-r--r--Makefile.depend4
-rw-r--r--cgi.c30
-rw-r--r--demandoc.c21
-rw-r--r--libman.h5
-rw-r--r--libmdoc.h6
-rw-r--r--main.c37
-rw-r--r--main.h20
-rw-r--r--man.c4
-rw-r--r--man_html.c12
-rw-r--r--man_macro.c4
-rw-r--r--man_term.c11
-rw-r--r--mandoc.367
-rw-r--r--mandoc.c5
-rw-r--r--mandoc_headers.373
-rw-r--r--mandoc_parse.h8
-rw-r--r--mandocd.c24
-rw-r--r--mandocdb.c46
-rw-r--r--mdoc.c4
-rw-r--r--mdoc.h5
-rw-r--r--mdoc_html.c12
-rw-r--r--mdoc_macro.c4
-rw-r--r--mdoc_man.c11
-rw-r--r--mdoc_markdown.c20
-rw-r--r--mdoc_state.c3
-rw-r--r--mdoc_term.c12
-rw-r--r--mdoc_validate.c6
-rw-r--r--read.c48
-rw-r--r--roff.c31
-rw-r--r--roff.h45
-rw-r--r--roff_int.h48
-rw-r--r--tree.c12
31 files changed, 301 insertions, 337 deletions
diff --git a/Makefile.depend b/Makefile.depend
index 5817765c..c0e855c8 100644
--- a/Makefile.depend
+++ b/Makefile.depend
@@ -38,7 +38,7 @@ man_html.o: man_html.c config.h mandoc_aux.h mandoc.h roff.h man.h out.h html.h
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_aux.h mandoc.h roff.h mdoc.h out.h html
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
diff --git a/cgi.c b/cgi.c
index 652a6bb5..167fd84e 100644
--- a/cgi.c
+++ b/cgi.c
@@ -1,4 +1,4 @@
-/* $Id: cgi.c,v 1.163 2018/12/14 01:18:25 schwarze Exp $ */
+/* $Id: cgi.c,v 1.164 2018/12/30 00:49:54 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2016, 2017, 2018 Ingo Schwarze <schwarze@usta.de>
@@ -849,7 +849,7 @@ resp_format(const struct req *req, const char *file)
{
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 char *file)
}
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 char *file)
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);
diff --git a/demandoc.c b/demandoc.c
index c8dd35f9..e6af906c 100644
--- a/demandoc.c
+++ b/demandoc.c
@@ -1,4 +1,4 @@
-/* $Id: demandoc.c,v 1.31 2018/12/14 01:18:25 schwarze Exp $ */
+/* $Id: demandoc.c,v 1.32 2018/12/30 00:49:54 schwarze Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -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');
diff --git a/libman.h b/libman.h
index 92f49e7f..a9dd5418 100644
--- a/libman.h
+++ b/libman.h
@@ -1,4 +1,4 @@
-/* $Id: libman.h,v 1.83 2018/08/26 16:21:23 schwarze Exp $ */
+/* $Id: libman.h,v 1.84 2018/12/30 00:49:54 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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, \
diff --git a/libmdoc.h b/libmdoc.h
index dbe6ccfb..4f393da4 100644
--- a/libmdoc.h
+++ b/libmdoc.h
@@ -1,4 +1,4 @@
-/* $Id: libmdoc.h,v 1.115 2018/12/21 17:15:18 schwarze Exp $ */
+/* $Id: libmdoc.h,v 1.116 2018/12/30 00:49:54 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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, \
diff --git a/main.c b/main.c
index 150e808a..ad9ebf97 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.314 2018/12/20 21:30:32 schwarze Exp $ */
+/* $Id: main.c,v 1.315 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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, const struct manpaths *paths,
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, const char *file)
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, const char *file)
case OUTT_UTF8:
case OUTT_LOCALE:
case OUTT_PS:
- terminal_man(curp->outdata, man);
+ terminal_man(curp->outdata, meta);
break;
default:
break;
diff --git a/main.h b/main.h
index c3e09be6..772ea648 100644
--- a/main.h
+++ b/main.h
@@ -1,4 +1,4 @@
-/* $Id: main.h,v 1.28 2018/08/23 19:33:27 schwarze Exp $ */
+/* $Id: main.h,v 1.29 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 *);
diff --git a/man.c b/man.c
index b62f3ed1..2a198dd9 100644
--- a/man.c
+++ b/man.c
@@ -1,4 +1,4 @@
-/* $Id: man.c,v 1.181 2018/12/14 05:18:02 schwarze Exp $ */
+/* $Id: man.c,v 1.182 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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;
}
diff --git a/man_html.c b/man_html.c
index bd04b5bc..e226e563 100644
--- a/man_html.c
+++ b/man_html.c
@@ -1,4 +1,4 @@
-/* $Id: man_html.c,v 1.160 2018/12/16 00:17:02 schwarze Exp $ */
+/* $Id: man_html.c,v 1.161 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -139,7 +139,7 @@ print_bvspace(struct html *h, const struct roff_node *n)
}
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_man *man)
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);
}
diff --git a/man_macro.c b/man_macro.c
index 63ffc131..a08cdca6 100644
--- a/man_macro.c
+++ b/man_macro.c
@@ -1,4 +1,4 @@
-/* $Id: man_macro.c,v 1.137 2018/12/21 17:15:18 schwarze Exp $ */
+/* $Id: man_macro.c,v 1.138 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2012-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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;
}
diff --git a/man_term.c b/man_term.c
index 8361634e..99c2b794 100644
--- a/man_term.c
+++ b/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.222 2018/12/13 11:55:46 schwarze Exp $ */
+/* $Id: man_term.c,v 1.223 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 roff_man *man)
!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;
diff --git a/mandoc.3 b/mandoc.3
index 8ef7ff1b..4ecfbdeb 100644
--- a/mandoc.3
+++ b/mandoc.3
@@ -1,4 +1,4 @@
-.\" $Id: mandoc.3,v 1.43 2018/12/14 01:18:25 schwarze Exp $
+.\" $Id: mandoc.3,v 1.44 2018/12/30 00:49:55 schwarze Exp $
.\"
.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -15,14 +15,12 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: December 14 2018 $
+.Dd $Mdocdate: December 30 2018 $
.Dt MANDOC 3
.Os
.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 nodes.
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 honoured.
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
diff --git a/mandoc.c b/mandoc.c
index d1e7356b..fb9395a5 100644
--- a/mandoc.c
+++ b/mandoc.c
@@ -1,4 +1,4 @@
-/* $Id: mandoc.c,v 1.113 2018/12/18 22:00:02 schwarze Exp $ */
+/* $Id: mandoc.c,v 1.114 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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, char *in, int ln, int pos)
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. */
diff --git a/mandoc_headers.3 b/mandoc_headers.3
index e7138d73..32138473 100644
--- a/mandoc_headers.3
+++ b/mandoc_headers.3
@@ -1,4 +1,4 @@
-.Dd $Mdocdate: December 16 2018 $
+.Dd $Mdocdate: December 30 2018 $
.Dt MANDOC_HEADERS 3
.Os
.Sh NAME
@@ -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 formatters.
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.
diff --git a/mandoc_parse.h b/mandoc_parse.h
index 5ad0f07b..61341f0d 100644
--- a/mandoc_parse.h
+++ b/mandoc_parse.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc_parse.h,v 1.3 2018/12/14 01:24:49 schwarze Exp $ */
+/* $Id: mandoc_parse.h,v 1.4 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014,2015,2016,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 *);
diff --git a/mandocd.c b/mandocd.c
index 130849b8..77fd3d0d 100644
--- a/mandocd.c
+++ b/mandocd.c
@@ -1,4 +1,4 @@
-/* $Id: mandocd.c,v 1.8 2018/12/14 01:18:26 schwarze Exp $ */
+/* $Id: mandocd.c,v 1.9 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2017 Michael Stapelberg <stapelberg@debian.org>
* Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -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;
}
}
diff --git a/mandocdb.c b/mandocdb.c
index 497e2fef..222350c9 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -1,4 +1,4 @@
-/* $Id: mandocdb.c,v 1.261 2018/12/14 01:18:26 schwarze Exp $ */
+/* $Id: mandocdb.c,v 1.262 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 mparse *mp)
{
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 mparse *mp)
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 mparse *mp)
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 mparse *mp)
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)
diff --git a/mdoc.c b/mdoc.c
index ac33e9f7..c70b4838 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.271 2018/12/14 05:18:02 schwarze Exp $ */
+/* $Id: mdoc.c,v 1.272 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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);
}
diff --git a/mdoc.h b/mdoc.h
index 1628e0c8..2f32fa49 100644
--- a/mdoc.h
+++ b/mdoc.h
@@ -1,4 +1,4 @@
-/* $Id: mdoc.h,v 1.145 2017/04/24 23:06:18 schwarze Exp $ */
+/* $Id: mdoc.h,v 1.146 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 */
diff --git a/mdoc_html.c b/mdoc_html.c
index a3c05f08..25dace6d 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_html.c,v 1.320 2018/12/25 00:06:25 schwarze Exp $ */
+/* $Id: mdoc_html.c,v 1.321 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014,2015,2016,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -283,7 +283,7 @@ synopsis_pre(struct html *h, const struct roff_node *n)
}
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_man *mdoc)
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);
}
diff --git a/mdoc_macro.c b/mdoc_macro.c
index 062021de..a9343d67 100644
--- a/mdoc_macro.c
+++ b/mdoc_macro.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_macro.c,v 1.228 2018/12/21 17:15:19 schwarze Exp $ */
+/* $Id: mdoc_macro.c,v 1.229 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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);
}
diff --git a/mdoc_man.c b/mdoc_man.c
index c4e0be79..a67c9f67 100644
--- a/mdoc_man.c
+++ b/mdoc_man.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_man.c,v 1.130 2018/12/15 19:30:26 schwarze Exp $ */
+/* $Id: mdoc_man.c,v 1.131 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2011-2018 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -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_man *mdoc)
}
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_man *mdoc)
*fontqueue.tail = 'R';
}
for (; n != NULL; n = n->next)
- print_node(&mdoc->meta, n);
+ print_node(mdoc, n);
putchar('\n');
}
diff --git a/mdoc_markdown.c b/mdoc_markdown.c
index 35bae5bc..e9a93121 100644
--- a/mdoc_markdown.c
+++ b/mdoc_markdown.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_markdown.c,v 1.29 2018/12/15 19:30:26 schwarze Exp $ */
+/* $Id: mdoc_markdown.c,v 1.30 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -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 roff_man *mdoc)
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');
}
diff --git a/mdoc_state.c b/mdoc_state.c
index 22a3d268..e592dcce 100644
--- a/mdoc_state.c
+++ b/mdoc_state.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_state.c,v 1.11 2018/12/14 01:18:26 schwarze Exp $ */
+/* $Id: mdoc_state.c,v 1.12 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -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
diff --git a/mdoc_term.c b/mdoc_term.c
index 590a41ee..e06576a6 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.370 2018/12/13 11:55:47 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.371 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 roff_man *mdoc)
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 roff_man *mdoc)
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 roff_man *mdoc)
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;
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 3c773a52..c0469e88 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.365 2018/12/14 05:18:02 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.366 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 &&
diff --git a/read.c b/read.c
index 17200e09..8ab3c803 100644
--- a/read.c
+++ b/read.c
@@ -1,4 +1,4 @@
-/* $Id: read.c,v 1.208 2018/12/20 21:30:32 schwarze Exp $ */
+/* $Id: read.c,v 1.209 2018/12/30 00:49:55 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 fd, struct buf *fb, int *with_mmap)
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 os_e, const char *os_s)
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
diff --git a/roff.c b/roff.c
index 43a9d5ef..2262c961 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.355 2018/12/21 17:15:19 schwarze Exp $ */
+/* $Id: roff.c,v 1.356 2018/12/30 00:49:56 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 line, struct tbl_node *tbl)
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, struct roff_node *n)
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 *name, size_t len,
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 *name, size_t len,
}
}
}
- 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')
diff --git a/roff.h b/roff.h
index 624fcb00..8af8661b 100644
--- a/roff.h
+++ b/roff.h
@@ -1,4 +1,4 @@
-/* $Id: roff.h,v 1.65 2018/12/14 06:33:14 schwarze Exp $ */
+/* $Id: roff.h,v 1.66 2018/12/30 00:49:56 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 *);
diff --git a/roff_int.h b/roff_int.h
index 8b49065e..8cde310e 100644
--- a/roff_int.h
+++ b/roff_int.h
@@ -1,4 +1,4 @@
-/* $Id: roff_int.h,v 1.11 2018/12/13 06:18:20 schwarze Exp $ */
+/* $Id: roff_int.h,v 1.12 2018/12/30 00:49:56 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 *);
@@ -36,6 +80,8 @@ 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,
* not in libmdoc.h or libman.h, even if they are specific
diff --git a/tree.c b/tree.c
index 67358243..7888b40f 100644
--- a/tree.c
+++ b/tree.c
@@ -1,4 +1,4 @@
-/* $Id: tree.c,v 1.82 2018/12/13 05:23:38 schwarze Exp $ */
+/* $Id: tree.c,v 1.83 2018/12/30 00:49:56 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
@@ -41,18 +41,18 @@ static void print_span(const struct tbl_span *, int);
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);