From: Ingo Schwarze Date: Fri, 14 Feb 2014 22:27:41 +0000 (+0000) Subject: Handle some predefined read-only number registers, e.g. .H and .V. X-Git-Tag: VERSION_1_13_1~255 X-Git-Url: https://git.cameronkatri.com/mandoc.git/commitdiff_plain/e3f171fb597272f23e088ee32a2578bfb4a22aa7 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 more than two years ago. Written at Christchurch International Airport. --- diff --git a/TODO b/TODO index 26f42c23..afe950ad 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,6 @@ ************************************************************************ * Official mandoc TODO. -* $Id: TODO,v 1.162 2013/12/25 14:40:34 schwarze Exp $ +* $Id: TODO,v 1.163 2014/02/14 22:27:41 schwarze Exp $ ************************************************************************ ************************************************************************ @@ -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 - 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 ca8ab7bb..a3e34186 100644 --- a/roff.c +++ b/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.191 2014/01/06 23:46:07 schwarze Exp $ */ +/* $Id: roff.c,v 1.192 2014/02/14 22:27:41 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -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 &&