diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2015-01-23 00:42:00 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2015-01-23 00:42:00 +0000 |
commit | 5d66739b249d811455e368f2eb74af651ba8ffac (patch) | |
tree | c755c7ea7ca5da728c276e9ea0971aeb8cccfbbb /roff.c | |
parent | 3f21939a391eaea3a1eab39d7ae539fdd04cb52a (diff) | |
download | mandoc-5d66739b249d811455e368f2eb74af651ba8ffac.tar.gz mandoc-5d66739b249d811455e368f2eb74af651ba8ffac.tar.zst mandoc-5d66739b249d811455e368f2eb74af651ba8ffac.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 'roff.c')
-rw-r--r-- | roff.c | 44 |
1 files changed, 41 insertions, 3 deletions
@@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.253 2015/01/22 22:51:43 schwarze Exp $ */ +/* $Id: roff.c,v 1.254 2015/01/23 00:42:00 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -1641,8 +1641,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); } /* |