source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: mandoc: Implement spacing of columns as defined in the table layout;
Date: Tue, 27 Jun 2017 13:25:32 -0500 (EST)	[thread overview]
Message-ID: <4616196900460725921.enqueue@fantadrom.bsd.lv> (raw)

Log Message:
-----------
Implement spacing of columns as defined in the table layout;
this is for example used by lftp(1) 
and, ironically, misused by our very own tbl(7) manual...

Modified Files:
--------------
    mandoc:
        out.c
        out.h
        tbl_layout.c
        tbl_term.c

Revision Data
-------------
Index: out.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/out.c,v
retrieving revision 1.69
retrieving revision 1.70
diff -Lout.c -Lout.c -u -p -r1.69 -r1.70
--- out.c
+++ out.c
@@ -20,6 +20,7 @@
 #include <sys/types.h>
 
 #include <assert.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
@@ -140,8 +141,8 @@ tblcalc(struct rofftbl *tbl, const struc
 			if (1 < spans)
 				continue;
 			icol = dp->layout->col;
-			if (maxcol < icol)
-				maxcol = icol;
+			while (maxcol < icol)
+				tbl->cols[++maxcol].spacing = SIZE_MAX;
 			col = tbl->cols + icol;
 			col->flags |= dp->layout->flags;
 			if (dp->layout->flags & TBL_CELL_WIGN)
@@ -154,6 +155,10 @@ tblcalc(struct rofftbl *tbl, const struc
 				    (*tbl->sulen)(&su, tbl->arg);
 			if (col->width < dp->layout->width)
 				col->width = dp->layout->width;
+			if (dp->layout->spacing != SIZE_MAX &&
+			    (col->spacing == SIZE_MAX ||
+			     col->spacing < dp->layout->spacing))
+				col->spacing = dp->layout->spacing;
 			tblcalc_data(tbl, col, opts, dp,
 			    dp->block == 0 ? 0 :
 			    dp->layout->width ? dp->layout->width :
@@ -172,6 +177,8 @@ tblcalc(struct rofftbl *tbl, const struc
 	ewidth = xwidth = 0;
 	for (icol = 0; icol <= maxcol; icol++) {
 		col = tbl->cols + icol;
+		if (col->spacing == SIZE_MAX || icol == maxcol)
+			col->spacing = 3;
 		if (col->flags & TBL_CELL_EQUAL) {
 			necol++;
 			if (ewidth < col->width)
Index: out.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/out.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -Lout.h -Lout.h -u -p -r1.30 -r1.31
--- out.h
+++ out.h
@@ -33,6 +33,7 @@ enum	roffscale {
 struct	roffcol {
 	size_t		 width; /* width of cell */
 	size_t		 decimal; /* decimal position in cell */
+	size_t		 spacing; /* spacing after the column */
 	int		 flags; /* layout flags, see tbl_cell */
 };
 
Index: tbl_term.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/tbl_term.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -Ltbl_term.c -Ltbl_term.c -u -p -r1.54 -r1.55
--- tbl_term.c
+++ tbl_term.c
@@ -101,7 +101,7 @@ term_tbl(struct termp *tp, const struct 
 		for (ic = 0; ic < sp->opts->cols; ic++) {
 			coloff += tp->tbl.cols[ic].width;
 			term_tab_iset(coloff);
-			coloff += 3;
+			coloff += tp->tbl.cols[ic].spacing;
 		}
 
 		/* Center the table as a whole. */
@@ -110,9 +110,11 @@ term_tbl(struct termp *tp, const struct 
 		if (sp->opts->opts & TBL_OPT_CENTRE) {
 			tsz = sp->opts->opts & (TBL_OPT_BOX | TBL_OPT_DBOX)
 			    ? 2 : !!sp->opts->lvert + !!sp->opts->rvert;
-			for (ic = 0; ic < sp->opts->cols; ic++)
-				tsz += tp->tbl.cols[ic].width + 3;
-			tsz -= 3;
+			for (ic = 0; ic + 1 < sp->opts->cols; ic++)
+				tsz += tp->tbl.cols[ic].width +
+				    tp->tbl.cols[ic].spacing;
+			if (sp->opts->cols)
+				tsz += tp->tbl.cols[sp->opts->cols - 1].width;
 			if (offset + tsz > tp->tcol->rmargin)
 				tsz -= 1;
 			tp->tcol->offset = offset + tp->tcol->rmargin > tsz ?
@@ -159,9 +161,8 @@ term_tbl(struct termp *tp, const struct 
 			}
 			coloff += tp->tbl.cols[ic].width;
 			tp->tcol->rmargin = coloff;
-			coloff++;
 			if (ic + 1 < sp->opts->cols)
-				coloff += 2;
+				coloff += tp->tbl.cols[ic].spacing;
 			if (spans) {
 				spans--;
 				continue;
@@ -175,7 +176,7 @@ term_tbl(struct termp *tp, const struct 
 		/* Set up a column for a right vertical frame. */
 
 		tp->tcol++;
-		tp->tcol->offset = coloff;
+		tp->tcol->offset = coloff + 1;
 		tp->tcol->rmargin = tp->maxrmargin;
 
 		/* Spans may have reduced the number of columns. */
@@ -327,13 +328,13 @@ term_tbl(struct termp *tp, const struct 
 				    tp->tcol + 1 == tp->tcols + tp->lasttcol))
 					continue;
 
-				if (tp->tcol->rmargin > tp->viscol) {
+				if (tp->viscol < tp->tcol->rmargin) {
 					(*tp->advance)(tp, tp->tcol->rmargin
 					   - tp->viscol);
 					tp->viscol = tp->tcol->rmargin;
 				}
-
-				if (tp->tcol->rmargin + 1 > tp->viscol) {
+				while (tp->viscol < tp->tcol->rmargin +
+				    tp->tbl.cols[ic].spacing / 2) {
 					(*tp->letter)(tp, fc);
 					tp->viscol++;
 				}
@@ -353,10 +354,11 @@ term_tbl(struct termp *tp, const struct 
 						break;
 					}
 				}
-
-				(*tp->letter)(tp,
-				    fc == ' ' ? '|' : vert ? '+' : fc);
-				tp->viscol++;
+				if (tp->tbl.cols[ic].spacing) {
+					(*tp->letter)(tp, fc == ' ' ? '|' :
+					    vert ? '+' : fc);
+					tp->viscol++;
+				}
 
 				if (fc != ' ') {
 					if (cp != NULL &&
@@ -368,7 +370,8 @@ term_tbl(struct termp *tp, const struct 
 					else
 						fc = ' ';
 				}
-				if (vert > 1 || fc != ' ') {
+				if (tp->tbl.cols[ic].spacing > 2 &&
+				    (vert > 1 || fc != ' ')) {
 					(*tp->letter)(tp, fc == ' ' ? '|' :
 					    vert > 1 ? '+' : fc);
 					tp->viscol++;
@@ -448,6 +451,7 @@ static void
 tbl_hrule(struct termp *tp, const struct tbl_span *sp, int kind)
 {
 	const struct tbl_cell *cp, *cpn, *cpp;
+	const struct roffcol *col;
 	int	 vert;
 	char	 line, cross;
 
@@ -464,7 +468,8 @@ tbl_hrule(struct termp *tp, const struct
 	if (cpn == cp)
 		cpn = NULL;
 	for (;;) {
-		tbl_char(tp, line, tp->tbl.cols[cp->col].width + 1);
+		col = tp->tbl.cols + cp->col;
+		tbl_char(tp, line, col->width + col->spacing / 2);
 		vert = cp->vert;
 		if ((cp = cp->next) == NULL)
 			 break;
@@ -480,10 +485,12 @@ tbl_hrule(struct termp *tp, const struct
 		}
 		if (sp->opts->opts & TBL_OPT_ALLBOX && !vert)
 			vert = 1;
-		if (vert)
-			tbl_char(tp, cross, vert);
-		if (vert < 2)
-			tbl_char(tp, line, 2 - vert);
+		if (col->spacing)
+			tbl_char(tp, vert ? cross : line, 1);
+		if (col->spacing > 2)
+			tbl_char(tp, vert > 1 ? cross : line, 1);
+		if (col->spacing > 4)
+			tbl_char(tp, line, (col->spacing - 3) / 2);
 	}
 	if (kind) {
 		term_word(tp, "+");
Index: tbl_layout.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/tbl_layout.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -Ltbl_layout.c -Ltbl_layout.c -u -p -r1.43 -r1.44
--- tbl_layout.c
+++ tbl_layout.c
@@ -20,6 +20,7 @@
 #include <sys/types.h>
 
 #include <ctype.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
@@ -357,6 +358,7 @@ cell_alloc(struct tbl_node *tbl, struct 
 	struct tbl_cell	*p, *pp;
 
 	p = mandoc_calloc(1, sizeof(*p));
+	p->spacing = SIZE_MAX;
 	p->pos = pos;
 
 	if ((pp = rp->last) != NULL) {
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

                 reply	other threads:[~2017-06-27 18:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4616196900460725921.enqueue@fantadrom.bsd.lv \
    --to=schwarze@mandoc.bsd.lv \
    --cc=source@mandoc.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).