summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/mandoc/cgi.c14
-rw-r--r--usr.bin/mandoc/main.c13
-rw-r--r--usr.bin/mandoc/man.c3
-rw-r--r--usr.bin/mandoc/mandoc.h4
-rw-r--r--usr.bin/mandoc/mandocdb.c20
-rw-r--r--usr.bin/mandoc/mdoc.c3
-rw-r--r--usr.bin/mandoc/read.c92
-rw-r--r--usr.bin/mandoc/roff.h9
8 files changed, 77 insertions, 81 deletions
diff --git a/usr.bin/mandoc/cgi.c b/usr.bin/mandoc/cgi.c
index 7adef3aa648..4d72f06e921 100644
--- a/usr.bin/mandoc/cgi.c
+++ b/usr.bin/mandoc/cgi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cgi.c,v 1.46 2015/04/18 16:04:40 schwarze Exp $ */
+/* $OpenBSD: cgi.c,v 1.47 2015/04/18 16:34:03 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@usta.de>
@@ -28,8 +28,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"
@@ -817,7 +818,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;
@@ -844,8 +844,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();
@@ -856,8 +856,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/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
index cb854d11544..d5e561c0b13 100644
--- a/usr.bin/mandoc/main.c
+++ b/usr.bin/mandoc/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.139 2015/04/18 16:04:40 schwarze Exp $ */
+/* $OpenBSD: main.c,v 1.140 2015/04/18 16:34:03 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -607,7 +607,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. */
@@ -695,14 +694,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/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c
index fcf289faa0e..010590b415e 100644
--- a/usr.bin/mandoc/man.c
+++ b/usr.bin/mandoc/man.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: man.c,v 1.101 2015/04/18 16:04:40 schwarze Exp $ */
+/* $OpenBSD: man.c,v 1.102 2015/04/18 16:34:03 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -147,6 +147,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/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h
index 3f63912f32e..249db667584 100644
--- a/usr.bin/mandoc/mandoc.h
+++ b/usr.bin/mandoc/mandoc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mandoc.h,v 1.144 2015/04/18 16:04:40 schwarze Exp $ */
+/* $OpenBSD: mandoc.h,v 1.145 2015/04/18 16:34:03 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -431,7 +431,7 @@ void mparse_keep(struct mparse *);
enum mandoclevel mparse_open(struct mparse *, int *, const char *);
enum mandoclevel mparse_readfd(struct mparse *, int, 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/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c
index 2a3683e3ed0..1bb19e44eb5 100644
--- a/usr.bin/mandoc/mandocdb.c
+++ b/usr.bin/mandoc/mandocdb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mandocdb.c,v 1.144 2015/04/18 16:04:40 schwarze Exp $ */
+/* $OpenBSD: mandocdb.c,v 1.145 2015/04/18 16:34:03 schwarze Exp $ */
/*
* Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -1089,7 +1089,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;
@@ -1117,7 +1116,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;
@@ -1133,7 +1131,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) {
@@ -1177,17 +1175,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);
@@ -1213,8 +1211,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/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c
index a442343bcab..f17ade34b77 100644
--- a/usr.bin/mandoc/mdoc.c
+++ b/usr.bin/mandoc/mdoc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc.c,v 1.131 2015/04/18 16:04:40 schwarze Exp $ */
+/* $OpenBSD: mdoc.c,v 1.132 2015/04/18 16:34:03 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -133,6 +133,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/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c
index 53694145f81..3df1956d8b7 100644
--- a/usr.bin/mandoc/read.c
+++ b/usr.bin/mandoc/read.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: read.c,v 1.109 2015/04/18 16:04:40 schwarze Exp $ */
+/* $OpenBSD: read.c,v 1.110 2015/04/18 16:34:03 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -42,10 +42,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 */
@@ -288,23 +285,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;
}
/*
@@ -570,7 +567,8 @@ rerun:
* parsers with each one.
*/
- if ( ! (curp->man || curp->mdoc))
+ if (curp->man == NULL ||
+ curp->man->macroset == MACROSET_NONE)
choose_parser(curp);
/*
@@ -584,17 +582,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;
@@ -682,22 +680,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);
}
@@ -879,11 +869,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);
@@ -896,16 +886,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;
@@ -915,10 +906,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)
@@ -930,17 +921,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/usr.bin/mandoc/roff.h b/usr.bin/mandoc/roff.h
index efbeff97521..03bda5e403f 100644
--- a/usr.bin/mandoc/roff.h
+++ b/usr.bin/mandoc/roff.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: roff.h,v 1.13 2015/04/18 16:04:40 schwarze Exp $ */
+/* $OpenBSD: roff.h,v 1.14 2015/04/18 16:34:03 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -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. */