From a99c9a30e9f41eb3ce553ac0b2ac6ff963ebe49d Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Thu, 23 Aug 2018 14:29:38 +0000 Subject: Implement the roff(7) .shift and .return requests, for example used by groff_hdtbl(7) and groff_mom(7). Also correctly interpolate arguments during nested macro execution even after .shift and .return, implemented using a stack of argument arrays. Note that only read.c, but not roff.c can detect the end of a macro execution, and the existence of .shift implies that arguments cannot be interpolated up front, so unfortunately, this includes a partial revert of roff.c rev. 1.337, moving argument interpolation back into the function roff_res(). --- regress/roff/Makefile | 4 ++-- regress/roff/de/infinite.in | 6 +++--- regress/roff/de/infinite.out_ascii | 4 ++-- regress/roff/de/infinite.out_lint | 3 ++- regress/roff/return/Makefile | 6 ++++++ regress/roff/return/basic.in | 23 +++++++++++++++++++++++ regress/roff/return/basic.out_ascii | 15 +++++++++++++++ regress/roff/return/basic.out_lint | 3 +++ regress/roff/shift/Makefile | 6 ++++++ regress/roff/shift/bad.in | 30 ++++++++++++++++++++++++++++++ regress/roff/shift/bad.out_ascii | 25 +++++++++++++++++++++++++ regress/roff/shift/bad.out_lint | 7 +++++++ regress/roff/shift/basic.in | 35 +++++++++++++++++++++++++++++++++++ regress/roff/shift/basic.out_ascii | 25 +++++++++++++++++++++++++ 14 files changed, 184 insertions(+), 8 deletions(-) create mode 100644 regress/roff/return/Makefile create mode 100644 regress/roff/return/basic.in create mode 100644 regress/roff/return/basic.out_ascii create mode 100644 regress/roff/return/basic.out_lint create mode 100644 regress/roff/shift/Makefile create mode 100644 regress/roff/shift/bad.in create mode 100644 regress/roff/shift/bad.out_ascii create mode 100644 regress/roff/shift/bad.out_lint create mode 100644 regress/roff/shift/basic.in create mode 100644 regress/roff/shift/basic.out_ascii (limited to 'regress') diff --git a/regress/roff/Makefile b/regress/roff/Makefile index 61501033..7c6f5e16 100644 --- a/regress/roff/Makefile +++ b/regress/roff/Makefile @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile,v 1.20 2015/02/06 16:05:51 schwarze Exp $ +# $OpenBSD: Makefile,v 1.25 2018/08/23 14:16:12 schwarze Exp $ SUBDIR = args cond esc scale string -SUBDIR += br cc de ds ft ig it ll na nr po ps rm rn sp ta ti tr +SUBDIR += br cc de ds ft ig it ll na nr po ps return rm rn shift sp ta ti tr .include "../Makefile.sub" .include diff --git a/regress/roff/de/infinite.in b/regress/roff/de/infinite.in index 62f66965..33f71642 100644 --- a/regress/roff/de/infinite.in +++ b/regress/roff/de/infinite.in @@ -1,4 +1,4 @@ -.\" $OpenBSD: infinite.in,v 1.3 2017/07/04 14:53:27 schwarze Exp $ +.\" $OpenBSD: infinite.in,v 1.4 2018/08/23 14:16:12 schwarze Exp $ .Dd $Mdocdate$ .Dt DE-INFINITE 1 .Os @@ -10,8 +10,8 @@ initial text .de mym .Op \\$1 \\$2 .. -.mym $1 \$1 -.mym \$1 nothing +.mym $1 \$1 end +.mym \$1 middle end middle text .de mym .mym diff --git a/regress/roff/de/infinite.out_ascii b/regress/roff/de/infinite.out_ascii index 452af775..074362da 100644 --- a/regress/roff/de/infinite.out_ascii +++ b/regress/roff/de/infinite.out_ascii @@ -4,6 +4,6 @@ NNAAMMEE ddee--iinnffiinniittee - inifinte recursion in a user-defined macro DDEESSCCRRIIPPTTIIOONN - initial text [$1 $1] middle text final text + initial text [$1 end] [middle end] middle text final text -OpenBSD July 4, 2017 OpenBSD +OpenBSD August 23, 2018 OpenBSD diff --git a/regress/roff/de/infinite.out_lint b/regress/roff/de/infinite.out_lint index e7beb090..06254be5 100644 --- a/regress/roff/de/infinite.out_lint +++ b/regress/roff/de/infinite.out_lint @@ -1,2 +1,3 @@ -mandoc: infinite.in:14:5: ERROR: input stack limit exceeded, infinite loop? +mandoc: infinite.in:13:9: ERROR: using macro argument outside macro: \$1 +mandoc: infinite.in:14:6: ERROR: using macro argument outside macro: \$1 mandoc: infinite.in:20:5: ERROR: input stack limit exceeded, infinite loop? diff --git a/regress/roff/return/Makefile b/regress/roff/return/Makefile new file mode 100644 index 00000000..f7d510f7 --- /dev/null +++ b/regress/roff/return/Makefile @@ -0,0 +1,6 @@ +# $OpenBSD: Makefile,v 1.1 2018/08/23 14:16:12 schwarze Exp $ + +REGRESS_TARGETS = basic +LINT_TARGETS = basic + +.include diff --git a/regress/roff/return/basic.in b/regress/roff/return/basic.in new file mode 100644 index 00000000..e001f59e --- /dev/null +++ b/regress/roff/return/basic.in @@ -0,0 +1,23 @@ +.\" $OpenBSD: basic.in,v 1.1 2018/08/23 14:16:12 schwarze Exp $ +.Dd $Mdocdate$ +.Dt RETURN-BASIC 1 +.Os +.Sh NAME +.Nm return-basic +.Nd the return request +.Sh DESCRIPTION +return before macro +.return +.Pp +.de mymacro +text from macro (\\n(.$ argument: "\\$1"), +.return +not printed, +.. +.mymacro myarg +\n(.$ arguments after return: "\$1", +.Pp +return after macro +.return +.Pp +final text diff --git a/regress/roff/return/basic.out_ascii b/regress/roff/return/basic.out_ascii new file mode 100644 index 00000000..25f66744 --- /dev/null +++ b/regress/roff/return/basic.out_ascii @@ -0,0 +1,15 @@ +RETURN-BASIC(1) General Commands Manual RETURN-BASIC(1) + +NNAAMMEE + rreettuurrnn--bbaassiicc - the return request + +DDEESSCCRRIIPPTTIIOONN + return before macro + + text from macro (1 argument: "myarg"), 0 arguments after return: "", + + return after macro + + final text + +OpenBSD August 23, 2018 OpenBSD diff --git a/regress/roff/return/basic.out_lint b/regress/roff/return/basic.out_lint new file mode 100644 index 00000000..f4b15bac --- /dev/null +++ b/regress/roff/return/basic.out_lint @@ -0,0 +1,3 @@ +mandoc: basic.in:10:2: ERROR: ignoring request outside macro: return +mandoc: basic.in:18:32: ERROR: using macro argument outside macro: \$1 +mandoc: basic.in:21:2: ERROR: ignoring request outside macro: return diff --git a/regress/roff/shift/Makefile b/regress/roff/shift/Makefile new file mode 100644 index 00000000..d356b963 --- /dev/null +++ b/regress/roff/shift/Makefile @@ -0,0 +1,6 @@ +# $OpenBSD: Makefile,v 1.1 2018/08/23 14:16:12 schwarze Exp $ + +REGRESS_TARGETS = basic bad +LINT_TARGETS = bad + +.include diff --git a/regress/roff/shift/bad.in b/regress/roff/shift/bad.in new file mode 100644 index 00000000..809832de --- /dev/null +++ b/regress/roff/shift/bad.in @@ -0,0 +1,30 @@ +.\" $OpenBSD: bad.in,v 1.1 2018/08/23 14:16:12 schwarze Exp $ +.TH SHIFT_BAD 1 "August 23, 2018" +.SH NAME +.B shift-bad +\(en wrong usage of macro arguments +.SH DESCRIPTION +initial text +.de mym +in macro: "\\$1" +.PP +invalid argument number 'x': "\\$x" +.. +.PP +argument used before call: "\$1" +.shift +.PP +.mym argument +.PP +argument used after call: "\$1" +.shift 2 +.PP +.de mym +.shift badarg +after shift badarg: "\\$1" +.shift 2 +after excessive shift: \\n(.$ "\\$1" +.. +.mym arg1 arg2 +.PP +final text diff --git a/regress/roff/shift/bad.out_ascii b/regress/roff/shift/bad.out_ascii new file mode 100644 index 00000000..0b21f574 --- /dev/null +++ b/regress/roff/shift/bad.out_ascii @@ -0,0 +1,25 @@ +SHIFT_BAD(1) General Commands Manual SHIFT_BAD(1) + + + +NNAAMMEE + sshhiifftt--bbaadd - wrong usage of macro arguments + +DDEESSCCRRIIPPTTIIOONN + initial text + + argument used before call: "" + + in macro: "argument" + + invalid argument number 'x': "" + + argument used after call: "" + + after shift badarg: "arg2" after excessive shift: 0 "" + + final text + + + +OpenBSD August 23, 2018 SHIFT_BAD(1) diff --git a/regress/roff/shift/bad.out_lint b/regress/roff/shift/bad.out_lint new file mode 100644 index 00000000..1f696fc8 --- /dev/null +++ b/regress/roff/shift/bad.out_lint @@ -0,0 +1,7 @@ +mandoc: bad.in:14:29: ERROR: using macro argument outside macro: \$1 +mandoc: bad.in:15:2: ERROR: ignoring request outside macro: shift +mandoc: bad.in:17:31: ERROR: argument number is not numeric: \$x +mandoc: bad.in:19:28: ERROR: using macro argument outside macro: \$1 +mandoc: bad.in:20:2: ERROR: ignoring request outside macro: shift +mandoc: bad.in:28:8: ERROR: argument is not numeric, using 1: shift badarg +mandoc: bad.in:28:9: ERROR: excessive shift: 2, but max is 1 diff --git a/regress/roff/shift/basic.in b/regress/roff/shift/basic.in new file mode 100644 index 00000000..982042db --- /dev/null +++ b/regress/roff/shift/basic.in @@ -0,0 +1,35 @@ +.\" $OpenBSD: basic.in,v 1.1 2018/08/23 14:16:12 schwarze Exp $ +.TH SHIFT_BASIC 1 "August 23, 2018" +.SH NAME +.B shift-basic +\(en the shift request +.SH DESCRIPTION +.de showargs +original arguments: +.BI \\$@ +.PP +.shift 2 +after shift 2: +.BI \\$@ +.PP +.shift +after shift without argument: +.BI \\$@ +.PP +.shift 0 +after shift 0: +.BI \\$@ +.. +.de useargs +<\\$*> +.. +.showargs one two three four five +.PP +expand to less than three bytes: +.useargs 1 +.PP +expand to exactly three bytes: +.useargs x y +.PP +expand to more than three bytes: +.useargs "a longer argument..." "and another" diff --git a/regress/roff/shift/basic.out_ascii b/regress/roff/shift/basic.out_ascii new file mode 100644 index 00000000..40675c67 --- /dev/null +++ b/regress/roff/shift/basic.out_ascii @@ -0,0 +1,25 @@ +SHIFT_BASIC(1) General Commands Manual SHIFT_BASIC(1) + + + +NNAAMMEE + sshhiifftt--bbaassiicc - the shift request + +DDEESSCCRRIIPPTTIIOONN + original arguments: oonnee_t_w_otthhrreeee_f_o_u_rffiivvee + + after shift 2: tthhrreeee_f_o_u_rffiivvee + + after shift without argument: ffoouurr_f_i_v_e + + after shift 0: ffoouurr_f_i_v_e + + expand to less than three bytes: <1> + + expand to exactly three bytes: + + expand to more than three bytes: + + + +OpenBSD August 23, 2018 SHIFT_BASIC(1) -- cgit