summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2014-10-20 15:04:37 +0000
committerschwarze <schwarze@openbsd.org>2014-10-20 15:04:37 +0000
commit55e7d5da12d922a5d44f8aed4195d1b4135c6f53 (patch)
tree61059f4398176c121ac622c9875441a6b69998cb
parentRemove the "interface" option from the "transparent forward" directive. (diff)
downloadwireguard-openbsd-55e7d5da12d922a5d44f8aed4195d1b4135c6f53.tar.xz
wireguard-openbsd-55e7d5da12d922a5d44f8aed4195d1b4135c6f53.zip
correctly parse spacing around in-line equations
at the beginning and at the end of input lines; issue reported by kristaps@
-rw-r--r--usr.bin/mandoc/roff.c43
1 files changed, 37 insertions, 6 deletions
diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c
index c65fa2f009c..c6f0338759f 100644
--- a/usr.bin/mandoc/roff.c
+++ b/usr.bin/mandoc/roff.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: roff.c,v 1.104 2014/10/20 02:31:44 schwarze Exp $ */
+/* $OpenBSD: roff.c,v 1.105 2014/10/20 15:04:37 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -1855,7 +1855,8 @@ roff_T_(ROFF_ARGS)
static enum rofferr
roff_eqndelim(struct roff *r, char **bufp, size_t *szp, int pos)
{
- char *cp1, *cp2;
+ char *cp1, *cp2;
+ const char *bef_pr, *bef_nl, *mac, *aft_nl, *aft_pr;
/*
* Outside equations, look for an opening delimiter.
@@ -1870,11 +1871,41 @@ roff_eqndelim(struct roff *r, char **bufp, size_t *szp, int pos)
if (cp2 == NULL)
return(ROFF_CONT);
- /* Replace the delimiter with an equation macro. */
-
*cp2++ = '\0';
- *szp = mandoc_asprintf(&cp1, "%s%s%s", *bufp,
- r->eqn == NULL ? "\\&\n.EQ\n" : "\n.EN\n\\&", cp2) + 1;
+ bef_pr = bef_nl = aft_nl = aft_pr = "";
+
+ /* Handle preceding text, protecting whitespace. */
+
+ if (**bufp != '\0') {
+ if (r->eqn == NULL)
+ bef_pr = "\\&";
+ bef_nl = "\n";
+ }
+
+ /*
+ * Prepare replacing the delimiter with an equation macro
+ * and drop leading white space from the equation.
+ */
+
+ if (r->eqn == NULL) {
+ while (*cp2 == ' ')
+ cp2++;
+ mac = ".EQ";
+ } else
+ mac = ".EN";
+
+ /* Handle following text, protecting whitespace. */
+
+ if (*cp2 != '\0') {
+ aft_nl = "\n";
+ if (r->eqn != NULL)
+ aft_pr = "\\&";
+ }
+
+ /* Do the actual replacement. */
+
+ *szp = mandoc_asprintf(&cp1, "%s%s%s%s%s%s%s", *bufp,
+ bef_pr, bef_nl, mac, aft_nl, aft_pr, cp2) + 1;
free(*bufp);
*bufp = cp1;