tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Subject: Re: integrate tbl into mandoc
Date: Thu, 14 Oct 2010 23:55:30 +0200	[thread overview]
Message-ID: <20101014215530.GC30282@iris.usta.de> (raw)
In-Reply-To: <20101014211831.GB30282@iris.usta.de>

Hi,

this one corrects alignment by using term_*len() functions.
I guess not all details are 100% correct yet,
but this will get us started with respect to alignment.

It is cumulative to the last patch i sent just before.

Yours,
  Ingo


diff -Naur mandoc-tbl-term/man_term.c mandoc-tbl/man_term.c
--- mandoc-tbl-term/man_term.c	Thu Oct 14 22:49:10 2010
+++ mandoc-tbl/man_term.c	Thu Oct 14 23:43:50 2010
@@ -838,7 +838,7 @@
 	if (MAN_BLOCK != n->type)
 		return(0);
 
-	if ( ! tbl_close(n->data.TS, "<man>", n->line))
+	if ( ! tbl_close(p, n->data.TS, "<man>", n->line))
 		return(0);
 
 	tbl_write(p, n->data.TS);
diff -Naur mandoc-tbl-term/tbl.c mandoc-tbl/tbl.c
--- mandoc-tbl-term/tbl.c	Thu Oct 14 22:50:44 2010
+++ mandoc-tbl/tbl.c	Wed Oct 13 22:55:39 2010
@@ -90,7 +90,7 @@
 
 
 int
