]>
git.cameronkatri.com Git - mandoc.git/blob - tbl.c
1 /* $Id: tbl.c,v 1.44 2018/12/13 02:06:07 schwarze Exp $ */
3 * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2011, 2015 Ingo Schwarze <schwarze@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
28 #include "mandoc_aux.h"
31 #include "libmandoc.h"
32 #include "tbl_parse.h"
37 tbl_read(struct tbl_node
*tbl
, int ln
, const char *p
, int pos
)
43 * In the options section, proceed to the layout section
44 * after a semicolon, or right away if there is no semicolon.
45 * Ignore semicolons in arguments.
48 if (tbl
->part
== TBL_PART_OPTS
) {
49 tbl
->part
= TBL_PART_LAYOUT
;
51 for (cp
= p
+ pos
; *cp
!= '\0'; cp
++) {
69 tbl_option(tbl
, ln
, p
, &pos
);
75 /* Process the other section types. */
79 tbl_layout(tbl
, ln
, p
, pos
);
82 tbl_cdata(tbl
, ln
, p
, pos
);
85 tbl_data(tbl
, ln
, p
, pos
);
91 tbl_alloc(int pos
, int line
, struct mparse
*parse
, struct tbl_node
*last_tbl
)
95 tbl
= mandoc_calloc(1, sizeof(*tbl
));
101 tbl
->part
= TBL_PART_OPTS
;
102 tbl
->opts
.tab
= '\t';
103 tbl
->opts
.decimal
= '.';
108 tbl_free(struct tbl_node
*tbl
)
110 struct tbl_node
*old_tbl
;
116 while (tbl
!= NULL
) {
117 while ((rp
= tbl
->first_row
) != NULL
) {
118 tbl
->first_row
= rp
->next
;
119 while (rp
->first
!= NULL
) {
121 rp
->first
= cp
->next
;
127 while ((sp
= tbl
->first_span
) != NULL
) {
128 tbl
->first_span
= sp
->next
;
129 while (sp
->first
!= NULL
) {
131 sp
->first
= dp
->next
;
144 tbl_restart(int line
, int pos
, struct tbl_node
*tbl
)
146 if (tbl
->part
== TBL_PART_CDATA
)
147 mandoc_msg(MANDOCERR_TBLDATA_BLK
, tbl
->parse
,
150 tbl
->part
= TBL_PART_LAYOUT
;
156 tbl_span(struct tbl_node
*tbl
)
158 struct tbl_span
*span
;
160 span
= tbl
->current_span
? tbl
->current_span
->next
163 tbl
->current_span
= span
;
168 tbl_end(struct tbl_node
*tbl
, int still_open
)
173 mandoc_msg(MANDOCERR_BLK_NOEND
, tbl
->parse
,
174 tbl
->line
, tbl
->pos
, "TS");
175 else if (tbl
->part
== TBL_PART_CDATA
)
176 mandoc_msg(MANDOCERR_TBLDATA_BLK
, tbl
->parse
,
177 tbl
->line
, tbl
->pos
, "TE");
179 sp
= tbl
->first_span
;
180 while (sp
!= NULL
&& sp
->first
== NULL
)
183 mandoc_msg(MANDOCERR_TBLDATA_NONE
, tbl
->parse
,
184 tbl
->line
, tbl
->pos
, NULL
);