summaryrefslogtreecommitdiffstats
path: root/roff.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2013-12-15 21:23:52 +0000
committerIngo Schwarze <schwarze@openbsd.org>2013-12-15 21:23:52 +0000
commit281129cb0c7f8658dbddf1c3861189908a4b31a5 (patch)
treece62f9f0c1ce0befc4e905b6057f4426ab4eb703 /roff.c
parent1785eefc0e123397ec0468858110d9ed6ff815db (diff)
downloadmandoc-281129cb0c7f8658dbddf1c3861189908a4b31a5.tar.gz
The "value" argument to the roff(7) .nr requests ends right before
the first non-digit character. While here, implement and document an optional sign, requesting increment or decrement, as documented in the Ossanna/Kernighan/Ritter troff manual and supported by groff. Reported by bentley@ on discuss@.
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/roff.c b/roff.c
index c8382154..2f3d1498 100644
--- a/roff.c
+++ b/roff.c
@@ -1360,7 +1360,7 @@ roff_ds(ROFF_ARGS)
}
void
-roff_setreg(struct roff *r, const char *name, int val)
+roff_setreg(struct roff *r, const char *name, int val, char sign)
{
struct roffreg *reg;
@@ -1375,11 +1375,17 @@ roff_setreg(struct roff *r, const char *name, int val)
reg = mandoc_malloc(sizeof(struct roffreg));
reg->key.p = mandoc_strdup(name);
reg->key.sz = strlen(name);
+ reg->val = 0;
reg->next = r->regtab;
r->regtab = reg;
}
- reg->val = val;
+ if ('+' == sign)
+ reg->val += val;
+ else if ('-' == sign)
+ reg->val -= val;
+ else
+ reg->val = val;
}
int
@@ -1426,14 +1432,21 @@ roff_nr(ROFF_ARGS)
{
const char *key;
char *val;
+ size_t sz;
int iv;
+ char sign;
val = *bufp + pos;
key = roff_getname(r, &val, ln, pos);
- iv = mandoc_strntoi(val, strlen(val), 10);
+ sign = *val;
+ if ('+' == sign || '-' == sign)
+ val++;
+
+ sz = strspn(val, "0123456789");
+ iv = sz ? mandoc_strntoi(val, sz, 10) : 0;
- roff_setreg(r, key, iv);
+ roff_setreg(r, key, iv, sign);
return(ROFF_IGN);
}