]>
git.cameronkatri.com Git - mandoc.git/blob - tbl_data.c
1 /* $Id: tbl_data.c,v 1.2 2010/12/30 09:34:07 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.
23 #include "libmandoc.h"
26 static void data(struct tbl
*, struct tbl_span
*,
27 int, const char *, int *);
30 data(struct tbl
*tbl
, struct tbl_span
*dp
,
31 int ln
, const char *p
, int *pos
)
36 /* FIXME: warn about losing data contents if cell is HORIZ. */
38 dat
= mandoc_calloc(1, sizeof(struct tbl_dat
));
44 dp
->last
= dp
->first
= dat
;
47 while (p
[*pos
] && p
[*pos
] != tbl
->tab
)
50 dat
->string
= mandoc_malloc(*pos
- sv
+ 1);
51 memcpy(dat
->string
, &p
[sv
], *pos
- sv
);
52 dat
->string
[*pos
- sv
] = '\0';
57 /* XXX: do the strcmps, then malloc(). */
59 if ( ! strcmp(dat
->string
, "_"))
60 dat
->flags
|= TBL_DATA_HORIZ
;
61 else if ( ! strcmp(dat
->string
, "="))
62 dat
->flags
|= TBL_DATA_DHORIZ
;
63 else if ( ! strcmp(dat
->string
, "\\_"))
64 dat
->flags
|= TBL_DATA_NHORIZ
;
65 else if ( ! strcmp(dat
->string
, "\\="))
66 dat
->flags
|= TBL_DATA_NDHORIZ
;
70 tbl_data(struct tbl
*tbl
, int ln
, const char *p
)
78 TBL_MSG(tbl
, MANDOCERR_TBL
, ln
, pos
);
82 dp
= mandoc_calloc(1, sizeof(struct tbl_span
));
85 tbl
->last_span
->next
= dp
;
88 tbl
->last_span
= tbl
->first_span
= dp
;
90 if ( ! strcmp(p
, "_")) {
91 dp
->flags
|= TBL_SPAN_HORIZ
;
93 } else if ( ! strcmp(p
, "=")) {
94 dp
->flags
|= TBL_SPAN_DHORIZ
;
98 while ('\0' != p
[pos
])
99 data(tbl
, dp
, ln
, p
, &pos
);