=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/tbl_data.c,v retrieving revision 1.5 retrieving revision 1.6 diff -c -r1.5 -r1.6 *** src/usr.bin/mandoc/tbl_data.c 2011/01/09 14:30:48 1.5 --- src/usr.bin/mandoc/tbl_data.c 2011/01/16 01:11:50 1.6 *************** *** 1,4 **** ! /* $Id: tbl_data.c,v 1.5 2011/01/09 14:30:48 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * --- 1,4 ---- ! /* $Id: tbl_data.c,v 1.6 2011/01/16 01:11:50 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * *************** *** 33,39 **** { struct tbl_dat *dat; struct tbl_cell *cp; ! int sv; cp = NULL; if (dp->last && dp->last->layout) --- 33,39 ---- { struct tbl_dat *dat; struct tbl_cell *cp; ! int sv, spans; cp = NULL; if (dp->last && dp->last->layout) *************** *** 51,63 **** TBL_CELL_SPAN == cp->pos)) cp = cp->next; 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); if (dp->last) { dp->last->next = dat; dp->last = dat; --- 51,83 ---- TBL_CELL_SPAN == cp->pos)) cp = cp->next; + /* + * Stop processing when we reach the end of the available layout + * cells. This means that we have extra input. + */ + + if (NULL == cp) { + TBL_MSG(tbl, MANDOCERR_TBLEXTRADAT, ln, *pos); + /* Skip to the end... */ + while (p[*pos]) + (*pos)++; + return(1); + } + dat = mandoc_calloc(1, sizeof(struct tbl_dat)); dat->layout = cp; dat->pos = TBL_DATA_NONE; ! assert(TBL_CELL_SPAN != cp->pos); + for (spans = 0, cp = cp->next; cp; cp = cp->next) + if (TBL_CELL_SPAN == cp->pos) + spans++; + else + break; + + dat->spans = spans; + if (dp->last) { dp->last->next = dat; dp->last = dat; *************** *** 97,107 **** 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); --- 117,125 ---- else dat->pos = TBL_DATA_DATA; if (TBL_CELL_HORIZ == dat->layout->pos || ! TBL_CELL_DHORIZ == dat->layout->pos || ! TBL_CELL_DOWN == dat->layout->pos) if (TBL_DATA_DATA == dat->pos && '\0' != *dat->string) TBL_MSG(tbl, MANDOCERR_TBLIGNDATA, ln, sv); *************** *** 119,125 **** pos = 0; dat = tbl->last_span->last; - dat->pos = TBL_DATA_DATA; if (p[pos] == 'T' && p[pos + 1] == '}') { pos += 2; --- 137,142 ---- *************** *** 135,140 **** --- 152,159 ---- /* Fallthrough: T} is part of a word. */ } + dat->pos = TBL_DATA_DATA; + if (dat->string) { sz = strlen(p) + strlen(dat->string) + 2; dat->string = mandoc_realloc(dat->string, sz); *************** *** 143,148 **** --- 162,170 ---- } else dat->string = mandoc_strdup(p); + if (TBL_CELL_DOWN == dat->layout->pos) + TBL_MSG(tbl, MANDOCERR_TBLIGNDATA, ln, pos); + return(0); } *************** *** 163,179 **** /* * Choose a layout row: take the one following the last parsed * span's. If that doesn't exist, use the last parsed span's. ! * If there's no last parsed span, use the first row. This can ! * be NULL! */ if (tbl->last_span) { assert(tbl->last_span->layout); ! rp = tbl->last_span->layout->next; if (NULL == rp) rp = tbl->last_span->layout; } else rp = tbl->first_row; dp = mandoc_calloc(1, sizeof(struct tbl_span)); dp->tbl = &tbl->opts; --- 185,208 ---- /* * Choose a layout row: take the one following the last parsed * span's. If that doesn't exist, use the last parsed span's. ! * 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). */ if (tbl->last_span) { assert(tbl->last_span->layout); ! if (tbl->last_span->pos == TBL_SPAN_DATA) ! 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;