=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/roff.c,v retrieving revision 1.144 retrieving revision 1.145 diff -c -r1.144 -r1.145 *** src/usr.bin/mandoc/roff.c 2015/06/27 13:25:30 1.144 --- src/usr.bin/mandoc/roff.c 2015/08/29 20:24:34 1.145 *************** *** 1,4 **** ! /* $OpenBSD: roff.c,v 1.144 2015/06/27 13:25:30 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2010-2015 Ingo Schwarze --- 1,4 ---- ! /* $OpenBSD: roff.c,v 1.145 2015/08/29 20:24:34 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2010-2015 Ingo Schwarze *************** *** 333,338 **** --- 333,339 ---- 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 */ }; *************** *** 409,415 **** 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 const char *roff_getstrn(const struct roff *, const char *, size_t); static int roff_hasregn(const struct roff *, --- 410,417 ---- static int roff_getop(const char *, int *, char *); static int roff_getregn(const struct roff *, const char *, size_t); ! 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 *, *************** *** 2573,2582 **** * were to turn up, another special value would have to be chosen. */ static int ! roff_getregro(const char *name) { switch (*name) { case 'A': /* ASCII approximation mode is always off. */ return(0); case 'g': /* Groff compatibility mode is always on. */ --- 2575,2586 ---- * were to turn up, another special value would have to be chosen. */ static int ! 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. */ *************** *** 2601,2607 **** int val; if ('.' == name[0] && '\0' != name[1] && '\0' == name[2]) { ! val = roff_getregro(name + 1); if (-1 != val) return (val); } --- 2605,2611 ---- int val; if ('.' == name[0] && '\0' != name[1] && '\0' == name[2]) { ! val = roff_getregro(r, name + 1); if (-1 != val) return (val); } *************** *** 2620,2626 **** int val; if ('.' == name[0] && 2 == len) { ! val = roff_getregro(name + 1); if (-1 != val) return (val); } --- 2624,2630 ---- int val; if ('.' == name[0] && 2 == len) { ! val = roff_getregro(r, name + 1); if (-1 != val) return (val); } *************** *** 2640,2646 **** int val; if ('.' == name[0] && 2 == len) { ! val = roff_getregro(name + 1); if (-1 != val) return(1); } --- 2644,2650 ---- int val; if ('.' == name[0] && 2 == len) { ! val = roff_getregro(r, name + 1); if (-1 != val) return(1); } *************** *** 3082,3091 **** * and NUL-terminate them. */ cp = buf->buf + pos; ! for (i = 0; i < 9; i++) ! arg[i] = *cp == '\0' ? "" : ! mandoc_getarg(r->parse, &cp, ln, &pos); /* * Expand macro arguments. --- 3086,3101 ---- * and NUL-terminate them. */ + r->argc = 0; cp = buf->buf + 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.