From b20e20ea7b174c2b9444ad012482e1a7f6afd7a1 Mon Sep 17 00:00:00 2001 From: schwarze Date: Fri, 10 Aug 2018 04:41:21 +0000 Subject: [PATCH] Implement the roff(7) .nop (no operation) request. Examples of manual pages (ab)using it include groff(7), chem(1), groff_mom(7), and groff_hdtbl(7). --- share/man/man7/roff.7 | 15 +++++++++------ usr.bin/mandoc/roff.c | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/share/man/man7/roff.7 b/share/man/man7/roff.7 index daddc9c2f1d..5721081b519 100644 --- a/share/man/man7/roff.7 +++ b/share/man/man7/roff.7 @@ -1,4 +1,4 @@ -.\" $OpenBSD: roff.7,v 1.76 2018/04/10 00:52:21 schwarze Exp $ +.\" $OpenBSD: roff.7,v 1.77 2018/08/10 04:41:21 schwarze Exp $ .\" .\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons .\" Copyright (c) 2010-2018 Ingo Schwarze @@ -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: April 10 2018 $ +.Dd $Mdocdate: August 10 2018 $ .Dt ROFF 7 .Os .Sh NAME @@ -204,7 +204,7 @@ Unescaped trailing spaces are stripped from text line input unless in a literal context. In general, trailing whitespace on any input line is discouraged for reasons of portability. -In the rare case that a blank character is needed at the end of an +In the rare case that a space character is needed at the end of an input line, it may be forced by .Sq \e\ \e& . .Pp @@ -663,7 +663,7 @@ produces .Pp in the input stream, and thus in the output: \fI\^XtFree\^\fP. Each occurrence of \e\e$* is replaced with all the arguments, -joined together with single blank characters. +joined together with single space characters. .Pp Since macros and user-defined strings share a common string table, defining a macro @@ -1344,8 +1344,11 @@ Currently unsupported. Temporarily turn off line numbering. Currently unsupported. .It Ic \&nop Ar body -Execute the rest of the input line as a request or macro line. -Currently unsupported. +Execute the rest of the input line as a request, macro, or text line, +skipping the +.Ic \&nop +request and any space characters immediately following it. +This is mostly used to indent text lines inside macro definitions. .It Ic \&nr Ar register Oo Cm + Ns | Ns Cm - Oc Ns Ar expression Op Ar stepsize Define or change a register. A register is an arbitrary string value that defines some sort of state, diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index 2e4e9c11757..71b595abb0f 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roff.c,v 1.201 2018/08/01 15:39:47 schwarze Exp $ */ +/* $OpenBSD: roff.c,v 1.202 2018/08/10 04:41:21 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze @@ -195,6 +195,7 @@ static enum rofferr roff_line_ignore(ROFF_ARGS); static void roff_man_alloc1(struct roff_man *); static void roff_man_free1(struct roff_man *); static enum rofferr roff_manyarg(ROFF_ARGS); +static enum rofferr roff_nop(ROFF_ARGS); static enum rofferr roff_nr(ROFF_ARGS); static enum rofferr roff_onearg(ROFF_ARGS); static enum roff_tok roff_parse(struct roff *, char *, int *, @@ -488,7 +489,7 @@ static struct roffmac roffs[TOKEN_NONE] = { { roff_line_ignore, NULL, NULL, 0 }, /* nhychar */ { roff_unsupp, NULL, NULL, 0 }, /* nm */ { roff_unsupp, NULL, NULL, 0 }, /* nn */ - { roff_unsupp, NULL, NULL, 0 }, /* nop */ + { roff_nop, NULL, NULL, 0 }, /* nop */ { roff_nr, NULL, NULL, 0 }, /* nr */ { roff_unsupp, NULL, NULL, 0 }, /* nrf */ { roff_line_ignore, NULL, NULL, 0 }, /* nroff */ @@ -3158,6 +3159,15 @@ roff_eo(ROFF_ARGS) return ROFF_IGN; } +static enum rofferr +roff_nop(ROFF_ARGS) +{ + while (buf->buf[pos] == ' ') + pos++; + *offs = pos; + return ROFF_RERUN; +} + static enum rofferr roff_tr(ROFF_ARGS) { -- 2.20.1