diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2018-08-23 14:16:13 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2018-08-23 14:16:13 +0000 |
commit | fc469ea850621ad85ab19d7482c03478fc263bcb (patch) | |
tree | 29ee64e3e0a1e94868f5a145d1dd55610ad040db /regress/usr.bin | |
parent | 19b02c78f13b5e52f321e82720b4b70346dbb581 (diff) |
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.209, moving argument interpolation back into
the function roff_res().
Diffstat (limited to 'regress/usr.bin')
-rw-r--r-- | regress/usr.bin/mandoc/roff/Makefile | 4 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/de/infinite.in | 8 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/de/infinite.out_ascii | 4 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/de/infinite.out_lint | 3 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/return/Makefile | 6 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/return/basic.in | 23 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/return/basic.out_ascii | 15 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/return/basic.out_lint | 3 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/shift/Makefile | 6 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/shift/bad.in | 30 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/shift/bad.out_ascii | 25 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/shift/bad.out_lint | 7 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/shift/basic.in | 35 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/shift/basic.out_ascii | 25 |
14 files changed, 185 insertions, 9 deletions
diff --git a/regress/usr.bin/mandoc/roff/Makefile b/regress/usr.bin/mandoc/roff/Makefile index 7afa56d9b53..7c6f5e16dda 100644 --- a/regress/usr.bin/mandoc/roff/Makefile +++ b/regress/usr.bin/mandoc/roff/Makefile @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile,v 1.24 2017/06/18 17:35:40 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 <bsd.subdir.mk> diff --git a/regress/usr.bin/mandoc/roff/de/infinite.in b/regress/usr.bin/mandoc/roff/de/infinite.in index 00931a06c18..dd17885f608 100644 --- a/regress/usr.bin/mandoc/roff/de/infinite.in +++ b/regress/usr.bin/mandoc/roff/de/infinite.in @@ -1,5 +1,5 @@ -.\" $OpenBSD: infinite.in,v 1.3 2017/07/04 14:53:27 schwarze Exp $ -.Dd $Mdocdate: July 4 2017 $ +.\" $OpenBSD: infinite.in,v 1.4 2018/08/23 14:16:12 schwarze Exp $ +.Dd $Mdocdate: August 23 2018 $ .Dt DE-INFINITE 1 .Os .Sh NAME @@ -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/usr.bin/mandoc/roff/de/infinite.out_ascii b/regress/usr.bin/mandoc/roff/de/infinite.out_ascii index 452af775982..074362da409 100644 --- a/regress/usr.bin/mandoc/roff/de/infinite.out_ascii +++ b/regress/usr.bin/mandoc/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/usr.bin/mandoc/roff/de/infinite.out_lint b/regress/usr.bin/mandoc/roff/de/infinite.out_lint index e7beb090aa5..06254be506e 100644 --- a/regress/usr.bin/mandoc/roff/de/infinite.out_lint +++ b/regress/usr.bin/mandoc/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/usr.bin/mandoc/roff/return/Makefile b/regress/usr.bin/mandoc/roff/return/Makefile new file mode 100644 index 00000000000..f7d510f7885 --- /dev/null +++ b/regress/usr.bin/mandoc/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 <bsd.regress.mk> diff --git a/regress/usr.bin/mandoc/roff/return/basic.in b/regress/usr.bin/mandoc/roff/return/basic.in new file mode 100644 index 00000000000..f0a777c15f1 --- /dev/null +++ b/regress/usr.bin/mandoc/roff/return/basic.in @@ -0,0 +1,23 @@ +.\" $OpenBSD: basic.in,v 1.1 2018/08/23 14:16:12 schwarze Exp $ +.Dd $Mdocdate: August 23 2018 $ +.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/usr.bin/mandoc/roff/return/basic.out_ascii b/regress/usr.bin/mandoc/roff/return/basic.out_ascii new file mode 100644 index 00000000000..25f667442fc --- /dev/null +++ b/regress/usr.bin/mandoc/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/usr.bin/mandoc/roff/return/basic.out_lint b/regress/usr.bin/mandoc/roff/return/basic.out_lint new file mode 100644 index 00000000000..f4b15bac840 --- /dev/null +++ b/regress/usr.bin/mandoc/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/usr.bin/mandoc/roff/shift/Makefile b/regress/usr.bin/mandoc/roff/shift/Makefile new file mode 100644 index 00000000000..d356b963c85 --- /dev/null +++ b/regress/usr.bin/mandoc/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 <bsd.regress.mk> diff --git a/regress/usr.bin/mandoc/roff/shift/bad.in b/regress/usr.bin/mandoc/roff/shift/bad.in new file mode 100644 index 00000000000..809832defd8 --- /dev/null +++ b/regress/usr.bin/mandoc/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/usr.bin/mandoc/roff/shift/bad.out_ascii b/regress/usr.bin/mandoc/roff/shift/bad.out_ascii new file mode 100644 index 00000000000..0b21f574a48 --- /dev/null +++ b/regress/usr.bin/mandoc/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/usr.bin/mandoc/roff/shift/bad.out_lint b/regress/usr.bin/mandoc/roff/shift/bad.out_lint new file mode 100644 index 00000000000..1f696fc8681 --- /dev/null +++ b/regress/usr.bin/mandoc/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/usr.bin/mandoc/roff/shift/basic.in b/regress/usr.bin/mandoc/roff/shift/basic.in new file mode 100644 index 00000000000..982042db278 --- /dev/null +++ b/regress/usr.bin/mandoc/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/usr.bin/mandoc/roff/shift/basic.out_ascii b/regress/usr.bin/mandoc/roff/shift/basic.out_ascii new file mode 100644 index 00000000000..40675c67543 --- /dev/null +++ b/regress/usr.bin/mandoc/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: <x y> + + expand to more than three bytes: <a longer argument... and another> + + + +OpenBSD August 23, 2018 SHIFT_BASIC(1) |