summaryrefslogtreecommitdiffstats
path: root/usr.bin/mandoc/roff.c
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2015-01-23 00:38:42 +0000
committerschwarze <schwarze@openbsd.org>2015-01-23 00:38:42 +0000
commit4a635483eb5cd55f68d24c217fde341ec0c20d1c (patch)
treea66ff5ff893733680ae2e9f3c834806e839e4417 /usr.bin/mandoc/roff.c
parentSlightly improve \w width measurements: (diff)
downloadwireguard-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@.
Diffstat (limited to 'usr.bin/mandoc/roff.c')
-rw-r--r--usr.bin/mandoc/roff.c44
1 files changed, 41 insertions, 3 deletions
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);
}
/*