=================================================================== RCS file: /cvs/mandoc/roff.c,v retrieving revision 1.193 retrieving revision 1.196 diff -u -p -r1.193 -r1.196 --- mandoc/roff.c 2014/02/14 23:05:20 1.193 +++ mandoc/roff.c 2014/03/07 18:30:11 1.196 @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.193 2014/02/14 23:05:20 schwarze Exp $ */ +/* $Id: roff.c,v 1.196 2014/03/07 18:30:11 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -42,6 +42,7 @@ enum rofft { ROFF_am1, ROFF_as, ROFF_cc, + ROFF_ce, ROFF_de, ROFF_dei, ROFF_de1, @@ -71,7 +72,6 @@ enum rofft { ROFF_EQ, ROFF_EN, ROFF_cblock, - ROFF_ccond, ROFF_USERDEF, ROFF_MAX }; @@ -179,7 +179,7 @@ static enum rofferr roff_block_text(ROFF_ARGS); static enum rofferr roff_block_sub(ROFF_ARGS); static enum rofferr roff_cblock(ROFF_ARGS); static enum rofferr roff_cc(ROFF_ARGS); -static enum rofferr roff_ccond(ROFF_ARGS); +static void roff_ccond(struct roff *, int, int); static enum rofferr roff_cond(ROFF_ARGS); static enum rofferr roff_cond_text(ROFF_ARGS); static enum rofferr roff_cond_sub(ROFF_ARGS); @@ -236,6 +236,7 @@ static struct roffmac roffs[ROFF_MAX] = { { "am1", roff_block, roff_block_text, roff_block_sub, 0, NULL }, { "as", roff_ds, NULL, NULL, 0, NULL }, { "cc", roff_cc, NULL, NULL, 0, NULL }, + { "ce", roff_line_ignore, NULL, NULL, 0, NULL }, { "de", roff_block, roff_block_text, roff_block_sub, 0, NULL }, { "dei", roff_block, roff_block_text, roff_block_sub, 0, NULL }, { "de1", roff_block, roff_block_text, roff_block_sub, 0, NULL }, @@ -265,7 +266,6 @@ static struct roffmac roffs[ROFF_MAX] = { { "EQ", roff_EQ, NULL, NULL, 0, NULL }, { "EN", roff_EN, NULL, NULL, 0, NULL }, { ".", roff_cblock, NULL, NULL, 0, NULL }, - { "\\}", roff_ccond, NULL, NULL, 0, NULL }, { NULL, roff_userdef, NULL, NULL, 0, NULL }, }; @@ -788,14 +788,10 @@ roff_parse(struct roff *r, const char *buf, int *pos) '\t' == buf[*pos] || ' ' == buf[*pos]) return(ROFF_MAX); - /* - * We stop the macro parse at an escape, tab, space, or nil. - * However, `\}' is also a valid macro, so make sure we don't - * clobber it by seeing the `\' as the end of token. - */ + /* We stop the macro parse at an escape, tab, space, or nil. */ mac = buf + *pos; - maclen = strcspn(mac + 1, " \\\t\0") + 1; + maclen = strcspn(mac, " \\\t\0"); t = (r->current_string = roff_getstrn(r, mac, maclen)) ? ROFF_USERDEF : roffhash_find(mac, maclen); @@ -864,14 +860,13 @@ roffnode_cleanscope(struct roff *r) } -/* ARGSUSED */ -static enum rofferr -roff_ccond(ROFF_ARGS) +static void +roff_ccond(struct roff *r, int ln, int ppos) { if (NULL == r->last) { mandoc_msg(MANDOCERR_NOSCOPE, r->parse, ln, ppos, NULL); - return(ROFF_IGN); + return; } switch (r->last->tok) { @@ -883,20 +878,17 @@ roff_ccond(ROFF_ARGS) break; default: mandoc_msg(MANDOCERR_NOSCOPE, r->parse, ln, ppos, NULL); - return(ROFF_IGN); + return; } if (r->last->endspan > -1) { mandoc_msg(MANDOCERR_NOSCOPE, r->parse, ln, ppos, NULL); - return(ROFF_IGN); + return; } - if ((*bufp)[pos]) - mandoc_msg(MANDOCERR_ARGSLOST, r->parse, ln, pos, NULL); - roffnode_pop(r); roffnode_cleanscope(r); - return(ROFF_IGN); + return; } @@ -1071,35 +1063,29 @@ roff_cond_sub(ROFF_ARGS) */ if ((ROFF_MAX != t) && - (ROFF_ccond == t || ROFFRULE_ALLOW == rr || + (ROFFRULE_ALLOW == rr || ROFFMAC_STRUCT & roffs[t].flags)) { assert(roffs[t].proc); return((*roffs[t].proc)(r, t, bufp, szp, ln, ppos, pos, offs)); } + /* + * If `\}' occurs on a macro line without a preceding macro, + * drop the line completely. + */ + + ep = *bufp + pos; + if ('\\' == ep[0] && '}' == ep[1]) + rr = ROFFRULE_DENY; + /* Always check for the closing delimiter `\}'. */ - ep = &(*bufp)[pos]; while (NULL != (ep = strchr(ep, '\\'))) { if ('}' != *(++ep)) continue; - - /* - * If we're at the end of line, then just chop - * off the \} and resize the buffer. - * If we aren't, then convert it to spaces. - */ - - if ('\0' == *(ep + 1)) { - *--ep = '\0'; - *szp -= 2; - } else - *(ep - 1) = *ep = ' '; - - roff_ccond(r, ROFF_ccond, bufp, szp, - ln, pos, pos + 2, offs); - break; + *ep = '&'; + roff_ccond(r, ln, pos); } return(ROFFRULE_DENY == rr ? ROFF_IGN : ROFF_CONT); } @@ -1120,8 +1106,7 @@ roff_cond_text(ROFF_ARGS) if ('}' != *ep) continue; *ep = '&'; - roff_ccond(r, ROFF_ccond, bufp, szp, - ln, pos, pos + 2, offs); + roff_ccond(r, ln, pos); } return(ROFFRULE_DENY == rr ? ROFF_IGN : ROFF_CONT); }