371584c2eae4cf827fd406ba26c14f021adaaa70Yuri Pankov/* $Id: tbl_data.c,v 1.41 2015/10/06 18:32:20 schwarze Exp $ */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov * Copyright (c) 2011, 2015 Ingo Schwarze <schwarze@openbsd.org>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Permission to use, copy, modify, and distribute this software for any
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * purpose with or without fee is hereby granted, provided that the above
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * copyright notice and this permission notice appear in all copies.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankovstatic void getdata(struct tbl_node *, struct tbl_span *,
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore int, const char *, int *);
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankovstatic struct tbl_span *newspan(struct tbl_node *, int,
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankovgetdata(struct tbl_node *tbl, struct tbl_span *dp,
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov /* Advance to the next layout cell, skipping spanners. */
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov cp = dp->last == NULL ? dp->layout->first : dp->last->layout->next;
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Stop processing when we reach the end of the available layout
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * cells. This means that we have extra input.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* Skip to the end... */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Check for a continued-data scope opening. This consists of a
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * trailing `T{' at the end of the line. Subsequent lines,
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * until a standalone `T}', are included in our cell.
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov if (*pos - sv == 2 && p[sv] == 'T' && p[sv + 1] == '{') {
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov dat->string = mandoc_strndup(p + sv, *pos - sv);
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankov dat->pos == TBL_DATA_DATA && *dat->string != '\0')
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankovtbl_cdata(struct tbl_node *tbl, int ln, const char *p, int pos)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* Fallthrough: T} is part of a word. */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore dat->string = mandoc_realloc(dat->string, sz);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic struct tbl_span *
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorenewspan(struct tbl_node *tbl, int line, struct tbl_row *rp)
260e9a87725c090ba5835b1f9f0b62fa2f96036fYuri Pankovtbl_data(struct tbl_node *tbl, int ln, const char *p, int pos)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Choose a layout row: take the one following the last parsed
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * span's. If that doesn't exist, use the last parsed span's.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * If there's no last parsed span, use the first row. Lastly,
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * if the last span was a horizontal line, use the same layout
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * (it doesn't "consume" the layout).