=================================================================== RCS file: /cvs/mandoc/roff.c,v retrieving revision 1.251 retrieving revision 1.258 diff -u -p -r1.251 -r1.258 --- mandoc/roff.c 2015/01/20 21:16:51 1.251 +++ mandoc/roff.c 2015/01/28 17:32:07 1.258 @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.251 2015/01/20 21:16:51 schwarze Exp $ */ +/* $Id: roff.c,v 1.258 2015/01/28 17:32:07 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012, 2014 Kristaps Dzonsons * Copyright (c) 2010-2015 Ingo Schwarze @@ -179,7 +179,7 @@ enum rofft { ROFF_minss, ROFF_mk, ROFF_mso, - /* MAN_na; ignored in mdoc(7) */ + ROFF_na, ROFF_ne, /* MAN_nf; ignored in mdoc(7) */ ROFF_nh, @@ -580,6 +580,7 @@ static struct roffmac roffs[ROFF_MAX] = { { "minss", roff_line_ignore, NULL, NULL, 0, NULL }, { "mk", roff_line_ignore, NULL, NULL, 0, NULL }, { "mso", roff_insec, NULL, NULL, 0, NULL }, + { "na", roff_line_ignore, NULL, NULL, 0, NULL }, { "ne", roff_line_ignore, NULL, NULL, 0, NULL }, { "nh", roff_line_ignore, NULL, NULL, 0, NULL }, { "nhychar", roff_line_ignore, NULL, NULL, 0, NULL }, @@ -608,7 +609,7 @@ static struct roffmac roffs[ROFF_MAX] = { { "po", roff_line_ignore, NULL, NULL, 0, NULL }, { "ps", roff_line_ignore, NULL, NULL, 0, NULL }, { "psbb", roff_unsupp, NULL, NULL, 0, NULL }, - { "pshape", roff_line_ignore, NULL, NULL, 0, NULL }, + { "pshape", roff_unsupp, NULL, NULL, 0, NULL }, { "pso", roff_insec, NULL, NULL, 0, NULL }, { "ptr", roff_line_ignore, NULL, NULL, 0, NULL }, { "pvs", roff_line_ignore, NULL, NULL, 0, NULL }, @@ -640,11 +641,11 @@ static struct roffmac roffs[ROFF_MAX] = { { "sv", roff_line_ignore, NULL, NULL, 0, NULL }, { "sy", roff_insec, NULL, NULL, 0, NULL }, { "T&", roff_T_, NULL, NULL, 0, NULL }, - { "ta", roff_line_ignore, NULL, NULL, 0, NULL }, + { "ta", roff_unsupp, NULL, NULL, 0, NULL }, { "tc", roff_unsupp, NULL, NULL, 0, NULL }, { "TE", roff_TE, NULL, NULL, 0, NULL }, { "TH", roff_TH, NULL, NULL, 0, NULL }, - { "ti", roff_line_ignore, NULL, NULL, 0, NULL }, + { "ti", roff_unsupp, NULL, NULL, 0, NULL }, { "tkf", roff_line_ignore, NULL, NULL, 0, NULL }, { "tl", roff_unsupp, NULL, NULL, 0, NULL }, { "tm", roff_line_ignore, NULL, NULL, 0, NULL }, @@ -1004,8 +1005,9 @@ roff_res(struct roff *r, struct buf *buf, int ln, int /* Advance to the end of the name. */ + naml = 0; arg_complete = 1; - for (naml = 0; maxl == 0 || naml < maxl; naml++, cp++) { + while (maxl == 0 || naml < maxl) { if (*cp == '\0') { mandoc_msg(MANDOCERR_ESC_BAD, r->parse, ln, (int)(stesc - buf->buf), stesc); @@ -1016,6 +1018,23 @@ roff_res(struct roff *r, struct buf *buf, int ln, int cp++; break; } + if (*cp++ != '\\' || stesc[1] != 'w') { + naml++; + continue; + } + switch (mandoc_escape(&cp, NULL, NULL)) { + case ESCAPE_SPECIAL: + /* FALLTHROUGH */ + case ESCAPE_UNICODE: + /* FALLTHROUGH */ + case ESCAPE_NUMBERED: + /* FALLTHROUGH */ + case ESCAPE_OVERSTRIKE: + naml++; + break; + default: + break; + } } /* @@ -1166,13 +1185,13 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, /* * First, if a scope is open and we're not a macro, pass the - * text through the macro's filter. If a scope isn't open and - * we're not a macro, just let it through. - * Finally, if there's an equation scope open, divert it into it - * no matter our state. + * text through the macro's filter. + * Equations process all content themselves. + * Tables process almost all content themselves, but we want + * to warn about macros before passing it there. */ - if (r->last && ! ctl) { + if (r->last != NULL && ! ctl) { t = r->last->tok; assert(roffs[t].text); e = (*roffs[t].text)(r, t, buf, ln, pos, pos, offs); @@ -1180,13 +1199,12 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, if (e != ROFF_CONT) return(e); } - if (r->eqn) + if (r->eqn != NULL) return(eqn_read(&r->eqn, ln, buf->buf, ppos, offs)); - if ( ! ctl) { - if (r->tbl) - return(tbl_read(r->tbl, ln, buf->buf, pos)); + if (r->tbl != NULL && ( ! ctl || buf->buf[pos] == '\0')) + return(tbl_read(r->tbl, ln, buf->buf, pos)); + if ( ! ctl) return(roff_parsetext(buf, pos, offs)); - } /* Skip empty request lines. */ @@ -1219,7 +1237,13 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, if (r->tbl != NULL && (t == ROFF_MAX || t == ROFF_TS)) { mandoc_msg(MANDOCERR_TBLMACRO, r->parse, ln, pos, buf->buf + spos); - return(ROFF_IGN); + if (t == ROFF_TS) + return(ROFF_IGN); + while (buf->buf[pos] != '\0' && buf->buf[pos] != ' ') + pos++; + while (buf->buf[pos] != '\0' && buf->buf[pos] == ' ') + pos++; + return(tbl_read(r->tbl, ln, buf->buf, pos)); } /* @@ -1624,8 +1648,46 @@ roff_getnum(const char *v, int *pos, int *res) if (n) *res = -*res; - *pos = p; - return 1; + /* Each number may be followed by one optional scaling unit. */ + + switch (v[p]) { + case 'f': + *res *= 65536; + break; + case 'i': + *res *= 240; + break; + case 'c': + *res *= 240; + *res /= 2.54; + break; + case 'v': + /* FALLTROUGH */ + case 'P': + *res *= 40; + break; + case 'm': + /* FALLTROUGH */ + case 'n': + *res *= 24; + break; + case 'p': + *res *= 10; + *res /= 3; + break; + case 'u': + break; + case 'M': + *res *= 6; + *res /= 25; + break; + default: + p--; + break; + } + + *pos = p + 1; + return(1); } /* @@ -2314,9 +2376,12 @@ roff_TE(ROFF_ARGS) if (NULL == r->tbl) mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse, ln, ppos, "TE"); - else - tbl_end(&r->tbl); - + else if ( ! tbl_end(&r->tbl)) { + free(buf->buf); + buf->buf = mandoc_strdup(".sp"); + buf->sz = 4; + return(ROFF_REPARSE); + } return(ROFF_IGN); }