From 2a7ad7cc27a054ffb9b426860d023ebc687b10c9 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Tue, 4 Jan 2011 15:02:00 +0000 Subject: Support `T{' and `T}' data blocks. When a standalone `T{' is encountered as a line's last data cell, move into TBL_PART_CDATA mode whilst leaving the cell's designation as TBL_DATA_NONE. When new data arrives that's not a standalone `T}', append it to the cell contends. Close out and warn appropriately. --- libroff.h | 6 ++++-- main.c | 3 ++- mandoc.h | 4 +++- roff.7 | 7 ++++++- tbl.c | 11 +++++++++-- tbl_data.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ tbl_html.c | 5 +++-- tbl_term.c | 14 ++++++-------- 8 files changed, 86 insertions(+), 23 deletions(-) diff --git a/libroff.h b/libroff.h index 70c21398..b4e043a7 100644 --- a/libroff.h +++ b/libroff.h @@ -1,4 +1,4 @@ -/* $Id: libroff.h,v 1.15 2011/01/02 10:10:57 kristaps Exp $ */ +/* $Id: libroff.h,v 1.16 2011/01/04 15:02:00 kristaps Exp $ */ /* * Copyright (c) 2009, 2010 Kristaps Dzonsons * @@ -22,7 +22,8 @@ __BEGIN_DECLS enum tbl_part { TBL_PART_OPTS, /* in options (first line) */ TBL_PART_LAYOUT, /* describing layout */ - TBL_PART_DATA /* creating data rows */ + TBL_PART_DATA, /* creating data rows */ + TBL_PART_CDATA /* continue previous row */ }; struct tbl_node { @@ -52,6 +53,7 @@ enum rofferr tbl_read(struct tbl_node *, int, const char *, int); 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 *); void tbl_end(struct tbl_node *); diff --git a/main.c b/main.c index 63b778f4..2be68a93 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.134 2011/01/04 12:06:21 kristaps Exp $ */ +/* $Id: main.c,v 1.135 2011/01/04 15:02:00 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010 Ingo Schwarze @@ -190,6 +190,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "no table layout cells specified", "no table data cells specified", "ignore data in cell", + "data block still open", "input stack limit exceeded, infinite loop?", "skipping bad character", diff --git a/mandoc.h b/mandoc.h index 75d8f1d3..7da2e541 100644 --- a/mandoc.h +++ b/mandoc.h @@ -1,4 +1,4 @@ -/* $Id: mandoc.h,v 1.47 2011/01/04 12:06:21 kristaps Exp $ */ +/* $Id: mandoc.h,v 1.48 2011/01/04 15:02:00 kristaps Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons * @@ -112,6 +112,7 @@ enum mandocerr { MANDOCERR_TBLNOLAYOUT, /* no table layout cells specified */ MANDOCERR_TBLNODATA, /* no table data cells specified */ MANDOCERR_TBLIGNDATA, /* ignore data in cell */ + MANDOCERR_TBLBLOCK, /* data block still open */ MANDOCERR_ROFFLOOP, /* input stack limit exceeded, infinite loop? */ MANDOCERR_BADCHAR, /* skipping bad character */ @@ -224,6 +225,7 @@ struct tbl_row { }; enum tbl_datt { + TBL_DATA_NONE, TBL_DATA_DATA, TBL_DATA_HORIZ, TBL_DATA_DHORIZ, diff --git a/roff.7 b/roff.7 index cdf20a27..1967a1d7 100644 --- a/roff.7 +++ b/roff.7 @@ -1,4 +1,4 @@ -.\" $Id: roff.7,v 1.21 2011/01/04 12:06:21 kristaps Exp $ +.\" $Id: roff.7,v 1.22 2011/01/04 15:02:00 kristaps Exp $ .\" .\" Copyright (c) 2010 Kristaps Dzonsons .\" Copyright (c) 2010 Ingo Schwarze @@ -736,6 +736,11 @@ or .Cm \e= is specified, a line is drawn within the data field (i.e., terminating within the cell and not draw to the border). +If the last cell of a line is +.Cm T{ , +all subsequent lines are included as part of the cell until +.Cm T} +is specified on its own line. .Sh COMPATIBILITY This section documents compatibility between mandoc and other other .Nm diff --git a/tbl.c b/tbl.c index 1ea37f5a..ba591ceb 100644 --- a/tbl.c +++ b/tbl.c @@ -1,4 +1,4 @@ -/* $Id: tbl.c,v 1.20 2011/01/03 13:59:21 kristaps Exp $ */ +/* $Id: tbl.c,v 1.21 2011/01/04 15:02:00 kristaps Exp $ */ /* * Copyright (c) 2009, 2010 Kristaps Dzonsons * @@ -52,7 +52,9 @@ tbl_read(struct tbl_node *tbl, int ln, const char *p, int offs) return(tbl_option(tbl, ln, p) ? ROFF_IGN : ROFF_ERR); case (TBL_PART_LAYOUT): return(tbl_layout(tbl, ln, p) ? ROFF_IGN : ROFF_ERR); - case (TBL_PART_DATA): + case (TBL_PART_CDATA): + return(tbl_cdata(tbl, ln, p) ? ROFF_TBL : ROFF_IGN); + default: break; } @@ -122,6 +124,8 @@ tbl_free(struct tbl_node *p) void tbl_restart(int line, int pos, struct tbl_node *tbl) { + if (TBL_PART_CDATA == tbl->part) + TBL_MSG(tbl, MANDOCERR_TBLBLOCK, tbl->line, tbl->pos); tbl->part = TBL_PART_LAYOUT; tbl->line = line; @@ -148,5 +152,8 @@ tbl_end(struct tbl_node *tbl) if (tbl->last_span) tbl->last_span->flags |= TBL_SPAN_LAST; + + if (TBL_PART_CDATA == tbl->part) + TBL_MSG(tbl, MANDOCERR_TBLBLOCK, tbl->line, tbl->pos); } diff --git a/tbl_data.c b/tbl_data.c index 40264b9c..030f8c12 100644 --- a/tbl_data.c +++ b/tbl_data.c @@ -1,4 +1,4 @@ -/* $Id: tbl_data.c,v 1.10 2011/01/04 12:06:21 kristaps Exp $ */ +/* $Id: tbl_data.c,v 1.11 2011/01/04 15:02:00 kristaps Exp $ */ /* * Copyright (c) 2009, 2010 Kristaps Dzonsons * @@ -14,6 +14,10 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include @@ -24,10 +28,10 @@ #include "libmandoc.h" #include "libroff.h" -static void data(struct tbl_node *, struct tbl_span *, +static int data(struct tbl_node *, struct tbl_span *, int, const char *, int *); -void +static int data(struct tbl_node *tbl, struct tbl_span *dp, int ln, const char *p, int *pos) { @@ -47,10 +51,9 @@ data(struct tbl_node *tbl, struct tbl_span *dp, TBL_CELL_DVERT == cp->pos)) cp = cp->next; - /* FIXME: warn about losing data contents if cell is HORIZ. */ - dat = mandoc_calloc(1, sizeof(struct tbl_dat)); dat->layout = cp; + dat->pos = TBL_DATA_NONE; if (NULL == dat->layout) TBL_MSG(tbl, MANDOCERR_TBLEXTRADAT, ln, *pos); @@ -65,6 +68,17 @@ data(struct tbl_node *tbl, struct tbl_span *dp, while (p[*pos] && p[*pos] != tbl->opts.tab) (*pos)++; + /* + * Check for a continued-data scope opening. This consists of a + * trailing `T{' at the end of the line. Subsequent lines, + * until a standalone `T}', are included in our cell. + */ + + if (*pos - sv == 2 && 'T' == p[sv] && '{' == p[sv + 1]) { + tbl->part = TBL_PART_CDATA; + return(0); + } + dat->string = mandoc_malloc(*pos - sv + 1); memcpy(dat->string, &p[sv], *pos - sv); dat->string[*pos - sv] = '\0'; @@ -83,10 +97,40 @@ data(struct tbl_node *tbl, struct tbl_span *dp, else dat->pos = TBL_DATA_DATA; + if (NULL == dat->layout) + return(1); + if (TBL_CELL_HORIZ == dat->layout->pos || TBL_CELL_DHORIZ == dat->layout->pos) if (TBL_DATA_DATA == dat->pos && '\0' != *dat->string) TBL_MSG(tbl, MANDOCERR_TBLIGNDATA, ln, sv); + + return(1); +} + +int +tbl_cdata(struct tbl_node *tbl, int ln, const char *p) +{ + struct tbl_dat *dat; + size_t sz; + + if (0 == strcmp(p, "T}")) { + tbl->part = TBL_PART_DATA; + return(1); + } + + dat = tbl->last_span->last; + dat->pos = TBL_DATA_DATA; + + if (dat->string) { + sz = strlen(p) + strlen(dat->string) + 2; + dat->string = mandoc_realloc(dat->string, sz); + strlcat(dat->string, " ", sz); + strlcat(dat->string, p, sz); + } else + dat->string = mandoc_strdup(p); + + return(0); } int @@ -141,8 +185,11 @@ tbl_data(struct tbl_node *tbl, int ln, const char *p) dp->pos = TBL_SPAN_DATA; + /* This returns 0 when TBL_PART_CDATA is entered. */ + while ('\0' != p[pos]) - data(tbl, dp, ln, p, &pos); + if ( ! data(tbl, dp, ln, p, &pos)) + return(0); return(1); } diff --git a/tbl_html.c b/tbl_html.c index e3c710dc..2abbf4ca 100644 --- a/tbl_html.c +++ b/tbl_html.c @@ -1,4 +1,4 @@ -/* $Id: tbl_html.c,v 1.1 2011/01/04 10:29:41 kristaps Exp $ */ +/* $Id: tbl_html.c,v 1.2 2011/01/04 15:02:00 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -63,7 +63,8 @@ print_tbl(struct html *h, const struct tbl_span *sp) } tt = print_otag(h, TAG_TD, 0, NULL); if (dp) { - print_text(h, dp->string); + if (dp->string) + print_text(h, dp->string); dp = dp->next; } print_tagq(h, tt); diff --git a/tbl_term.c b/tbl_term.c index a6c78e1d..267c3d14 100644 --- a/tbl_term.c +++ b/tbl_term.c @@ -1,4 +1,4 @@ -/* $Id: tbl_term.c,v 1.9 2011/01/04 13:21:45 kristaps Exp $ */ +/* $Id: tbl_term.c,v 1.10 2011/01/04 15:02:00 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -253,6 +253,9 @@ tbl_data(struct termp *tp, const struct tbl *tbl, } switch (dp->pos) { + case (TBL_DATA_NONE): + tbl_char(tp, ASCII_NBRSP, tbp->width); + return; case (TBL_DATA_HORIZ): /* FALLTHROUGH */ case (TBL_DATA_NHORIZ): @@ -420,14 +423,9 @@ tbl_calc(struct termp *tp, const struct tbl_span *sp) hp = sp->head; for ( ; sp; sp = sp->next) { - switch (sp->pos) { - case (TBL_DATA_HORIZ): - /* FALLTHROUGH */ - case (TBL_DATA_DHORIZ): + if (TBL_SPAN_DATA != sp->pos) continue; - default: - break; - } + for (dp = sp->first; dp; dp = dp->next) { if (NULL == dp->layout) continue; -- cgit v1.2.3-56-ge451