summaryrefslogtreecommitdiffstats
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
commit19dfb5cab356150bf46d159f43ead732a6a6ade5 (patch)
tree79243b72064d2dfc284d040592d6f69b6a983ad7
parent87a05fb3c50ab6e9a1befb22c6e63e3e47f571f3 (diff)
downloadmandoc-19dfb5cab356150bf46d159f43ead732a6a6ade5.tar.gz
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.c12
-rw-r--r--demandoc.c13
-rw-r--r--main.c11
-rw-r--r--man.c1
-rw-r--r--mandoc.h2
-rw-r--r--mandocdb.c18
-rw-r--r--mdoc.c1
-rw-r--r--read.c90
-rw-r--r--roff.h7
9 files changed, 75 insertions, 80 deletions
diff --git a/cgi.c b/cgi.c
index aac1d362..751cbcb5 100644
--- a/cgi.c
+++ b/cgi.c
@@ -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 679de959..937145de 100644
--- a/demandoc.c
+++ b/demandoc.c
@@ -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 9678b314..ed73e687 100644
--- a/main.c
+++ b/main.c
@@ -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 b01eefa4..337f9a99 100644
--- a/man.c
+++ b/man.c
@@ -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 1d8d6fd2..7a0fae10 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -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 ab673c52..161e2d5f 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -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 16b2ffaa..ba9cccc4 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -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 67d4f802..c0b566f5 100644
--- a/read.c
+++ b/read.c
@@ -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. */