]> git.cameronkatri.com Git - mandoc.git/blob - mdoc_action.c
Move `Lb' handling from mdoc_action.c into mdoc_validate.c.
[mandoc.git] / mdoc_action.c
1 /* $Id: mdoc_action.c,v 1.83 2010/11/29 14:56:43 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008, 2009, 2010 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 #ifndef OSNAME
22 #include <sys/utsname.h>
23 #endif
24
25 #include <assert.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <time.h>
30
31 #include "mandoc.h"
32 #include "libmdoc.h"
33 #include "libmandoc.h"
34
35 /*
36 * FIXME: this file is deprecated. All future "actions" should be
37 * pushed into mdoc_validate.c.
38 */
39
40 #define POST_ARGS struct mdoc *m, struct mdoc_node *n
41 #define PRE_ARGS struct mdoc *m, struct mdoc_node *n
42
43 #define NUMSIZ 32
44 #define DATESIZ 32
45
46 struct actions {
47 int (*pre)(PRE_ARGS);
48 int (*post)(POST_ARGS);
49 };
50
51 static int concat(struct mdoc *, char *,
52 const struct mdoc_node *, size_t);
53
54 static int post_bl(POST_ARGS);
55 static int post_bl_head(POST_ARGS);
56 static int post_bl_tagwidth(POST_ARGS);
57 static int post_bl_width(POST_ARGS);
58 static int post_dd(POST_ARGS);
59 static int post_display(POST_ARGS);
60 static int post_dt(POST_ARGS);
61 static int post_nm(POST_ARGS);
62 static int post_os(POST_ARGS);
63 static int post_pa(POST_ARGS);
64 static int post_prol(POST_ARGS);
65 static int post_st(POST_ARGS);
66 static int post_std(POST_ARGS);
67
68 static int pre_bd(PRE_ARGS);
69 static int pre_dl(PRE_ARGS);
70
71 static const struct actions mdoc_actions[MDOC_MAX] = {
72 { NULL, NULL }, /* Ap */
73 { NULL, post_dd }, /* Dd */
74 { NULL, post_dt }, /* Dt */
75 { NULL, post_os }, /* Os */
76 { NULL, NULL }, /* Sh */
77 { NULL, NULL }, /* Ss */
78 { NULL, NULL }, /* Pp */
79 { NULL, NULL }, /* D1 */
80 { pre_dl, post_display }, /* Dl */
81 { pre_bd, post_display }, /* Bd */
82 { NULL, NULL }, /* Ed */
83 { NULL, post_bl }, /* Bl */
84 { NULL, NULL }, /* El */
85 { NULL, NULL }, /* It */
86 { NULL, NULL }, /* Ad */
87 { NULL, NULL }, /* An */
88 { NULL, NULL }, /* Ar */
89 { NULL, NULL }, /* Cd */
90 { NULL, NULL }, /* Cm */
91 { NULL, NULL }, /* Dv */
92 { NULL, NULL }, /* Er */
93 { NULL, NULL }, /* Ev */
94 { NULL, post_std }, /* Ex */
95 { NULL, NULL }, /* Fa */
96 { NULL, NULL }, /* Fd */
97 { NULL, NULL }, /* Fl */
98 { NULL, NULL }, /* Fn */
99 { NULL, NULL }, /* Ft */
100 { NULL, NULL }, /* Ic */
101 { NULL, NULL }, /* In */
102 { NULL, NULL }, /* Li */
103 { NULL, NULL }, /* Nd */
104 { NULL, post_nm }, /* Nm */
105 { NULL, NULL }, /* Op */
106 { NULL, NULL }, /* Ot */
107 { NULL, post_pa }, /* Pa */
108 { NULL, post_std }, /* Rv */
109 { NULL, post_st }, /* St */
110 { NULL, NULL }, /* Va */
111 { NULL, NULL }, /* Vt */
112 { NULL, NULL }, /* Xr */
113 { NULL, NULL }, /* %A */
114 { NULL, NULL }, /* %B */
115 { NULL, NULL }, /* %D */
116 { NULL, NULL }, /* %I */
117 { NULL, NULL }, /* %J */
118 { NULL, NULL }, /* %N */
119 { NULL, NULL }, /* %O */
120 { NULL, NULL }, /* %P */
121 { NULL, NULL }, /* %R */
122 { NULL, NULL }, /* %T */
123 { NULL, NULL }, /* %V */
124 { NULL, NULL }, /* Ac */
125 { NULL, NULL }, /* Ao */
126 { NULL, NULL }, /* Aq */
127 { NULL, NULL }, /* At */
128 { NULL, NULL }, /* Bc */
129 { NULL, NULL }, /* Bf */
130 { NULL, NULL }, /* Bo */
131 { NULL, NULL }, /* Bq */
132 { NULL, NULL }, /* Bsx */
133 { NULL, NULL }, /* Bx */
134 { NULL, NULL }, /* Db */
135 { NULL, NULL }, /* Dc */
136 { NULL, NULL }, /* Do */
137 { NULL, NULL }, /* Dq */
138 { NULL, NULL }, /* Ec */
139 { NULL, NULL }, /* Ef */
140 { NULL, NULL }, /* Em */
141 { NULL, NULL }, /* Eo */
142 { NULL, NULL }, /* Fx */
143 { NULL, NULL }, /* Ms */
144 { NULL, NULL }, /* No */
145 { NULL, NULL }, /* Ns */
146 { NULL, NULL }, /* Nx */
147 { NULL, NULL }, /* Ox */
148 { NULL, NULL }, /* Pc */
149 { NULL, NULL }, /* Pf */
150 { NULL, NULL }, /* Po */
151 { NULL, NULL }, /* Pq */
152 { NULL, NULL }, /* Qc */
153 { NULL, NULL }, /* Ql */
154 { NULL, NULL }, /* Qo */
155 { NULL, NULL }, /* Qq */
156 { NULL, NULL }, /* Re */
157 { NULL, NULL }, /* Rs */
158 { NULL, NULL }, /* Sc */
159 { NULL, NULL }, /* So */
160 { NULL, NULL }, /* Sq */
161 { NULL, NULL }, /* Sm */
162 { NULL, NULL }, /* Sx */
163 { NULL, NULL }, /* Sy */
164 { NULL, NULL }, /* Tn */
165 { NULL, NULL }, /* Ux */
166 { NULL, NULL }, /* Xc */
167 { NULL, NULL }, /* Xo */
168 { NULL, NULL }, /* Fo */
169 { NULL, NULL }, /* Fc */
170 { NULL, NULL }, /* Oo */
171 { NULL, NULL }, /* Oc */
172 { NULL, NULL }, /* Bk */
173 { NULL, NULL }, /* Ek */
174 { NULL, NULL }, /* Bt */
175 { NULL, NULL }, /* Hf */
176 { NULL, NULL }, /* Fr */
177 { NULL, NULL }, /* Ud */
178 { NULL, NULL }, /* Lb */
179 { NULL, NULL }, /* Lp */
180 { NULL, NULL }, /* Lk */
181 { NULL, NULL }, /* Mt */
182 { NULL, NULL }, /* Brq */
183 { NULL, NULL }, /* Bro */
184 { NULL, NULL }, /* Brc */
185 { NULL, NULL }, /* %C */
186 { NULL, NULL }, /* Es */
187 { NULL, NULL }, /* En */
188 { NULL, NULL }, /* Dx */
189 { NULL, NULL }, /* %Q */
190 { NULL, NULL }, /* br */
191 { NULL, NULL }, /* sp */
192 { NULL, NULL }, /* %U */
193 { NULL, NULL }, /* Ta */
194 };
195
196 #define RSORD_MAX 14
197
198 static const enum mdoct rsord[RSORD_MAX] = {
199 MDOC__A,
200 MDOC__T,
201 MDOC__B,
202 MDOC__I,
203 MDOC__J,
204 MDOC__R,
205 MDOC__N,
206 MDOC__V,
207 MDOC__P,
208 MDOC__Q,
209 MDOC__D,
210 MDOC__O,
211 MDOC__C,
212 MDOC__U
213 };
214
215
216 int
217 mdoc_action_pre(struct mdoc *m, struct mdoc_node *n)
218 {
219
220 switch (n->type) {
221 case (MDOC_ROOT):
222 /* FALLTHROUGH */
223 case (MDOC_TEXT):
224 return(1);
225 default:
226 break;
227 }
228
229 if (NULL == mdoc_actions[n->tok].pre)
230 return(1);
231 return((*mdoc_actions[n->tok].pre)(m, n));
232 }
233
234
235 int
236 mdoc_action_post(struct mdoc *m)
237 {
238
239 if (MDOC_ACTED & m->last->flags)
240 return(1);
241 m->last->flags |= MDOC_ACTED;
242
243 switch (m->last->type) {
244 case (MDOC_TEXT):
245 /* FALLTHROUGH */
246 case (MDOC_ROOT):
247 return(1);
248 default:
249 break;
250 }
251
252 if (NULL == mdoc_actions[m->last->tok].post)
253 return(1);
254 return((*mdoc_actions[m->last->tok].post)(m, m->last));
255 }
256
257
258 /*
259 * Concatenate sibling nodes together. All siblings must be of type
260 * MDOC_TEXT or an assertion is raised. Concatenation is separated by a
261 * single whitespace.
262 */
263 static int
264 concat(struct mdoc *m, char *p, const struct mdoc_node *n, size_t sz)
265 {
266
267 assert(sz);
268 p[0] = '\0';
269 for ( ; n; n = n->next) {
270 assert(MDOC_TEXT == n->type);
271 /*
272 * XXX: yes, these can technically be resized, but it's
273 * highly unlikely that we're going to get here, so let
274 * it slip for now.
275 */
276 if (strlcat(p, n->string, sz) >= sz) {
277 mdoc_nmsg(m, n, MANDOCERR_MEM);
278 return(0);
279 }
280 if (NULL == n->next)
281 continue;
282 if (strlcat(p, " ", sz) >= sz) {
283 mdoc_nmsg(m, n, MANDOCERR_MEM);
284 return(0);
285 }
286 }
287
288 return(1);
289 }
290
291
292 /*
293 * Macros accepting `-std' as an argument have the name of the current
294 * document (`Nm') filled in as the argument if it's not provided.
295 */
296 static int
297 post_std(POST_ARGS)
298 {
299 struct mdoc_node *nn;
300
301 if (n->child)
302 return(1);
303 if (NULL == m->meta.name)
304 return(1);
305
306 nn = n;
307 m->next = MDOC_NEXT_CHILD;
308
309 if ( ! mdoc_word_alloc(m, n->line, n->pos, m->meta.name))
310 return(0);
311 m->last = nn;
312 return(1);
313 }
314
315
316 /*
317 * The `Nm' macro's first use sets the name of the document. See also
318 * post_std(), etc.
319 */
320 static int
321 post_nm(POST_ARGS)
322 {
323 char buf[BUFSIZ];
324
325 if (m->meta.name)
326 return(1);
327 if ( ! concat(m, buf, n->child, BUFSIZ))
328 return(0);
329 m->meta.name = mandoc_strdup(buf);
330 return(1);
331 }
332
333 /*
334 * Substitute the value of `St' for the corresponding formatted string.
335 * We're guaranteed that this exists (it's been verified during the
336 * validation phase).
337 */
338 /* ARGSUSED */
339 static int
340 post_st(POST_ARGS)
341 {
342 const char *p;
343
344 assert(MDOC_TEXT == n->child->type);
345 p = mdoc_a2st(n->child->string);
346 if (p != NULL) {
347 free(n->child->string);
348 n->child->string = mandoc_strdup(p);
349 }
350 return(1);
351 }
352
353
354 /*
355 * Parse out the contents of `Dt'. See in-line documentation for how we
356 * handle the various fields of this macro.
357 */
358 static int
359 post_dt(POST_ARGS)
360 {
361 struct mdoc_node *nn;
362 const char *cp;
363
364 if (m->meta.title)
365 free(m->meta.title);
366 if (m->meta.vol)
367 free(m->meta.vol);
368 if (m->meta.arch)
369 free(m->meta.arch);
370
371 m->meta.title = m->meta.vol = m->meta.arch = NULL;
372 /* Handles: `.Dt'
373 * --> title = unknown, volume = local, msec = 0, arch = NULL
374 */
375
376 if (NULL == (nn = n->child)) {
377 /* XXX: make these macro values. */
378 /* FIXME: warn about missing values. */
379 m->meta.title = mandoc_strdup("UNKNOWN");
380 m->meta.vol = mandoc_strdup("LOCAL");
381 m->meta.msec = mandoc_strdup("1");
382 return(post_prol(m, n));
383 }
384
385 /* Handles: `.Dt TITLE'
386 * --> title = TITLE, volume = local, msec = 0, arch = NULL
387 */
388
389 m->meta.title = mandoc_strdup
390 ('\0' == nn->string[0] ? "UNKNOWN" : nn->string);
391
392 if (NULL == (nn = nn->next)) {
393 /* FIXME: warn about missing msec. */
394 /* XXX: make this a macro value. */
395 m->meta.vol = mandoc_strdup("LOCAL");
396 m->meta.msec = mandoc_strdup("1");
397 return(post_prol(m, n));
398 }
399
400 /* Handles: `.Dt TITLE SEC'
401 * --> title = TITLE, volume = SEC is msec ?
402 * format(msec) : SEC,
403 * msec = SEC is msec ? atoi(msec) : 0,
404 * arch = NULL
405 */
406
407 cp = mdoc_a2msec(nn->string);
408 if (cp) {
409 m->meta.vol = mandoc_strdup(cp);
410 m->meta.msec = mandoc_strdup(nn->string);
411 } else if (mdoc_nmsg(m, n, MANDOCERR_BADMSEC)) {
412 m->meta.vol = mandoc_strdup(nn->string);
413 m->meta.msec = mandoc_strdup(nn->string);
414 } else
415 return(0);
416
417 if (NULL == (nn = nn->next))
418 return(post_prol(m, n));
419
420 /* Handles: `.Dt TITLE SEC VOL'
421 * --> title = TITLE, volume = VOL is vol ?
422 * format(VOL) :
423 * VOL is arch ? format(arch) :
424 * VOL
425 */
426
427 cp = mdoc_a2vol(nn->string);
428 if (cp) {
429 free(m->meta.vol);
430 m->meta.vol = mandoc_strdup(cp);
431 } else {
432 /* FIXME: warn about bad arch. */
433 cp = mdoc_a2arch(nn->string);
434 if (NULL == cp) {
435 free(m->meta.vol);
436 m->meta.vol = mandoc_strdup(nn->string);
437 } else
438 m->meta.arch = mandoc_strdup(cp);
439 }
440
441 /* Ignore any subsequent parameters... */
442 /* FIXME: warn about subsequent parameters. */
443
444 return(post_prol(m, n));
445 }
446
447
448 /*
449 * Set the operating system by way of the `Os' macro. Note that if an
450 * argument isn't provided and -DOSNAME="\"foo\"" is provided during
451 * compilation, this value will be used instead of filling in "sysname
452 * release" from uname().
453 */
454 static int
455 post_os(POST_ARGS)
456 {
457 char buf[BUFSIZ];
458 #ifndef OSNAME
459 struct utsname utsname;
460 #endif
461
462 if (m->meta.os)
463 free(m->meta.os);
464
465 if ( ! concat(m, buf, n->child, BUFSIZ))
466 return(0);
467
468 /* XXX: yes, these can all be dynamically-adjusted buffers, but
469 * it's really not worth the extra hackery.
470 */
471
472 if ('\0' == buf[0]) {
473 #ifdef OSNAME
474 if (strlcat(buf, OSNAME, BUFSIZ) >= BUFSIZ) {
475 mdoc_nmsg(m, n, MANDOCERR_MEM);
476 return(0);
477 }
478 #else /*!OSNAME */
479 if (-1 == uname(&utsname))
480 return(mdoc_nmsg(m, n, MANDOCERR_UTSNAME));
481
482 if (strlcat(buf, utsname.sysname, BUFSIZ) >= BUFSIZ) {
483 mdoc_nmsg(m, n, MANDOCERR_MEM);
484 return(0);
485 }
486 if (strlcat(buf, " ", 64) >= BUFSIZ) {
487 mdoc_nmsg(m, n, MANDOCERR_MEM);
488 return(0);
489 }
490 if (strlcat(buf, utsname.release, BUFSIZ) >= BUFSIZ) {
491 mdoc_nmsg(m, n, MANDOCERR_MEM);
492 return(0);
493 }
494 #endif /*!OSNAME*/
495 }
496
497 m->meta.os = mandoc_strdup(buf);
498 return(post_prol(m, n));
499 }
500
501
502 /*
503 * Calculate the -width for a `Bl -tag' list if it hasn't been provided.
504 * Uses the first head macro. NOTE AGAIN: this is ONLY if the -width
505 * argument has NOT been provided. See post_bl_width() for converting
506 * the -width string.
507 */
508 static int
509 post_bl_tagwidth(POST_ARGS)
510 {
511 struct mdoc_node *nn;
512 size_t sz, ssz;
513 int i;
514 char buf[NUMSIZ];
515
516 sz = 10;
517
518 for (nn = n->body->child; nn; nn = nn->next) {
519 if (MDOC_It != nn->tok)
520 continue;
521
522 assert(MDOC_BLOCK == nn->type);
523 nn = nn->head->child;
524
525 if (nn == NULL) {
526 /* No -width for .Bl and first .It is emtpy */
527 if ( ! mdoc_nmsg(m, n, MANDOCERR_NOWIDTHARG))
528 return(0);
529 break;
530 }
531
532 if (MDOC_TEXT == nn->type) {
533 sz = strlen(nn->string) + 1;
534 break;
535 }
536
537 if (0 != (ssz = mdoc_macro2len(nn->tok)))
538 sz = ssz;
539 else if ( ! mdoc_nmsg(m, n, MANDOCERR_NOWIDTHARG))
540 return(0);
541
542 break;
543 }
544
545 /* Defaults to ten ens. */
546
547 snprintf(buf, NUMSIZ, "%zun", sz);
548
549 /*
550 * We have to dynamically add this to the macro's argument list.
551 * We're guaranteed that a MDOC_Width doesn't already exist.
552 */
553
554 assert(n->args);
555 i = (int)(n->args->argc)++;
556
557 n->args->argv = mandoc_realloc(n->args->argv,
558 n->args->argc * sizeof(struct mdoc_argv));
559
560 n->args->argv[i].arg = MDOC_Width;
561 n->args->argv[i].line = n->line;
562 n->args->argv[i].pos = n->pos;
563 n->args->argv[i].sz = 1;
564 n->args->argv[i].value = mandoc_malloc(sizeof(char *));
565 n->args->argv[i].value[0] = mandoc_strdup(buf);
566
567 /* Set our width! */
568 n->data.Bl->width = n->args->argv[i].value[0];
569 return(1);
570 }
571
572
573 /*
574 * Calculate the real width of a list from the -width string, which may
575 * contain a macro (with a known default width), a literal string, or a
576 * scaling width.
577 */
578 static int
579 post_bl_width(POST_ARGS)
580 {
581 size_t width;
582 int i;
583 enum mdoct tok;
584 char buf[NUMSIZ];
585
586 /*
587 * If the value to -width is a macro, then we re-write it to be
588 * the macro's width as set in share/tmac/mdoc/doc-common.
589 */
590
591 if (0 == strcmp(n->data.Bl->width, "Ds"))
592 width = 6;
593 else if (MDOC_MAX == (tok = mdoc_hash_find(n->data.Bl->width)))
594 return(1);
595 else if (0 == (width = mdoc_macro2len(tok)))
596 return(mdoc_nmsg(m, n, MANDOCERR_BADWIDTH));
597
598 /* The value already exists: free and reallocate it. */
599
600 assert(n->args);
601
602 for (i = 0; i < (int)n->args->argc; i++)
603 if (MDOC_Width == n->args->argv[i].arg)
604 break;
605
606 assert(i < (int)n->args->argc);
607
608 snprintf(buf, NUMSIZ, "%zun", width);
609 free(n->args->argv[i].value[0]);
610 n->args->argv[i].value[0] = mandoc_strdup(buf);
611
612 /* Set our width! */
613 n->data.Bl->width = n->args->argv[i].value[0];
614 return(1);
615 }
616
617
618 /*
619 * Do processing for -column lists, which can have two distinct styles
620 * of invocation. Merge this two styles into a consistent form.
621 */
622 /* ARGSUSED */
623 static int
624 post_bl_head(POST_ARGS)
625 {
626 int i, c;
627 struct mdoc_node *np, *nn, *nnp;
628
629 if (LIST_column != n->data.Bl->type)
630 return(1);
631 else if (NULL == n->child)
632 return(1);
633
634 np = n->parent;
635 assert(np->args);
636
637 for (c = 0; c < (int)np->args->argc; c++)
638 if (MDOC_Column == np->args->argv[c].arg)
639 break;
640
641 assert(c < (int)np->args->argc);
642 assert(0 == np->args->argv[c].sz);
643
644 /*
645 * Accomodate for new-style groff column syntax. Shuffle the
646 * child nodes, all of which must be TEXT, as arguments for the
647 * column field. Then, delete the head children.
648 */
649
650 np->args->argv[c].sz = (size_t)n->nchild;
651 np->args->argv[c].value = mandoc_malloc
652 ((size_t)n->nchild * sizeof(char *));
653
654 n->data.Bl->ncols = np->args->argv[c].sz;
655 n->data.Bl->cols = (const char **)np->args->argv[c].value;
656
657 for (i = 0, nn = n->child; nn; i++) {
658 np->args->argv[c].value[i] = nn->string;
659 nn->string = NULL;
660 nnp = nn;
661 nn = nn->next;
662 mdoc_node_delete(NULL, nnp);
663 }
664
665 n->nchild = 0;
666 n->child = NULL;
667 return(1);
668 }
669
670
671 static int
672 post_bl(POST_ARGS)
673 {
674
675 if (MDOC_HEAD == n->type)
676 return(post_bl_head(m, n));
677 if (MDOC_BLOCK != n->type)
678 return(1);
679
680 /*
681 * These are fairly complicated, so we've broken them into two
682 * functions. post_bl_tagwidth() is called when a -tag is
683 * specified, but no -width (it must be guessed). The second
684 * when a -width is specified (macro indicators must be
685 * rewritten into real lengths).
686 */
687
688 if (LIST_tag == n->data.Bl->type && NULL == n->data.Bl->width) {
689 if ( ! post_bl_tagwidth(m, n))
690 return(0);
691 } else if (NULL != n->data.Bl->width) {
692 if ( ! post_bl_width(m, n))
693 return(0);
694 } else
695 return(1);
696
697 assert(n->data.Bl->width);
698 return(1);
699 }
700
701
702 /*
703 * The `Pa' macro defaults to a tilde if no value is provided as an
704 * argument.
705 */
706 static int
707 post_pa(POST_ARGS)
708 {
709 struct mdoc_node *np;
710
711 if (n->child)
712 return(1);
713
714 np = n;
715 m->next = MDOC_NEXT_CHILD;
716 if ( ! mdoc_word_alloc(m, n->line, n->pos, "~"))
717 return(0);
718 m->last = np;
719 return(1);
720 }
721
722
723 /*
724 * Parse the date field in `Dd'.
725 */
726 static int
727 post_dd(POST_ARGS)
728 {
729 char buf[DATESIZ];
730
731 if (NULL == n->child) {
732 m->meta.date = time(NULL);
733 return(post_prol(m, n));
734 }
735
736 if ( ! concat(m, buf, n->child, DATESIZ))
737 return(0);
738
739 m->meta.date = mandoc_a2time
740 (MTIME_MDOCDATE | MTIME_CANONICAL, buf);
741
742 if (0 == m->meta.date) {
743 if ( ! mdoc_nmsg(m, n, MANDOCERR_BADDATE))
744 return(0);
745 m->meta.date = time(NULL);
746 }
747
748 return(post_prol(m, n));
749 }
750
751
752 /*
753 * Remove prologue macros from the document after they're processed.
754 * The final document uses mdoc_meta for these values and discards the
755 * originals.
756 */
757 static int
758 post_prol(POST_ARGS)
759 {
760
761 mdoc_node_delete(m, n);
762 if (m->meta.title && m->meta.date && m->meta.os)
763 m->flags |= MDOC_PBODY;
764 return(1);
765 }
766
767
768 /*
769 * Trigger a literal context.
770 */
771 static int
772 pre_dl(PRE_ARGS)
773 {
774
775 if (MDOC_BODY == n->type)
776 m->flags |= MDOC_LITERAL;
777 return(1);
778 }
779
780
781 static int
782 pre_bd(PRE_ARGS)
783 {
784
785 if (MDOC_BODY != n->type)
786 return(1);
787
788 assert(n->data.Bd);
789 if (DISP_literal == n->data.Bd->type)
790 m->flags |= MDOC_LITERAL;
791 if (DISP_unfilled == n->data.Bd->type)
792 m->flags |= MDOC_LITERAL;
793
794 return(1);
795 }
796
797
798 static int
799 post_display(POST_ARGS)
800 {
801
802 if (MDOC_BODY == n->type)
803 m->flags &= ~MDOC_LITERAL;
804 return(1);
805 }