From 5fbabdf032b370e99e8685958b6e15eb3b2ff0f7 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Thu, 4 May 2017 17:48:28 +0000 Subject: Parser reorg: Generate the first node on the roff level: .br Fix some column numbers in diagnostic messages while here. --- roff.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'roff.c') diff --git a/roff.c b/roff.c index 9476cb93..fb4e4830 100644 --- a/roff.c +++ b/roff.c @@ -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_tok, 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); @@ -209,6 +210,7 @@ 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", NULL, "ab", "ad", "af", "aln", "als", "am", "am1", "ami", "ami1", "as", "as1", "asciify", @@ -298,14 +300,14 @@ const char *__roff_name[MAN_MAX + 1] = { "Fr", "Ud", "Lb", "Lp", "Lk", "Mt", "Brq", "Bro", "Brc", "%C", "Es", "En", - "Dx", "%Q", "br", "sp", + "Dx", "%Q", "sp", "%U", "Ta", "ll", 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", + "sp", "nf", "fi", "RE", "RS", "DT", "UC", "PD", "AT", "in", "ft", "OP", "EX", "EE", "UR", @@ -314,6 +316,8 @@ const char *__roff_name[MAN_MAX + 1] = { const char *const *roff_name = __roff_name; static struct roffmac roffs[TOKEN_NONE] = { + { roff_br, NULL, NULL, 0 }, /* br */ + { 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 +341,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 */ @@ -610,6 +614,8 @@ roffhash_alloc(enum roff_tok mintok, enum roff_tok maxtok) 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 +830,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 +1480,7 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs) /* 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 +2640,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 +2767,15 @@ roff_TS(ROFF_ARGS) } static enum rofferr -roff_brp(ROFF_ARGS) +roff_br(ROFF_ARGS) { - - buf->buf[pos - 1] = '\0'; - return ROFF_CONT; + 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 -- cgit