* mdocml: Implement the roff(7) `r' (register exists) conditional.
@ 2015-05-31 23:13 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-05-31 23:13 UTC (permalink / raw)
To: source
Log Message:
-----------
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.
Modified Files:
--------------
mdocml:
roff.7
roff.c
Revision Data
-------------
Index: roff.7
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.7,v
retrieving revision 1.71
retrieving revision 1.72
diff -Lroff.7 -Lroff.7 -u -p -r1.71 -r1.72
--- roff.7
+++ roff.7
@@ -1057,14 +1057,17 @@ 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
.Sq v
.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
Index: roff.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.c,v
retrieving revision 1.270
retrieving revision 1.271
diff -Lroff.c -Lroff.c -u -p -r1.270 -r1.271
--- roff.c
+++ roff.c
@@ -397,8 +397,7 @@ static enum rofferr roff_cond_text(ROFF
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 r
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, co
/* 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;
}
@@ -2623,6 +2629,26 @@ roff_getregn(const struct roff *r, const
if (len == reg->key.sz &&
0 == strncmp(name, reg->key.p, len))
return(reg->val);
+
+ 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);
}
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-05-31 23:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-31 23:13 mdocml: Implement the roff(7) `r' (register exists) conditional schwarze
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).