From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Minimal implementation of the read-only number register \n(.$
Date: Sat, 29 Aug 2015 15:26:34 -0500 (EST) [thread overview]
Message-ID: <331191743022580026.enqueue@fantadrom.bsd.lv> (raw)
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
reply other threads:[~2015-08-29 20:26 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=331191743022580026.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).