source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: implement the roff(7) d (macro or string defined) conditional
@ 2017-06-14 14:02 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2017-06-14 14:02 UTC (permalink / raw)
  To: source

Log Message:
-----------
implement the roff(7) d (macro or string defined) conditional

Modified Files:
--------------
    mdocml:
        roff.7
        roff.c
    mdocml/regress/roff/cond:
        Makefile

Added Files:
-----------
    mdocml/regress/roff/cond:
        string.in
        string.out_ascii

Revision Data
-------------
Index: roff.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.c,v
retrieving revision 1.309
retrieving revision 1.310
diff -Lroff.c -Lroff.c -u -p -r1.309 -r1.310
--- roff.c
+++ roff.c
@@ -2065,7 +2065,7 @@ roff_evalcond(struct roff *r, int ln, ch
 {
 	char	*cp, *name;
 	size_t	 sz;
-	int	 number, savepos, wanttrue;
+	int	 number, savepos, istrue, wanttrue;
 
 	if ('!' == v[*pos]) {
 		wanttrue = 0;
@@ -2081,17 +2081,23 @@ roff_evalcond(struct roff *r, int ln, ch
 		(*pos)++;
 		return wanttrue;
 	case 'c':
-	case 'd':
 	case 'e':
 	case 't':
 	case 'v':
 		(*pos)++;
 		return !wanttrue;
+	case 'd':
 	case 'r':
-		cp = name = v + ++*pos;
-		sz = roff_getname(r, &cp, ln, *pos);
+		cp = v + *pos + 1;
+		while (*cp == ' ')
+			cp++;
+		name = cp;
+		sz = roff_getname(r, &cp, ln, cp - v);
+		istrue = sz && (v[*pos] == 'r' ? roff_hasregn(r, name, sz) :
+		    (roff_getstrn(r, name, sz) != NULL ||
+		     roff_getrenn(r, name, sz) != NULL));
 		*pos = cp - v;
-		return (sz && roff_hasregn(r, name, sz)) == wanttrue;
+		return istrue == wanttrue;
 	default:
 		break;
 	}
Index: roff.7
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.7,v
retrieving revision 1.89
retrieving revision 1.90
diff -Lroff.7 -Lroff.7 -u -p -r1.89 -r1.90
--- roff.7
+++ roff.7
@@ -1045,8 +1045,6 @@ If the first character of
 is
 .Sq c
 .Pq character available ,
-.Sq d
-.Pq string defined ,
 .Sq e
 .Pq even page ,
 .Sq t
@@ -1055,6 +1053,15 @@ or
 .Sq v
 .Pq vroff mode ,
 it evaluates to false.
+.It
+If the first character of
+.Ar condition
+is
+.Sq d ,
+it evaluates to true if the rest of
+.Ar condition
+is the name of an existing user defined macro or string;
+otherwise, it evaluates to false.
 .It
 If the first character of
 .Ar condition
--- /dev/null
+++ regress/roff/cond/string.out_ascii
@@ -0,0 +1,20 @@
+STRING(1)                   General Commands Manual                  STRING(1)
+
+
+
+N\bNA\bAM\bME\bE
+       string - conditional testing whether a string is defined
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+       mystr not yet defined
+       now defined
+
+       mymac not yet defined
+       now defined
+
+       myren not yet defined
+       now defined
+
+
+
+OpenBSD                          June 14, 2017                       STRING(1)
--- /dev/null
+++ regress/roff/cond/string.in
@@ -0,0 +1,29 @@
+.TH STRING 1 "June 14, 2017" OpenBSD
+.SH NAME
+string \- conditional testing whether a string is defined
+.SH DESCRIPTION
+.ie d mystr OOPS
+.el mystr not yet defined
+.br
+.ds mystr mystrval
+.ie d mystr now defined
+.el OOPS
+.if !d mystr OOPS
+.PP
+.ie d mymac OOPS
+.el mymac not yet defined
+.br
+.de mymac
+mymacval
+..
+.ie dmymac now defined
+.el OOPS
+.if !d  mymac OOPS
+.PP
+.ie d myren OOPS
+.el myren not yet defined
+.br
+.rn SM myren
+.ie d myren now defined
+.el OOPS
+.if !d myren OOPS
Index: Makefile
===================================================================
RCS file: /home/cvs/mdocml/mdocml/regress/roff/cond/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lregress/roff/cond/Makefile -Lregress/roff/cond/Makefile -u -p -r1.1 -r1.2
--- regress/roff/cond/Makefile
+++ regress/roff/cond/Makefile
@@ -1,6 +1,6 @@
 # $OpenBSD: Makefile,v 1.8 2015/05/31 23:12:17 schwarze Exp $
 
-REGRESS_TARGETS = if ie close numeric register strcmp before-Dd
+REGRESS_TARGETS	= if ie close numeric register strcmp string before-Dd
 LINT_TARGETS	= if close
 
 .include <bsd.regress.mk>
--
 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:[~2017-06-14 14:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-14 14:02 mdocml: implement the roff(7) d (macro or string defined) 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).