-.\" $OpenBSD: roff.7,v 1.51 2015/04/29 18:32:57 schwarze Exp $
+.\" $OpenBSD: roff.7,v 1.52 2015/05/31 23:12:16 schwarze Exp $
.\"
.\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2010, 2011, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
.\" 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
.Pq string defined ,
.Sq e
.Pq even page ,
-.Sq r
-.Pq register accessed ,
.Sq t
.Pq troff mode ,
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
-/* $OpenBSD: roff.c,v 1.142 2015/05/01 16:01:53 schwarze Exp $ */
+/* $OpenBSD: roff.c,v 1.143 2015/05/31 23:12:16 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
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,
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);
* 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]) {
/* 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;
}
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)
{