Print this page
9718 update mandoc to 1.14.4
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mandoc/tree.c
+++ new/usr/src/cmd/mandoc/tree.c
1 -/* $Id: tree.c,v 1.77 2017/07/08 14:51:05 schwarze Exp $ */
1 +/* $Id: tree.c,v 1.78 2018/04/11 17:11:13 schwarze Exp $ */
2 2 /*
3 3 * Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 - * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
4 + * Copyright (c) 2013,2014,2015,2017,2018 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 AUTHORS DISCLAIM ALL WARRANTIES
11 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 #include "config.h"
19 19
20 20 #include <sys/types.h>
21 21
22 22 #include <assert.h>
23 23 #include <limits.h>
24 24 #include <stdio.h>
25 25 #include <stdlib.h>
26 26 #include <time.h>
27 27
28 28 #include "mandoc.h"
29 29 #include "roff.h"
30 30 #include "mdoc.h"
31 31 #include "man.h"
32 32 #include "main.h"
33 33
34 34 static void print_box(const struct eqn_box *, int);
35 35 static void print_man(const struct roff_node *, int);
36 36 static void print_meta(const struct roff_meta *);
37 37 static void print_mdoc(const struct roff_node *, int);
38 38 static void print_span(const struct tbl_span *, int);
39 39
40 40
41 41 void
42 42 tree_mdoc(void *arg, const struct roff_man *mdoc)
43 43 {
44 44 print_meta(&mdoc->meta);
45 45 putchar('\n');
46 46 print_mdoc(mdoc->first->child, 0);
47 47 }
48 48
49 49 void
50 50 tree_man(void *arg, const struct roff_man *man)
51 51 {
52 52 print_meta(&man->meta);
53 53 if (man->meta.hasbody == 0)
54 54 puts("body = empty");
55 55 putchar('\n');
56 56 print_man(man->first->child, 0);
57 57 }
58 58
59 59 static void
60 60 print_meta(const struct roff_meta *meta)
61 61 {
62 62 if (meta->title != NULL)
63 63 printf("title = \"%s\"\n", meta->title);
64 64 if (meta->name != NULL)
65 65 printf("name = \"%s\"\n", meta->name);
66 66 if (meta->msec != NULL)
67 67 printf("sec = \"%s\"\n", meta->msec);
68 68 if (meta->vol != NULL)
69 69 printf("vol = \"%s\"\n", meta->vol);
70 70 if (meta->arch != NULL)
71 71 printf("arch = \"%s\"\n", meta->arch);
72 72 if (meta->os != NULL)
73 73 printf("os = \"%s\"\n", meta->os);
74 74 if (meta->date != NULL)
75 75 printf("date = \"%s\"\n", meta->date);
76 76 }
77 77
78 78 static void
79 79 print_mdoc(const struct roff_node *n, int indent)
80 80 {
81 81 const char *p, *t;
82 82 int i, j;
83 83 size_t argc;
84 84 struct mdoc_argv *argv;
85 85
86 86 if (n == NULL)
87 87 return;
88 88
89 89 argv = NULL;
90 90 argc = 0;
91 91 t = p = NULL;
92 92
93 93 switch (n->type) {
94 94 case ROFFT_ROOT:
95 95 t = "root";
96 96 break;
97 97 case ROFFT_BLOCK:
98 98 t = "block";
99 99 break;
100 100 case ROFFT_HEAD:
101 101 t = "head";
102 102 break;
103 103 case ROFFT_BODY:
104 104 if (n->end)
105 105 t = "body-end";
106 106 else
107 107 t = "body";
↓ open down ↓ |
93 lines elided |
↑ open up ↑ |
108 108 break;
109 109 case ROFFT_TAIL:
110 110 t = "tail";
111 111 break;
112 112 case ROFFT_ELEM:
113 113 t = "elem";
114 114 break;
115 115 case ROFFT_TEXT:
116 116 t = "text";
117 117 break;
118 + case ROFFT_COMMENT:
119 + t = "comment";
120 + break;
118 121 case ROFFT_TBL:
119 122 break;
120 123 case ROFFT_EQN:
121 124 t = "eqn";
122 125 break;
123 126 default:
124 127 abort();
125 128 }
126 129
127 130 switch (n->type) {
128 131 case ROFFT_TEXT:
132 + case ROFFT_COMMENT:
129 133 p = n->string;
130 134 break;
131 135 case ROFFT_BODY:
132 136 p = roff_name[n->tok];
133 137 break;
134 138 case ROFFT_HEAD:
135 139 p = roff_name[n->tok];
136 140 break;
137 141 case ROFFT_TAIL:
138 142 p = roff_name[n->tok];
139 143 break;
140 144 case ROFFT_ELEM:
141 145 p = roff_name[n->tok];
142 146 if (n->args) {
143 147 argv = n->args->argv;
144 148 argc = n->args->argc;
145 149 }
146 150 break;
147 151 case ROFFT_BLOCK:
148 152 p = roff_name[n->tok];
149 153 if (n->args) {
150 154 argv = n->args->argv;
151 155 argc = n->args->argc;
152 156 }
153 157 break;
154 158 case ROFFT_TBL:
155 159 break;
156 160 case ROFFT_EQN:
157 161 p = "EQ";
158 162 break;
159 163 case ROFFT_ROOT:
160 164 p = "root";
161 165 break;
162 166 default:
163 167 abort();
164 168 }
165 169
166 170 if (n->span) {
167 171 assert(NULL == p && NULL == t);
168 172 print_span(n->span, indent);
169 173 } else {
170 174 for (i = 0; i < indent; i++)
171 175 putchar(' ');
172 176
173 177 printf("%s (%s)", p, t);
174 178
175 179 for (i = 0; i < (int)argc; i++) {
176 180 printf(" -%s", mdoc_argnames[argv[i].arg]);
177 181 if (argv[i].sz > 0)
178 182 printf(" [");
179 183 for (j = 0; j < (int)argv[i].sz; j++)
180 184 printf(" [%s]", argv[i].value[j]);
181 185 if (argv[i].sz > 0)
182 186 printf(" ]");
183 187 }
184 188
185 189 putchar(' ');
186 190 if (NODE_DELIMO & n->flags)
187 191 putchar('(');
188 192 if (NODE_LINE & n->flags)
189 193 putchar('*');
190 194 printf("%d:%d", n->line, n->pos + 1);
191 195 if (NODE_DELIMC & n->flags)
192 196 putchar(')');
193 197 if (NODE_EOS & n->flags)
194 198 putchar('.');
195 199 if (NODE_BROKEN & n->flags)
196 200 printf(" BROKEN");
197 201 if (NODE_NOSRC & n->flags)
198 202 printf(" NOSRC");
199 203 if (NODE_NOPRT & n->flags)
200 204 printf(" NOPRT");
201 205 putchar('\n');
202 206 }
203 207
204 208 if (n->eqn)
205 209 print_box(n->eqn->first, indent + 4);
206 210 if (n->child)
207 211 print_mdoc(n->child, indent +
208 212 (n->type == ROFFT_BLOCK ? 2 : 4));
209 213 if (n->next)
210 214 print_mdoc(n->next, indent);
211 215 }
212 216
213 217 static void
214 218 print_man(const struct roff_node *n, int indent)
215 219 {
216 220 const char *p, *t;
217 221 int i;
218 222
219 223 if (n == NULL)
220 224 return;
221 225
222 226 t = p = NULL;
223 227
↓ open down ↓ |
85 lines elided |
↑ open up ↑ |
224 228 switch (n->type) {
225 229 case ROFFT_ROOT:
226 230 t = "root";
227 231 break;
228 232 case ROFFT_ELEM:
229 233 t = "elem";
230 234 break;
231 235 case ROFFT_TEXT:
232 236 t = "text";
233 237 break;
238 + case ROFFT_COMMENT:
239 + t = "comment";
240 + break;
234 241 case ROFFT_BLOCK:
235 242 t = "block";
236 243 break;
237 244 case ROFFT_HEAD:
238 245 t = "head";
239 246 break;
240 247 case ROFFT_BODY:
241 248 t = "body";
242 249 break;
243 250 case ROFFT_TBL:
244 251 break;
245 252 case ROFFT_EQN:
246 253 t = "eqn";
247 254 break;
248 255 default:
249 256 abort();
250 257 }
251 258
252 259 switch (n->type) {
253 260 case ROFFT_TEXT:
261 + case ROFFT_COMMENT:
254 262 p = n->string;
255 263 break;
256 264 case ROFFT_ELEM:
257 265 case ROFFT_BLOCK:
258 266 case ROFFT_HEAD:
259 267 case ROFFT_BODY:
260 268 p = roff_name[n->tok];
261 269 break;
262 270 case ROFFT_ROOT:
263 271 p = "root";
264 272 break;
265 273 case ROFFT_TBL:
266 274 break;
267 275 case ROFFT_EQN:
268 276 p = "EQ";
269 277 break;
270 278 default:
271 279 abort();
272 280 }
273 281
274 282 if (n->span) {
275 283 assert(NULL == p && NULL == t);
276 284 print_span(n->span, indent);
277 285 } else {
278 286 for (i = 0; i < indent; i++)
279 287 putchar(' ');
280 288 printf("%s (%s) ", p, t);
281 289 if (NODE_LINE & n->flags)
282 290 putchar('*');
283 291 printf("%d:%d", n->line, n->pos + 1);
284 292 if (NODE_EOS & n->flags)
285 293 putchar('.');
286 294 putchar('\n');
287 295 }
288 296
289 297 if (n->eqn)
290 298 print_box(n->eqn->first, indent + 4);
291 299 if (n->child)
292 300 print_man(n->child, indent +
293 301 (n->type == ROFFT_BLOCK ? 2 : 4));
294 302 if (n->next)
295 303 print_man(n->next, indent);
296 304 }
297 305
298 306 static void
299 307 print_box(const struct eqn_box *ep, int indent)
300 308 {
301 309 int i;
302 310 const char *t;
303 311
304 312 static const char *posnames[] = {
305 313 NULL, "sup", "subsup", "sub",
306 314 "to", "from", "fromto",
307 315 "over", "sqrt", NULL };
308 316
309 317 if (NULL == ep)
310 318 return;
311 319 for (i = 0; i < indent; i++)
312 320 putchar(' ');
313 321
314 322 t = NULL;
315 323 switch (ep->type) {
316 324 case EQN_LIST:
317 325 t = "eqn-list";
318 326 break;
319 327 case EQN_SUBEXPR:
320 328 t = "eqn-expr";
321 329 break;
322 330 case EQN_TEXT:
323 331 t = "eqn-text";
324 332 break;
325 333 case EQN_PILE:
326 334 t = "eqn-pile";
327 335 break;
328 336 case EQN_MATRIX:
329 337 t = "eqn-matrix";
330 338 break;
331 339 }
332 340
333 341 fputs(t, stdout);
334 342 if (ep->pos)
335 343 printf(" pos=%s", posnames[ep->pos]);
336 344 if (ep->left)
337 345 printf(" left=\"%s\"", ep->left);
338 346 if (ep->right)
339 347 printf(" right=\"%s\"", ep->right);
340 348 if (ep->top)
341 349 printf(" top=\"%s\"", ep->top);
342 350 if (ep->bottom)
343 351 printf(" bottom=\"%s\"", ep->bottom);
344 352 if (ep->text)
345 353 printf(" text=\"%s\"", ep->text);
346 354 if (ep->font)
347 355 printf(" font=%d", ep->font);
348 356 if (ep->size != EQN_DEFSIZE)
349 357 printf(" size=%d", ep->size);
350 358 if (ep->expectargs != UINT_MAX && ep->expectargs != ep->args)
351 359 printf(" badargs=%zu(%zu)", ep->args, ep->expectargs);
352 360 else if (ep->args)
353 361 printf(" args=%zu", ep->args);
354 362 putchar('\n');
355 363
356 364 print_box(ep->first, indent + 4);
357 365 print_box(ep->next, indent);
358 366 }
359 367
360 368 static void
361 369 print_span(const struct tbl_span *sp, int indent)
362 370 {
363 371 const struct tbl_dat *dp;
364 372 int i;
365 373
366 374 for (i = 0; i < indent; i++)
367 375 putchar(' ');
368 376
369 377 switch (sp->pos) {
370 378 case TBL_SPAN_HORIZ:
371 379 putchar('-');
372 380 return;
373 381 case TBL_SPAN_DHORIZ:
374 382 putchar('=');
375 383 return;
376 384 default:
377 385 break;
378 386 }
379 387
380 388 for (dp = sp->first; dp; dp = dp->next) {
381 389 switch (dp->pos) {
382 390 case TBL_DATA_HORIZ:
383 391 case TBL_DATA_NHORIZ:
384 392 putchar('-');
385 393 continue;
386 394 case TBL_DATA_DHORIZ:
387 395 case TBL_DATA_NDHORIZ:
388 396 putchar('=');
389 397 continue;
390 398 default:
391 399 break;
392 400 }
393 401 printf("[\"%s\"", dp->string ? dp->string : "");
394 402 if (dp->spans)
395 403 printf("(%d)", dp->spans);
396 404 if (NULL == dp->layout)
397 405 putchar('*');
398 406 putchar(']');
399 407 putchar(' ');
400 408 }
401 409
402 410 printf("(tbl) %d:1\n", sp->line);
403 411 }
↓ open down ↓ |
140 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX