aboutsummaryrefslogtreecommitdiffstatshomepage
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
commita303f40898d21cb0d5552a2252710ddc741a1cec (patch)
treed38b1f7764118039b866dffbf2f2395e33241aff /roff.c
parent9e9da087dda5194812500db223832a351d496b16 (diff)
downloadmandoc-a303f40898d21cb0d5552a2252710ddc741a1cec.tar.gz
mandoc-a303f40898d21cb0d5552a2252710ddc741a1cec.tar.zst
mandoc-a303f40898d21cb0d5552a2252710ddc741a1cec.zip
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.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/roff.c b/roff.c
index 83738cef..e4c43c13 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.186 2013/10/22 20:38:00 schwarze Exp $ */
+/* $Id: roff.c,v 1.187 2013/12/15 21:23:52 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -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);
}