summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-03-19 22:20:43 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-03-19 22:20:43 +0000
commit007dd8781c55fce01e2e54e6386731c355ad463d (patch)
tree744a417db38add0952cd00dc0691ba84dac03f0b
parentcd337f65ece6ac4cd6eb91fcbd5a7a970956eb3f (diff)
downloadmandoc-007dd8781c55fce01e2e54e6386731c355ad463d.tar.gz
Without the MPARSE_SO option, if the file contains nothing but a
single .so request, do not read the file pointed to, but instead let mparse_result() provide the file name pointed to as a return value. To be used by makewhatis(8) in the future.
-rw-r--r--cgi.c2
-rw-r--r--demandoc.c2
-rw-r--r--main.c2
-rw-r--r--mandoc.h2
-rw-r--r--mandocdb.c2
-rw-r--r--read.c21
6 files changed, 24 insertions, 7 deletions
diff --git a/cgi.c b/cgi.c
index 7255ce9c..380c445b 100644
--- a/cgi.c
+++ b/cgi.c
@@ -753,7 +753,7 @@ format(const struct req *req, const char *file)
/*"includes=/cgi-bin/man.cgi/usr/include/%%I"*/,
progname);
- mparse_result(mp, &mdoc, &man);
+ mparse_result(mp, &mdoc, &man, NULL);
if (NULL == man && NULL == mdoc) {
resp_baddb();
mparse_free(mp);
diff --git a/demandoc.c b/demandoc.c
index b120da2f..a757bf91 100644
--- a/demandoc.c
+++ b/demandoc.c
@@ -110,7 +110,7 @@ pmandoc(struct mparse *mp, int fd, const char *fn, int list)
return;
}
- mparse_result(mp, &mdoc, &man);
+ mparse_result(mp, &mdoc, &man, NULL);
line = 1;
col = 0;
diff --git a/main.c b/main.c
index 20d02e7a..738f0972 100644
--- a/main.c
+++ b/main.c
@@ -294,7 +294,7 @@ parse(struct curparse *curp, int fd,
}
}
- mparse_result(curp->mp, &mdoc, &man);
+ mparse_result(curp->mp, &mdoc, &man, NULL);
/* Execute the out device, if it exists. */
diff --git a/mandoc.h b/mandoc.h
index 268ed343..02070c5c 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -427,7 +427,7 @@ enum mandoclevel mparse_readmem(struct mparse *, const void *, size_t,
const char *);
void mparse_reset(struct mparse *);
void mparse_result(struct mparse *,
- struct mdoc **, struct man **);
+ struct mdoc **, struct man **, char **);
const char *mparse_getkeep(const struct mparse *);
const char *mparse_strerror(enum mandocerr);
const char *mparse_strlevel(enum mandoclevel);
diff --git a/mandocdb.c b/mandocdb.c
index 6cf259a2..772f191d 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -999,7 +999,7 @@ mpages_merge(struct mchars *mc, struct mparse *mp)
FORM_CAT != mpage->mlinks->fform) {
lvl = mparse_readfd(mp, -1, mpage->mlinks->file);
if (lvl < MANDOCLEVEL_FATAL)
- mparse_result(mp, &mdoc, &man);
+ mparse_result(mp, &mdoc, &man, NULL);
}
if (NULL != mdoc) {
diff --git a/read.c b/read.c
index 43e7a758..f325b148 100644
--- a/read.c
+++ b/read.c
@@ -59,6 +59,7 @@ struct mparse {
struct man *man; /* man parser */
struct mdoc *mdoc; /* mdoc parser */
struct roff *roff; /* roff parser (!NULL) */
+ char *sodest; /* filename pointed to by .so */
int reparse_count; /* finite interp. stack */
mandocmsg mmsg; /* warning/error message handler */
const char *file;
@@ -490,6 +491,12 @@ rerun:
assert(MANDOCLEVEL_FATAL <= curp->file_status);
break;
case (ROFF_SO):
+ if (0 == (MPARSE_SO & curp->options) &&
+ (i >= (int)blk.sz || '\0' == blk.buf[i])) {
+ curp->sodest = mandoc_strdup(ln.buf + of);
+ free(ln.buf);
+ return;
+ }
/*
* We remove `so' clauses from our lookaside
* buffer because we're going to descend into
@@ -676,7 +683,7 @@ mparse_end(struct mparse *curp)
return;
}
- if ( ! (curp->man || curp->mdoc)) {
+ if ( ! (curp->mdoc || curp->man || curp->sodest)) {
mandoc_msg(MANDOCERR_NOTMANUAL, curp, 1, 0, NULL);
curp->file_status = MANDOCLEVEL_FATAL;
return;
@@ -798,6 +805,9 @@ mparse_reset(struct mparse *curp)
curp->file_status = MANDOCLEVEL_OK;
curp->mdoc = NULL;
curp->man = NULL;
+
+ free(curp->sodest);
+ curp->sodest = NULL;
}
void
@@ -814,13 +824,20 @@ mparse_free(struct mparse *curp)
free(curp->secondary->buf);
free(curp->secondary);
+ free(curp->sodest);
free(curp);
}
void
-mparse_result(struct mparse *curp, struct mdoc **mdoc, struct man **man)
+mparse_result(struct mparse *curp,
+ struct mdoc **mdoc, struct man **man, char **sodest)
{
+ if (sodest && NULL != (*sodest = curp->sodest)) {
+ *mdoc = NULL;
+ *man = NULL;
+ return;
+ }
if (mdoc)
*mdoc = curp->mdoc;
if (man)