=================================================================== RCS file: /cvs/mandoc/roff.c,v retrieving revision 1.295 retrieving revision 1.300 diff -u -p -r1.295 -r1.300 --- mandoc/roff.c 2017/04/29 12:45:42 1.295 +++ mandoc/roff.c 2017/05/07 17:31:45 1.300 @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.295 2017/04/29 12:45:42 schwarze Exp $ */ +/* $Id: roff.c,v 1.300 2017/05/07 17:31:45 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2010-2015, 2017 Ingo Schwarze @@ -77,6 +77,7 @@ struct roffreq { struct roff { struct mparse *parse; /* parse point */ + struct roff_man *man; /* mdoc or man parser */ struct roffnode *last; /* leaf of stack */ int *rstack; /* stack of inverted `ie' values */ struct ohash *reqtab; /* request lookup table */ @@ -146,7 +147,7 @@ static void roffnode_push(struct roff *, enum roff_t static enum rofferr roff_block(ROFF_ARGS); static enum rofferr roff_block_text(ROFF_ARGS); static enum rofferr roff_block_sub(ROFF_ARGS); -static enum rofferr roff_brp(ROFF_ARGS); +static enum rofferr roff_br(ROFF_ARGS); static enum rofferr roff_cblock(ROFF_ARGS); static enum rofferr roff_cc(ROFF_ARGS); static void roff_ccond(struct roff *, int, int); @@ -180,7 +181,9 @@ static enum rofferr roff_it(ROFF_ARGS); static enum rofferr roff_line_ignore(ROFF_ARGS); static void roff_man_alloc1(struct roff_man *); static void roff_man_free1(struct roff_man *); +static enum rofferr roff_manyarg(ROFF_ARGS); static enum rofferr roff_nr(ROFF_ARGS); +static enum rofferr roff_onearg(ROFF_ARGS); static enum roff_tok roff_parse(struct roff *, char *, int *, int, int); static enum rofferr roff_parsetext(struct buf *, int, int *); @@ -209,6 +212,8 @@ static enum rofferr roff_userdef(ROFF_ARGS); #define ROFFNUM_WHITE (1 << 1) /* Skip whitespace in roff_evalnum(). */ const char *__roff_name[MAN_MAX + 1] = { + "br", "ft", "ll", "sp", + "ta", NULL, "ab", "ad", "af", "aln", "als", "am", "am1", "ami", "ami1", "as", "as1", "asciify", @@ -258,7 +263,7 @@ const char *__roff_name[MAN_MAX + 1] = { "shc", "shift", "sizes", "so", "spacewidth", "special", "spreadwarn", "ss", "sty", "substring", "sv", "sy", - "T&", "ta", "tc", "TE", + "T&", "tc", "TE", "TH", "ti", "tkf", "tl", "tm", "tm1", "tmc", "tr", "track", "transchar", "trf", "trimat", @@ -298,22 +303,28 @@ const char *__roff_name[MAN_MAX + 1] = { "Fr", "Ud", "Lb", "Lp", "Lk", "Mt", "Brq", "Bro", "Brc", "%C", "Es", "En", - "Dx", "%Q", "br", "sp", - "%U", "Ta", "ll", NULL, + "Dx", "%Q", "%U", "Ta", + NULL, "TH", "SH", "SS", "TP", "LP", "PP", "P", "IP", "HP", "SM", "SB", "BI", "IB", "BR", "RB", "R", "B", "I", "IR", "RI", - "br", "sp", "nf", "fi", + "nf", "fi", "RE", "RS", "DT", "UC", - "PD", "AT", "in", "ft", + "PD", "AT", "in", "OP", "EX", "EE", "UR", - "UE", "ll", NULL + "UE", NULL }; const char *const *roff_name = __roff_name; static struct roffmac roffs[TOKEN_NONE] = { + { roff_br, NULL, NULL, 0 }, /* br */ + { roff_onearg, NULL, NULL, 0 }, /* ft */ + { roff_onearg, NULL, NULL, 0 }, /* ll */ + { roff_onearg, NULL, NULL, 0 }, /* sp */ + { roff_manyarg, NULL, NULL, 0 }, /* ta */ + { NULL, NULL, NULL, 0 }, /* ROFF_MAX */ { roff_unsupp, NULL, NULL, 0 }, /* ab */ { roff_line_ignore, NULL, NULL, 0 }, /* ad */ { roff_line_ignore, NULL, NULL, 0 }, /* af */ @@ -337,7 +348,7 @@ static struct roffmac roffs[TOKEN_NONE] = { { roff_unsupp, NULL, NULL, 0 }, /* break */ { roff_line_ignore, NULL, NULL, 0 }, /* breakchar */ { roff_line_ignore, NULL, NULL, 0 }, /* brnl */ - { roff_brp, NULL, NULL, 0 }, /* brp */ + { roff_br, NULL, NULL, 0 }, /* brp */ { roff_line_ignore, NULL, NULL, 0 }, /* brpnl */ { roff_unsupp, NULL, NULL, 0 }, /* c2 */ { roff_cc, NULL, NULL, 0 }, /* cc */ @@ -511,7 +522,6 @@ static struct roffmac roffs[TOKEN_NONE] = { { roff_line_ignore, NULL, NULL, 0 }, /* sv */ { roff_insec, NULL, NULL, 0 }, /* sy */ { roff_T_, NULL, NULL, 0 }, /* T& */ - { roff_unsupp, NULL, NULL, 0 }, /* ta */ { roff_unsupp, NULL, NULL, 0 }, /* tc */ { roff_TE, NULL, NULL, 0 }, /* TE */ { roff_TH, NULL, NULL, 0 }, /* TH */ @@ -610,6 +620,8 @@ roffhash_alloc(enum roff_tok mintok, enum roff_tok max mandoc_ohash_init(htab, 8, offsetof(struct roffreq, name)); for (tok = mintok; tok < maxtok; tok++) { + if (roff_name[tok] == NULL) + continue; sz = strlen(roff_name[tok]); req = mandoc_malloc(sizeof(*req) + sz + 1); req->tok = tok; @@ -824,6 +836,7 @@ roff_man_alloc(struct roff *roff, struct mparse *parse man->defos = defos; man->quick = quick; roff_man_alloc1(man); + roff->man = man; return man; } @@ -1473,7 +1486,7 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, /* Execute a roff request or a user defined macro. */ - return (*roffs[t].proc)(r, t, buf, ln, ppos, pos, offs); + return (*roffs[t].proc)(r, t, buf, ln, spos, pos, offs); } void @@ -2633,7 +2646,7 @@ roff_T_(ROFF_ARGS) mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse, ln, ppos, "T&"); else - tbl_restart(ppos, ln, r->tbl); + tbl_restart(ln, ppos, r->tbl); return ROFF_IGN; } @@ -2760,11 +2773,66 @@ roff_TS(ROFF_ARGS) } static enum rofferr -roff_brp(ROFF_ARGS) +roff_onearg(ROFF_ARGS) { + struct roff_node *n; + char *cp; - buf->buf[pos - 1] = '\0'; - return ROFF_CONT; + roff_elem_alloc(r->man, ln, ppos, tok); + n = r->man->last; + + cp = buf->buf + pos; + if (*cp != '\0') { + while (*cp != '\0' && *cp != ' ') + cp++; + while (*cp == ' ') + *cp++ = '\0'; + if (*cp != '\0') + mandoc_vmsg(MANDOCERR_ARG_EXCESS, + r->parse, ln, cp - buf->buf, + "%s ... %s", roff_name[tok], cp); + roff_word_alloc(r->man, ln, pos, buf->buf + pos); + } + + n->flags |= NODE_LINE | NODE_VALID | NODE_ENDED; + r->man->last = n; + r->man->next = ROFF_NEXT_SIBLING; + return ROFF_IGN; +} + +static enum rofferr +roff_manyarg(ROFF_ARGS) +{ + struct roff_node *n; + char *sp, *ep; + + roff_elem_alloc(r->man, ln, ppos, tok); + n = r->man->last; + + for (sp = ep = buf->buf + pos; *sp != '\0'; sp = ep) { + while (*ep != '\0' && *ep != ' ') + ep++; + while (*ep == ' ') + *ep++ = '\0'; + roff_word_alloc(r->man, ln, sp - buf->buf, sp); + } + + n->flags |= NODE_LINE | NODE_VALID | NODE_ENDED; + r->man->last = n; + r->man->next = ROFF_NEXT_SIBLING; + return ROFF_IGN; +} + +static enum rofferr +roff_br(ROFF_ARGS) +{ + roff_elem_alloc(r->man, ln, ppos, ROFF_br); + if (buf->buf[pos] != '\0') + mandoc_vmsg(MANDOCERR_ARG_SKIP, r->parse, ln, pos, + "%s %s", roff_name[tok], buf->buf + pos); + r->man->last->flags |= NODE_LINE | NODE_VALID | NODE_ENDED; + r->man->next = ROFF_NEXT_SIBLING; + return ROFF_IGN; } static enum rofferr