source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Implement the roff(7) `r' (register exists) conditional.
Date: Sun, 31 May 2015 18:13:52 -0500 (EST)	[thread overview]
Message-ID: <13065753442048952191.enqueue@fantadrom.bsd.lv> (raw)

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

                 reply	other threads:[~2015-05-31 23:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=13065753442048952191.enqueue@fantadrom.bsd.lv \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).