From: kristaps@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Clean up the tbl top-level printing code and document the parts
Date: Mon, 3 Jan 2011 09:57:04 -0500 (EST) [thread overview]
Message-ID: <201101031457.p03Ev4kS022586@krisdoz.my.domain> (raw)
Log Message:
-----------
Clean up the tbl top-level printing code and document the parts of it.
Modified Files:
--------------
mdocml:
tbl_term.c
Revision Data
-------------
Index: tbl_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/tbl_term.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -Ltbl_term.c -Ltbl_term.c -u -p -r1.3 -r1.4
--- tbl_term.c
+++ tbl_term.c
@@ -72,6 +72,18 @@ term_tbl(struct termp *tp, const struct
const struct tbl_head *hp;
const struct tbl_dat *dp;
+ /* Inhibit printing of spaces: we do padding ourselves. */
+
+ tp->flags |= TERMP_NONOSPACE;
+ tp->flags |= TERMP_NOSPACE;
+
+ /*
+ * The first time we're invoked for a given table block, create
+ * the termp_tbl structure. This contains the column
+ * configuration for the entire table, e.g., table-wide column
+ * width, decimal point, etc.
+ */
+
if (TBL_SPAN_FIRST & sp->flags) {
assert(NULL == tp->tbl);
tp->tbl = calloc
@@ -81,52 +93,63 @@ term_tbl(struct termp *tp, const struct
exit(EXIT_FAILURE);
}
tbl_calc(tp, sp);
+
+ /* Flush out any preceding data. */
term_flushln(tp);
}
+ /* Horizontal frame at the start of boxed tables. */
+
if (TBL_SPAN_FIRST & sp->flags)
tbl_hframe(tp, sp);
- tp->flags |= TERMP_NONOSPACE;
- tp->flags |= TERMP_NOSPACE;
+ /* Vertical frame at the start of each row. */
tbl_vframe(tp, sp->tbl);
+ /*
+ * Now print the actual data itself depending on the span type.
+ * Spanner spans get a horizontal rule; data spanners have their
+ * data printed by matching data to header.
+ */
+
switch (sp->pos) {
case (TBL_SPAN_HORIZ):
/* FALLTHROUGH */
case (TBL_SPAN_DHORIZ):
tbl_hrule(tp, sp);
- tbl_vframe(tp, sp->tbl);
- term_newln(tp);
- goto end;
- default:
break;
- }
+ case (TBL_SPAN_DATA):
+ /* Iterate over template headers. */
+ dp = sp->first;
+ for (hp = sp->head; hp; hp = hp->next) {
+ switch (hp->pos) {
+ case (TBL_HEAD_VERT):
+ /* FALLTHROUGH */
+ case (TBL_HEAD_DVERT):
+ tbl_spanner(tp, hp);
+ continue;
+ case (TBL_HEAD_DATA):
+ break;
+ }
+ tbl_data(tp, sp->tbl, dp,
+ &tp->tbl[hp->ident]);
- dp = sp->first;
- for (hp = sp->head; hp; hp = hp->next) {
- switch (hp->pos) {
- case (TBL_HEAD_VERT):
- /* FALLTHROUGH */
- case (TBL_HEAD_DVERT):
- tbl_spanner(tp, hp);
- break;
- case (TBL_HEAD_DATA):
- tbl_data(tp, sp->tbl, dp, &tp->tbl[hp->ident]);
+ /* Go to the next data cell. */
if (dp)
dp = dp->next;
- break;
- default:
- abort();
- /* NOTREACHED */
}
+ break;
}
tbl_vframe(tp, sp->tbl);
term_flushln(tp);
-end:
+ /*
+ * If we're the last row, clean up after ourselves: clear the
+ * existing table configuration and set it to NULL.
+ */
+
if (TBL_SPAN_LAST & sp->flags) {
tbl_hframe(tp, sp);
assert(tp->tbl);
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
reply other threads:[~2011-01-03 14:57 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=201101031457.p03Ev4kS022586@krisdoz.my.domain \
--to=kristaps@mdocml.bsd.lv \
--cc=source@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).