mandoc 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +7 -0
- data/COPYING +674 -0
- data/README.md +117 -0
- data/ext/mandoc/extconf.rb +59 -0
- data/ext/mandoc/rb_mandoc.c +548 -0
- data/ext/mandoc/rb_mandoc.h +22 -0
- data/lib/mandoc/version.rb +19 -0
- data/lib/mandoc.rb +26 -0
- data/mandoc-1.14.6/LICENSE +55 -0
- data/mandoc-1.14.6/arch.c +54 -0
- data/mandoc-1.14.6/att.c +49 -0
- data/mandoc-1.14.6/catman.c +260 -0
- data/mandoc-1.14.6/cgi.c +1279 -0
- data/mandoc-1.14.6/chars.c +507 -0
- data/mandoc-1.14.6/compat_err.c +103 -0
- data/mandoc-1.14.6/compat_fts.c +696 -0
- data/mandoc-1.14.6/compat_fts.h +106 -0
- data/mandoc-1.14.6/compat_getline.c +59 -0
- data/mandoc-1.14.6/compat_getsubopt.c +87 -0
- data/mandoc-1.14.6/compat_isblank.c +23 -0
- data/mandoc-1.14.6/compat_mkdtemp.c +50 -0
- data/mandoc-1.14.6/compat_mkstemps.c +63 -0
- data/mandoc-1.14.6/compat_ohash.c +330 -0
- data/mandoc-1.14.6/compat_ohash.h +72 -0
- data/mandoc-1.14.6/compat_progname.c +31 -0
- data/mandoc-1.14.6/compat_reallocarray.c +40 -0
- data/mandoc-1.14.6/compat_recallocarray.c +99 -0
- data/mandoc-1.14.6/compat_strcasestr.c +64 -0
- data/mandoc-1.14.6/compat_stringlist.c +135 -0
- data/mandoc-1.14.6/compat_stringlist.h +48 -0
- data/mandoc-1.14.6/compat_strlcat.c +57 -0
- data/mandoc-1.14.6/compat_strlcpy.c +52 -0
- data/mandoc-1.14.6/compat_strndup.c +42 -0
- data/mandoc-1.14.6/compat_strsep.c +70 -0
- data/mandoc-1.14.6/compat_strtonum.c +67 -0
- data/mandoc-1.14.6/compat_vasprintf.c +47 -0
- data/mandoc-1.14.6/config.h +52 -0
- data/mandoc-1.14.6/dba.c +508 -0
- data/mandoc-1.14.6/dba.h +50 -0
- data/mandoc-1.14.6/dba_array.c +190 -0
- data/mandoc-1.14.6/dba_array.h +47 -0
- data/mandoc-1.14.6/dba_read.c +74 -0
- data/mandoc-1.14.6/dba_write.c +127 -0
- data/mandoc-1.14.6/dba_write.h +30 -0
- data/mandoc-1.14.6/dbm.c +480 -0
- data/mandoc-1.14.6/dbm.h +68 -0
- data/mandoc-1.14.6/dbm_map.c +194 -0
- data/mandoc-1.14.6/dbm_map.h +29 -0
- data/mandoc-1.14.6/demandoc.c +260 -0
- data/mandoc-1.14.6/eqn.c +1132 -0
- data/mandoc-1.14.6/eqn.h +72 -0
- data/mandoc-1.14.6/eqn_html.c +246 -0
- data/mandoc-1.14.6/eqn_parse.h +48 -0
- data/mandoc-1.14.6/eqn_term.c +174 -0
- data/mandoc-1.14.6/html.c +1102 -0
- data/mandoc-1.14.6/html.h +142 -0
- data/mandoc-1.14.6/lib.c +35 -0
- data/mandoc-1.14.6/libman.h +42 -0
- data/mandoc-1.14.6/libmandoc.h +85 -0
- data/mandoc-1.14.6/libmdoc.h +87 -0
- data/mandoc-1.14.6/main.c +1375 -0
- data/mandoc-1.14.6/main.h +53 -0
- data/mandoc-1.14.6/man.c +345 -0
- data/mandoc-1.14.6/man.h +21 -0
- data/mandoc-1.14.6/man_html.c +640 -0
- data/mandoc-1.14.6/man_macro.c +470 -0
- data/mandoc-1.14.6/man_term.c +1143 -0
- data/mandoc-1.14.6/man_validate.c +660 -0
- data/mandoc-1.14.6/manconf.h +58 -0
- data/mandoc-1.14.6/mandoc.c +669 -0
- data/mandoc-1.14.6/mandoc.h +329 -0
- data/mandoc-1.14.6/mandoc_aux.c +118 -0
- data/mandoc-1.14.6/mandoc_aux.h +27 -0
- data/mandoc-1.14.6/mandoc_msg.c +375 -0
- data/mandoc-1.14.6/mandoc_ohash.c +65 -0
- data/mandoc-1.14.6/mandoc_ohash.h +23 -0
- data/mandoc-1.14.6/mandoc_parse.h +44 -0
- data/mandoc-1.14.6/mandoc_xr.c +123 -0
- data/mandoc-1.14.6/mandoc_xr.h +31 -0
- data/mandoc-1.14.6/mandocd.c +282 -0
- data/mandoc-1.14.6/mandocdb.c +2448 -0
- data/mandoc-1.14.6/manpath.c +363 -0
- data/mandoc-1.14.6/mansearch.c +851 -0
- data/mandoc-1.14.6/mansearch.h +118 -0
- data/mandoc-1.14.6/mdoc.c +433 -0
- data/mandoc-1.14.6/mdoc.h +158 -0
- data/mandoc-1.14.6/mdoc_argv.c +682 -0
- data/mandoc-1.14.6/mdoc_html.c +1762 -0
- data/mandoc-1.14.6/mdoc_macro.c +1600 -0
- data/mandoc-1.14.6/mdoc_man.c +1850 -0
- data/mandoc-1.14.6/mdoc_markdown.c +1610 -0
- data/mandoc-1.14.6/mdoc_state.c +256 -0
- data/mandoc-1.14.6/mdoc_term.c +1964 -0
- data/mandoc-1.14.6/mdoc_validate.c +3062 -0
- data/mandoc-1.14.6/msec.c +37 -0
- data/mandoc-1.14.6/out.c +544 -0
- data/mandoc-1.14.6/out.h +70 -0
- data/mandoc-1.14.6/preconv.c +179 -0
- data/mandoc-1.14.6/read.c +732 -0
- data/mandoc-1.14.6/roff.c +4390 -0
- data/mandoc-1.14.6/roff.h +561 -0
- data/mandoc-1.14.6/roff_html.c +119 -0
- data/mandoc-1.14.6/roff_int.h +94 -0
- data/mandoc-1.14.6/roff_term.c +266 -0
- data/mandoc-1.14.6/roff_validate.c +151 -0
- data/mandoc-1.14.6/soelim.c +182 -0
- data/mandoc-1.14.6/st.c +82 -0
- data/mandoc-1.14.6/tag.c +327 -0
- data/mandoc-1.14.6/tag.h +35 -0
- data/mandoc-1.14.6/tbl.c +183 -0
- data/mandoc-1.14.6/tbl.h +121 -0
- data/mandoc-1.14.6/tbl_data.c +323 -0
- data/mandoc-1.14.6/tbl_html.c +293 -0
- data/mandoc-1.14.6/tbl_int.h +47 -0
- data/mandoc-1.14.6/tbl_layout.c +376 -0
- data/mandoc-1.14.6/tbl_opts.c +173 -0
- data/mandoc-1.14.6/tbl_parse.h +30 -0
- data/mandoc-1.14.6/tbl_term.c +948 -0
- data/mandoc-1.14.6/term.c +1113 -0
- data/mandoc-1.14.6/term.h +158 -0
- data/mandoc-1.14.6/term_ascii.c +424 -0
- data/mandoc-1.14.6/term_ps.c +1362 -0
- data/mandoc-1.14.6/term_tab.c +130 -0
- data/mandoc-1.14.6/term_tag.c +227 -0
- data/mandoc-1.14.6/term_tag.h +34 -0
- data/mandoc-1.14.6/tree.c +536 -0
- metadata +170 -0
data/mandoc-1.14.6/tbl.h
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/* $Id: tbl.h,v 1.2 2021/08/10 12:55:04 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
|
|
4
|
+
* Copyright (c) 2014,2015,2017,2018,2021 Ingo Schwarze <schwarze@openbsd.org>
|
|
5
|
+
*
|
|
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.
|
|
9
|
+
*
|
|
10
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
|
|
11
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
12
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
struct tbl_opts {
|
|
20
|
+
int opts;
|
|
21
|
+
#define TBL_OPT_ALLBOX (1 << 0) /* Option "allbox". */
|
|
22
|
+
#define TBL_OPT_BOX (1 << 1) /* Option "box". */
|
|
23
|
+
#define TBL_OPT_CENTRE (1 << 2) /* Option "center". */
|
|
24
|
+
#define TBL_OPT_DBOX (1 << 3) /* Option "doublebox". */
|
|
25
|
+
#define TBL_OPT_EXPAND (1 << 4) /* Option "expand". */
|
|
26
|
+
#define TBL_OPT_NOKEEP (1 << 5) /* Option "nokeep". */
|
|
27
|
+
#define TBL_OPT_NOSPACE (1 << 6) /* Option "nospaces". */
|
|
28
|
+
#define TBL_OPT_NOWARN (1 << 7) /* Option "nowarn". */
|
|
29
|
+
int cols; /* Number of columns. */
|
|
30
|
+
int lvert; /* Width of left vertical line. */
|
|
31
|
+
int rvert; /* Width of right vertical line. */
|
|
32
|
+
char tab; /* Option "tab": cell separator. */
|
|
33
|
+
char decimal; /* Option "decimalpoint". */
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
enum tbl_cellt {
|
|
37
|
+
TBL_CELL_CENTRE, /* c, C */
|
|
38
|
+
TBL_CELL_RIGHT, /* r, R */
|
|
39
|
+
TBL_CELL_LEFT, /* l, L */
|
|
40
|
+
TBL_CELL_NUMBER, /* n, N */
|
|
41
|
+
TBL_CELL_SPAN, /* s, S */
|
|
42
|
+
TBL_CELL_LONG, /* a, A */
|
|
43
|
+
TBL_CELL_DOWN, /* ^ */
|
|
44
|
+
TBL_CELL_HORIZ, /* _, - */
|
|
45
|
+
TBL_CELL_DHORIZ, /* = */
|
|
46
|
+
TBL_CELL_MAX
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/*
|
|
50
|
+
* A cell in a layout row.
|
|
51
|
+
*/
|
|
52
|
+
struct tbl_cell {
|
|
53
|
+
struct tbl_cell *next; /* Layout cell to the right. */
|
|
54
|
+
char *wstr; /* Min width represented as a string. */
|
|
55
|
+
size_t width; /* Minimum column width. */
|
|
56
|
+
size_t spacing; /* To the right of the column. */
|
|
57
|
+
int vert; /* Width of subsequent vertical line. */
|
|
58
|
+
int col; /* Column number, starting from 0. */
|
|
59
|
+
int flags;
|
|
60
|
+
#define TBL_CELL_TALIGN (1 << 2) /* t, T */
|
|
61
|
+
#define TBL_CELL_UP (1 << 3) /* u, U */
|
|
62
|
+
#define TBL_CELL_BALIGN (1 << 4) /* d, D */
|
|
63
|
+
#define TBL_CELL_WIGN (1 << 5) /* z, Z */
|
|
64
|
+
#define TBL_CELL_EQUAL (1 << 6) /* e, E */
|
|
65
|
+
#define TBL_CELL_WMAX (1 << 7) /* x, X */
|
|
66
|
+
enum mandoc_esc font;
|
|
67
|
+
enum tbl_cellt pos;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/*
|
|
71
|
+
* A layout row.
|
|
72
|
+
*/
|
|
73
|
+
struct tbl_row {
|
|
74
|
+
struct tbl_row *next; /* Layout row below. */
|
|
75
|
+
struct tbl_cell *first; /* Leftmost layout cell. */
|
|
76
|
+
struct tbl_cell *last; /* Rightmost layout cell. */
|
|
77
|
+
int vert; /* Width of left vertical line. */
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
enum tbl_datt {
|
|
81
|
+
TBL_DATA_NONE, /* Uninitialized row. */
|
|
82
|
+
TBL_DATA_DATA, /* Contains data rather than a line. */
|
|
83
|
+
TBL_DATA_HORIZ, /* _: connecting horizontal line. */
|
|
84
|
+
TBL_DATA_DHORIZ, /* =: connecting double horizontal line. */
|
|
85
|
+
TBL_DATA_NHORIZ, /* \_: isolated horizontal line. */
|
|
86
|
+
TBL_DATA_NDHORIZ /* \=: isolated double horizontal line. */
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/*
|
|
90
|
+
* A cell within a row of data. The "string" field contains the
|
|
91
|
+
* actual string value that's in the cell. The rest is layout.
|
|
92
|
+
*/
|
|
93
|
+
struct tbl_dat {
|
|
94
|
+
struct tbl_dat *next; /* Data cell to the right. */
|
|
95
|
+
struct tbl_cell *layout; /* Associated layout cell. */
|
|
96
|
+
char *string; /* Data, or NULL if not TBL_DATA_DATA. */
|
|
97
|
+
int hspans; /* How many horizontal spans follow. */
|
|
98
|
+
int vspans; /* How many vertical spans follow. */
|
|
99
|
+
int block; /* T{ text block T} */
|
|
100
|
+
enum tbl_datt pos;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
enum tbl_spant {
|
|
104
|
+
TBL_SPAN_DATA, /* Contains data rather than a line. */
|
|
105
|
+
TBL_SPAN_HORIZ, /* _: horizontal line. */
|
|
106
|
+
TBL_SPAN_DHORIZ /* =: double horizontal line. */
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/*
|
|
110
|
+
* A row of data in a table.
|
|
111
|
+
*/
|
|
112
|
+
struct tbl_span {
|
|
113
|
+
struct tbl_opts *opts; /* Options for the table as a whole. */
|
|
114
|
+
struct tbl_span *prev; /* Data row above. */
|
|
115
|
+
struct tbl_span *next; /* Data row below. */
|
|
116
|
+
struct tbl_row *layout; /* Associated layout row. */
|
|
117
|
+
struct tbl_dat *first; /* Leftmost data cell. */
|
|
118
|
+
struct tbl_dat *last; /* Rightmost data cell. */
|
|
119
|
+
int line; /* Input file line number. */
|
|
120
|
+
enum tbl_spant pos;
|
|
121
|
+
};
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/* $Id: tbl_data.c,v 1.59 2021/09/10 13:24:38 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
|
|
4
|
+
* Copyright (c) 2011,2015,2017-2019,2021 Ingo Schwarze <schwarze@openbsd.org>
|
|
5
|
+
*
|
|
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.
|
|
9
|
+
*
|
|
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.
|
|
17
|
+
*/
|
|
18
|
+
#include "config.h"
|
|
19
|
+
|
|
20
|
+
#include <sys/types.h>
|
|
21
|
+
|
|
22
|
+
#include <assert.h>
|
|
23
|
+
#include <ctype.h>
|
|
24
|
+
#include <stdint.h>
|
|
25
|
+
#include <stdio.h>
|
|
26
|
+
#include <stdlib.h>
|
|
27
|
+
#include <string.h>
|
|
28
|
+
#include <time.h>
|
|
29
|
+
|
|
30
|
+
#include "mandoc_aux.h"
|
|
31
|
+
#include "mandoc.h"
|
|
32
|
+
#include "tbl.h"
|
|
33
|
+
#include "libmandoc.h"
|
|
34
|
+
#include "tbl_int.h"
|
|
35
|
+
|
|
36
|
+
static void getdata(struct tbl_node *, struct tbl_span *,
|
|
37
|
+
int, const char *, int *);
|
|
38
|
+
static struct tbl_span *newspan(struct tbl_node *, int,
|
|
39
|
+
struct tbl_row *);
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
static void
|
|
43
|
+
getdata(struct tbl_node *tbl, struct tbl_span *dp,
|
|
44
|
+
int ln, const char *p, int *pos)
|
|
45
|
+
{
|
|
46
|
+
struct tbl_dat *dat, *pdat;
|
|
47
|
+
struct tbl_cell *cp;
|
|
48
|
+
struct tbl_span *pdp;
|
|
49
|
+
const char *ccp;
|
|
50
|
+
int startpos, endpos;
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
* Determine the length of the string in the cell
|
|
54
|
+
* and advance the parse point to the end of the cell.
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
startpos = *pos;
|
|
58
|
+
ccp = p + startpos;
|
|
59
|
+
while (*ccp != '\0' && *ccp != tbl->opts.tab)
|
|
60
|
+
if (*ccp++ == '\\')
|
|
61
|
+
mandoc_escape(&ccp, NULL, NULL);
|
|
62
|
+
*pos = ccp - p;
|
|
63
|
+
|
|
64
|
+
/* Advance to the next layout cell, skipping spanners. */
|
|
65
|
+
|
|
66
|
+
cp = dp->last == NULL ? dp->layout->first : dp->last->layout->next;
|
|
67
|
+
while (cp != NULL && cp->pos == TBL_CELL_SPAN)
|
|
68
|
+
cp = cp->next;
|
|
69
|
+
|
|
70
|
+
/*
|
|
71
|
+
* If the current layout row is out of cells, allocate
|
|
72
|
+
* a new cell if another row of the table has at least
|
|
73
|
+
* this number of columns, or discard the input if we
|
|
74
|
+
* are beyond the last column of the table as a whole.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
if (cp == NULL) {
|
|
78
|
+
if (dp->layout->last->col + 1 < dp->opts->cols) {
|
|
79
|
+
cp = mandoc_calloc(1, sizeof(*cp));
|
|
80
|
+
cp->pos = TBL_CELL_LEFT;
|
|
81
|
+
cp->font = ESCAPE_FONTROMAN;
|
|
82
|
+
cp->spacing = SIZE_MAX;
|
|
83
|
+
dp->layout->last->next = cp;
|
|
84
|
+
cp->col = dp->layout->last->col + 1;
|
|
85
|
+
dp->layout->last = cp;
|
|
86
|
+
} else {
|
|
87
|
+
mandoc_msg(MANDOCERR_TBLDATA_EXTRA,
|
|
88
|
+
ln, startpos, "%s", p + startpos);
|
|
89
|
+
while (p[*pos] != '\0')
|
|
90
|
+
(*pos)++;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
dat = mandoc_malloc(sizeof(*dat));
|
|
96
|
+
dat->layout = cp;
|
|
97
|
+
dat->next = NULL;
|
|
98
|
+
dat->string = NULL;
|
|
99
|
+
dat->hspans = 0;
|
|
100
|
+
dat->vspans = 0;
|
|
101
|
+
dat->block = 0;
|
|
102
|
+
dat->pos = TBL_DATA_NONE;
|
|
103
|
+
|
|
104
|
+
/*
|
|
105
|
+
* Increment the number of vertical spans in a data cell above,
|
|
106
|
+
* if this cell vertically extends one or more cells above.
|
|
107
|
+
* The iteration must be done over data rows,
|
|
108
|
+
* not over layout rows, because one layout row
|
|
109
|
+
* can be reused for more than one data row.
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
if (cp->pos == TBL_CELL_DOWN ||
|
|
113
|
+
(*pos - startpos == 2 &&
|
|
114
|
+
p[startpos] == '\\' && p[startpos + 1] == '^')) {
|
|
115
|
+
pdp = dp;
|
|
116
|
+
while ((pdp = pdp->prev) != NULL) {
|
|
117
|
+
pdat = pdp->first;
|
|
118
|
+
while (pdat != NULL &&
|
|
119
|
+
pdat->layout->col < dat->layout->col)
|
|
120
|
+
pdat = pdat->next;
|
|
121
|
+
if (pdat == NULL)
|
|
122
|
+
break;
|
|
123
|
+
if (pdat->layout->pos != TBL_CELL_DOWN &&
|
|
124
|
+
strcmp(pdat->string, "\\^") != 0) {
|
|
125
|
+
pdat->vspans++;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/*
|
|
132
|
+
* Count the number of horizontal spans to the right of this cell.
|
|
133
|
+
* This is purely a matter of the layout, independent of the data.
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
for (cp = cp->next; cp != NULL; cp = cp->next)
|
|
137
|
+
if (cp->pos == TBL_CELL_SPAN)
|
|
138
|
+
dat->hspans++;
|
|
139
|
+
else
|
|
140
|
+
break;
|
|
141
|
+
|
|
142
|
+
/* Append the new data cell to the data row. */
|
|
143
|
+
|
|
144
|
+
if (dp->last == NULL)
|
|
145
|
+
dp->first = dat;
|
|
146
|
+
else
|
|
147
|
+
dp->last->next = dat;
|
|
148
|
+
dp->last = dat;
|
|
149
|
+
|
|
150
|
+
/* Strip leading and trailing spaces, if requested. */
|
|
151
|
+
|
|
152
|
+
endpos = *pos;
|
|
153
|
+
if (dp->opts->opts & TBL_OPT_NOSPACE) {
|
|
154
|
+
while (p[startpos] == ' ')
|
|
155
|
+
startpos++;
|
|
156
|
+
while (endpos > startpos && p[endpos - 1] == ' ')
|
|
157
|
+
endpos--;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/*
|
|
161
|
+
* Check for a continued-data scope opening. This consists of a
|
|
162
|
+
* trailing `T{' at the end of the line. Subsequent lines,
|
|
163
|
+
* until a standalone `T}', are included in our cell.
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
if (endpos - startpos == 2 &&
|
|
167
|
+
p[startpos] == 'T' && p[startpos + 1] == '{') {
|
|
168
|
+
tbl->part = TBL_PART_CDATA;
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
dat->string = mandoc_strndup(p + startpos, endpos - startpos);
|
|
173
|
+
|
|
174
|
+
if (p[*pos] != '\0')
|
|
175
|
+
(*pos)++;
|
|
176
|
+
|
|
177
|
+
if ( ! strcmp(dat->string, "_"))
|
|
178
|
+
dat->pos = TBL_DATA_HORIZ;
|
|
179
|
+
else if ( ! strcmp(dat->string, "="))
|
|
180
|
+
dat->pos = TBL_DATA_DHORIZ;
|
|
181
|
+
else if ( ! strcmp(dat->string, "\\_"))
|
|
182
|
+
dat->pos = TBL_DATA_NHORIZ;
|
|
183
|
+
else if ( ! strcmp(dat->string, "\\="))
|
|
184
|
+
dat->pos = TBL_DATA_NDHORIZ;
|
|
185
|
+
else
|
|
186
|
+
dat->pos = TBL_DATA_DATA;
|
|
187
|
+
|
|
188
|
+
if ((dat->layout->pos == TBL_CELL_HORIZ ||
|
|
189
|
+
dat->layout->pos == TBL_CELL_DHORIZ ||
|
|
190
|
+
dat->layout->pos == TBL_CELL_DOWN) &&
|
|
191
|
+
dat->pos == TBL_DATA_DATA && *dat->string != '\0')
|
|
192
|
+
mandoc_msg(MANDOCERR_TBLDATA_SPAN,
|
|
193
|
+
ln, startpos, "%s", dat->string);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
void
|
|
197
|
+
tbl_cdata(struct tbl_node *tbl, int ln, const char *p, int pos)
|
|
198
|
+
{
|
|
199
|
+
struct tbl_dat *dat;
|
|
200
|
+
size_t sz;
|
|
201
|
+
|
|
202
|
+
dat = tbl->last_span->last;
|
|
203
|
+
|
|
204
|
+
if (p[pos] == 'T' && p[pos + 1] == '}') {
|
|
205
|
+
pos += 2;
|
|
206
|
+
if (tbl->opts.opts & TBL_OPT_NOSPACE)
|
|
207
|
+
while (p[pos] == ' ')
|
|
208
|
+
pos++;
|
|
209
|
+
if (p[pos] == tbl->opts.tab) {
|
|
210
|
+
tbl->part = TBL_PART_DATA;
|
|
211
|
+
pos++;
|
|
212
|
+
while (p[pos] != '\0')
|
|
213
|
+
getdata(tbl, tbl->last_span, ln, p, &pos);
|
|
214
|
+
return;
|
|
215
|
+
} else if (p[pos] == '\0') {
|
|
216
|
+
tbl->part = TBL_PART_DATA;
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/* Fallthrough: T} is part of a word. */
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
dat->pos = TBL_DATA_DATA;
|
|
224
|
+
dat->block = 1;
|
|
225
|
+
|
|
226
|
+
if (dat->string != NULL) {
|
|
227
|
+
sz = strlen(p + pos) + strlen(dat->string) + 2;
|
|
228
|
+
dat->string = mandoc_realloc(dat->string, sz);
|
|
229
|
+
(void)strlcat(dat->string, " ", sz);
|
|
230
|
+
(void)strlcat(dat->string, p + pos, sz);
|
|
231
|
+
} else
|
|
232
|
+
dat->string = mandoc_strdup(p + pos);
|
|
233
|
+
|
|
234
|
+
if (dat->layout->pos == TBL_CELL_DOWN)
|
|
235
|
+
mandoc_msg(MANDOCERR_TBLDATA_SPAN,
|
|
236
|
+
ln, pos, "%s", dat->string);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
static struct tbl_span *
|
|
240
|
+
newspan(struct tbl_node *tbl, int line, struct tbl_row *rp)
|
|
241
|
+
{
|
|
242
|
+
struct tbl_span *dp;
|
|
243
|
+
|
|
244
|
+
dp = mandoc_calloc(1, sizeof(*dp));
|
|
245
|
+
dp->line = line;
|
|
246
|
+
dp->opts = &tbl->opts;
|
|
247
|
+
dp->layout = rp;
|
|
248
|
+
dp->prev = tbl->last_span;
|
|
249
|
+
|
|
250
|
+
if (dp->prev == NULL) {
|
|
251
|
+
tbl->first_span = dp;
|
|
252
|
+
tbl->current_span = NULL;
|
|
253
|
+
} else
|
|
254
|
+
dp->prev->next = dp;
|
|
255
|
+
tbl->last_span = dp;
|
|
256
|
+
|
|
257
|
+
return dp;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
void
|
|
261
|
+
tbl_data(struct tbl_node *tbl, int ln, const char *p, int pos)
|
|
262
|
+
{
|
|
263
|
+
struct tbl_row *rp;
|
|
264
|
+
struct tbl_cell *cp;
|
|
265
|
+
struct tbl_span *sp;
|
|
266
|
+
|
|
267
|
+
for (sp = tbl->last_span; sp != NULL; sp = sp->prev)
|
|
268
|
+
if (sp->pos == TBL_SPAN_DATA)
|
|
269
|
+
break;
|
|
270
|
+
rp = sp == NULL ? tbl->first_row :
|
|
271
|
+
sp->layout->next == NULL ? sp->layout : sp->layout->next;
|
|
272
|
+
assert(rp != NULL);
|
|
273
|
+
|
|
274
|
+
if (p[1] == '\0') {
|
|
275
|
+
switch (p[0]) {
|
|
276
|
+
case '.':
|
|
277
|
+
/*
|
|
278
|
+
* Empty request lines must be handled here
|
|
279
|
+
* and cannot be discarded in roff_parseln()
|
|
280
|
+
* because in the layout section, they
|
|
281
|
+
* are significant and end the layout.
|
|
282
|
+
*/
|
|
283
|
+
return;
|
|
284
|
+
case '_':
|
|
285
|
+
sp = newspan(tbl, ln, rp);
|
|
286
|
+
sp->pos = TBL_SPAN_HORIZ;
|
|
287
|
+
return;
|
|
288
|
+
case '=':
|
|
289
|
+
sp = newspan(tbl, ln, rp);
|
|
290
|
+
sp->pos = TBL_SPAN_DHORIZ;
|
|
291
|
+
return;
|
|
292
|
+
default:
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/*
|
|
298
|
+
* If the layout row contains nothing but horizontal lines,
|
|
299
|
+
* allocate an empty span for it and assign the current span
|
|
300
|
+
* to the next layout row accepting data.
|
|
301
|
+
*/
|
|
302
|
+
|
|
303
|
+
while (rp->next != NULL) {
|
|
304
|
+
if (rp->last->col + 1 < tbl->opts.cols)
|
|
305
|
+
break;
|
|
306
|
+
for (cp = rp->first; cp != NULL; cp = cp->next)
|
|
307
|
+
if (cp->pos != TBL_CELL_HORIZ &&
|
|
308
|
+
cp->pos != TBL_CELL_DHORIZ)
|
|
309
|
+
break;
|
|
310
|
+
if (cp != NULL)
|
|
311
|
+
break;
|
|
312
|
+
sp = newspan(tbl, ln, rp);
|
|
313
|
+
sp->pos = TBL_SPAN_DATA;
|
|
314
|
+
rp = rp->next;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/* Process a real data row. */
|
|
318
|
+
|
|
319
|
+
sp = newspan(tbl, ln, rp);
|
|
320
|
+
sp->pos = TBL_SPAN_DATA;
|
|
321
|
+
while (p[pos] != '\0')
|
|
322
|
+
getdata(tbl, sp, ln, p, &pos);
|
|
323
|
+
}
|