/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2015 Ingo Schwarze <schwarze@openbsd.org>
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2015 Ingo Schwarze <schwarze@openbsd.org>
- cp = NULL;
- if (dp->last && dp->last->layout)
- cp = dp->last->layout->next;
- else if (NULL == dp->last)
- cp = dp->layout->first;
+ /* Advance to the next layout cell, skipping spanners. */
- /*
- * Skip over spanners, since
- * we want to match data with data layout cells in the header.
- */
-
- while (cp && TBL_CELL_SPAN == cp->pos)
+ cp = dp->last == NULL ? dp->layout->first : dp->last->layout->next;
+ while (cp != NULL && cp->pos == TBL_CELL_SPAN)
-
- assert(TBL_CELL_SPAN != cp->pos);
-
- for (spans = 0, cp = cp->next; cp; cp = cp->next)
- if (TBL_CELL_SPAN == cp->pos)
- spans++;
+ dat->spans = 0;
+ for (cp = cp->next; cp != NULL; cp = cp->next)
+ if (cp->pos == TBL_CELL_SPAN)
+ dat->spans++;
- assert(*pos - sv >= 0);
-
- dat->string = mandoc_malloc((size_t)(*pos - sv + 1));
- memcpy(dat->string, &p[sv], (size_t)(*pos - sv));
- dat->string[*pos - sv] = '\0';
+ dat->string = mandoc_strndup(p + sv, *pos - sv);
- 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)
- mandoc_msg(MANDOCERR_TBLDATA_SPAN,
- tbl->parse, ln, sv, dat->string);
-
- return;
+ if ((dat->layout->pos == TBL_CELL_HORIZ ||
+ dat->layout->pos == TBL_CELL_DHORIZ ||
+ dat->layout->pos == TBL_CELL_DOWN) &&
+ dat->pos == TBL_DATA_DATA && *dat->string != '\0')
+ mandoc_msg(MANDOCERR_TBLDATA_SPAN,
+ tbl->parse, ln, sv, dat->string);
- getdata(tbl, tbl->last_span, ln, p, &pos);
- return(1);
- } else if ('\0' == p[pos]) {
+ while (p[pos] != '\0')
+ getdata(tbl, tbl->last_span, ln, p, &pos);
+ return 1;
+ } else if (p[pos] == '\0') {
sz = strlen(p + pos) + strlen(dat->string) + 2;
dat->string = mandoc_realloc(dat->string, sz);
(void)strlcat(dat->string, " ", sz);
sz = strlen(p + pos) + strlen(dat->string) + 2;
dat->string = mandoc_realloc(dat->string, sz);
(void)strlcat(dat->string, " ", sz);
switch (rp->first->pos) {
case TBL_CELL_HORIZ:
dp = newspan(tbl, ln, rp);
switch (rp->first->pos) {
case TBL_CELL_HORIZ:
dp = newspan(tbl, ln, rp);
getdata(tbl, dp, ln, p, &pos);
}
getdata(tbl, dp, ln, p, &pos);
}