arguments of mparse_result() by one. No functional change.
Written on the ICE Bruxelles-Koeln on the way back from p2k15.
-/* $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>
#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"
struct manoutput conf;
struct mparse *mp;
struct mchars *mchars;
- struct roff_man *mdoc;
struct roff_man *man;
void *vp;
int fd;
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();
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);
-/* $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>
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. */
}
}
- 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
-/* $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>
{
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;
-/* $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>
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);
-/* $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>
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;
ohash_init(&names, 4, &str_info);
ohash_init(&strings, 6, &str_info);
mparse_reset(mp);
- mdoc = NULL;
man = NULL;
sodest = NULL;
*/
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) {
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);
}
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
-/* $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>
{
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));
-/* $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>
#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 */
}
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;
}
/*
* parsers with each one.
*/
- if ( ! (curp->man || curp->mdoc))
+ if (curp->man == NULL ||
+ curp->man->macroset == MACROSET_NONE)
choose_parser(curp);
/*
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;
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);
}
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);
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;
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)
}
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;
}
-/* $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>
struct mdoc_arg;
union mdoc_data;
+enum roff_macroset {
+ MACROSET_NONE = 0,
+ MACROSET_MDOC,
+ MACROSET_MAN
+};
+
enum roff_sec {
SEC_NONE = 0,
SEC_NAME,
#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. */