diff options
author | 2015-01-23 00:38:42 +0000 | |
---|---|---|
committer | 2015-01-23 00:38:42 +0000 | |
commit | 4a635483eb5cd55f68d24c217fde341ec0c20d1c (patch) | |
tree | a66ff5ff893733680ae2e9f3c834806e839e4417 | |
parent | Slightly improve \w width measurements: (diff) | |
download | wireguard-openbsd-4a635483eb5cd55f68d24c217fde341ec0c20d1c.tar.xz wireguard-openbsd-4a635483eb5cd55f68d24c217fde341ec0c20d1c.zip |
Wonders of roff(7): Integer numbers in numerical expressions can carry
scaling units, and some manuals (e.g. in devel/grcs) actually use that,
so let's support it. Missing feature reported by naddy@.
-rw-r--r-- | regress/usr.bin/mandoc/roff/nr/Makefile | 4 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/nr/scale.in | 26 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/roff/nr/scale.out_ascii | 13 | ||||
-rw-r--r-- | share/man/man7/roff.7 | 12 | ||||
-rw-r--r-- | usr.bin/mandoc/roff.c | 44 |
5 files changed, 92 insertions, 7 deletions
diff --git a/regress/usr.bin/mandoc/roff/nr/Makefile b/regress/usr.bin/mandoc/roff/nr/Makefile index e5b14f41098..8da6887869c 100644 --- a/regress/usr.bin/mandoc/roff/nr/Makefile +++ b/regress/usr.bin/mandoc/roff/nr/Makefile @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile,v 1.8 2014/11/10 20:59:41 schwarze Exp $ +# $OpenBSD: Makefile,v 1.9 2015/01/23 00:38:43 schwarze Exp $ -REGRESS_TARGETS = argc divzero eval escname int predef rr +REGRESS_TARGETS = argc divzero eval escname int predef rr scale LINT_TARGETS = divzero escname .include <bsd.regress.mk> diff --git a/regress/usr.bin/mandoc/roff/nr/scale.in b/regress/usr.bin/mandoc/roff/nr/scale.in new file mode 100644 index 00000000000..6f63c589736 --- /dev/null +++ b/regress/usr.bin/mandoc/roff/nr/scale.in @@ -0,0 +1,26 @@ +.TH NR-INT 1 "January 23, 2015" OpenBSD +.SH NAME +nr-scale \- scaling units in numeric expressions +.SH DESCRIPTION +.nr Y 1f+1 +\nY +.nr Y 1i+1 +\nY +.nr Y 10c+1 +\nY +.nr Y 1v+1 +\nY +.nr Y 1P+1 +\nY +.nr Y 1m+1 +\nY +.nr Y 1n+1 +\nY +.nr Y 10p+1 +\nY +.nr Y 1u+1 +\nY +.nr Y 100M+1 +\nY +.nr Y 1X+2 +\nY diff --git a/regress/usr.bin/mandoc/roff/nr/scale.out_ascii b/regress/usr.bin/mandoc/roff/nr/scale.out_ascii new file mode 100644 index 00000000000..c6f79b2af8a --- /dev/null +++ b/regress/usr.bin/mandoc/roff/nr/scale.out_ascii @@ -0,0 +1,13 @@ +NR-INT(1) General Commands Manual NR-INT(1) + + + +NNAAMMEE + nr-scale - scaling units in numeric expressions + +DDEESSCCRRIIPPTTIIOONN + 65537 241 945 41 41 25 25 34 2 25 1 + + + +OpenBSD January 23, 2015 NR-INT(1) diff --git a/share/man/man7/roff.7 b/share/man/man7/roff.7 index b670366b38b..b14dccdcc2a 100644 --- a/share/man/man7/roff.7 +++ b/share/man/man7/roff.7 @@ -1,4 +1,4 @@ -.\" $OpenBSD: roff.7,v 1.45 2015/01/21 23:48:05 jmc Exp $ +.\" $OpenBSD: roff.7,v 1.46 2015/01/23 00:38:42 schwarze Exp $ .\" .\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> .\" Copyright (c) 2010, 2011, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -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: January 21 2015 $ +.Dd $Mdocdate: January 23 2015 $ .Dt ROFF 7 .Os .Sh NAME @@ -1713,6 +1713,14 @@ prefixed by an optional sign .Sq + or .Sq - . +Each number may be followed by one optional scaling unit described below +.Sx Scaling Widths . +The following equations hold: +.Bd -literal -offset indent +1i = 6v = 6P = 10m = 10n = 72p = 1000M = 240u = 240 +254c = 100i = 24000u = 24000 +1f = 65536u = 65536 +.Ed .Pp The following binary operators are implemented. Unless otherwise stated, they behave as in the C language: diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index 6e38f63443c..223cc407ff1 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roff.c,v 1.125 2015/01/22 22:50:31 schwarze Exp $ */ +/* $OpenBSD: roff.c,v 1.126 2015/01/23 00:38:42 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -1639,8 +1639,46 @@ roff_getnum(const char *v, int *pos, int *res) if (n) *res = -*res; - *pos = p; - return 1; + /* Each number may be followed by one optional scaling unit. */ + + switch (v[p]) { + case 'f': + *res *= 65536; + break; + case 'i': + *res *= 240; + break; + case 'c': + *res *= 240; + *res /= 2.54; + break; + case 'v': + /* FALLTROUGH */ + case 'P': + *res *= 40; + break; + case 'm': + /* FALLTROUGH */ + case 'n': + *res *= 24; + break; + case 'p': + *res *= 10; + *res /= 3; + break; + case 'u': + break; + case 'M': + *res *= 6; + *res /= 25; + break; + default: + p--; + break; + } + + *pos = p + 1; + return(1); } /* |