summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-02-14 22:27:41 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-02-14 22:27:41 +0000
commit96df27d03244a434b09208c3f24e65e71bd5f50b (patch)
treec88409d690ad3e132ef5b9b0530107d9a8ea0b8b
parente85fc05ee906b4db80b3b3aaca1f986a1678beac (diff)
downloadmandoc-96df27d03244a434b09208c3f24e65e71bd5f50b.tar.gz
Handle some predefined read-only number registers, e.g. .H and .V.
In particular, this improves handling of the pod2man(1) preamble; for examples of the effect, see some author names in perlthrtut(1). Missing feature reported by Andreas Voegele <mail at andreasvoegele dot com> more than two years ago. Written at Christchurch International Airport.
-rw-r--r--TODO5
-rw-r--r--roff.c43
2 files changed, 43 insertions, 5 deletions
diff --git a/TODO b/TODO
index 84389ec5..a1e27add 100644
--- a/TODO
+++ b/TODO
@@ -15,11 +15,6 @@ None known.
--- missing roff features ----------------------------------------------
-- roff.c should treat \n(.H>23 and \n(.V>19 in the pod2man(1)
- preamble as true, see for example AUTHORS in MooseX::Getopt.3p
- reported by Andreas Voegele <mail at andreasvoegele dot com>
- Tue, 22 Nov 2011 15:34:47 +0100 on ports@
-
- .ad (adjust margins)
.ad l -- adjust left margin only (flush left)
.ad r -- adjust right margin only (flush right)
diff --git a/roff.c b/roff.c
index 45197765..06ecc9a7 100644
--- a/roff.c
+++ b/roff.c
@@ -192,6 +192,7 @@ static int roff_getnum(const char *, int *, int *);
static int roff_getop(const char *, int *, char *);
static int roff_getregn(const struct roff *,
const char *, size_t);
+static int roff_getregro(const char *name);
static const char *roff_getstrn(const struct roff *,
const char *, size_t);
static enum rofferr roff_it(ROFF_ARGS);
@@ -1380,10 +1381,45 @@ roff_setreg(struct roff *r, const char *name, int val, char sign)
reg->val = val;
}
+/*
+ * Handle some predefined read-only number registers.
+ * For now, return -1 if the requested register is not predefined;
+ * in case a predefined read-only register having the value -1
+ * were to turn up, another special value would have to be chosen.
+ */
+static int
+roff_getregro(const char *name)
+{
+
+ switch (*name) {
+ case ('A'): /* ASCII approximation mode is always off. */
+ return(0);
+ case ('g'): /* Groff compatibility mode is always on. */
+ return(1);
+ case ('H'): /* Fixed horizontal resolution. */
+ return (24);
+ case ('j'): /* Always adjust left margin only. */
+ return(0);
+ case ('T'): /* Some output device is always defined. */
+ return(1);
+ case ('V'): /* Fixed vertical resolution. */
+ return (40);
+ default:
+ return (-1);
+ }
+}
+
int
roff_getreg(const struct roff *r, const char *name)
{
struct roffreg *reg;
+ int val;
+
+ if ('.' == name[0] && '\0' != name[1] && '\0' == name[2]) {
+ val = roff_getregro(name + 1);
+ if (-1 != val)
+ return (val);
+ }
for (reg = r->regtab; reg; reg = reg->next)
if (0 == strcmp(name, reg->key.p))
@@ -1396,6 +1432,13 @@ static int
roff_getregn(const struct roff *r, const char *name, size_t len)
{
struct roffreg *reg;
+ int val;
+
+ if ('.' == name[0] && 2 == len) {
+ val = roff_getregro(name + 1);
+ if (-1 != val)
+ return (val);
+ }
for (reg = r->regtab; reg; reg = reg->next)
if (len == reg->key.sz &&