summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2013-12-15 21:18:01 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2013-12-15 21:18:01 +0000
commitee8f3980ad6c08aa008115495ca99bf641aca115 (patch)
tree9610c80897f4fcf4beefb5b0300c2f91cca8ee85 /usr.bin
parent426fcb420507ecdcf179807d7c8ff374460f590a (diff)
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 at mdocml.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/libmandoc.h4
-rw-r--r--usr.bin/mandoc/mdoc_validate.c6
-rw-r--r--usr.bin/mandoc/roff.c23
3 files changed, 23 insertions, 10 deletions
diff --git a/usr.bin/mandoc/libmandoc.h b/usr.bin/mandoc/libmandoc.h
index 302187d965d..9f24af6b95c 100644
--- a/usr.bin/mandoc/libmandoc.h
+++ b/usr.bin/mandoc/libmandoc.h
@@ -1,4 +1,4 @@
-/* $Id: libmandoc.h,v 1.21 2013/10/03 22:04:08 schwarze Exp $ */
+/* $Id: libmandoc.h,v 1.22 2013/12/15 21:18:00 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -68,7 +68,7 @@ void roff_reset(struct roff *);
enum rofferr roff_parseln(struct roff *, int,
char **, size_t *, int, int *);
void roff_endparse(struct roff *);
-void roff_setreg(struct roff *, const char *, int);
+void roff_setreg(struct roff *, const char *, int, char sign);
int roff_getreg(const struct roff *, const char *);
char *roff_strdup(const struct roff *, const char *);
int roff_getcontrol(const struct roff *,
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index 2d85c62f0a5..683e6464049 100644
--- a/usr.bin/mandoc/mdoc_validate.c
+++ b/usr.bin/mandoc/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.115 2013/10/21 23:32:33 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.116 2013/12/15 21:18:00 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -1987,10 +1987,10 @@ post_sh_head(POST_ARGS)
/* The SYNOPSIS gets special attention in other areas. */
if (SEC_SYNOPSIS == sec) {
- roff_setreg(mdoc->roff, "nS", 1);
+ roff_setreg(mdoc->roff, "nS", 1, '=');
mdoc->flags |= MDOC_SYNOPSIS;
} else {
- roff_setreg(mdoc->roff, "nS", 0);
+ roff_setreg(mdoc->roff, "nS", 0, '=');
mdoc->flags &= ~MDOC_SYNOPSIS;
}
diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c
index 2b98bab84a9..6c9dfa97282 100644
--- a/usr.bin/mandoc/roff.c
+++ b/usr.bin/mandoc/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.59 2013/10/22 20:37:54 schwarze Exp $ */
+/* $Id: roff.c,v 1.60 2013/12/15 21:18:00 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -1356,7 +1356,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;
@@ -1371,11 +1371,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
@@ -1422,14 +1428,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);
}