From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]); by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id 9c24d38d; for ; Sun, 31 May 2015 18:13:52 -0500 (EST) Date: Sun, 31 May 2015 18:13:52 -0500 (EST) Message-Id: <13065753442048952191.enqueue@fantadrom.bsd.lv> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: schwarze@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Implement the roff(7) `r' (register exists) conditional. X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Implement the roff(7) `r' (register exists) conditional. Missing feature found by Markus 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