aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-04-18 16:34:25 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-04-18 16:34:25 +0000
commit70a9dbd1a5a305812354c332d729472bd2c06561 (patch)
tree063eba43441d0af27e5bfb6e4db4bd1ce0c4e545
parent90913383a1a42f4ed3816d5206553df9db14e839 (diff)
downloadmandoc-70a9dbd1a5a305812354c332d729472bd2c06561.tar.gz
mandoc-70a9dbd1a5a305812354c332d729472bd2c06561.tar.zst
mandoc-70a9dbd1a5a305812354c332d729472bd2c06561.zip
Profit from the unified struct roff_man and reduce the number of
arguments of mparse_result() by one. No functional change. Written on the ICE Bruxelles-Koeln on the way back from p2k15.
-rw-r--r--cgi.c14
-rw-r--r--demandoc.c15
-rw-r--r--main.c13
-rw-r--r--man.c3
-rw-r--r--mandoc.h4
-rw-r--r--mandocdb.c20
-rw-r--r--mdoc.c3
-rw-r--r--read.c92
-rw-r--r--roff.h7
9 files changed, 83 insertions, 88 deletions
diff --git a/cgi.c b/cgi.c
index e3136c9a..14ff5f8b 100644
--- a/cgi.c
+++ b/cgi.c
@@ -1,4 +1,4 @@
-/* $Id: cgi.c,v 1.107 2015/04/18 16:06:39 schwarze Exp $ */
+/* $Id: cgi.c,v 1.108 2015/04/18 16:34:25 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@usta.de>
@@ -30,8 +30,9 @@
#include <string.h>
#include <unistd.h>
-#include "mandoc.h"
#include "mandoc_aux.h"
+#include "mandoc.h"
+#include "roff.h"
#include "main.h"
#include "manconf.h"
#include "mansearch.h"
@@ -819,7 +820,6 @@ format(const struct req *req, const char *file)
struct manoutput conf;
struct mparse *mp;
struct mchars *mchars;
- struct roff_man *mdoc;
struct roff_man *man;
void *vp;
int fd;
@@ -846,8 +846,8 @@ format(const struct req *req, const char *file)
usepath ? "&manpath=" : "",
usepath ? req->q.manpath : "");
- mparse_result(mp, &mdoc, &man, NULL);
- if (NULL == man && NULL == mdoc) {
+ mparse_result(mp, &man, NULL);
+ if (man == NULL) {
fprintf(stderr, "fatal mandoc error: %s/%s\n",
req->q.manpath, file);
pg_error_internal();
@@ -858,8 +858,8 @@ format(const struct req *req, const char *file)
vp = html_alloc(mchars, &conf);
- if (NULL != mdoc)
- html_mdoc(vp, mdoc);
+ if (man->macroset == MACROSET_MDOC)
+ html_mdoc(vp, man);
else
html_man(vp, man);
diff --git a/demandoc.c b/demandoc.c
index 10f3d909..d4667c48 100644
--- a/demandoc.c
+++ b/demandoc.c
@@ -1,4 +1,4 @@
-/* $Id: demandoc.c,v 1.18 2015/04/18 16:06:39 schwarze Exp $ */
+/* $Id: demandoc.c,v 1.19 2015/04/18 16:34:25 schwarze Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -110,21 +110,20 @@ usage(void)
static void
pmandoc(struct mparse *mp, int fd, const char *fn, int list)
{
- struct roff_man *mdoc;
struct roff_man *man;
int line, col;
mparse_readfd(mp, fd, fn);
- mparse_result(mp, &mdoc, &man, NULL);
+ mparse_result(mp, &man, NULL);
line = 1;
col = 0;
- if (mdoc)
- pmdoc(mdoc_node(mdoc), &line, &col, list);
- else if (man)
- pman(man_node(man), &line, &col, list);
- else
+ if (man == NULL)
return;
+ if (man->macroset == MACROSET_MDOC)
+ pmdoc(mdoc_node(man), &line, &col, list);
+ else
+ pman(man_node(man), &line, &col, list);
if ( ! list)
putchar('\n');
diff --git a/main.c b/main.c
index 8417f8cd..d7606d3c 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.234 2015/04/18 16:06:40 schwarze Exp $ */
+/* $Id: main.c,v 1.235 2015/04/18 16:34:25 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -632,7 +632,6 @@ static void
parse(struct curparse *curp, int fd, const char *file)
{
enum mandoclevel rctmp;
- struct roff_man *mdoc;
struct roff_man *man;
/* Begin by parsing the file itself. */
@@ -720,14 +719,16 @@ parse(struct curparse *curp, int fd, const char *file)
}
}
- mparse_result(curp->mp, &mdoc, &man, NULL);
+ mparse_result(curp->mp, &man, NULL);
/* Execute the out device, if it exists. */
- if (man && curp->outman)
+ if (man == NULL)
+ return;
+ if (curp->outmdoc != NULL && man->macroset == MACROSET_MDOC)
+ (*curp->outmdoc)(curp->outdata, man);
+ if (curp->outman != NULL && man->macroset == MACROSET_MAN)
(*curp->outman)(curp->outdata, man);
- if (mdoc && curp->outmdoc)
- (*curp->outmdoc)(curp->outdata, mdoc);
}
static void
diff --git a/man.c b/man.c
index 29785f31..105dd9c1 100644
--- a/man.c
+++ b/man.c
@@ -1,4 +1,4 @@
-/* $Id: man.c,v 1.153 2015/04/18 16:06:40 schwarze Exp $ */
+/* $Id: man.c,v 1.154 2015/04/18 16:34:25 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -149,6 +149,7 @@ man_alloc1(struct roff_man *man)
{
memset(&man->meta, 0, sizeof(man->meta));
+ man->macroset = MACROSET_MAN;
man->flags = 0;
man->last = mandoc_calloc(1, sizeof(*man->last));
man->first = man->last;
diff --git a/mandoc.h b/mandoc.h
index f6212b16..d3b95986 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc.h,v 1.202 2015/04/18 16:06:40 schwarze Exp $ */
+/* $Id: mandoc.h,v 1.203 2015/04/18 16:34:25 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -433,7 +433,7 @@ enum mandoclevel mparse_readfd(struct mparse *, int, const char *);
enum mandoclevel mparse_readmem(struct mparse *, void *, size_t,
const char *);
void mparse_reset(struct mparse *);
-void mparse_result(struct mparse *, struct roff_man **,
+void mparse_result(struct mparse *,
struct roff_man **, char **);
const char *mparse_getkeep(const struct mparse *);
const char *mparse_strerror(enum mandocerr);
diff --git a/mandocdb.c b/mandocdb.c
index 03f6ab20..398f1666 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -1,4 +1,4 @@
-/* $Id: mandocdb.c,v 1.191 2015/04/18 16:06:40 schwarze Exp $ */
+/* $Id: mandocdb.c,v 1.192 2015/04/18 16:34:25 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -1107,7 +1107,6 @@ mpages_merge(struct mparse *mp)
struct ohash_info str_info;
struct mpage *mpage, *mpage_dest;
struct mlink *mlink, *mlink_dest;
- struct roff_man *mdoc;
struct roff_man *man;
char *sodest;
char *cp;
@@ -1135,7 +1134,6 @@ mpages_merge(struct mparse *mp)
ohash_init(&names, 4, &str_info);
ohash_init(&strings, 6, &str_info);
mparse_reset(mp);
- mdoc = NULL;
man = NULL;
sodest = NULL;
@@ -1151,7 +1149,7 @@ mpages_merge(struct mparse *mp)
*/
if (mlink->dform != FORM_CAT || mlink->fform != FORM_CAT) {
mparse_readfd(mp, fd, mlink->file);
- mparse_result(mp, &mdoc, &man, &sodest);
+ mparse_result(mp, &man, &sodest);
}
if (sodest != NULL) {
@@ -1195,17 +1193,17 @@ mpages_merge(struct mparse *mp)
mpage->mlinks = NULL;
}
goto nextpage;
- } else if (mdoc != NULL) {
+ } else if (man != NULL && man->macroset == MACROSET_MDOC) {
mpage->form = FORM_SRC;
- mpage->sec = mdoc_meta(mdoc)->msec;
+ mpage->sec = mdoc_meta(man)->msec;
mpage->sec = mandoc_strdup(
mpage->sec == NULL ? "" : mpage->sec);
- mpage->arch = mdoc_meta(mdoc)->arch;
+ mpage->arch = mdoc_meta(man)->arch;
mpage->arch = mandoc_strdup(
mpage->arch == NULL ? "" : mpage->arch);
mpage->title =
- mandoc_strdup(mdoc_meta(mdoc)->title);
- } else if (man != NULL) {
+ mandoc_strdup(mdoc_meta(man)->title);
+ } else if (man != NULL && man->macroset == MACROSET_MAN) {
mpage->form = FORM_SRC;
mpage->sec = mandoc_strdup(man_meta(man)->msec);
mpage->arch = mandoc_strdup(mlink->arch);
@@ -1231,8 +1229,8 @@ mpages_merge(struct mparse *mp)
}
assert(mpage->desc == NULL);
- if (mdoc != NULL)
- parse_mdoc(mpage, mdoc_meta(mdoc), mdoc_node(mdoc));
+ if (man != NULL && man->macroset == MACROSET_MDOC)
+ parse_mdoc(mpage, mdoc_meta(man), mdoc_node(man));
else if (man != NULL)
parse_man(mpage, man_meta(man), man_node(man));
else
diff --git a/mdoc.c b/mdoc.c
index 7f4909ae..04b2a21a 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.242 2015/04/18 16:06:40 schwarze Exp $ */
+/* $Id: mdoc.c,v 1.243 2015/04/18 16:34:25 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -135,6 +135,7 @@ mdoc_alloc1(struct roff_man *mdoc)
{
memset(&mdoc->meta, 0, sizeof(mdoc->meta));
+ mdoc->macroset = MACROSET_MDOC;
mdoc->flags = 0;
mdoc->lastnamed = mdoc->lastsec = SEC_NONE;
mdoc->last = mandoc_calloc(1, sizeof(*mdoc->last));
diff --git a/read.c b/read.c
index de4ed177..bde299c9 100644
--- a/read.c
+++ b/read.c
@@ -1,4 +1,4 @@
-/* $Id: read.c,v 1.134 2015/04/18 16:06:41 schwarze Exp $ */
+/* $Id: read.c,v 1.135 2015/04/18 16:34:25 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -47,10 +47,7 @@
#define REPARSE_LIMIT 1000
struct mparse {
- struct roff_man *pman; /* persistent man parser */
- struct roff_man *pmdoc; /* persistent mdoc parser */
struct roff_man *man; /* man parser */
- struct roff_man *mdoc; /* mdoc parser */
struct roff *roff; /* roff parser (!NULL) */
const struct mchars *mchars; /* character table */
char *sodest; /* filename pointed to by .so */
@@ -293,23 +290,23 @@ choose_parser(struct mparse *curp)
}
if (format == MPARSE_MDOC) {
- if (NULL == curp->pmdoc)
- curp->pmdoc = mdoc_alloc(
+ if (curp->man == NULL)
+ curp->man = mdoc_alloc(
curp->roff, curp, curp->defos,
MPARSE_QUICK & curp->options ? 1 : 0);
- assert(curp->pmdoc);
- curp->mdoc = curp->pmdoc;
+ else
+ curp->man->macroset = MACROSET_MDOC;
return;
}
/* Fall back to man(7) as a last resort. */
- if (NULL == curp->pman)
- curp->pman = man_alloc(
+ if (curp->man == NULL)
+ curp->man = man_alloc(
curp->roff, curp, curp->defos,
MPARSE_QUICK & curp->options ? 1 : 0);
- assert(curp->pman);
- curp->man = curp->pman;
+ else
+ curp->man->macroset = MACROSET_MAN;
}
/*
@@ -575,7 +572,8 @@ rerun:
* parsers with each one.
*/
- if ( ! (curp->man || curp->mdoc))
+ if (curp->man == NULL ||
+ curp->man->macroset == MACROSET_NONE)
choose_parser(curp);
/*
@@ -589,17 +587,17 @@ rerun:
if (rr == ROFF_TBL) {
while ((span = roff_span(curp->roff)) != NULL)
- if (curp->man == NULL)
- mdoc_addspan(curp->mdoc, span);
+ if (curp->man->macroset == MACROSET_MDOC)
+ mdoc_addspan(curp->man, span);
else
man_addspan(curp->man, span);
} else if (rr == ROFF_EQN) {
- if (curp->man == NULL)
- mdoc_addeqn(curp->mdoc, roff_eqn(curp->roff));
+ if (curp->man->macroset == MACROSET_MDOC)
+ mdoc_addeqn(curp->man, roff_eqn(curp->roff));
else
man_addeqn(curp->man, roff_eqn(curp->roff));
- } else if ((curp->man == NULL ?
- mdoc_parseln(curp->mdoc, curp->line, ln.buf, of) :
+ } else if ((curp->man->macroset == MACROSET_MDOC ?
+ mdoc_parseln(curp->man, curp->line, ln.buf, of) :
man_parseln(curp->man, curp->line, ln.buf, of)) == 2)
break;
@@ -689,22 +687,14 @@ static void
mparse_end(struct mparse *curp)
{
- if (curp->mdoc == NULL &&
- curp->man == NULL &&
- curp->sodest == NULL) {
- if (curp->options & MPARSE_MDOC)
- curp->mdoc = curp->pmdoc;
- else {
- if (curp->pman == NULL)
- curp->pman = man_alloc(
- curp->roff, curp, curp->defos,
- curp->options & MPARSE_QUICK ? 1 : 0);
- curp->man = curp->pman;
- }
- }
- if (curp->mdoc)
- mdoc_endparse(curp->mdoc);
- if (curp->man)
+ if (curp->man == NULL && curp->sodest == NULL)
+ curp->man = man_alloc(curp->roff, curp, curp->defos,
+ curp->options & MPARSE_QUICK ? 1 : 0);
+ if (curp->man->macroset == MACROSET_NONE)
+ curp->man->macroset = MACROSET_MAN;
+ if (curp->man->macroset == MACROSET_MDOC)
+ mdoc_endparse(curp->man);
+ else
man_endparse(curp->man);
roff_endparse(curp->roff);
}
@@ -901,11 +891,11 @@ mparse_alloc(int options, enum mandoclevel wlevel, mandocmsg mmsg,
curp->mchars = mchars;
curp->roff = roff_alloc(curp, curp->mchars, options);
if (curp->options & MPARSE_MDOC)
- curp->pmdoc = mdoc_alloc(
+ curp->man = mdoc_alloc(
curp->roff, curp, curp->defos,
curp->options & MPARSE_QUICK ? 1 : 0);
if (curp->options & MPARSE_MAN)
- curp->pman = man_alloc(
+ curp->man = man_alloc(
curp->roff, curp, curp->defos,
curp->options & MPARSE_QUICK ? 1 : 0);
@@ -918,16 +908,17 @@ mparse_reset(struct mparse *curp)
roff_reset(curp->roff);
- if (curp->mdoc)
- mdoc_reset(curp->mdoc);
- if (curp->man)
- man_reset(curp->man);
+ if (curp->man != NULL) {
+ if (curp->man->macroset == MACROSET_MDOC)
+ mdoc_reset(curp->man);
+ else
+ man_reset(curp->man);
+ curp->man->macroset = MACROSET_NONE;
+ }
if (curp->secondary)
curp->secondary->sz = 0;
curp->file_status = MANDOCLEVEL_OK;
- curp->mdoc = NULL;
- curp->man = NULL;
free(curp->sodest);
curp->sodest = NULL;
@@ -937,10 +928,10 @@ void
mparse_free(struct mparse *curp)
{
- if (curp->pmdoc)
- mdoc_free(curp->pmdoc);
- if (curp->pman)
- man_free(curp->pman);
+ if (curp->man->macroset == MACROSET_MDOC)
+ mdoc_free(curp->man);
+ if (curp->man->macroset == MACROSET_MAN)
+ man_free(curp->man);
if (curp->roff)
roff_free(curp->roff);
if (curp->secondary)
@@ -952,17 +943,14 @@ mparse_free(struct mparse *curp)
}
void
-mparse_result(struct mparse *curp, struct roff_man **mdoc,
- struct roff_man **man, char **sodest)
+mparse_result(struct mparse *curp, struct roff_man **man,
+ char **sodest)
{
if (sodest && NULL != (*sodest = curp->sodest)) {
- *mdoc = NULL;
*man = NULL;
return;
}
- if (mdoc)
- *mdoc = curp->mdoc;
if (man)
*man = curp->man;
}
diff --git a/roff.h b/roff.h
index a73b523a..fd73ad73 100644
--- a/roff.h
+++ b/roff.h
@@ -19,6 +19,12 @@
struct mdoc_arg;
union mdoc_data;
+enum roff_macroset {
+ MACROSET_NONE = 0,
+ MACROSET_MDOC,
+ MACROSET_MAN
+};
+
enum roff_sec {
SEC_NONE = 0,
SEC_NAME,
@@ -145,6 +151,7 @@ struct roff_man {
#define MAN_BLINE (1 << 12) /* Next-line block scope. */
#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. */