From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id 97d19dde for ; Sat, 8 Jul 2017 12:53:20 -0500 (EST) Date: Sat, 8 Jul 2017 12:53:20 -0500 (EST) Message-Id: <12877179027201893827.enqueue@fantadrom.bsd.lv> X-Mailinglist: mandoc-source Reply-To: source@mandoc.bsd.lv MIME-Version: 1.0 From: schwarze@mandoc.bsd.lv To: source@mandoc.bsd.lv Subject: mandoc: Simplify by creating struct roff_node syntax tree nodes for X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Simplify by creating struct roff_node syntax tree nodes for tbl(7) right from roff_parseln() rather than delegating to read.c, similar to what i just did for eqn(7). The interface function roff_span() becomes obsolete and is deleted, the former interface function roff_addtbl() becomes static, the interface functions tbl_read() and tbl_cdata() become void, and minus twelve linus of code. No functional change. Modified Files: -------------- mandoc: libmandoc.h libroff.h mandoc_headers.3 read.c roff.c roff_int.h tbl.c tbl_data.c Revision Data ------------- Index: mandoc_headers.3 =================================================================== RCS file: /home/cvs/mandoc/mandoc/mandoc_headers.3,v retrieving revision 1.17 retrieving revision 1.18 diff -Lmandoc_headers.3 -Lmandoc_headers.3 -u -p -r1.17 -r1.18 --- mandoc_headers.3 +++ mandoc_headers.3 @@ -264,15 +264,11 @@ and from .Pa roff.c for function prototypes. -Uses the types -.Vt struct tbl_span -from -.Pa mandoc.h -and +Uses the type .Vt struct roff_man from .Pa roff.h -as opaque types for function prototypes. +as an opaque type for function prototypes. .It Qq Pa roff_int.h Requires .Qq Pa roff.h @@ -289,14 +285,11 @@ because the latter two are needed by .Qq Pa roff.c . .Pp Uses the types -.Vt struct tbl_span -from -.Pa mandoc.h , .Vt struct roff_man and .Vt struct roff_node from -.Pa roff.h , +.Pa roff.h and .Vt struct mdoc_arg from @@ -368,16 +361,13 @@ or Requires .In sys/types.h for -.Vt size_t , +.Vt size_t +and .Qq Pa mandoc.h for .Vt struct tbl_* and -.Vt struct eqn_box , -and -.Qq Pa libmandoc.h -for -.Vt enum rofferr . +.Vt struct eqn_box . .Pp Provides .Vt enum tbl_part , Index: read.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/read.c,v retrieving revision 1.190 retrieving revision 1.191 diff -Lread.c -Lread.c -u -p -r1.190 -r1.191 --- read.c +++ read.c @@ -42,7 +42,6 @@ #include "mdoc.h" #include "man.h" #include "libmandoc.h" -#include "roff_int.h" #define REPARSE_LIMIT 1000 @@ -343,7 +342,6 @@ choose_parser(struct mparse *curp) static int mparse_buf_r(struct mparse *curp, struct buf blk, size_t i, int start) { - const struct tbl_span *span; struct buf ln; const char *save_file; char *cp; @@ -534,18 +532,7 @@ rerun: if (curp->man->macroset == MACROSET_NONE) choose_parser(curp); - /* - * Lastly, push down into the parsers themselves. - * If libroff returns ROFF_TBL, then add it to the - * currently open parse. Since we only get here if - * there does exist data (see tbl_data.c), we're - * guaranteed that something's been allocated. - */ - - if (rr == ROFF_TBL) - while ((span = roff_span(curp->roff)) != NULL) - roff_addtbl(curp->man, span); - else if ((curp->man->macroset == MACROSET_MDOC ? + if ((curp->man->macroset == MACROSET_MDOC ? mdoc_parseln(curp->man, curp->line, ln.buf, of) : man_parseln(curp->man, curp->line, ln.buf, of)) == 2) break; Index: libmandoc.h =================================================================== RCS file: /home/cvs/mandoc/mandoc/libmandoc.h,v retrieving revision 1.69 retrieving revision 1.70 diff -Llibmandoc.h -Llibmandoc.h -u -p -r1.69 -r1.70 --- libmandoc.h +++ libmandoc.h @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons - * Copyright (c) 2013, 2014, 2015 Ingo Schwarze + * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -23,7 +23,6 @@ enum rofferr { ROFF_REPARSE, /* re-run main parser on the result */ ROFF_SO, /* include another file */ ROFF_IGN, /* ignore current line */ - ROFF_TBL, /* a table row was successfully parsed */ }; struct buf { @@ -33,7 +32,6 @@ struct buf { struct mparse; -struct tbl_span; struct roff; struct roff_man; @@ -73,5 +71,3 @@ char *roff_strdup(const struct roff *, int roff_getcontrol(const struct roff *, const char *, int *); int roff_getformat(const struct roff *); - -const struct tbl_span *roff_span(const struct roff *); Index: libroff.h =================================================================== RCS file: /home/cvs/mandoc/mandoc/libroff.h,v retrieving revision 1.41 retrieving revision 1.42 diff -Llibroff.h -Llibroff.h -u -p -r1.41 -r1.42 --- libroff.h +++ libroff.h @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2014, 2015 Ingo Schwarze + * Copyright (c) 2014, 2015, 2017 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -65,13 +65,13 @@ struct tbl_node *tbl_alloc(int, int, str void tbl_restart(int, int, struct tbl_node *); void tbl_free(struct tbl_node *); void tbl_reset(struct tbl_node *); -enum rofferr tbl_read(struct tbl_node *, int, const char *, int); +void tbl_read(struct tbl_node *, int, const char *, int); void tbl_option(struct tbl_node *, int, const char *, int *); void tbl_layout(struct tbl_node *, int, const char *, int); void tbl_data(struct tbl_node *, int, const char *, int); -int tbl_cdata(struct tbl_node *, int, const char *, int); +void tbl_cdata(struct tbl_node *, int, const char *, int); const struct tbl_span *tbl_span(struct tbl_node *); -int tbl_end(struct tbl_node **); +int tbl_end(struct tbl_node *); struct eqn_node *eqn_alloc(struct mparse *); void eqn_box_free(struct eqn_box *); void eqn_free(struct eqn_node *); Index: roff.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/roff.c,v retrieving revision 1.320 retrieving revision 1.321 diff -Lroff.c -Lroff.c -u -p -r1.320 -r1.321 --- roff.c +++ roff.c @@ -153,6 +153,7 @@ static void roffnode_cleanscope(struct static void roffnode_pop(struct roff *); static void roffnode_push(struct roff *, enum roff_tok, const char *, int, int); +static void roff_addtbl(struct roff_man *, struct tbl_node *); static enum rofferr roff_als(ROFF_ARGS); static enum rofferr roff_block(ROFF_ARGS); static enum rofferr roff_block_text(ROFF_ARGS); @@ -979,18 +980,21 @@ roff_body_alloc(struct roff_man *man, in return n; } -void -roff_addtbl(struct roff_man *man, const struct tbl_span *tbl) +static void +roff_addtbl(struct roff_man *man, struct tbl_node *tbl) { struct roff_node *n; + const struct tbl_span *span; if (man->macroset == MACROSET_MAN) man_breakscope(man, ROFF_TS); - n = roff_node_alloc(man, tbl->line, 0, ROFFT_TBL, TOKEN_NONE); - n->span = tbl; - roff_node_append(man, n); - n->flags |= NODE_VALID | NODE_ENDED; - man->next = ROFF_NEXT_SIBLING; + while ((span = tbl_span(tbl)) != NULL) { + n = roff_node_alloc(man, tbl->line, 0, ROFFT_TBL, TOKEN_NONE); + n->span = span; + roff_node_append(man, n); + n->flags |= NODE_VALID | NODE_ENDED; + man->next = ROFF_NEXT_SIBLING; + } } void @@ -1501,8 +1505,11 @@ roff_parseln(struct roff *r, int ln, str eqn_read(r->eqn, buf->buf + ppos); return ROFF_IGN; } - if (r->tbl != NULL && ( ! ctl || buf->buf[pos] == '\0')) - return tbl_read(r->tbl, ln, buf->buf, ppos); + if (r->tbl != NULL && (ctl == 0 || buf->buf[pos] == '\0')) { + tbl_read(r->tbl, ln, buf->buf, ppos); + roff_addtbl(r->man, r->tbl); + return ROFF_IGN; + } if ( ! ctl) return roff_parsetext(r, buf, pos, offs); @@ -1543,7 +1550,9 @@ roff_parseln(struct roff *r, int ln, str pos++; while (buf->buf[pos] == ' ') pos++; - return tbl_read(r->tbl, ln, buf->buf, pos); + tbl_read(r->tbl, ln, buf->buf, pos); + roff_addtbl(r->man, r->tbl); + return ROFF_IGN; } /* For now, let high level macros abort .ce mode. */ @@ -1572,23 +1581,23 @@ roff_parseln(struct roff *r, int ln, str void roff_endparse(struct roff *r) { - - if (r->last) + if (r->last != NULL) mandoc_msg(MANDOCERR_BLK_NOEND, r->parse, r->last->line, r->last->col, roff_name[r->last->tok]); - if (r->eqn) { + if (r->eqn != NULL) { mandoc_msg(MANDOCERR_BLK_NOEND, r->parse, r->eqn->node->line, r->eqn->node->pos, "EQ"); eqn_parse(r->eqn); r->eqn = NULL; } - if (r->tbl) { + if (r->tbl != NULL) { mandoc_msg(MANDOCERR_BLK_NOEND, r->parse, r->tbl->line, r->tbl->pos, "TS"); - tbl_end(&r->tbl); + tbl_end(r->tbl); + r->tbl = NULL; } } @@ -2770,16 +2779,19 @@ roff_Dd(ROFF_ARGS) static enum rofferr roff_TE(ROFF_ARGS) { - - if (NULL == r->tbl) + if (r->tbl == NULL) { mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse, ln, ppos, "TE"); - else if ( ! tbl_end(&r->tbl)) { + return ROFF_IGN; + } + if (tbl_end(r->tbl) == 0) { + r->tbl = NULL; free(buf->buf); buf->buf = mandoc_strdup(".sp"); buf->sz = 4; return ROFF_REPARSE; } + r->tbl = NULL; return ROFF_IGN; } @@ -2907,22 +2919,17 @@ roff_EN(ROFF_ARGS) static enum rofferr roff_TS(ROFF_ARGS) { - struct tbl_node *tbl; - - if (r->tbl) { + if (r->tbl != NULL) { mandoc_msg(MANDOCERR_BLK_BROKEN, r->parse, ln, ppos, "TS breaks TS"); - tbl_end(&r->tbl); + tbl_end(r->tbl); } - - tbl = tbl_alloc(ppos, ln, r->parse); - + r->tbl = tbl_alloc(ppos, ln, r->parse); if (r->last_tbl) - r->last_tbl->next = tbl; + r->last_tbl->next = r->tbl; else - r->first_tbl = r->last_tbl = tbl; - - r->tbl = r->last_tbl = tbl; + r->first_tbl = r->tbl; + r->last_tbl = r->tbl; return ROFF_IGN; } @@ -3600,13 +3607,6 @@ roff_freestr(struct roffkv *r) } /* --- accessors and utility functions ------------------------------------ */ - -const struct tbl_span * -roff_span(const struct roff *r) -{ - - return r->tbl ? tbl_span(r->tbl) : NULL; -} /* * Duplicate an input string, making the appropriate character Index: tbl_data.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/tbl_data.c,v retrieving revision 1.44 retrieving revision 1.45 diff -Ltbl_data.c -Ltbl_data.c -u -p -r1.44 -r1.45 --- tbl_data.c +++ tbl_data.c @@ -128,7 +128,7 @@ getdata(struct tbl_node *tbl, struct tbl tbl->parse, ln, sv, dat->string); } -int +void tbl_cdata(struct tbl_node *tbl, int ln, const char *p, int pos) { struct tbl_dat *dat; @@ -143,10 +143,10 @@ tbl_cdata(struct tbl_node *tbl, int ln, pos++; while (p[pos] != '\0') getdata(tbl, tbl->last_span, ln, p, &pos); - return 1; + return; } else if (p[pos] == '\0') { tbl->part = TBL_PART_DATA; - return 1; + return; } /* Fallthrough: T} is part of a word. */ @@ -166,8 +166,6 @@ tbl_cdata(struct tbl_node *tbl, int ln, if (dat->layout->pos == TBL_CELL_DOWN) mandoc_msg(MANDOCERR_TBLDATA_SPAN, tbl->parse, ln, pos, dat->string); - - return 0; } static struct tbl_span * Index: tbl.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/tbl.c,v retrieving revision 1.41 retrieving revision 1.42 diff -Ltbl.c -Ltbl.c -u -p -r1.41 -r1.42 --- tbl.c +++ tbl.c @@ -31,7 +31,7 @@ #include "libroff.h" -enum rofferr +void tbl_read(struct tbl_node *tbl, int ln, const char *p, int pos) { const char *cp; @@ -66,7 +66,7 @@ tbl_read(struct tbl_node *tbl, int ln, c if (*cp == ';') { tbl_option(tbl, ln, p, &pos); if (p[pos] == '\0') - return ROFF_IGN; + return; } } @@ -75,15 +75,14 @@ tbl_read(struct tbl_node *tbl, int ln, c switch (tbl->part) { case TBL_PART_LAYOUT: tbl_layout(tbl, ln, p, pos); - return ROFF_IGN; + break; case TBL_PART_CDATA: - return tbl_cdata(tbl, ln, p, pos) ? ROFF_TBL : ROFF_IGN; + tbl_cdata(tbl, ln, p, pos); + break; default: + tbl_data(tbl, ln, p, pos); break; } - - tbl_data(tbl, ln, p, pos); - return ROFF_TBL; } struct tbl_node * @@ -160,13 +159,9 @@ tbl_span(struct tbl_node *tbl) } int -tbl_end(struct tbl_node **tblp) +tbl_end(struct tbl_node *tbl) { - struct tbl_node *tbl; struct tbl_span *sp; - - tbl = *tblp; - *tblp = NULL; if (tbl->part == TBL_PART_CDATA) mandoc_msg(MANDOCERR_TBLDATA_BLK, tbl->parse, Index: roff_int.h =================================================================== RCS file: /home/cvs/mandoc/mandoc/roff_int.h,v retrieving revision 1.8 retrieving revision 1.9 diff -Lroff_int.h -Lroff_int.h -u -p -r1.8 -r1.9 --- roff_int.h +++ roff_int.h @@ -25,7 +25,6 @@ void roff_elem_alloc(struct roff_man struct roff_node *roff_block_alloc(struct roff_man *, int, int, int); struct roff_node *roff_head_alloc(struct roff_man *, int, int, int); struct roff_node *roff_body_alloc(struct roff_man *, int, int, int); -void roff_addtbl(struct roff_man *, const struct tbl_span *); void roff_node_unlink(struct roff_man *, struct roff_node *); void roff_node_free(struct roff_node *); void roff_node_delete(struct roff_man *, struct roff_node *); -- To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv