tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
* [PATCH] multiple tbl improvements
@ 2011-01-24 22:43 Ingo Schwarze
  2011-01-24 23:08 ` Kristaps Dzonsons
  0 siblings, 1 reply; 2+ messages in thread
From: Ingo Schwarze @ 2011-01-24 22:43 UTC (permalink / raw)
  To: tech

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] multiple tbl improvements
  2011-01-24 22:43 [PATCH] multiple tbl improvements Ingo Schwarze
@ 2011-01-24 23:08 ` Kristaps Dzonsons
  0 siblings, 0 replies; 2+ messages in thread
From: Kristaps Dzonsons @ 2011-01-24 23:08 UTC (permalink / raw)
  To: tech; +Cc: Ingo Schwarze

> 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?

Ingo,

This is all pretty easy to understand, so I've no problem with it.

>   * 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.

Out of curiosity---where do you see this last one being an issue?  It 
makes perfect sense.

>
>   * man_term.c:
>     avoid double blank line before a table

(man_html.c...?)

>
> OK?

Ok kristaps.

> 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.

I've a bit of time too, so feel free to bounce patches off of me.  I'm 
only aware of the bullet patch causing problems, and those are "hard" 
problems in terms of -Tps segfaulting.

The festival looks like fun, though...

Thanks!

Kristaps
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-01-24 23:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-24 22:43 [PATCH] multiple tbl improvements Ingo Schwarze
2011-01-24 23:08 ` Kristaps Dzonsons

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).