]> git.cameronkatri.com Git - mandoc.git/blob - mdoc.c
4848b04574db59aeb91cf31037d6ef5216caa5ef
[mandoc.git] / mdoc.c
1 /* $Id: mdoc.c,v 1.149 2010/06/27 15:52:41 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(const struct regset *regs,
196 void *data, 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 if (MDOC_NEWLINE & m->flags)
372 p->flags |= MDOC_LINE;
373 m->flags &= ~MDOC_NEWLINE;
374 return(p);
375 }
376
377
378 int
379 mdoc_tail_alloc(struct mdoc *m, int line, int pos, enum mdoct tok)
380 {
381 struct mdoc_node *p;
382
383 p = node_alloc(m, line, pos, tok, MDOC_TAIL);
384 if ( ! node_append(m, p))
385 return(0);
386 m->next = MDOC_NEXT_CHILD;
387 return(1);
388 }
389
390
391 int
392 mdoc_head_alloc(struct mdoc *m, int line, int pos, enum mdoct tok)
393 {
394 struct mdoc_node *p;
395
396 assert(m->first);
397 assert(m->last);
398
399 p = node_alloc(m, line, pos, tok, MDOC_HEAD);
400 if ( ! node_append(m, p))
401 return(0);
402 m->next = MDOC_NEXT_CHILD;
403 return(1);
404 }
405
406
407 int
408 mdoc_body_alloc(struct mdoc *m, int line, int pos, enum mdoct tok)
409 {
410 struct mdoc_node *p;
411
412 p = node_alloc(m, line, pos, tok, MDOC_BODY);
413 if ( ! node_append(m, p))
414 return(0);
415 m->next = MDOC_NEXT_CHILD;
416 return(1);
417 }
418
419
420 int
421 mdoc_block_alloc(struct mdoc *m, int line, int pos,
422 enum mdoct tok, struct mdoc_arg *args)
423 {
424 struct mdoc_node *p;
425
426 p = node_alloc(m, line, pos, tok, MDOC_BLOCK);
427 p->args = args;
428 if (p->args)
429 (args->refcnt)++;
430 if ( ! node_append(m, p))
431 return(0);
432 m->next = MDOC_NEXT_CHILD;
433 return(1);
434 }
435
436
437 int
438 mdoc_elem_alloc(struct mdoc *m, int line, int pos,
439 enum mdoct tok, struct mdoc_arg *args)
440 {
441 struct mdoc_node *p;
442
443 p = node_alloc(m, line, pos, tok, MDOC_ELEM);
444 p->args = args;
445 if (p->args)
446 (args->refcnt)++;
447 if ( ! node_append(m, p))
448 return(0);
449 m->next = MDOC_NEXT_CHILD;
450 return(1);
451 }
452
453
454 int
455 mdoc_word_alloc(struct mdoc *m, int line, int pos, const char *p)
456 {
457 struct mdoc_node *n;
458 size_t sv, len;
459
460 len = strlen(p);
461
462 n = node_alloc(m, line, pos, MDOC_MAX, MDOC_TEXT);
463 n->string = mandoc_malloc(len + 1);
464 sv = strlcpy(n->string, p, len + 1);
465
466 /* Prohibit truncation. */
467 assert(sv < len + 1);
468
469 if ( ! node_append(m, n))
470 return(0);
471
472 m->next = MDOC_NEXT_SIBLING;
473 return(1);
474 }
475
476
477 void
478 mdoc_node_free(struct mdoc_node *p)
479 {
480
481 if (p->string)
482 free(p->string);
483 if (p->args)
484 mdoc_argv_free(p->args);
485 free(p);
486 }
487
488
489 static void
490 mdoc_node_unlink(struct mdoc *m, struct mdoc_node *n)
491 {
492
493 /* Adjust siblings. */
494
495 if (n->prev)
496 n->prev->next = n->next;
497 if (n->next)
498 n->next->prev = n->prev;
499
500 /* Adjust parent. */
501
502 if (n->parent) {
503 n->parent->nchild--;
504 if (n->parent->child == n)
505 n->parent->child = n->prev ? n->prev : n->next;
506 }
507
508 /* Adjust parse point, if applicable. */
509
510 if (m && m->last == n) {
511 if (n->prev) {
512 m->last = n->prev;
513 m->next = MDOC_NEXT_SIBLING;
514 } else {
515 m->last = n->parent;
516 m->next = MDOC_NEXT_CHILD;
517 }
518 }
519
520 if (m && m->first == n)
521 m->first = NULL;
522 }
523
524
525 void
526 mdoc_node_delete(struct mdoc *m, struct mdoc_node *p)
527 {
528
529 while (p->child) {
530 assert(p->nchild);
531 mdoc_node_delete(m, p->child);
532 }
533 assert(0 == p->nchild);
534
535 mdoc_node_unlink(m, p);
536 mdoc_node_free(p);
537 }
538
539
540 /*
541 * Parse free-form text, that is, a line that does not begin with the
542 * control character.
543 */
544 static int
545 mdoc_ptext(struct mdoc *m, int line, char *buf, int offs)
546 {
547 char *c, *ws, *end;
548 struct mdoc_node *n;
549
550 /* Ignore bogus comments. */
551
552 if ('\\' == buf[offs] &&
553 '.' == buf[offs + 1] &&
554 '"' == buf[offs + 2])
555 return(mdoc_pmsg(m, line, offs, MANDOCERR_BADCOMMENT));
556
557 /* No text before an initial macro. */
558
559 if (SEC_NONE == m->lastnamed)
560 return(mdoc_pmsg(m, line, offs, MANDOCERR_NOTEXT));
561
562 assert(m->last);
563 n = m->last;
564
565 /*
566 * Divert directly to list processing if we're encountering a
567 * columnar MDOC_BLOCK with or without a prior MDOC_BLOCK entry
568 * (a MDOC_BODY means it's already open, in which case we should
569 * process within its context in the normal way).
570 */
571
572 if (MDOC_Bl == n->tok && MDOC_BODY == n->type &&
573 LIST_column == n->data.Bl.type) {
574 /* `Bl' is open without any children. */
575 m->flags |= MDOC_FREECOL;
576 return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf));
577 }
578
579 if (MDOC_It == n->tok && MDOC_BLOCK == n->type &&
580 NULL != n->parent &&
581 MDOC_Bl == n->parent->tok &&
582 LIST_column == n->parent->data.Bl.type) {
583 /* `Bl' has block-level `It' children. */
584 m->flags |= MDOC_FREECOL;
585 return(mdoc_macro(m, MDOC_It, line, offs, &offs, buf));
586 }
587
588 /*
589 * Search for the beginning of unescaped trailing whitespace (ws)
590 * and for the first character not to be output (end).
591 */
592
593 /* FIXME: replace with strcspn(). */
594 ws = NULL;
595 for (c = end = buf + offs; *c; c++) {
596 switch (*c) {
597 case '-':
598 if (mandoc_hyph(buf + offs, c))
599 *c = ASCII_HYPH;
600 ws = NULL;
601 break;
602 case ' ':
603 if (NULL == ws)
604 ws = c;
605 continue;
606 case '\t':
607 /*
608 * Always warn about trailing tabs,
609 * even outside literal context,
610 * where they should be put on the next line.
611 */
612 if (NULL == ws)
613 ws = c;
614 /*
615 * Strip trailing tabs in literal context only;
616 * outside, they affect the next line.
617 */
618 if (MDOC_LITERAL & m->flags)
619 continue;
620 break;
621 case '\\':
622 /* Skip the escaped character, too, if any. */
623 if (c[1])
624 c++;
625 /* FALLTHROUGH */
626 default:
627 ws = NULL;
628 break;
629 }
630 end = c + 1;
631 }
632 *end = '\0';
633
634 if (ws)
635 if ( ! mdoc_pmsg(m, line, (int)(ws-buf), MANDOCERR_EOLNSPACE))
636 return(0);
637
638 if ('\0' == buf[offs] && ! (MDOC_LITERAL & m->flags)) {
639 if ( ! mdoc_pmsg(m, line, (int)(c-buf), MANDOCERR_NOBLANKLN))
640 return(0);
641
642 /*
643 * Insert a `Pp' in the case of a blank line. Technically,
644 * blank lines aren't allowed, but enough manuals assume this
645 * behaviour that we want to work around it.
646 */
647 if ( ! mdoc_elem_alloc(m, line, offs, MDOC_Pp, NULL))
648 return(0);
649
650 m->next = MDOC_NEXT_SIBLING;
651 return(1);
652 }
653
654 if ( ! mdoc_word_alloc(m, line, offs, buf+offs))
655 return(0);
656
657 if (MDOC_LITERAL & m->flags)
658 return(1);
659
660 /*
661 * End-of-sentence check. If the last character is an unescaped
662 * EOS character, then flag the node as being the end of a
663 * sentence. The front-end will know how to interpret this.
664 */
665
666 assert(buf < end);
667
668 if (mandoc_eos(buf+offs, (size_t)(end-buf-offs)))
669 m->last->flags |= MDOC_EOS;
670
671 return(1);
672 }
673
674
675 static int
676 macrowarn(struct mdoc *m, int ln, const char *buf, int offs)
677 {
678 int rc;
679
680 rc = mdoc_vmsg(m, MANDOCERR_MACRO, ln, offs,
681 "unknown macro: %s%s",
682 buf, strlen(buf) > 3 ? "..." : "");
683
684 /* FIXME: logic should be in driver. */
685 /* FIXME: broken, will error out and not omit a message. */
686 return(MDOC_IGN_MACRO & m->pflags ? rc : 0);
687 }
688
689
690 /*
691 * Parse a macro line, that is, a line beginning with the control
692 * character.
693 */
694 int
695 mdoc_pmacro(struct mdoc *m, int ln, char *buf, int offs)
696 {
697 enum mdoct tok;
698 int i, j, sv;
699 char mac[5];
700 struct mdoc_node *n;
701
702 /* Empty lines are ignored. */
703
704 offs++;
705
706 if ('\0' == buf[offs])
707 return(1);
708
709 i = offs;
710
711 /* Accept whitespace after the initial control char. */
712
713 if (' ' == buf[i]) {
714 i++;
715 while (buf[i] && ' ' == buf[i])
716 i++;
717 if ('\0' == buf[i])
718 return(1);
719 }
720
721 sv = i;
722
723 /* Copy the first word into a nil-terminated buffer. */
724
725 for (j = 0; j < 4; j++, i++) {
726 if ('\0' == (mac[j] = buf[i]))
727 break;
728 else if (' ' == buf[i])
729 break;
730
731 /* Check for invalid characters. */
732
733 if (isgraph((u_char)buf[i]))
734 continue;
735 if ( ! mdoc_pmsg(m, ln, i, MANDOCERR_BADCHAR))
736 return(0);
737 i--;
738 }
739
740 mac[j] = '\0';
741
742 if (j == 4 || j < 2) {
743 if ( ! macrowarn(m, ln, mac, sv))
744 goto err;
745 return(1);
746 }
747
748 if (MDOC_MAX == (tok = mdoc_hash_find(mac))) {
749 if ( ! macrowarn(m, ln, mac, sv))
750 goto err;
751 return(1);
752 }
753
754 /* The macro is sane. Jump to the next word. */
755
756 while (buf[i] && ' ' == buf[i])
757 i++;
758
759 /*
760 * Trailing whitespace. Note that tabs are allowed to be passed
761 * into the parser as "text", so we only warn about spaces here.
762 */
763
764 if ('\0' == buf[i] && ' ' == buf[i - 1])
765 if ( ! mdoc_pmsg(m, ln, i - 1, MANDOCERR_EOLNSPACE))
766 goto err;
767
768 /*
769 * If an initial macro or a list invocation, divert directly
770 * into macro processing.
771 */
772
773 if (NULL == m->last || MDOC_It == tok || MDOC_El == tok) {
774 if ( ! mdoc_macro(m, tok, ln, sv, &i, buf))
775 goto err;
776 return(1);
777 }
778
779 n = m->last;
780 assert(m->last);
781
782 /*
783 * If the first macro of a `Bl -column', open an `It' block
784 * context around the parsed macro.
785 */
786
787 if (MDOC_Bl == n->tok && MDOC_BODY == n->type &&
788 LIST_column == n->data.Bl.type) {
789 m->flags |= MDOC_FREECOL;
790 if ( ! mdoc_macro(m, MDOC_It, ln, sv, &sv, buf))
791 goto err;
792 return(1);
793 }
794
795 /*
796 * If we're following a block-level `It' within a `Bl -column'
797 * context (perhaps opened in the above block or in ptext()),
798 * then open an `It' block context around the parsed macro.
799 */
800
801 if (MDOC_It == n->tok && MDOC_BLOCK == n->type &&
802 NULL != n->parent &&
803 MDOC_Bl == n->parent->tok &&
804 LIST_column == n->parent->data.Bl.type) {
805 m->flags |= MDOC_FREECOL;
806 if ( ! mdoc_macro(m, MDOC_It, ln, sv, &sv, buf))
807 goto err;
808 return(1);
809 }
810
811 /* Normal processing of a macro. */
812
813 if ( ! mdoc_macro(m, tok, ln, sv, &i, buf))
814 goto err;
815
816 return(1);
817
818 err: /* Error out. */
819
820 m->flags |= MDOC_HALT;
821 return(0);
822 }
823
824