From 88d37636cf63e1b1a40bde35eee6f93549b1acc8 Mon Sep 17 00:00:00 2001 From: schwarze Date: Thu, 1 Jan 2015 09:06:39 +0000 Subject: [PATCH] The roff(7) language is Turing-complete, even the part implemented in mandoc(1). So practice some recursive programming to make sure it doesn't get broken. --- regress/usr.bin/mandoc/roff/de/Makefile | 4 +-- regress/usr.bin/mandoc/roff/de/factorial.in | 31 +++++++++++++++++++ .../mandoc/roff/de/factorial.out_ascii | 18 +++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 regress/usr.bin/mandoc/roff/de/factorial.in create mode 100644 regress/usr.bin/mandoc/roff/de/factorial.out_ascii diff --git a/regress/usr.bin/mandoc/roff/de/Makefile b/regress/usr.bin/mandoc/roff/de/Makefile index f186519ce99..9e48a3be0f9 100644 --- a/regress/usr.bin/mandoc/roff/de/Makefile +++ b/regress/usr.bin/mandoc/roff/de/Makefile @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile,v 1.6 2014/12/30 10:28:56 schwarze Exp $ +# $OpenBSD: Makefile,v 1.7 2015/01/01 09:06:39 schwarze Exp $ -REGRESS_TARGETS = append escname indir startde TH Dd +REGRESS_TARGETS = append escname factorial indir startde TH Dd LINT_TARGETS = escname indir .include diff --git a/regress/usr.bin/mandoc/roff/de/factorial.in b/regress/usr.bin/mandoc/roff/de/factorial.in new file mode 100644 index 00000000000..8d83714b4c0 --- /dev/null +++ b/regress/usr.bin/mandoc/roff/de/factorial.in @@ -0,0 +1,31 @@ +.Dd December 30, 2014 +.Dt FACTORIAL 1 +.Os OpenBSD +.Sh NAME +.Nm factorial +.Nd factorial sequence +.Sh DESCRIPTION +.\" recursively calculate a single factorial +.de rfac +. ie \\$1>1 \{\ +. No \\$1 * +. nr i \\$1-1 +. rfac \\ni +. nr acc \\n[acc]*\\$1 +. \} +. el .nr acc 1 +.. +.\" recursively print a sequence of factorials +.de fac +. No \\$1! = +. rfac \\$1 +. if \\$1>1 1 = +. No \\n[acc] +. if \\$1 \{\ +. br +. nr i \\$1-1 +. fac \\ni +. \} +.. +.\" main program +.fac 9 diff --git a/regress/usr.bin/mandoc/roff/de/factorial.out_ascii b/regress/usr.bin/mandoc/roff/de/factorial.out_ascii new file mode 100644 index 00000000000..cdc019ed833 --- /dev/null +++ b/regress/usr.bin/mandoc/roff/de/factorial.out_ascii @@ -0,0 +1,18 @@ +FACTORIAL(1) General Commands Manual FACTORIAL(1) + +NNAAMMEE + ffaaccttoorriiaall - factorial sequence + +DDEESSCCRRIIPPTTIIOONN + 9! = 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1 = 362880 + 8! = 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1 = 40320 + 7! = 7 * 6 * 5 * 4 * 3 * 2 * 1 = 5040 + 6! = 6 * 5 * 4 * 3 * 2 * 1 = 720 + 5! = 5 * 4 * 3 * 2 * 1 = 120 + 4! = 4 * 3 * 2 * 1 = 24 + 3! = 3 * 2 * 1 = 6 + 2! = 2 * 1 = 2 + 1! = 1 + 0! = 1 + +OpenBSD December 30, 2014 OpenBSD -- 2.20.1