]>
git.cameronkatri.com Git - mandoc.git/blob - tbl_data.c
1 /* $Id: tbl_data.c,v 1.9 2011/01/02 12:04:23 kristaps Exp $ */
3 * Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #include "libmandoc.h"
27 static void data(struct tbl_node
*, struct tbl_span
*,
28 int, const char *, int *);
31 data(struct tbl_node
*tbl
, struct tbl_span
*dp
,
32 int ln
, const char *p
, int *pos
)
39 if (dp
->last
&& dp
->last
->layout
)
40 cp
= dp
->last
->layout
->next
;
41 else if (NULL
== dp
->last
)
42 cp
= dp
->layout
->first
;
44 /* Skip over spanners to data formats. */
46 while (cp
&& (TBL_CELL_VERT
== cp
->pos
||
47 TBL_CELL_DVERT
== cp
->pos
))
50 /* FIXME: warn about losing data contents if cell is HORIZ. */
52 dat
= mandoc_calloc(1, sizeof(struct tbl_dat
));
55 if (NULL
== dat
->layout
)
56 TBL_MSG(tbl
, MANDOCERR_TBLEXTRADAT
, ln
, *pos
);
62 dp
->last
= dp
->first
= dat
;
65 while (p
[*pos
] && p
[*pos
] != tbl
->opts
.tab
)
68 dat
->string
= mandoc_malloc(*pos
- sv
+ 1);
69 memcpy(dat
->string
, &p
[sv
], *pos
- sv
);
70 dat
->string
[*pos
- sv
] = '\0';
75 if ( ! strcmp(dat
->string
, "_"))
76 dat
->pos
= TBL_DATA_HORIZ
;
77 else if ( ! strcmp(dat
->string
, "="))
78 dat
->pos
= TBL_DATA_DHORIZ
;
79 else if ( ! strcmp(dat
->string
, "\\_"))
80 dat
->pos
= TBL_DATA_NHORIZ
;
81 else if ( ! strcmp(dat
->string
, "\\="))
82 dat
->pos
= TBL_DATA_NDHORIZ
;
84 dat
->pos
= TBL_DATA_DATA
;
88 tbl_data(struct tbl_node
*tbl
, int ln
, const char *p
)
97 TBL_MSG(tbl
, MANDOCERR_TBL
, ln
, pos
);
102 * Choose a layout row: take the one following the last parsed
103 * span's. If that doesn't exist, use the last parsed span's.
104 * If there's no last parsed span, use the first row. This can
108 if (tbl
->last_span
) {
109 assert(tbl
->last_span
->layout
);
110 rp
= tbl
->last_span
->layout
->next
;
112 rp
= tbl
->last_span
->layout
;
116 dp
= mandoc_calloc(1, sizeof(struct tbl_span
));
117 dp
->tbl
= &tbl
->opts
;
119 dp
->head
= tbl
->first_head
;
121 if (tbl
->last_span
) {
122 tbl
->last_span
->next
= dp
;
125 tbl
->last_span
= tbl
->first_span
= dp
;
126 dp
->flags
|= TBL_SPAN_FIRST
;
129 if ( ! strcmp(p
, "_")) {
130 dp
->pos
= TBL_SPAN_HORIZ
;
132 } else if ( ! strcmp(p
, "=")) {
133 dp
->pos
= TBL_SPAN_DHORIZ
;
137 dp
->pos
= TBL_SPAN_DATA
;
139 while ('\0' != p
[pos
])
140 data(tbl
, dp
, ln
, p
, &pos
);