From: schwarze Date: Tue, 31 May 2022 18:08:02 +0000 (+0000) Subject: Trivial patch to put the roff(7) \g (interpolate format of register) X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=6f49ebc4e90d59b1157669bec6dc9206be1e5038;p=openbsd Trivial patch to put the roff(7) \g (interpolate format of register) escape sequence into the correct parsing class, ESCAPE_EXPAND. Expansion of \g is supposed to work exactly like the expansion of the related escape sequence \n (interpolate register value), but since we ignore the .af (assign output format) request, we just interpolate an empty string to replace the \g sequence. Surprising as it may seem, this actually makes a formatting difference for deviate input like ".O\gNx" which used to raise bogus "escaped character not allowed in a name" and "skipping unknown macro" errors and printed nothing, whereas now it correctly prints "OpenBSD". --- diff --git a/share/man/man7/roff.7 b/share/man/man7/roff.7 index 6e885037dff..191f35628c1 100644 --- a/share/man/man7/roff.7 +++ b/share/man/man7/roff.7 @@ -1,4 +1,4 @@ -.\" $OpenBSD: roff.7,v 1.99 2022/05/30 22:50:40 schwarze Exp $ +.\" $OpenBSD: roff.7,v 1.100 2022/05/31 18:08:02 schwarze Exp $ .\" .\" Copyright (c) 2010-2019, 2022 Ingo Schwarze .\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: May 30 2022 $ +.Dd $Mdocdate: May 31 2022 $ .Dt ROFF 7 .Os .Sh NAME @@ -2085,7 +2085,8 @@ defaults to .Ic \efP . .It Ic \eg[ Ns Ar name Ns Ic \&] Interpolate the format of a number register; ignored by -.Xr mandoc 1 . +.Xr mandoc 1 , +which interpolates an empty string instead. For short names, there are variants .Ic \eg Ns Ar c and diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index 9986dff6435..7158fa6e8cd 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roff.c,v 1.261 2022/05/30 22:50:40 schwarze Exp $ */ +/* $OpenBSD: roff.c,v 1.262 2022/05/31 18:08:02 schwarze Exp $ */ /* * Copyright (c) 2010-2015, 2017-2022 Ingo Schwarze * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons @@ -1533,6 +1533,8 @@ roff_expand(struct roff *r, struct buf *buf, int ln, int pos, char ec) roff_expand_patch(buf, iendarg, "}", iend); roff_expand_patch(buf, iesc, "${", iarg); continue; + case 'g': + break; case 'n': if (iendarg > iarg) (void)snprintf(ubuf, sizeof(ubuf), "%d", diff --git a/usr.bin/mandoc/roff_escape.c b/usr.bin/mandoc/roff_escape.c index 0a71b999da6..f8f59bcab27 100644 --- a/usr.bin/mandoc/roff_escape.c +++ b/usr.bin/mandoc/roff_escape.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roff_escape.c,v 1.3 2022/05/30 22:50:40 schwarze Exp $ */ +/* $OpenBSD: roff_escape.c,v 1.4 2022/05/31 18:08:02 schwarze Exp $ */ /* * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2017, 2018, 2020, 2022 * Ingo Schwarze @@ -158,6 +158,7 @@ roff_escape(const char *buf, const int ln, const int aesc, case '$': case '*': case 'V': + case 'g': case 'n': rval = ESCAPE_EXPAND; break; @@ -165,7 +166,6 @@ roff_escape(const char *buf, const int ln, const int aesc, case 'M': case 'O': case 'Y': - case 'g': case 'k': case 'm': rval = ESCAPE_IGNORE;