diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2013-12-15 21:23:52 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2013-12-15 21:23:52 +0000 |
commit | 281129cb0c7f8658dbddf1c3861189908a4b31a5 (patch) | |
tree | ce62f9f0c1ce0befc4e905b6057f4426ab4eb703 /roff.c | |
parent | 1785eefc0e123397ec0468858110d9ed6ff815db (diff) | |
download | mandoc-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.c | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -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); } |