=================================================================== RCS file: /cvs/mandoc/roff.c,v retrieving revision 1.214 retrieving revision 1.219 diff -u -p -r1.214 -r1.219 --- mandoc/roff.c 2014/06/29 23:26:00 1.214 +++ mandoc/roff.c 2014/07/06 19:09:00 1.219 @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.214 2014/06/29 23:26:00 schwarze Exp $ */ +/* $Id: roff.c,v 1.219 2014/07/06 19:09:00 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -500,7 +500,7 @@ roff_res(struct roff *r, char **bufp, size_t *szp, int size_t naml; /* actual length of the escape name */ int expand_count; /* to avoid infinite loops */ int npos; /* position in numeric expression */ - int irc; /* return code from roff_evalnum() */ + int arg_complete; /* argument not interrupted by eol */ char term; /* character terminating the escape */ expand_count = 0; @@ -542,8 +542,9 @@ roff_res(struct roff *r, char **bufp, size_t *szp, int break; default: if (ESCAPE_ERROR == mandoc_escape(&cp, NULL, NULL)) - mandoc_msg(MANDOCERR_BADESCAPE, r->parse, - ln, (int)(stesc - *bufp), NULL); + mandoc_vmsg(MANDOCERR_ESC_BAD, + r->parse, ln, (int)(stesc - *bufp), + "%.*s", (int)(cp - stesc), stesc); continue; } @@ -585,10 +586,12 @@ roff_res(struct roff *r, char **bufp, size_t *szp, int /* Advance to the end of the name. */ + arg_complete = 1; for (naml = 0; 0 == maxl || naml < maxl; naml++, cp++) { if ('\0' == *cp) { - mandoc_msg(MANDOCERR_BADESCAPE, r->parse, - ln, (int)(stesc - *bufp), NULL); + mandoc_msg(MANDOCERR_ESC_BAD, r->parse, + ln, (int)(stesc - *bufp), stesc); + arg_complete = 0; break; } if (0 == maxl && *cp == term) { @@ -604,28 +607,34 @@ roff_res(struct roff *r, char **bufp, size_t *szp, int switch (stesc[1]) { case '*': - res = roff_getstrn(r, stnam, naml); + if (arg_complete) + res = roff_getstrn(r, stnam, naml); break; case 'B': npos = 0; - irc = roff_evalnum(stnam, &npos, NULL, 0); - ubuf[0] = irc && stnam + npos + 1 == cp - ? '1' : '0'; + ubuf[0] = arg_complete && + roff_evalnum(stnam, &npos, NULL, 0) && + stnam + npos + 1 == cp ? '1' : '0'; ubuf[1] = '\0'; break; case 'n': - (void)snprintf(ubuf, sizeof(ubuf), "%d", - roff_getregn(r, stnam, naml)); + if (arg_complete) + (void)snprintf(ubuf, sizeof(ubuf), "%d", + roff_getregn(r, stnam, naml)); + else + ubuf[0] = '\0'; break; case 'w': + /* use even incomplete args */ (void)snprintf(ubuf, sizeof(ubuf), "%d", 24 * (int)naml); break; } if (NULL == res) { - mandoc_msg(MANDOCERR_BADESCAPE, r->parse, - ln, (int)(stesc - *bufp), NULL); + mandoc_vmsg(MANDOCERR_STR_UNDEF, + r->parse, ln, (int)(stesc - *bufp), + "%.*s", (int)naml, stnam); res = ""; } @@ -856,7 +865,8 @@ roff_cblock(ROFF_ARGS) } if ((*bufp)[pos]) - mandoc_msg(MANDOCERR_ARGSLOST, r->parse, ln, pos, NULL); + mandoc_vmsg(MANDOCERR_ARG_SKIP, r->parse, ln, pos, + ".. %s", *bufp + pos); roffnode_pop(r); roffnode_cleanscope(r); @@ -917,7 +927,8 @@ roff_block(ROFF_ARGS) if (ROFF_ig != tok) { if ('\0' == *cp) { - mandoc_msg(MANDOCERR_NOARGS, r->parse, ln, ppos, NULL); + mandoc_msg(MANDOCERR_REQ_EMPTY, r->parse, + ln, ppos, roffs[tok].name); return(ROFF_IGN); } @@ -959,7 +970,8 @@ roff_block(ROFF_ARGS) r->last->end = mandoc_strndup(name, namesz); if ('\0' != *cp) - mandoc_msg(MANDOCERR_ARGSLOST, r->parse, ln, pos, NULL); + mandoc_vmsg(MANDOCERR_ARG_EXCESS, r->parse, + ln, pos, ".%s ... %s", roffs[tok].name, cp); return(ROFF_IGN); } @@ -1285,7 +1297,8 @@ roff_cond(ROFF_ARGS) */ if ('\0' == (*bufp)[pos]) - mandoc_msg(MANDOCERR_NOARGS, r->parse, ln, ppos, NULL); + mandoc_msg(MANDOCERR_COND_EMPTY, r->parse, + ln, ppos, roffs[tok].name); r->last->endspan = 1; @@ -1883,9 +1896,8 @@ roff_tr(ROFF_ARGS) if ('\\' == *first) { esc = mandoc_escape(&p, NULL, NULL); if (ESCAPE_ERROR == esc) { - mandoc_msg(MANDOCERR_BADESCAPE, - r->parse, ln, - (int)(p - *bufp), NULL); + mandoc_msg(MANDOCERR_ESC_BAD, r->parse, + ln, (int)(p - *bufp), first); return(ROFF_IGN); } fsz = (size_t)(p - first); @@ -1895,9 +1907,8 @@ roff_tr(ROFF_ARGS) if ('\\' == *second) { esc = mandoc_escape(&p, NULL, NULL); if (ESCAPE_ERROR == esc) { - mandoc_msg(MANDOCERR_BADESCAPE, - r->parse, ln, - (int)(p - *bufp), NULL); + mandoc_msg(MANDOCERR_ESC_BAD, r->parse, + ln, (int)(p - *bufp), second); return(ROFF_IGN); } ssz = (size_t)(p - second); @@ -2018,10 +2029,12 @@ roff_getname(struct roff *r, char **cpp, int ln, int p } if ('\\' != *cp) continue; + namesz = cp - name; + if ('{' == cp[1] || '}' == cp[1]) + break; cp++; if ('\\' == *cp) continue; - namesz = cp - name - 1; mandoc_msg(MANDOCERR_NAMESC, r->parse, ln, pos, NULL); mandoc_escape((const char **)&cp, NULL, NULL); break;