From 83a9dfe1b143d86e38d14e824e87df26892a9d48 Mon Sep 17 00:00:00 2001 From: schwarze Date: Mon, 30 May 2022 22:50:40 +0000 Subject: [PATCH] Dummy implementation of the roff(7) \V (interpolate environment variable) escape sequence. This is needed to get \V into the correct parsing class, ESCAPE_EXPAND. It is intentional that mandoc(1) output is *not* influenced by environment variables, so interpolate the name of the variable with some decorating punctuation rather than interpolating its value. --- regress/usr.bin/mandoc/roff/esc/Makefile | 11 ++++++++--- regress/usr.bin/mandoc/roff/esc/V1.in | 10 ++++++++++ regress/usr.bin/mandoc/roff/esc/V1.out_ascii | 11 +++++++++++ regress/usr.bin/mandoc/roff/esc/V1.out_lint | 3 +++ share/man/man7/roff.7 | 12 ++++++++---- usr.bin/mandoc/roff.c | 13 +++++++++---- usr.bin/mandoc/roff_escape.c | 4 ++-- 7 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 regress/usr.bin/mandoc/roff/esc/V1.in create mode 100644 regress/usr.bin/mandoc/roff/esc/V1.out_ascii create mode 100644 regress/usr.bin/mandoc/roff/esc/V1.out_lint diff --git a/regress/usr.bin/mandoc/roff/esc/Makefile b/regress/usr.bin/mandoc/roff/esc/Makefile index bd39e37883d..dd816f585c7 100644 --- a/regress/usr.bin/mandoc/roff/esc/Makefile +++ b/regress/usr.bin/mandoc/roff/esc/Makefile @@ -1,10 +1,10 @@ -# $OpenBSD: Makefile,v 1.21 2022/05/20 13:06:27 schwarze Exp $ +# $OpenBSD: Makefile,v 1.22 2022/05/30 22:50:40 schwarze Exp $ REGRESS_TARGETS = one two multi comment -REGRESS_TARGETS += B bs_man bs_mdoc c c_man E1 e f h hneg l O1 o p r w z +REGRESS_TARGETS += B bs_man bs_mdoc c c_man E1 e f h hneg l O1 o p r V1 w z REGRESS_TARGETS += ignore invalid unsupp HTML_TARGETS = f -LINT_TARGETS = comment B h l O1 r w ignore invalid unsupp +LINT_TARGETS = comment B h l O1 r V1 w ignore invalid unsupp # mandoc defects: # - \h with a negative argument replaces output characters @@ -13,4 +13,9 @@ LINT_TARGETS = comment B h l O1 r w ignore invalid unsupp SKIP_GROFF = hneg r +# intentional difference: +# - mandoc does not inspect the environment + +SKIP_GROFF += V1 + .include diff --git a/regress/usr.bin/mandoc/roff/esc/V1.in b/regress/usr.bin/mandoc/roff/esc/V1.in new file mode 100644 index 00000000000..3f1d76f709b --- /dev/null +++ b/regress/usr.bin/mandoc/roff/esc/V1.in @@ -0,0 +1,10 @@ +.\" $OpenBSD: V1.in,v 1.1 2022/05/30 22:50:40 schwarze Exp $ +.TH ESC-V1 1 "May 31, 2022" +.SH NAME +esc-V1 \- interpolate environment variables +.SH DESCRIPTION +single-character name: "\VN" +.br +double-character name: "\V(VN" +.br +multi-character name: "\V[VARNAME]" diff --git a/regress/usr.bin/mandoc/roff/esc/V1.out_ascii b/regress/usr.bin/mandoc/roff/esc/V1.out_ascii new file mode 100644 index 00000000000..2f22e58ef5d --- /dev/null +++ b/regress/usr.bin/mandoc/roff/esc/V1.out_ascii @@ -0,0 +1,11 @@ +ESC-V1(1) General Commands Manual ESC-V1(1) + +NNAAMMEE + esc-V1 - interpolate environment variables + +DDEESSCCRRIIPPTTIIOONN + single-character name: "${N}" + double-character name: "${VN}" + multi-character name: "${VARNAME}" + +OpenBSD May 31, 2022 ESC-V1(1) diff --git a/regress/usr.bin/mandoc/roff/esc/V1.out_lint b/regress/usr.bin/mandoc/roff/esc/V1.out_lint new file mode 100644 index 00000000000..f580e4d276e --- /dev/null +++ b/regress/usr.bin/mandoc/roff/esc/V1.out_lint @@ -0,0 +1,3 @@ +mandoc: V1.in:6:25: UNSUPP: unsupported feature: \VN +mandoc: V1.in:8:25: UNSUPP: unsupported feature: \V(VN +mandoc: V1.in:10:24: UNSUPP: unsupported feature: \V[VARNAME] diff --git a/share/man/man7/roff.7 b/share/man/man7/roff.7 index cd334c0f30c..6e885037dff 100644 --- a/share/man/man7/roff.7 +++ b/share/man/man7/roff.7 @@ -1,4 +1,4 @@ -.\" $OpenBSD: roff.7,v 1.98 2022/05/20 13:06:27 schwarze Exp $ +.\" $OpenBSD: roff.7,v 1.99 2022/05/30 22:50:40 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 20 2022 $ +.Dd $Mdocdate: May 30 2022 $ .Dt ROFF 7 .Os .Sh NAME @@ -2188,12 +2188,16 @@ Horizontal tab; ignored by Move up by half a line; ignored by .Xr mandoc 1 . .It Ic \eV[ Ns Ar name Ns Ic \&] -Interpolate an environment variable; ignored by -.Xr mandoc 1 . +Interpolate an environment variable. For short names, there are variants .Ic \eV Ns Ar c and .Ic \eV( Ns Ar cc . +This escape sequence is intentionally unsupported; +.Xr mandoc 1 +prints the string +.Dq Pf $ Brq Ar name +instead of inspecting the environment. .It Ic \ev\(aq Ns Ar number Ns Ic \(aq Vertical motion; ignored by .Xr mandoc 1 . diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index 783eba55256..9986dff6435 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roff.c,v 1.260 2022/05/19 15:17:51 schwarze Exp $ */ +/* $OpenBSD: roff.c,v 1.261 2022/05/30 22:50:40 schwarze Exp $ */ /* * Copyright (c) 2010-2015, 2017-2022 Ingo Schwarze * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons @@ -1527,6 +1527,12 @@ roff_expand(struct roff *r, struct buf *buf, int ln, int pos, char ec) ubuf[1] = '\0'; res = ubuf; break; + case 'V': + mandoc_msg(MANDOCERR_UNSUPP, ln, iesc, + "%.*s", iend - iesc, buf->buf + iesc); + roff_expand_patch(buf, iendarg, "}", iend); + roff_expand_patch(buf, iesc, "${", iarg); + continue; case 'n': if (iendarg > iarg) (void)snprintf(ubuf, sizeof(ubuf), "%d", @@ -1565,9 +1571,8 @@ roff_expand_patch(struct buf *buf, int start, const char *repl, int end) { char *nbuf; - buf->buf[start] = '\0'; - buf->sz = mandoc_asprintf(&nbuf, "%s%s%s", buf->buf, repl, - buf->buf + end) + 1; + buf->sz = mandoc_asprintf(&nbuf, "%.*s%s%s", start, buf->buf, + repl, buf->buf + end) + 1; free(buf->buf); buf->buf = nbuf; } diff --git a/usr.bin/mandoc/roff_escape.c b/usr.bin/mandoc/roff_escape.c index 0780cce2a0f..0a71b999da6 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.2 2022/05/20 13:06:26 schwarze Exp $ */ +/* $OpenBSD: roff_escape.c,v 1.3 2022/05/30 22:50:40 schwarze Exp $ */ /* * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2017, 2018, 2020, 2022 * Ingo Schwarze @@ -157,13 +157,13 @@ roff_escape(const char *buf, const int ln, const int aesc, case '$': case '*': + case 'V': case 'n': rval = ESCAPE_EXPAND; break; case 'F': case 'M': case 'O': - case 'V': case 'Y': case 'g': case 'k': -- 2.20.1