-tbl_close(struct tbl *tbl, const char *f, int ln)
+tbl_close(struct termp *p, struct tbl *tbl, const char *f, int ln)
 {
 
 	if (TBL_PART_DATA != tbl->part) 
@@ -98,7 +98,7 @@
 	if ( ! tbl_data_close(tbl, f, ln))
 		return(0);
 #if 1
-	return(tbl_calc_term(tbl));
+	return(tbl_calc_term(p, tbl));
 #else
 	return(tbl_calc_tree(tbl));
 #endif
diff -Naur mandoc-tbl-term/tbl.h mandoc-tbl/tbl.h
--- mandoc-tbl-term/tbl.h	Thu Oct 14 22:50:54 2010
+++ mandoc-tbl/tbl.h	Wed Oct 13 22:53:55 2010
@@ -26,7 +26,7 @@
 void		 tbl_reset(struct tbl *);
 
 int	 	 tbl_read(struct tbl *, const char *, int, const char *, int);
-int		 tbl_close(struct tbl *, const char *, int);
+int		 tbl_close(struct termp *, struct tbl *, const char *, int);
 int		 tbl_write(struct termp *, const struct tbl *);
 
 __END_DECLS
diff -Naur mandoc-tbl-term/tbl_extern.h mandoc-tbl/tbl_extern.h
--- mandoc-tbl-term/tbl_extern.h	Thu Oct 14 23:00:42 2010
+++ mandoc-tbl/tbl_extern.h	Wed Oct 13 22:56:31 2010
@@ -174,7 +174,7 @@
 struct tbl_data	*tbl_data_alloc(struct tbl_span *);
 
 int		 tbl_write_term(struct termp *, const struct tbl *);
-int		 tbl_calc_term(struct tbl *);
+int		 tbl_calc_term(struct termp *, struct tbl *);
 int		 tbl_write_tree(const struct tbl *);
 int		 tbl_calc_tree(struct tbl *);
 
diff -Naur mandoc-tbl-term/tbl_term.c mandoc-tbl/tbl_term.c
--- mandoc-tbl-term/tbl_term.c	Thu Oct 14 23:28:00 2010
+++ mandoc-tbl/tbl_term.c	Thu Oct 14 23:40:15 2010
@@ -29,10 +29,10 @@
 /* FIXME: `n' modifier doesn't always do the right thing. */
 /* FIXME: `n' modifier doesn't use the cell-spacing buffer. */
 
-static	void		 calc_data(struct tbl_data *);
-static	void		 calc_data_literal(struct tbl_data *);
-static	void		 calc_data_number(struct tbl_data *);
-static	void		 calc_data_spanner(struct tbl_data *);
+static	void		 calc_data(struct termp *, struct tbl_data *);
+static	void		 calc_data_literal(struct termp *, struct tbl_data *);
+static	void		 calc_data_number(struct termp *, struct tbl_data *);
+static	void		 calc_data_spanner(struct termp *, struct tbl_data *);
 static	inline void	 write_char(struct termp *, char, int);
 static	void		 write_data(struct termp *,
 				const struct tbl_data *, int);
@@ -118,7 +118,7 @@
 
 
 int
-tbl_calc_term(struct tbl *tbl)
+tbl_calc_term(struct termp *p, struct tbl *tbl)
 {
 	struct tbl_span	*span;
 	struct tbl_data	*data;
@@ -136,7 +136,7 @@
 		if (TBL_DATA_NDHORIZ & span->flags)
 			continue;
 		TAILQ_FOREACH(data, &span->data, entries)
-			calc_data(data);
+			calc_data(p, data);
 	}
 
 	/* Calculate width as the simple spanner value. */
@@ -144,10 +144,10 @@
 	TAILQ_FOREACH(head, &tbl->head, entries) 
 		switch (head->pos) {
 		case (TBL_HEAD_VERT):
-			head->width = 1;
+			head->width = term_len(p, 1);
 			break;
 		case (TBL_HEAD_DVERT):
-			head->width = 2;
+			head->width = term_len(p, 2);
 			break;
 		default:
 			break;
@@ -246,16 +246,16 @@
 
 
 static void
-calc_data_spanner(struct tbl_data *data)
+calc_data_spanner(struct termp *p, struct tbl_data *data)
 {
 
 	/* N.B., these are horiz spanners (not vert) so always 1. */
-	data->cell->head->width = 1;
+	data->cell->head->width = term_len(p, 1);
 }
 
 
 static void
-calc_data_number(struct tbl_data *data)
+calc_data_number(struct termp *p, struct tbl_data *data)
 {
 	int 		 sz, d;
 	char		*dp, pnt;
@@ -272,15 +272,14 @@
 	/* TODO: use spacing modifier. */
 
 	assert(data->string);
-	sz = (int)strlen(data->string);
+	sz = (int)term_strlen(p, data->string);
 	pnt = data->span->tbl->decimal;
 
-	if (NULL == (dp = strchr(data->string, pnt)))
-		d = sz + 1;
-	else
-		d = (int)(dp - data->string) + 1;
+	dp = strchr(data->string, pnt);
+	d = dp ? sz - (int)term_strlen(p, dp) : sz;
+	d += term_len(p, 1);
 
-	sz += 2;
+	sz += term_len(p, 2);
 
 	if (data->cell->head->decimal > d) {
 		sz += data->cell->head->decimal - d;
@@ -297,7 +296,7 @@
 
 
 static void
-calc_data_literal(struct tbl_data *data)
+calc_data_literal(struct termp *p, struct tbl_data *data)
 {
 	int		 sz, bufsz;
 
@@ -308,7 +307,7 @@
 	 */
 
 	assert(data->string);
-	sz = (int)strlen(data->string);
+	sz = (int)term_strlen(p, data->string);
 
 	switch (data->cell->pos) {
 	case (TBL_CELL_LONG):
@@ -325,21 +324,21 @@
 		bufsz = bufsz > data->cell->spacing ? 
 			bufsz : data->cell->spacing;
 
-	sz += bufsz;
+	sz += term_len(p, bufsz);
 	if (data->cell->head->width < sz)
 		data->cell->head->width = sz;
 }
 
 
 static void
-calc_data(struct tbl_data *data)
+calc_data(struct termp *p, struct tbl_data *data)
 {
 
 	switch (data->cell->pos) {
 	case (TBL_CELL_HORIZ):
 		/* FALLTHROUGH */
 	case (TBL_CELL_DHORIZ):
-		calc_data_spanner(data);
+		calc_data_spanner(p, data);
 		break;
 	case (TBL_CELL_LONG):
 		/* FALLTHROUGH */
@@ -348,10 +347,10 @@
 	case (TBL_CELL_LEFT):
 		/* FALLTHROUGH */
 	case (TBL_CELL_RIGHT):
-		calc_data_literal(data);
+		calc_data_literal(p, data);
 		break;
 	case (TBL_CELL_NUMBER):
-		calc_data_number(data);
+		calc_data_number(p, data);
 		break;
 	default:
 		abort();
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

  reply	other threads:[~2010-10-14 21:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-13  0:46 Ingo Schwarze
2010-10-14 21:18 ` Ingo Schwarze
2010-10-14 21:55   ` Ingo Schwarze [this message]
2010-10-14 22:19   ` Ingo Schwarze
2010-10-14 23:02     ` Ingo Schwarze
2010-10-18 16:20   ` Kristaps Dzonsons
2010-10-18 17:38     ` Joerg Sonnenberger

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=20101014215530.GC30282@iris.usta.de \
    --to=schwarze@usta.de \
    --cc=tech@mdocml.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).