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/tree.c
+++ new/usr/src/cmd/mandoc/tree.c
1 -/* $Id: tree.c,v 1.47 2011/09/18 14:14:15 schwarze Exp $ */
1 +/* $Id: tree.c,v 1.50 2013/12/24 19:11:46 schwarze Exp $ */
2 2 /*
3 3 * Copyright (c) 2008, 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 + * Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org>
4 5 *
5 6 * Permission to use, copy, modify, and distribute this software for any
6 7 * purpose with or without fee is hereby granted, provided that the above
7 8 * copyright notice and this permission notice appear in all copies.
8 9 *
9 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 17 */
17 18 #ifdef HAVE_CONFIG_H
18 19 #include "config.h"
19 20 #endif
20 21
21 22 #include <assert.h>
22 23 #include <limits.h>
23 24 #include <stdio.h>
24 25 #include <stdlib.h>
25 26 #include <time.h>
26 27
27 28 #include "mandoc.h"
28 29 #include "mdoc.h"
29 30 #include "man.h"
30 31 #include "main.h"
31 32
32 33 static void print_box(const struct eqn_box *, int);
33 34 static void print_man(const struct man_node *, int);
34 35 static void print_mdoc(const struct mdoc_node *, int);
35 36 static void print_span(const struct tbl_span *, int);
36 37
37 38
38 39 /* ARGSUSED */
39 40 void
40 41 tree_mdoc(void *arg, const struct mdoc *mdoc)
41 42 {
42 43
43 44 print_mdoc(mdoc_node(mdoc), 0);
44 45 }
45 46
46 47
47 48 /* ARGSUSED */
48 49 void
49 50 tree_man(void *arg, const struct man *man)
50 51 {
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
51 52
52 53 print_man(man_node(man), 0);
53 54 }
54 55
55 56
56 57 static void
57 58 print_mdoc(const struct mdoc_node *n, int indent)
58 59 {
59 60 const char *p, *t;
60 61 int i, j;
61 - size_t argc, sz;
62 - char **params;
62 + size_t argc;
63 63 struct mdoc_argv *argv;
64 64
65 65 argv = NULL;
66 - argc = sz = 0;
67 - params = NULL;
66 + argc = 0;
68 67 t = p = NULL;
69 68
70 69 switch (n->type) {
71 70 case (MDOC_ROOT):
72 71 t = "root";
73 72 break;
74 73 case (MDOC_BLOCK):
75 74 t = "block";
76 75 break;
77 76 case (MDOC_HEAD):
78 77 t = "block-head";
79 78 break;
80 79 case (MDOC_BODY):
81 80 if (n->end)
82 81 t = "body-end";
83 82 else
84 83 t = "block-body";
85 84 break;
86 85 case (MDOC_TAIL):
87 86 t = "block-tail";
88 87 break;
89 88 case (MDOC_ELEM):
90 89 t = "elem";
91 90 break;
92 91 case (MDOC_TEXT):
93 92 t = "text";
94 93 break;
95 94 case (MDOC_TBL):
96 95 /* FALLTHROUGH */
97 96 case (MDOC_EQN):
98 97 break;
99 98 default:
100 99 abort();
101 100 /* NOTREACHED */
102 101 }
103 102
104 103 switch (n->type) {
105 104 case (MDOC_TEXT):
106 105 p = n->string;
107 106 break;
108 107 case (MDOC_BODY):
109 108 p = mdoc_macronames[n->tok];
110 109 break;
111 110 case (MDOC_HEAD):
112 111 p = mdoc_macronames[n->tok];
113 112 break;
114 113 case (MDOC_TAIL):
115 114 p = mdoc_macronames[n->tok];
116 115 break;
117 116 case (MDOC_ELEM):
118 117 p = mdoc_macronames[n->tok];
119 118 if (n->args) {
120 119 argv = n->args->argv;
121 120 argc = n->args->argc;
122 121 }
123 122 break;
124 123 case (MDOC_BLOCK):
125 124 p = mdoc_macronames[n->tok];
126 125 if (n->args) {
127 126 argv = n->args->argv;
128 127 argc = n->args->argc;
129 128 }
130 129 break;
131 130 case (MDOC_TBL):
132 131 /* FALLTHROUGH */
133 132 case (MDOC_EQN):
134 133 break;
135 134 case (MDOC_ROOT):
136 135 p = "root";
137 136 break;
138 137 default:
139 138 abort();
140 139 /* NOTREACHED */
141 140 }
142 141
143 142 if (n->span) {
144 143 assert(NULL == p && NULL == t);
145 144 print_span(n->span, indent);
146 145 } else if (n->eqn) {
147 146 assert(NULL == p && NULL == t);
148 147 print_box(n->eqn->root, indent);
149 148 } else {
150 149 for (i = 0; i < indent; i++)
151 150 putchar('\t');
152 151
153 152 printf("%s (%s)", p, t);
↓ open down ↓ |
76 lines elided |
↑ open up ↑ |
154 153
155 154 for (i = 0; i < (int)argc; i++) {
156 155 printf(" -%s", mdoc_argnames[argv[i].arg]);
157 156 if (argv[i].sz > 0)
158 157 printf(" [");
159 158 for (j = 0; j < (int)argv[i].sz; j++)
160 159 printf(" [%s]", argv[i].value[j]);
161 160 if (argv[i].sz > 0)
162 161 printf(" ]");
163 162 }
164 -
165 - for (i = 0; i < (int)sz; i++)
166 - printf(" [%s]", params[i]);
167 163
168 - printf(" %d:%d\n", n->line, n->pos);
164 + putchar(' ');
165 + if (MDOC_LINE & n->flags)
166 + putchar('*');
167 + printf("%d:%d", n->line, n->pos);
168 + if (n->lastline != n->line)
169 + printf("-%d", n->lastline);
170 + putchar('\n');
169 171 }
170 172
171 173 if (n->child)
172 174 print_mdoc(n->child, indent + 1);
173 175 if (n->next)
174 176 print_mdoc(n->next, indent);
175 177 }
176 178
177 179
178 180 static void
179 181 print_man(const struct man_node *n, int indent)
180 182 {
181 183 const char *p, *t;
182 184 int i;
183 185
184 186 t = p = NULL;
185 187
186 188 switch (n->type) {
187 189 case (MAN_ROOT):
188 190 t = "root";
189 191 break;
190 192 case (MAN_ELEM):
191 193 t = "elem";
192 194 break;
193 195 case (MAN_TEXT):
194 196 t = "text";
195 197 break;
196 198 case (MAN_BLOCK):
197 199 t = "block";
198 200 break;
199 201 case (MAN_HEAD):
200 202 t = "block-head";
201 203 break;
202 204 case (MAN_BODY):
203 205 t = "block-body";
204 206 break;
205 207 case (MAN_TAIL):
206 208 t = "block-tail";
207 209 break;
208 210 case (MAN_TBL):
209 211 /* FALLTHROUGH */
210 212 case (MAN_EQN):
211 213 break;
212 214 default:
213 215 abort();
214 216 /* NOTREACHED */
215 217 }
216 218
217 219 switch (n->type) {
218 220 case (MAN_TEXT):
219 221 p = n->string;
220 222 break;
221 223 case (MAN_ELEM):
222 224 /* FALLTHROUGH */
223 225 case (MAN_BLOCK):
224 226 /* FALLTHROUGH */
225 227 case (MAN_HEAD):
226 228 /* FALLTHROUGH */
227 229 case (MAN_TAIL):
228 230 /* FALLTHROUGH */
229 231 case (MAN_BODY):
230 232 p = man_macronames[n->tok];
231 233 break;
232 234 case (MAN_ROOT):
233 235 p = "root";
234 236 break;
235 237 case (MAN_TBL):
236 238 /* FALLTHROUGH */
237 239 case (MAN_EQN):
238 240 break;
239 241 default:
240 242 abort();
241 243 /* NOTREACHED */
242 244 }
243 245
244 246 if (n->span) {
245 247 assert(NULL == p && NULL == t);
246 248 print_span(n->span, indent);
247 249 } else if (n->eqn) {
248 250 assert(NULL == p && NULL == t);
249 251 print_box(n->eqn->root, indent);
250 252 } else {
251 253 for (i = 0; i < indent; i++)
252 254 putchar('\t');
253 255 printf("%s (%s) %d:%d\n", p, t, n->line, n->pos);
254 256 }
255 257
256 258 if (n->child)
257 259 print_man(n->child, indent + 1);
258 260 if (n->next)
259 261 print_man(n->next, indent);
260 262 }
261 263
262 264 static void
263 265 print_box(const struct eqn_box *ep, int indent)
264 266 {
265 267 int i;
266 268 const char *t;
267 269
268 270 if (NULL == ep)
269 271 return;
270 272 for (i = 0; i < indent; i++)
271 273 putchar('\t');
272 274
273 275 t = NULL;
274 276 switch (ep->type) {
275 277 case (EQN_ROOT):
276 278 t = "eqn-root";
277 279 break;
278 280 case (EQN_LIST):
279 281 t = "eqn-list";
280 282 break;
281 283 case (EQN_SUBEXPR):
282 284 t = "eqn-expr";
283 285 break;
284 286 case (EQN_TEXT):
285 287 t = "eqn-text";
286 288 break;
287 289 case (EQN_MATRIX):
288 290 t = "eqn-matrix";
289 291 break;
290 292 }
291 293
292 294 assert(t);
293 295 printf("%s(%d, %d, %d, %d, %d, \"%s\", \"%s\") %s\n",
294 296 t, EQN_DEFSIZE == ep->size ? 0 : ep->size,
295 297 ep->pos, ep->font, ep->mark, ep->pile,
296 298 ep->left ? ep->left : "",
297 299 ep->right ? ep->right : "",
298 300 ep->text ? ep->text : "");
299 301
300 302 print_box(ep->first, indent + 1);
301 303 print_box(ep->next, indent);
302 304 }
303 305
304 306 static void
305 307 print_span(const struct tbl_span *sp, int indent)
306 308 {
307 309 const struct tbl_dat *dp;
308 310 int i;
309 311
310 312 for (i = 0; i < indent; i++)
311 313 putchar('\t');
312 314
313 315 switch (sp->pos) {
314 316 case (TBL_SPAN_HORIZ):
315 317 putchar('-');
316 318 return;
317 319 case (TBL_SPAN_DHORIZ):
318 320 putchar('=');
319 321 return;
320 322 default:
321 323 break;
322 324 }
323 325
324 326 for (dp = sp->first; dp; dp = dp->next) {
325 327 switch (dp->pos) {
326 328 case (TBL_DATA_HORIZ):
327 329 /* FALLTHROUGH */
328 330 case (TBL_DATA_NHORIZ):
329 331 putchar('-');
330 332 continue;
331 333 case (TBL_DATA_DHORIZ):
332 334 /* FALLTHROUGH */
333 335 case (TBL_DATA_NDHORIZ):
334 336 putchar('=');
335 337 continue;
336 338 default:
337 339 break;
338 340 }
339 341 printf("[\"%s\"", dp->string ? dp->string : "");
340 342 if (dp->spans)
341 343 printf("(%d)", dp->spans);
342 344 if (NULL == dp->layout)
343 345 putchar('*');
344 346 putchar(']');
345 347 putchar(' ');
346 348 }
347 349
348 350 printf("(tbl) %d:1\n", sp->line);
349 351 }
↓ open down ↓ |
171 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX