=================================================================== RCS file: /cvs/mandoc/roff.c,v retrieving revision 1.273 retrieving revision 1.275 diff -u -p -r1.273 -r1.275 --- mandoc/roff.c 2015/08/29 20:26:04 1.273 +++ mandoc/roff.c 2015/08/29 23:56:01 1.275 @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.273 2015/08/29 20:26:04 schwarze Exp $ */ +/* $Id: roff.c,v 1.275 2015/08/29 23:56:01 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2010-2015 Ingo Schwarze @@ -1484,9 +1484,7 @@ roff_res(struct roff *r, struct buf *buf, int ln, int } /* - * Process text streams: - * Convert all breakable hyphens into ASCII_HYPH. - * Decrement and spring input line trap. + * Process text streams. */ static enum rofferr roff_parsetext(struct buf *buf, int pos, int *offs) @@ -1497,6 +1495,22 @@ roff_parsetext(struct buf *buf, int pos, int *offs) int isz; enum mandoc_esc esc; + /* Spring the input line trap. */ + + if (roffit_lines == 1) { + isz = mandoc_asprintf(&p, "%s\n.%s", buf->buf, roffit_macro); + free(buf->buf); + buf->buf = p; + buf->sz = isz + 1; + *offs = 0; + free(roffit_macro); + roffit_lines = 0; + return(ROFF_REPARSE); + } else if (roffit_lines > 1) + --roffit_lines; + + /* Convert all breakable hyphens into ASCII_HYPH. */ + start = p = buf->buf + pos; while (*p != '\0') { @@ -1525,19 +1539,6 @@ roff_parsetext(struct buf *buf, int pos, int *offs) *p = ASCII_HYPH; p++; } - - /* Spring the input line trap. */ - if (roffit_lines == 1) { - isz = mandoc_asprintf(&p, "%s\n.%s", buf->buf, roffit_macro); - free(buf->buf); - buf->buf = p; - buf->sz = isz + 1; - *offs = 0; - free(roffit_macro); - roffit_lines = 0; - return(ROFF_REPARSE); - } else if (roffit_lines > 1) - --roffit_lines; return(ROFF_CONT); } @@ -3080,7 +3081,7 @@ roff_userdef(ROFF_ARGS) { const char *arg[9], *ap; char *cp, *n1, *n2; - int i; + int i, ib, ie; size_t asz, rsz; /* @@ -3114,9 +3115,14 @@ roff_userdef(ROFF_ARGS) continue; if (*cp++ != '$') continue; - i = *cp - '1'; - if (0 > i || 8 < i) - continue; + if (*cp == '*') { /* \\$* inserts all arguments */ + ib = 0; + ie = r->argc - 1; + } else { /* \\$1 .. \\$9 insert one argument */ + ib = ie = *cp - '1'; + if (ib < 0 || ib > 8) + continue; + } cp -= 2; /* @@ -3124,11 +3130,13 @@ roff_userdef(ROFF_ARGS) * taking escaping of quotes into account. */ - asz = 0; - for (ap = arg[i]; *ap != '\0'; ap++) { - asz++; - if (*ap == '"') - asz += 3; + asz = ie > ib ? ie - ib : 0; /* for blanks */ + for (i = ib; i <= ie; i++) { + for (ap = arg[i]; *ap != '\0'; ap++) { + asz++; + if (*ap == '"') + asz += 3; + } } if (asz != 3) { @@ -3169,12 +3177,16 @@ roff_userdef(ROFF_ARGS) /* Copy the expanded argument, escaping quotes. */ n2 = cp; - for (ap = arg[i]; *ap != '\0'; ap++) { - if (*ap == '"') { - memcpy(n2, "\\(dq", 4); - n2 += 4; - } else - *n2++ = *ap; + for (i = ib; i <= ie; i++) { + for (ap = arg[i]; *ap != '\0'; ap++) { + if (*ap == '"') { + memcpy(n2, "\\(dq", 4); + n2 += 4; + } else + *n2++ = *ap; + } + if (i < ie) + *n2++ = ' '; } }