source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Minimal implementation of the read-only number register \n(.$
@ 2015-08-29 20:26 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-08-29 20:26 UTC (permalink / raw)
  To: source

Log Message:
-----------
Minimal implementation of the read-only number register \n(.$
which returns the number of arguments of the current macro.
This is one of the missing features required for ocserv(8).
Problem reported by Kurt Jaeger <pi at FreeBSD>.

Modified Files:
--------------
    mdocml:
        roff.c

Revision Data
-------------
Index: roff.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/roff.c,v
retrieving revision 1.272
retrieving revision 1.273
diff -Lroff.c -Lroff.c -u -p -r1.272 -r1.273
--- roff.c
+++ roff.c
@@ -335,6 +335,7 @@ struct	roff {
 	int		 rstacksz; /* current size limit of rstack */
 	int		 rstackpos; /* position in rstack */
 	int		 format; /* current file in mdoc or man format */
+	int		 argc; /* number of args of the last macro */
 	char		 control; /* control character */
 };
 
@@ -411,7 +412,8 @@ static	int		 roff_getnum(const char *, i
 static	int		 roff_getop(const char *, int *, char *);
 static	int		 roff_getregn(const struct roff *,
 				const char *, size_t);
-static	int		 roff_getregro(const char *name);
+static	int		 roff_getregro(const struct roff *,
+				const char *name);
 static	const char	*roff_getstrn(const struct roff *,
 				const char *, size_t);
 static	int		 roff_hasregn(const struct roff *,
@@ -2575,10 +2577,12 @@ roff_setreg(struct roff *r, const char *
  * were to turn up, another special value would have to be chosen.
  */
 static int
-roff_getregro(const char *name)
+roff_getregro(const struct roff *r, const char *name)
 {
 
 	switch (*name) {
+	case '$':  /* Number of arguments of the last macro evaluated. */
+		return(r->argc);
 	case 'A':  /* ASCII approximation mode is always off. */
 		return(0);
 	case 'g':  /* Groff compatibility mode is always on. */
@@ -2603,7 +2607,7 @@ roff_getreg(const struct roff *r, const 
 	int		 val;
 
 	if ('.' == name[0] && '\0' != name[1] && '\0' == name[2]) {
-		val = roff_getregro(name + 1);
+		val = roff_getregro(r, name + 1);
 		if (-1 != val)
 			return (val);
 	}
@@ -2622,7 +2626,7 @@ roff_getregn(const struct roff *r, const
 	int		 val;
 
 	if ('.' == name[0] && 2 == len) {
-		val = roff_getregro(name + 1);
+		val = roff_getregro(r, name + 1);
 		if (-1 != val)
 			return (val);
 	}
@@ -2642,7 +2646,7 @@ roff_hasregn(const struct roff *r, const
 	int		 val;
 
 	if ('.' == name[0] && 2 == len) {
-		val = roff_getregro(name + 1);
+		val = roff_getregro(r, name + 1);
 		if (-1 != val)
 			return(1);
 	}
@@ -3084,10 +3088,16 @@ roff_userdef(ROFF_ARGS)
 	 * and NUL-terminate them.
 	 */
 
+	r->argc = 0;
 	cp = buf->buf + pos;
-	for (i = 0; i < 9; i++)
-		arg[i] = *cp == '\0' ? "" :
-		    mandoc_getarg(r->parse, &cp, ln, &pos);
+	for (i = 0; i < 9; i++) {
+		if (*cp == '\0')
+			arg[i] = "";
+		else {
+			arg[i] = mandoc_getarg(r->parse, &cp, ln, &pos);
+			r->argc = i + 1;
+		}
+	}
 
 	/*
 	 * Expand macro arguments.
--
 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-08-29 20:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-29 20:26 mdocml: Minimal implementation of the read-only number register \n(.$ 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).