aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roff.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-09-06 22:39:36 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-09-06 22:39:36 +0000
commit1e75b893a49c0cbdd978438e15c5a8fa8aebb510 (patch)
treebf90cf9b636235019a1d66752a1e2e08e9d832dd /roff.c
parenta828d911328c6ac46d0f8c2f2d99e9f0bb46e21d (diff)
downloadmandoc-1e75b893a49c0cbdd978438e15c5a8fa8aebb510.tar.gz
mandoc-1e75b893a49c0cbdd978438e15c5a8fa8aebb510.tar.zst
mandoc-1e75b893a49c0cbdd978438e15c5a8fa8aebb510.zip
Move main format autodetection from the parser dispatcher to the
roff parser where .Dd and .TH are already detected, anyway. This improves robustness because it correctly handles whitespace or an alternate control character before Dd. In the parser dispatcher, provide a fallback looking ahead in the input buffer instead of always assuming man(7). This corrects autodetection when Dd is preceded by other macros or macro-like handled requests like .ll. Triggered by reports from Daniel Levai about issues on Slackware Linux.
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/roff.c b/roff.c
index 33361402..1d8a3991 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.226 2014/08/19 16:52:32 schwarze Exp $ */
+/* $Id: roff.c,v 1.227 2014/09/06 22:39:36 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -122,6 +122,7 @@ struct roff {
int options; /* parse options */
int rstacksz; /* current size limit of rstack */
int rstackpos; /* position in rstack */
+ int format; /* current file in mdoc or man format */
char control; /* control character */
};
@@ -456,6 +457,7 @@ roff_reset(struct roff *r)
{
roff_free1(r);
+ r->format = r->options & (MPARSE_MDOC | MPARSE_MAN);
r->control = 0;
}
@@ -475,6 +477,7 @@ roff_alloc(struct mparse *parse, int options)
r = mandoc_calloc(1, sizeof(struct roff));
r->parse = parse;
r->options = options;
+ r->format = options & (MPARSE_MDOC | MPARSE_MAN);
r->rstackpos = -1;
roffhash_init();
@@ -1776,10 +1779,13 @@ roff_Dd(ROFF_ARGS)
{
const char *const *cp;
- if (0 == ((MPARSE_MDOC | MPARSE_QUICK) & r->options))
+ if ((r->options & (MPARSE_MDOC | MPARSE_QUICK)) == 0)
for (cp = __mdoc_reserved; *cp; cp++)
roff_setstr(r, *cp, NULL, 0);
+ if (r->format == 0)
+ r->format = MPARSE_MDOC;
+
return(ROFF_CONT);
}
@@ -1788,10 +1794,13 @@ roff_TH(ROFF_ARGS)
{
const char *const *cp;
- if (0 == (MPARSE_QUICK & r->options))
+ if ((r->options & MPARSE_QUICK) == 0)
for (cp = __man_reserved; *cp; cp++)
roff_setstr(r, *cp, NULL, 0);
+ if (r->format == 0)
+ r->format = MPARSE_MAN;
+
return(ROFF_CONT);
}
@@ -2307,6 +2316,13 @@ roff_strdup(const struct roff *r, const char *p)
return(res);
}
+int
+roff_getformat(const struct roff *r)
+{
+
+ return(r->format);
+}
+
/*
* Find out whether a line is a macro line or not.
* If it is, adjust the current position and return one; if it isn't,