]> git.cameronkatri.com Git - mandoc.git/blob - mdoc.c
1184c641415f18f41455be0aba3f884f528de591
[mandoc.git] / mdoc.c
1 /* $Id: mdoc.c,v 1.151 2010/06/27 16:36:22 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
4 *
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.
8 *
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.
16 */
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include <sys/types.h>
22
23 #include <assert.h>
24 #include <ctype.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <time.h>
30
31 #include "mandoc.h"
32 #include "regs.h"
33 #include "libmdoc.h"
34 #include "libmandoc.h"
35
36 const char *const __mdoc_macronames[MDOC_MAX] = {
37 "Ap", "Dd", "Dt", "Os",
38 "Sh", "Ss", "Pp", "D1",
39 "Dl", "Bd", "Ed", "Bl",
40 "El", "It", "Ad", "An",
41 "Ar", "Cd", "Cm", "Dv",
42 "Er", "Ev", "Ex", "Fa",
43 "Fd", "Fl", "Fn", "Ft",
44 "Ic", "In", "Li", "Nd",
45 "Nm", "Op", "Ot", "Pa",
46 "Rv", "St", "Va", "Vt",
47 /* LINTED */
48 "Xr", "%A", "%B", "%D",
49 /* LINTED */
50 "%I", "%J", "%N", "%O",
51 /* LINTED */
52 "%P", "%R", "%T", "%V",
53 "Ac", "Ao", "Aq", "At",
54 "Bc", "Bf", "Bo", "Bq",
55 "Bsx", "Bx", "Db", "Dc",
56 "Do", "Dq", "Ec", "Ef",
57 "Em", "Eo", "Fx", "Ms",
58 "No", "Ns", "Nx", "Ox",
59 "Pc", "Pf", "Po", "Pq",
60 "Qc", "Ql", "Qo", "Qq",
61 "Re", "Rs", "Sc", "So",
62 "Sq", "Sm", "Sx", "Sy",
63 "Tn", "Ux", "Xc", "Xo",
64 "Fo", "Fc", "Oo", "Oc",
65 "Bk", "Ek", "Bt", "Hf",
66 "Fr", "Ud", "Lb", "Lp",
67 "Lk", "Mt", "Brq", "Bro",
68 /* LINTED */
69 "Brc", "%C", "Es", "En",
70 /* LINTED */
71 "Dx", "%Q", "br", "sp",
72 /* LINTED */
73 "%U", "Ta"
74 };
75
76 const char *const __mdoc_argnames[MDOC_ARG_MAX] = {
77 "split", "nosplit", "ragged",
78 "unfilled", "literal", "file",
79 "offset", "bullet", "dash",
80 "hyphen", "item", "enum",
81 "tag", "diag", "hang",
82 "ohang", "inset", "column",
83 "width", "compact", "std",
84 "filled", "words", "emphasis",
85 "symbolic", "nested", "centered"
86 };
87
88 const char * const *mdoc_macronames = __mdoc_macronames;
89 const char * const *mdoc_argnames = __mdoc_argnames;
90
91 static void mdoc_node_free(struct mdoc_node *);
92 static void mdoc_node_unlink(struct mdoc *,
93 struct mdoc_node *);
94 static void mdoc_free1(struct mdoc *);
95 static void mdoc_alloc1(struct mdoc *);
96 static struct mdoc_node *node_alloc(struct mdoc *, int, int,
97 enum mdoct, enum mdoc_type);
98 static int node_append(struct mdoc *,
99 struct mdoc_node *);
100 static int mdoc_ptext(struct mdoc *, int, char *, int);
101 static int mdoc_pmacro(struct mdoc *, int, char *, int);
102 static int macrowarn(struct mdoc *, int,
103 const char *, int);
104
105
106 const struct mdoc_node *
107 mdoc_node(const struct mdoc *m)
108 {
109
110 return(MDOC_HALT & m->flags ? NULL : m->first);
111 }
112
113
114 const struct mdoc_meta *
115 mdoc_meta(const struct mdoc *m)
116 {
117
118 return(MDOC_HALT & m->flags ? NULL : &m->meta);
119 }
120
121
122 /*
123 * Frees volatile resources (parse tree, meta-data, fields).
124 */
125 static void
126 mdoc_free1(struct mdoc *mdoc)
127 {
128
129 if (mdoc->first)
130 mdoc_node_delete(mdoc, mdoc->first);
131 if (mdoc->meta.title)
132 free(mdoc->meta.title);
133 if (mdoc->meta.os)
134 free(mdoc->meta.os);
135 if (mdoc->meta.name)
136 free(mdoc->meta.name);
137 if (mdoc->meta.arch)
138 free(mdoc->meta.arch);
139 if (mdoc->meta.vol)
140 free(mdoc->meta.vol);
141 if (mdoc->meta.msec)
142 free(mdoc->meta.msec);
143 }
144
145
146 /*
147 * Allocate all volatile resources (parse tree, meta-data, fields).
148 */
149 static void
150 mdoc_alloc1(struct mdoc *mdoc)
151 {
152
153 memset(&mdoc->meta, 0, sizeof(struct mdoc_meta));
154 mdoc->flags = 0;
155 mdoc->lastnamed = mdoc->lastsec = SEC_NONE;
156 mdoc->last = mandoc_calloc(1, sizeof(struct mdoc_node));
157 mdoc->first = mdoc->last;
158 mdoc->last->type = MDOC_ROOT;
159 mdoc->next = MDOC_NEXT_CHILD;
160 }
161
162
163 /*
164 * Free up volatile resources (see mdoc_free1()) then re-initialises the
165 * data with mdoc_alloc1(). After invocation, parse data has been reset
166 * and the parser is ready for re-invocation on a new tree; however,
167 * cross-parse non-volatile data is kept intact.
168 */
169 void
170 mdoc_reset(struct mdoc *mdoc)
171 {
172
173 mdoc_free1(mdoc);
174 mdoc_alloc1(mdoc);
175 }
176
177
178 /*
179 * Completely free up all volatile and non-volatile parse resources.
180 * After invocation, the pointer is no longer usable.
181 */
182 void
183 mdoc_free(struct mdoc *mdoc)
184 {
185
186 mdoc_free1(mdoc);
187 free(mdoc);
188 }
189
190
191 /*
192 * Allocate volatile and non-volatile parse resources.
193 */
194 struct mdoc *
195 mdoc_alloc(struct regset *regs, void *data,
196 int pflags, mandocmsg msg)
197 {
198 struct mdoc *p;
199
200 p = mandoc_calloc(1, sizeof(struct mdoc));
201
202 p->msg = msg;
203 p->data = data;
204 p->pflags = pflags;
205 p->regs = regs;
206
207 mdoc_hash_init();
208 mdoc_alloc1(p);
209 return(p);
210 }
211
212
213 /*
214 * Climb back up the parse tree, validating open scopes. Mostly calls
215 * through to macro_end() in macro.c.
216 */
217 int
218 mdoc_endparse(struct mdoc *m)
219 {
220
221 if (MDOC_HALT & m->flags)
222 return(0);
223 else if (mdoc_macroend(m))
224 return(1);
225 m->flags |= MDOC_HALT;
226 return(0);
227 }
228
229
230 /*
231 * Main parse routine. Parses a single line -- really just hands off to
232 * the macro (mdoc_pmacro()) or text parser (mdoc_ptext()).
233 */
234 int
235 mdoc_parseln(struct mdoc *m, int ln, char *buf, int offs)
236 {
237
238 if (MDOC_HALT & m->flags)
239 return(0);
240
241 m->flags |= MDOC_NEWLINE;
242 return(('.' == buf[offs] || '\'' == buf[offs]) ?
243 mdoc_pmacro(m, ln, buf, offs) :
244 mdoc_ptext(m, ln, buf, offs));
245 }
246
247
248 int
249 mdoc_vmsg(struct mdoc *mdoc, enum mandocerr t,
250 int ln, int pos, const char *fmt, ...)
251 {
252 char buf[256];
253 va_list ap;
254
255 va_start(ap, fmt);
256 vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
257 va_end(ap);
258
259 return((*mdoc->msg)(t, mdoc->data, ln, pos, buf));
260 }
261
262
263 int
264 mdoc_macro(MACRO_PROT_ARGS)
265 {
266 assert(tok < MDOC_MAX);
267
268 /* If we're in the body, deny prologue calls. */
269
270 if (MDOC_PROLOGUE & mdoc_macros[tok].flags &&
271 MDOC_PBODY & m->flags)
272 return(mdoc_pmsg(m, line, ppos, MANDOCERR_BADBODY));
273
274 /* If we're in the prologue, deny "body" macros. */
275
276 if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) &&
277 ! (MDOC_PBODY & m->flags)) {
278 if ( ! mdoc_pmsg(m, line, ppos, MANDOCERR_BADPROLOG))
279 return(0);
280 if (NULL == m->meta.title)
281 m->meta.title = mandoc_strdup("UNKNOWN");
282 if (NULL == m->meta.vol)
283 m->meta.vol = mandoc_strdup("LOCAL");
284 if (NULL == m->meta.os)
285 m->meta.os = mandoc_strdup("LOCAL");
286 if (0 == m->meta.date)
287 m->meta.date = time(NULL);
288 m->flags |= MDOC_PBODY;
289 }
290
291 return((*mdoc_macros[tok].fp)(m, tok, line, ppos, pos, buf));
292 }
293
294
295 static int
296 node_append(struct mdoc *mdoc, struct mdoc_node *p)
297 {
298
299 assert(mdoc->last);
300 assert(mdoc->first);
301 assert(MDOC_ROOT != p->type);
302
303 switch (mdoc->next) {
304 case (MDOC_NEXT_SIBLING):
305 mdoc->last->next = p;
306 p->prev = mdoc->last;
307 p->parent = mdoc->last->parent;
308 break;
309 case (MDOC_NEXT_CHILD):
310 mdoc->last->child = p;
311 p->parent = mdoc->last;
312 break;
313 default:
314 abort();
315 /* NOTREACHED */
316 }
317
318 p->parent->nchild++;
319
320 if ( ! mdoc_valid_pre(mdoc, p))
321 return(0);
322 if ( ! mdoc_action_pre(mdoc, p))
323 return(0);
324
325 switch (p->type) {
326 case (MDOC_HEAD):
327 assert(MDOC_BLOCK == p->parent->type);
328 p->parent->head = p;
329 break;
330 case (MDOC_TAIL):
331 assert(MDOC_BLOCK == p->parent->type);
332 p->parent->tail = p;
333 break;
334 case (MDOC_BODY):
335 assert(MDOC_BLOCK == p->parent->type);
336 p->parent->body = p;
337 break;
338 default:
339 break;
340 }
341
342 mdoc->last = p;
343
344 switch (p->type) {
345 case (MDOC_TEXT):
346 if ( ! mdoc_valid_post(mdoc))
347 return(0);
348 if ( ! mdoc_action_post(mdoc))
349 return(0);
350 break;
351 default:
352 break;
353 }
354
355 return(1);
356 }
357
358
359 static struct mdoc_node *
360 node_alloc(struct mdoc *m, int line, int pos,
361 enum mdoct tok, enum mdoc_type type)
362 {
363 struct mdoc_node *p;
364
365 p = mandoc_calloc(1, sizeof(struct mdoc_node));
366 p->sec = m->lastsec;
367 p->line = line;
368 p->pos = pos;
369 p->tok = tok;
370 p->type = type;
371
372 /* Flag analysis. */
373
374 if (MDOC_NEWLINE & m->flags)
375 p->flags |= MDOC_LINE;
376 m->flags &= ~MDOC_NEWLINE;
377
378 /* Section analysis. */
379
380 if (SEC_SYNOPSIS == p->sec)
381 p->flags |= MDOC_SYNPRETTY;
382
383 /* Register analysis. */
384
385 if (m->regs->regs[(int)REG_nS].set) {
386 if (m->regs->regs[(int)REG_nS].v.u)
387 p->flags |= MDOC_SYNPRETTY;
388 else
389 p->flags &= ~MDOC_SYNPRETTY;
390 }
391
392 return(p);
393 }
394
395
396 int
397 mdoc_tail_alloc(struct mdoc *m, int line, int pos, enum mdoct tok)
398 {
399 struct mdoc_node *p;
400
401 p = node_alloc(m, line, pos, tok, MDOC_TAIL);
402 if ( ! node_append(m, p))
403 return(0);
404 m->next = MDOC_NEXT_CHILD;
405 return(1);
406 }
407
408
409 int
410 mdoc_head_alloc(struct mdoc *m, int line, int pos, enum mdoct tok)
411 {
412 struct mdoc_node *p;
413
414 assert(m->first);
415 assert(m->last);
416
417 p = node_alloc(m, line, pos, tok, MDOC_HEAD);
418 if ( ! node_append(m, p))
419 return(0);
420 m->next = MDOC_NEXT_CHILD;
421 return(1);
422 }
423
424
425 int
426 mdoc_body_alloc(struct mdoc *m, int line, int pos, enum mdoct tok)
427 {
428 struct mdoc_node *p;
429
430 p = node_alloc(m, line, pos, tok, MDOC_BODY);
431 if ( ! node_append(m, p))
432 return(0);
433 m->next = MDOC_NEXT_CHILD;
434 return(1);
435 }
436
437
438 int
439 mdoc_block_alloc(struct mdoc *m, int line, int pos,
440 enum mdoct tok, struct mdoc_arg *args)
441 {
442 struct mdoc_node *p;
443
444 p = node_alloc(m, line, pos, tok, MDOC_BLOCK);
445 p->args = args;
446 if (p->args)
447 (args->refcnt)++;
448 if ( ! node_append(m, p))
449 return(0);
450 m->next = MDOC_NEXT_CHILD;
451 return(1);
452 }
453
454
455 int
456 mdoc_elem_alloc(struct mdoc *m, int line, int pos,
457 enum mdoct tok, struct mdoc_arg *args)
458 {
459 struct mdoc_node *p;
460
461 p = node_alloc(m, line, pos, tok, MDOC_ELEM);
462 p->args = args;
463 if (p->args)
464 (args->refcnt)++;
465 if ( ! node_append(m, p))
466 return(0);
467 m->next = MDOC_NEXT_CHILD;
468 return(1);
469 }
470
471
472 int
473 mdoc_word_alloc(struct mdoc *m, int line, int pos, const char *p)
474 {
475 struct mdoc_node *n;
476 size_t sv, len;
477
478 len = strlen(p);
479
480 n = node_alloc(m, line, pos, MDOC_MAX, MDOC_TEXT);
481 n->string = mandoc_malloc(len + 1);
482 sv = strlcpy(n->string, p, len + 1);
483
484 /* Prohibit truncation. */
485 assert(sv < len + 1);
486
487 if ( ! node_append(m, n))
488 return(0);
489
490 m->next = MDOC_NEXT_SIBLING;
491 return(1);
492 }
493
494
495 void
496 mdoc_node_free(struct mdoc_node *p)
497 {
498
499 if (p->string)
500 free(p->string);
501 if (p->args)
502 mdoc_argv_free(p->args);
503 free(p);
504 }
505
506
507 static void
508 mdoc_node_unlink(struct mdoc *m, struct mdoc_node *n)
509 {
510
511 /* Adjust siblings. */
512
513 if (n->prev)
514 n->prev->next = n->next;
515 if (n->next)
516 n->next->prev = n->prev;
517
518 /* Adjust parent. */
519
520 if (n->parent) {
521 n->parent->nchild--;
522 if (n->parent->child == n)
523 n->parent->child = n->prev ? n->prev : n->next;
524 }
525
526 /* Adjust parse point, if applicable. */
527
528 if (m && m->last == n) {
529 if (n->prev) {
530 m->last = n->prev;
531 m->next = MDOC_NEXT_SIBLING;
532 } else {
533 m->last = n->parent;
534 m->next = MDOC_NEXT_CHILD;
535 }
536 }
537
538 if (m && m->first == n)
539 m->first = NULL;
540 }
541
542
543 void
544 mdoc_node_delete(struct mdoc *m, struct mdoc_node *p)
545 {
546
547 while (p->child) {
548 assert(p->nchild);
549 mdoc_node_delete(m, p->child);
550 }
551 assert(0 == p->nchild);
552
553 mdoc_node_unlink(m, p);
554 mdoc_node_free(p);
555 }
556
557
558 /*
559 * Parse free-form text, that is, a line that does not begin with the
560 * control character.
561 */
562 static int
563 mdoc_ptext(struct mdoc *m, int line, char *buf, int offs)
564 {
565 char *c, *ws, *end;
566 struct mdoc_node *n;
567
568 /* Ignore bogus comments. */
569
570 if ('\\' == buf[offs] &&
571 '.' == buf[offs + 1] &&
572 '"' == buf[offs + 2])
573 return(mdoc_pmsg(m, line, offs, MANDOCERR_BADCOMMENT));
574
575 /* No text before an initial macro. */
576
577 if (SEC_NONE == m->lastnamed)
578 return(mdoc_pmsg(m, line, offs, MANDOCERR_NOTEXT));
579
580 assert(m->last);
581 n = m->last;
582
583 /*
584 * Divert directly to list processing if we're encountering a
585 * columnar MDOC_BLOCK with or without a prior MDOC_BLOCK entry
586 * (a MDOC_BODY means it's already open, in which case we should
587 * process within its context in the normal way).
588 */
589
590 if (MDOC_Bl == n->tok && MDOC_BODY == n->type &&
591 LIST_column == n->data.Bl.type) {
592 /* `Bl' is open without any children. */
593 m->flags |= MDOC_FREECOL;
594 return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf));
595 }
596
597 if (MDOC_It == n->tok && MDOC_BLOCK == n->type &&
598 NULL != n->parent &&
599 MDOC_Bl == n->parent->tok &&
600 LIST_column == n->parent->data.Bl.type) {
601 /* `Bl' has block-level `It' children. */
602 m->flags |= MDOC_FREECOL;
603 return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf));
604 }
605
606 /*
607 * Search for the beginning of unescaped trailing whitespace (ws)
608 * and for the first character not to be output (end).
609 */
610
611 /* FIXME: replace with strcspn(). */
612 ws = NULL;
613 for (c = end = buf + offs; *c; c++) {
614 switch (*c) {
615 case '-':
616 if (mandoc_hyph(buf + offs, c))
617 *c = ASCII_HYPH;
618 ws = NULL;
619 break;
620 case ' ':
621 if (NULL == ws)
622 ws = c;
623 continue;
624 case '\t':
625 /*
626 * Always warn about trailing tabs,
627 * even outside literal context,
628 * where they should be put on the next line.
629 */
630 if (NULL == ws)
631 ws = c;
632 /*
633 * Strip trailing tabs in literal context only;
634 * outside, they affect the next line.
635 */
636 if (MDOC_LITERAL & m->flags)
637 continue;
638 break;
639 case '\\':
640 /* Skip the escaped character, too, if any. */
641 if (c[1])
642 c++;
643 /* FALLTHROUGH */
644 default:
645 ws = NULL;
646 break;
647 }
648 end = c + 1;
649 }
650 *end = '\0';
651
652 if (ws)
653 if ( ! mdoc_pmsg(m, line, (int)(ws-buf), MANDOCERR_EOLNSPACE))
654 return(0);
655
656 if ('\0' == buf[offs] && ! (MDOC_LITERAL & m->flags)) {
657 if ( ! mdoc_pmsg(m, line, (int)(c-buf), MANDOCERR_NOBLANKLN))
658 return(0);
659
660 /*
661 * Insert a `Pp' in the case of a blank line. Technically,
662 * blank lines aren't allowed, but enough manuals assume this
663 * behaviour that we want to work around it.
664 */
665 if ( ! mdoc_elem_alloc(m, line, offs, MDOC_Pp, NULL))
666 return(0);
667
668 m->next = MDOC_NEXT_SIBLING;
669 return(1);
670 }
671
672 if ( ! mdoc_word_alloc(m, line, offs, buf+offs))
673 return(0);
674
675 if (MDOC_LITERAL & m->flags)
676 return(1);
677
678 /*
679 * End-of-sentence check. If the last character is an unescaped
680 * EOS character, then flag the node as being the end of a
681 * sentence. The front-end will know how to interpret this.
682 */
683
684 assert(buf < end);
685
686 if (mandoc_eos(buf+offs, (size_t)(end-buf-offs)))
687 m->last->flags |= MDOC_EOS;
688
689 return(1);
690 }
691
692
693 static int
694 macrowarn(struct mdoc *m, int ln, const char *buf, int offs)
695 {
696 int rc;
697
698 rc = mdoc_vmsg(m, MANDOCERR_MACRO, ln, offs,
699 "unknown macro: %s%s",
700 buf, strlen(buf) > 3 ? "..." : "");
701
702 /* FIXME: logic should be in driver. */
703 /* FIXME: broken, will error out and not omit a message. */
704 return(MDOC_IGN_MACRO & m->pflags ? rc : 0);
705 }
706
707
708 /*
709 * Parse a macro line, that is, a line beginning with the control
710 * character.
711 */
712 int
713 mdoc_pmacro(struct mdoc *m, int ln, char *buf, int offs)
714 {
715 enum mdoct tok;
716 int i, j, sv;
717 char mac[5];
718 struct mdoc_node *n;
719
720 /* Empty lines are ignored. */
721
722 offs++;
723
724 if ('\0' == buf[offs])
725 return(1);
726
727 i = offs;
728
729 /* Accept whitespace after the initial control char. */
730
731 if (' ' == buf[i]) {
732 i++;
733 while (buf[i] && ' ' == buf[i])
734 i++;
735 if ('\0' == buf[i])
736 return(1);
737 }
738
739 sv = i;
740
741 /* Copy the first word into a nil-terminated buffer. */
742
743 for (j = 0; j < 4; j++, i++) {
744 if ('\0' == (mac[j] = buf[i]))
745 break;
746 else if (' ' == buf[i])
747 break;
748
749 /* Check for invalid characters. */
750
751 if (isgraph((u_char)buf[i]))
752 continue;
753 if ( ! mdoc_pmsg(m, ln, i, MANDOCERR_BADCHAR))
754 return(0);
755 i--;
756 }
757
758 mac[j] = '\0';
759
760 if (j == 4 || j < 2) {
761 if ( ! macrowarn(m, ln, mac, sv))
762 goto err;
763 return(1);
764 }
765
766 if (MDOC_MAX == (tok = mdoc_hash_find(mac))) {
767 if ( ! macrowarn(m, ln, mac, sv))
768 goto err;
769 return(1);
770 }
771
772 /* The macro is sane. Jump to the next word. */
773
774 while (buf[i] && ' ' == buf[i])
775 i++;
776
777 /*
778 * Trailing whitespace. Note that tabs are allowed to be passed
779 * into the parser as "text", so we only warn about spaces here.
780 */
781
782 if ('\0' == buf[i] && ' ' == buf[i - 1])
783 if ( ! mdoc_pmsg(m, ln, i - 1, MANDOCERR_EOLNSPACE))
784 goto err;
785
786 /*
787 * If an initial macro or a list invocation, divert directly
788 * into macro processing.
789 */
790
791 if (NULL == m->last || MDOC_It == tok || MDOC_El == tok) {
792 if ( ! mdoc_macro(m, tok, ln, sv, &i, buf))
793 goto err;
794 return(1);
795 }
796
797 n = m->last;
798 assert(m->last);
799
800 /*
801 * If the first macro of a `Bl -column', open an `It' block
802 * context around the parsed macro.
803 */
804
805 if (MDOC_Bl == n->tok && MDOC_BODY == n->type &&
806 LIST_column == n->data.Bl.type) {
807 m->flags |= MDOC_FREECOL;
808 if ( ! mdoc_macro(m, MDOC_It, ln, sv, &sv, buf))
809 goto err;
810 return(1);
811 }
812
813 /*
814 * If we're following a block-level `It' within a `Bl -column'
815 * context (perhaps opened in the above block or in ptext()),
816 * then open an `It' block context around the parsed macro.
817 */
818
819 if (MDOC_It == n->tok && MDOC_BLOCK == n->type &&
820 NULL != n->parent &&
821 MDOC_Bl == n->parent->tok &&
822 LIST_column == n->parent->data.Bl.type) {
823 m->flags |= MDOC_FREECOL;
824 if ( ! mdoc_macro(m, MDOC_It, ln, sv, &sv, buf))
825 goto err;
826 return(1);
827 }
828
829 /* Normal processing of a macro. */
830
831 if ( ! mdoc_macro(m, tok, ln, sv, &i, buf))
832 goto err;
833
834 return(1);
835
836 err: /* Error out. */
837
838 m->flags |= MDOC_HALT;
839 return(0);
840 }
841
842