From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.rz.uni-karlsruhe.de (Debian-exim@smtp1.rz.uni-karlsruhe.de [129.13.185.217]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id p0OMhsWZ004075 for ; Mon, 24 Jan 2011 17:43:56 -0500 (EST) Received: from hekate.usta.de (asta-nat.asta.uni-karlsruhe.de [172.22.63.82]) by smtp1.rz.uni-karlsruhe.de with esmtp (Exim 4.63 #1) id 1PhV8I-0007N5-Or; Mon, 24 Jan 2011 23:43:53 +0100 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.72) (envelope-from ) id 1PhV8I-0002le-Ll for tech@mdocml.bsd.lv; Mon, 24 Jan 2011 23:43:34 +0100 Received: from iris.usta.de ([172.24.96.5] helo=usta.de) by donnerwolke.usta.de with esmtp (Exim 4.69) (envelope-from ) id 1PhV8I-0005N6-KO for tech@mdocml.bsd.lv; Mon, 24 Jan 2011 23:43:34 +0100 Received: from schwarze by usta.de with local (Exim 4.72) (envelope-from ) id 1PhV8I-0003gX-AD for tech@mdocml.bsd.lv; Mon, 24 Jan 2011 23:43:34 +0100 Date: Mon, 24 Jan 2011 23:43:34 +0100 From: Ingo Schwarze To: tech@mdocml.bsd.lv Subject: [PATCH] multiple tbl improvements Message-ID: <20110124224333.GE16282@iris.usta.de> X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Hi, here is a cumulative patch to fix various issues in tbl. I'm planning to commit that in pieces, but i hate it when people send patchsets and find one large patch much easier to read - or do you feel the other way round? * out.c, tbl_term.c: Correct horizontal data spacing. Correct centered data alignment. Adjust the hrule width to the corrected spacing. * tbl_data.c: Do not skip data after horizontal lines in the layout. This causes one input line to produce two spans. * libroff.h, tbl.c, main.c: Actually use the additional span. * man_term.c: avoid double blank line before a table OK? I'm now going to start committing patches to OpenBSD even without OKs because my tree is getting too cluttered. We can fix the stuff in tree in case problems show up. Of course, i'm not committing those patches that faced opposition. Expect some activity during this week, i'm off my day job for a week, and even though a few other things need to be done (among others, i will once again be helping at http://www.usta.de/unifest , this time running the box office), there will also be some time for mandoc. Yours, Ingo diff --git a/libroff.h b/libroff.h index 17e4f8f..b543855 100644 --- a/libroff.h +++ b/libroff.h @@ -36,6 +36,7 @@ struct tbl_node { struct tbl_row *first_row; struct tbl_row *last_row; struct tbl_span *first_span; + struct tbl_span *current_span; struct tbl_span *last_span; struct tbl_head *first_head; struct tbl_head *last_head; @@ -54,7 +55,7 @@ int tbl_option(struct tbl_node *, int, const char *); int tbl_layout(struct tbl_node *, int, const char *); int tbl_data(struct tbl_node *, int, const char *); int tbl_cdata(struct tbl_node *, int, const char *); -const struct tbl_span *tbl_span(const struct tbl_node *); +const struct tbl_span *tbl_span(struct tbl_node *); void tbl_end(struct tbl_node *); __END_DECLS diff --git a/main.c b/main.c index c3bf1ba..7212a6c 100644 --- a/main.c +++ b/main.c @@ -641,6 +641,7 @@ pdesc(struct curparse *curp) static void parsebuf(struct curparse *curp, struct buf blk, int start) { + const struct tbl_span *span; struct buf ln; enum rofferr rr; int i, of, rc; @@ -823,11 +824,12 @@ rerun: if (ROFF_TBL == rr) { assert(curp->man || curp->mdoc); - if (curp->man) - man_addspan(curp->man, roff_span(curp->roff)); - else - mdoc_addspan(curp->mdoc, roff_span(curp->roff)); - + while (NULL != (span = roff_span(curp->roff))) { + if (curp->man) + man_addspan(curp->man, span); + else + mdoc_addspan(curp->mdoc, span); + } } else if (curp->man || curp->mdoc) { rc = curp->man ? man_parseln(curp->man, diff --git a/man_term.c b/man_term.c index 455d37c..2f62a2b 100644 --- a/man_term.c +++ b/man_term.c @@ -208,6 +208,9 @@ print_bvspace(struct termp *p, const struct man_node *n) { term_newln(p); + if (n->body && n->body->child && MAN_TBL == n->body->child->type) + return; + if (NULL == n->prev) return; diff --git a/out.c b/out.c index ffa0634..c847ae7 100644 --- a/out.c +++ b/out.c @@ -481,7 +481,7 @@ tblcalc_literal(struct rofftbl *tbl, struct roffcol *col, case (TBL_CELL_LONG): /* FALLTHROUGH */ case (TBL_CELL_CENTRE): - bufsz = (*tbl->len)(2, tbl->arg); + bufsz = (*tbl->len)(1, tbl->arg); break; default: bufsz = (*tbl->len)(1, tbl->arg); diff --git a/tbl.c b/tbl.c index 5636936..b7ffaa7 100644 --- a/tbl.c +++ b/tbl.c @@ -136,11 +136,16 @@ tbl_restart(int line, int pos, struct tbl_node *tbl) } const struct tbl_span * -tbl_span(const struct tbl_node *tbl) +tbl_span(struct tbl_node *tbl) { + struct tbl_span *span; assert(tbl); - return(tbl->last_span); + span = tbl->current_span ? tbl->current_span->next + : tbl->first_span; + if (span) + tbl->current_span = span; + return(span); } void diff --git a/tbl_data.c b/tbl_data.c index c9b26b5..2b9b2ca 100644 --- a/tbl_data.c +++ b/tbl_data.c @@ -26,6 +26,8 @@ static int data(struct tbl_node *, struct tbl_span *, int, const char *, int *); +static struct tbl_span *newspan(struct tbl_node *, struct tbl_row *); + static int data(struct tbl_node *tbl, struct tbl_span *dp, @@ -168,6 +170,28 @@ tbl_cdata(struct tbl_node *tbl, int ln, const char *p) return(0); } +static struct tbl_span * +newspan(struct tbl_node *tbl, struct tbl_row *rp) +{ + struct tbl_span *dp; + + dp = mandoc_calloc(1, sizeof(struct tbl_span)); + dp->tbl = &tbl->opts; + dp->layout = rp; + dp->head = tbl->first_head; + + if (tbl->last_span) { + tbl->last_span->next = dp; + tbl->last_span = dp; + } else { + tbl->last_span = tbl->first_span = dp; + tbl->current_span = NULL; + dp->flags |= TBL_SPAN_FIRST; + } + + return(dp); +} + int tbl_data(struct tbl_node *tbl, int ln, const char *p) { @@ -192,9 +216,24 @@ tbl_data(struct tbl_node *tbl, int ln, const char *p) if (tbl->last_span) { assert(tbl->last_span->layout); - if (tbl->last_span->pos == TBL_SPAN_DATA) - rp = tbl->last_span->layout->next; - else + if (tbl->last_span->pos == TBL_SPAN_DATA) { + for (rp = tbl->last_span->layout->next; + rp && rp->first; rp = rp->next) { + switch (rp->first->pos) { + case (TBL_CELL_HORIZ): + dp = newspan(tbl, rp); + dp->pos = TBL_SPAN_HORIZ; + continue; + case (TBL_CELL_DHORIZ): + dp = newspan(tbl, rp); + dp->pos = TBL_SPAN_DHORIZ; + continue; + default: + break; + } + break; + } + } else rp = tbl->last_span->layout; if (NULL == rp) @@ -204,18 +243,7 @@ tbl_data(struct tbl_node *tbl, int ln, const char *p) assert(rp); - dp = mandoc_calloc(1, sizeof(struct tbl_span)); - dp->tbl = &tbl->opts; - dp->layout = rp; - dp->head = tbl->first_head; - - if (tbl->last_span) { - tbl->last_span->next = dp; - tbl->last_span = dp; - } else { - tbl->last_span = tbl->first_span = dp; - dp->flags |= TBL_SPAN_FIRST; - } + dp = newspan(tbl, rp); if ( ! strcmp(p, "_")) { dp->pos = TBL_SPAN_HORIZ; diff --git a/tbl_term.c b/tbl_term.c index 53556e5..0e683bb 100644 --- a/tbl_term.c +++ b/tbl_term.c @@ -193,6 +193,8 @@ tbl_hrule(struct termp *tp, const struct tbl_span *sp) width = tp->tbl.cols[hp->ident].width; switch (hp->pos) { case (TBL_HEAD_DATA): + if (hp->next) + width += 2; tbl_char(tp, c, width); break; case (TBL_HEAD_DVERT): @@ -367,11 +369,11 @@ tbl_literal(struct termp *tp, const struct tbl_dat *dp, padr = col->width - term_strlen(tp, dp->string) - ssz; break; case (TBL_CELL_CENTRE): - padl = col->width - term_strlen(tp, dp->string); - if (padl % 2) - padr++; - padl /= 2; - padr += padl; + padr = col->width - term_strlen(tp, dp->string); + if (3 > padr) + break; + padl = (padr - 1) / 2; + padr -= padl; break; case (TBL_CELL_RIGHT): padl = col->width - term_strlen(tp, dp->string); @@ -383,7 +385,7 @@ tbl_literal(struct termp *tp, const struct tbl_dat *dp, tbl_char(tp, ASCII_NBRSP, padl); term_word(tp, dp->string); - tbl_char(tp, ASCII_NBRSP, padr); + tbl_char(tp, ASCII_NBRSP, padr + 2); } static void -- To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv