-/* $Id: mandoc.h,v 1.50 2011/01/10 14:40:30 kristaps Exp $ */
+/* $Id: mandoc.h,v 1.51 2011/01/10 15:31:00 kristaps Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
struct tbl_cell {
struct tbl_cell *next;
enum tbl_cellt pos;
- int spacing;
+ size_t spacing;
int flags;
#define TBL_CELL_TALIGN (1 << 0) /* t, T */
#define TBL_CELL_BALIGN (1 << 1) /* d, D */
};
enum tbl_datt {
- TBL_DATA_NONE,
- TBL_DATA_DATA,
- TBL_DATA_HORIZ,
- TBL_DATA_DHORIZ,
- TBL_DATA_NHORIZ,
- TBL_DATA_NDHORIZ
+ TBL_DATA_NONE, /* has no data */
+ TBL_DATA_DATA, /* consists of data/string */
+ TBL_DATA_HORIZ, /* horizontal line */
+ TBL_DATA_DHORIZ, /* double-horizontal line */
+ TBL_DATA_NHORIZ, /* squeezed horizontal line */
+ TBL_DATA_NDHORIZ /* squeezed double-horizontal line */
};
/*
* string value that's in the cell. The rest is layout.
*/
struct tbl_dat {
- struct tbl_cell *layout; /* layout cell: CAN BE NULL */
+ struct tbl_cell *layout; /* layout cell */
int spans; /* how many spans follow */
struct tbl_dat *next;
- char *string;
+ char *string; /* data (NULL if not TBL_DATA_DATA) */
enum tbl_datt pos;
};
struct tbl_span {
struct tbl *tbl;
struct tbl_head *head;
- struct tbl_row *layout; /* layout row: CAN BE NULL */
+ struct tbl_row *layout; /* layout row */
struct tbl_dat *first;
struct tbl_dat *last;
int flags;
-/* $Id: out.c,v 1.33 2011/01/10 14:40:30 kristaps Exp $ */
+/* $Id: out.c,v 1.34 2011/01/10 15:31:00 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
const struct tbl_dat *dp)
{
size_t sz, bufsz, spsz;
+ const char *str;
/*
* Calculate our width and use the spacing, with a minimum
* either side, while right/left get a single adjacent space).
*/
- sz = bufsz = spsz = 0;
- if (dp->string)
- sz = (*tbl->slen)(dp->string, tbl->arg);
+ bufsz = spsz = 0;
+ str = dp->string ? dp->string : "";
+ sz = (*tbl->slen)(str, tbl->arg);
+
+ /* FIXME: TBL_DATA_HORIZ et al.? */
assert(dp->layout);
switch (dp->layout->pos) {
const struct tbl *tp, const struct tbl_dat *dp)
{
int i;
- size_t sz, psz, ssz, d, max;
- char *cp;
+ size_t sz, psz, ssz, d;
const char *str;
+ char *cp;
char buf[2];
/*
* Finally, re-assign the stored values.
*/
- str = dp && dp->string ? dp->string : "";
- max = dp && dp->layout ? dp->layout->spacing : 0;
-
+ str = dp->string ? dp->string : "";
sz = (*tbl->slen)(str, tbl->arg);
+ /* FIXME: TBL_DATA_HORIZ et al.? */
+
buf[0] = tp->decimal;
buf[1] = '\0';
/* Adjust for stipulated width. */
- if (col->width < max)
- col->width = max;
+ if (col->width < dp->layout->spacing)
+ col->width = dp->layout->spacing;
}
-/* $Id: tbl_data.c,v 1.17 2011/01/10 14:56:06 kristaps Exp $ */
+/* $Id: tbl_data.c,v 1.18 2011/01/10 15:31:00 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
* If there's no last parsed span, use the first row. Lastly,
* if the last span was a horizontal line, use the same layout
* (it doesn't "consume" the layout).
- *
- * In the end, this can be NULL!
*/
if (tbl->last_span) {
rp = tbl->last_span->layout->next;
else
rp = tbl->last_span->layout;
+
if (NULL == rp)
rp = tbl->last_span->layout;
} else
rp = tbl->first_row;
+ assert(rp);
+
dp = mandoc_calloc(1, sizeof(struct tbl_span));
dp->tbl = &tbl->opts;
dp->layout = rp;
-/* $Id: tbl_layout.c,v 1.14 2011/01/10 14:40:30 kristaps Exp $ */
+/* $Id: tbl_layout.c,v 1.15 2011/01/10 15:31:00 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
}
*pos += i;
- cp->spacing = atoi(buf);
+ cp->spacing = (size_t)atoi(buf);
goto mod;
/* NOTREACHED */