aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-05-31 23:13:22 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-05-31 23:13:22 +0000
commitbe3e970f578850301090009923eccbd3a255b801 (patch)
tree755a8c3733f27b9fb0e351259dfe4891ef9da919
parent23ce90af4d0d1ec547a53b8a66448e146ec30065 (diff)
downloadmandoc-be3e970f578850301090009923eccbd3a255b801.tar.gz
mandoc-be3e970f578850301090009923eccbd3a255b801.tar.zst
mandoc-be3e970f578850301090009923eccbd3a255b801.zip
Implement the roff(7) `r' (register exists) conditional.
Missing feature found by Markus <Waldeck at gmx dot de> in Debian's bash(1) manual page.
-rw-r--r--roff.711
-rw-r--r--roff.c38
2 files changed, 39 insertions, 10 deletions
diff --git a/roff.7 b/roff.7
index 02b7212e..127504f8 100644
--- a/roff.7
+++ b/roff.7
@@ -1,4 +1,4 @@
-.\" $Id: roff.7,v 1.71 2015/04/29 18:35:00 schwarze Exp $
+.\" $Id: roff.7,v 1.72 2015/05/31 23:13:22 schwarze Exp $
.\"
.\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2010, 2011, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -15,7 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: April 29 2015 $
+.Dd $Mdocdate: May 31 2015 $
.Dt ROFF 7
.Os
.Sh NAME
@@ -1057,8 +1057,6 @@ If the first character of COND is
.Pq string defined ,
.Sq e
.Pq even page ,
-.Sq r
-.Pq register accessed ,
.Sq t
.Pq troff mode ,
or
@@ -1066,6 +1064,11 @@ or
.Pq vroff mode ,
COND evaluates to false.
.It
+If the first character of COND is
+.Sq r ,
+it evalutes to true if the rest of COND is the name of an existing
+number register; otherwise, it evaluates to false.
+.It
If COND starts with a parenthesis or with an optionally signed
integer number, it is evaluated according to the rules of
.Sx Numerical expressions
diff --git a/roff.c b/roff.c
index 31bed07a..0dfcb46c 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.270 2015/05/01 16:02:47 schwarze Exp $ */
+/* $Id: roff.c,v 1.271 2015/05/31 23:13:22 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -397,8 +397,7 @@ static enum rofferr roff_cond_text(ROFF_ARGS);
static enum rofferr roff_cond_sub(ROFF_ARGS);
static enum rofferr roff_ds(ROFF_ARGS);
static enum rofferr roff_eqndelim(struct roff *, struct buf *, int);
-static int roff_evalcond(struct roff *r, int,
- const char *, int *);
+static int roff_evalcond(struct roff *r, int, char *, int *);
static int roff_evalnum(struct roff *, int,
const char *, int *, int *, int);
static int roff_evalpar(struct roff *, int,
@@ -415,6 +414,8 @@ static int roff_getregn(const struct roff *,
static int roff_getregro(const char *name);
static const char *roff_getstrn(const struct roff *,
const char *, size_t);
+static int roff_hasregn(const struct roff *,
+ const char *, size_t);
static enum rofferr roff_insec(ROFF_ARGS);
static enum rofferr roff_it(ROFF_ARGS);
static enum rofferr roff_line_ignore(ROFF_ARGS);
@@ -2134,8 +2135,10 @@ out:
* or string condition.
*/
static int
-roff_evalcond(struct roff *r, int ln, const char *v, int *pos)
+roff_evalcond(struct roff *r, int ln, char *v, int *pos)
{
+ char *cp, *name;
+ size_t sz;
int number, savepos, wanttrue;
if ('!' == v[*pos]) {
@@ -2158,13 +2161,16 @@ roff_evalcond(struct roff *r, int ln, const char *v, int *pos)
/* FALLTHROUGH */
case 'e':
/* FALLTHROUGH */
- case 'r':
- /* FALLTHROUGH */
case 't':
/* FALLTHROUGH */
case 'v':
(*pos)++;
return(!wanttrue);
+ case 'r':
+ cp = name = v + ++*pos;
+ sz = roff_getname(r, &cp, ln, *pos);
+ *pos = cp - v;
+ return((sz && roff_hasregn(r, name, sz)) == wanttrue);
default:
break;
}
@@ -2627,6 +2633,26 @@ roff_getregn(const struct roff *r, const char *name, size_t len)
return(0);
}
+static int
+roff_hasregn(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(1);
+ }
+
+ for (reg = r->regtab; reg; reg = reg->next)
+ if (len == reg->key.sz &&
+ 0 == strncmp(name, reg->key.p, len))
+ return(1);
+
+ return(0);
+}
+
static void
roff_freereg(struct roffreg *reg)
{