Print this page
5051 import mdocml-1.12.3
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Approved by: TBD
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mandoc/tbl_data.c
+++ new/usr/src/cmd/mandoc/tbl_data.c
1 -/* $Id: tbl_data.c,v 1.24 2011/03/20 16:02:05 kristaps Exp $ */
1 +/* $Id: tbl_data.c,v 1.27 2013/06/01 04:56:50 schwarze Exp $ */
2 2 /*
3 3 * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 4 * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
5 5 *
6 6 * Permission to use, copy, modify, and distribute this software for any
7 7 * purpose with or without fee is hereby granted, provided that the above
8 8 * copyright notice and this permission notice appear in all copies.
9 9 *
10 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 17 */
18 18 #ifdef HAVE_CONFIG_H
19 19 #include "config.h"
20 20 #endif
21 21
22 22 #include <assert.h>
23 23 #include <ctype.h>
24 24 #include <stdlib.h>
25 25 #include <string.h>
26 26 #include <time.h>
27 27
28 28 #include "mandoc.h"
29 29 #include "libmandoc.h"
30 30 #include "libroff.h"
31 31
32 32 static int data(struct tbl_node *, struct tbl_span *,
33 33 int, const char *, int *);
34 34 static struct tbl_span *newspan(struct tbl_node *, int,
35 35 struct tbl_row *);
36 36
37 37 static int
38 38 data(struct tbl_node *tbl, struct tbl_span *dp,
39 39 int ln, const char *p, int *pos)
40 40 {
41 41 struct tbl_dat *dat;
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
42 42 struct tbl_cell *cp;
43 43 int sv, spans;
44 44
45 45 cp = NULL;
46 46 if (dp->last && dp->last->layout)
47 47 cp = dp->last->layout->next;
48 48 else if (NULL == dp->last)
49 49 cp = dp->layout->first;
50 50
51 51 /*
52 - * Skip over spanners and vertical lines to data formats, since
52 + * Skip over spanners, since
53 53 * we want to match data with data layout cells in the header.
54 54 */
55 55
56 - while (cp && (TBL_CELL_VERT == cp->pos ||
57 - TBL_CELL_DVERT == cp->pos ||
58 - TBL_CELL_SPAN == cp->pos))
56 + while (cp && TBL_CELL_SPAN == cp->pos)
59 57 cp = cp->next;
60 58
61 59 /*
62 60 * Stop processing when we reach the end of the available layout
63 61 * cells. This means that we have extra input.
64 62 */
65 63
66 64 if (NULL == cp) {
67 65 mandoc_msg(MANDOCERR_TBLEXTRADAT,
68 66 tbl->parse, ln, *pos, NULL);
69 67 /* Skip to the end... */
70 68 while (p[*pos])
71 69 (*pos)++;
72 70 return(1);
73 71 }
74 72
75 73 dat = mandoc_calloc(1, sizeof(struct tbl_dat));
76 74 dat->layout = cp;
77 75 dat->pos = TBL_DATA_NONE;
78 76
79 77 assert(TBL_CELL_SPAN != cp->pos);
80 78
81 79 for (spans = 0, cp = cp->next; cp; cp = cp->next)
82 80 if (TBL_CELL_SPAN == cp->pos)
83 81 spans++;
84 82 else
85 83 break;
86 84
87 85 dat->spans = spans;
88 86
89 87 if (dp->last) {
90 88 dp->last->next = dat;
91 89 dp->last = dat;
92 90 } else
93 91 dp->last = dp->first = dat;
94 92
95 93 sv = *pos;
96 94 while (p[*pos] && p[*pos] != tbl->opts.tab)
↓ open down ↓ |
28 lines elided |
↑ open up ↑ |
97 95 (*pos)++;
98 96
99 97 /*
100 98 * Check for a continued-data scope opening. This consists of a
101 99 * trailing `T{' at the end of the line. Subsequent lines,
102 100 * until a standalone `T}', are included in our cell.
103 101 */
104 102
105 103 if (*pos - sv == 2 && 'T' == p[sv] && '{' == p[sv + 1]) {
106 104 tbl->part = TBL_PART_CDATA;
107 - return(0);
105 + return(1);
108 106 }
109 107
110 108 assert(*pos - sv >= 0);
111 109
112 110 dat->string = mandoc_malloc((size_t)(*pos - sv + 1));
113 111 memcpy(dat->string, &p[sv], (size_t)(*pos - sv));
114 112 dat->string[*pos - sv] = '\0';
115 113
116 114 if (p[*pos])
117 115 (*pos)++;
118 116
119 117 if ( ! strcmp(dat->string, "_"))
120 118 dat->pos = TBL_DATA_HORIZ;
121 119 else if ( ! strcmp(dat->string, "="))
122 120 dat->pos = TBL_DATA_DHORIZ;
123 121 else if ( ! strcmp(dat->string, "\\_"))
124 122 dat->pos = TBL_DATA_NHORIZ;
125 123 else if ( ! strcmp(dat->string, "\\="))
126 124 dat->pos = TBL_DATA_NDHORIZ;
127 125 else
128 126 dat->pos = TBL_DATA_DATA;
129 127
130 128 if (TBL_CELL_HORIZ == dat->layout->pos ||
131 129 TBL_CELL_DHORIZ == dat->layout->pos ||
132 130 TBL_CELL_DOWN == dat->layout->pos)
133 131 if (TBL_DATA_DATA == dat->pos && '\0' != *dat->string)
134 132 mandoc_msg(MANDOCERR_TBLIGNDATA,
135 133 tbl->parse, ln, sv, NULL);
136 134
137 135 return(1);
138 136 }
139 137
140 138 /* ARGSUSED */
141 139 int
142 140 tbl_cdata(struct tbl_node *tbl, int ln, const char *p)
143 141 {
144 142 struct tbl_dat *dat;
145 143 size_t sz;
146 144 int pos;
147 145
148 146 pos = 0;
149 147
150 148 dat = tbl->last_span->last;
151 149
152 150 if (p[pos] == 'T' && p[pos + 1] == '}') {
153 151 pos += 2;
154 152 if (p[pos] == tbl->opts.tab) {
155 153 tbl->part = TBL_PART_DATA;
156 154 pos++;
157 155 return(data(tbl, tbl->last_span, ln, p, &pos));
158 156 } else if ('\0' == p[pos]) {
159 157 tbl->part = TBL_PART_DATA;
160 158 return(1);
161 159 }
162 160
163 161 /* Fallthrough: T} is part of a word. */
164 162 }
165 163
166 164 dat->pos = TBL_DATA_DATA;
167 165
168 166 if (dat->string) {
169 167 sz = strlen(p) + strlen(dat->string) + 2;
170 168 dat->string = mandoc_realloc(dat->string, sz);
171 169 strlcat(dat->string, " ", sz);
172 170 strlcat(dat->string, p, sz);
173 171 } else
174 172 dat->string = mandoc_strdup(p);
175 173
176 174 if (TBL_CELL_DOWN == dat->layout->pos)
177 175 mandoc_msg(MANDOCERR_TBLIGNDATA,
178 176 tbl->parse, ln, pos, NULL);
179 177
↓ open down ↓ |
62 lines elided |
↑ open up ↑ |
180 178 return(0);
181 179 }
182 180
183 181 static struct tbl_span *
184 182 newspan(struct tbl_node *tbl, int line, struct tbl_row *rp)
185 183 {
186 184 struct tbl_span *dp;
187 185
188 186 dp = mandoc_calloc(1, sizeof(struct tbl_span));
189 187 dp->line = line;
190 - dp->tbl = &tbl->opts;
188 + dp->opts = &tbl->opts;
191 189 dp->layout = rp;
192 190 dp->head = tbl->first_head;
193 191
194 192 if (tbl->last_span) {
195 193 tbl->last_span->next = dp;
196 194 tbl->last_span = dp;
197 195 } else {
198 196 tbl->last_span = tbl->first_span = dp;
199 197 tbl->current_span = NULL;
200 198 dp->flags |= TBL_SPAN_FIRST;
201 199 }
202 200
203 201 return(dp);
204 202 }
205 203
206 204 int
207 205 tbl_data(struct tbl_node *tbl, int ln, const char *p)
208 206 {
209 207 struct tbl_span *dp;
210 208 struct tbl_row *rp;
211 209 int pos;
212 210
213 211 pos = 0;
214 212
215 213 if ('\0' == p[pos]) {
216 214 mandoc_msg(MANDOCERR_TBL, tbl->parse, ln, pos, NULL);
217 215 return(0);
218 216 }
219 217
220 218 /*
221 219 * Choose a layout row: take the one following the last parsed
222 220 * span's. If that doesn't exist, use the last parsed span's.
223 221 * If there's no last parsed span, use the first row. Lastly,
224 222 * if the last span was a horizontal line, use the same layout
225 223 * (it doesn't "consume" the layout).
226 224 */
227 225
228 226 if (tbl->last_span) {
229 227 assert(tbl->last_span->layout);
230 228 if (tbl->last_span->pos == TBL_SPAN_DATA) {
231 229 for (rp = tbl->last_span->layout->next;
232 230 rp && rp->first; rp = rp->next) {
233 231 switch (rp->first->pos) {
234 232 case (TBL_CELL_HORIZ):
235 233 dp = newspan(tbl, ln, rp);
236 234 dp->pos = TBL_SPAN_HORIZ;
237 235 continue;
238 236 case (TBL_CELL_DHORIZ):
239 237 dp = newspan(tbl, ln, rp);
240 238 dp->pos = TBL_SPAN_DHORIZ;
241 239 continue;
242 240 default:
243 241 break;
244 242 }
245 243 break;
246 244 }
247 245 } else
248 246 rp = tbl->last_span->layout;
249 247
250 248 if (NULL == rp)
251 249 rp = tbl->last_span->layout;
252 250 } else
253 251 rp = tbl->first_row;
254 252
255 253 assert(rp);
256 254
257 255 dp = newspan(tbl, ln, rp);
258 256
259 257 if ( ! strcmp(p, "_")) {
260 258 dp->pos = TBL_SPAN_HORIZ;
261 259 return(1);
262 260 } else if ( ! strcmp(p, "=")) {
263 261 dp->pos = TBL_SPAN_DHORIZ;
264 262 return(1);
265 263 }
266 264
267 265 dp->pos = TBL_SPAN_DATA;
268 266
269 267 /* This returns 0 when TBL_PART_CDATA is entered. */
270 268
271 269 while ('\0' != p[pos])
272 270 if ( ! data(tbl, dp, ln, p, &pos))
273 271 return(0);
274 272
275 273 return(1);
276 274 }
↓ open down ↓ |
76 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX