]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_action.c
1 /* $Id: mdoc_action.c,v 1.75 2010/07/04 21:59:30 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
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.
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.
22 #include <sys/utsname.h>
33 #include "libmandoc.h"
36 * FIXME: this file is deprecated. All future "actions" should be
37 * pushed into mdoc_validate.c.
40 #define POST_ARGS struct mdoc *m, struct mdoc_node *n
41 #define PRE_ARGS struct mdoc *m, struct mdoc_node *n
48 int (*post
)(POST_ARGS
);
51 static int concat(struct mdoc
*, char *,
52 const struct mdoc_node
*, size_t);
53 static inline int order_rs(enum mdoct
);
55 static int post_ar(POST_ARGS
);
56 static int post_at(POST_ARGS
);
57 static int post_bl(POST_ARGS
);
58 static int post_bl_head(POST_ARGS
);
59 static int post_bl_tagwidth(POST_ARGS
);
60 static int post_bl_width(POST_ARGS
);
61 static int post_dd(POST_ARGS
);
62 static int post_display(POST_ARGS
);
63 static int post_dt(POST_ARGS
);
64 static int post_lb(POST_ARGS
);
65 static int post_li(POST_ARGS
);
66 static int post_nm(POST_ARGS
);
67 static int post_os(POST_ARGS
);
68 static int post_pa(POST_ARGS
);
69 static int post_prol(POST_ARGS
);
70 static int post_rs(POST_ARGS
);
71 static int post_sh(POST_ARGS
);
72 static int post_st(POST_ARGS
);
73 static int post_std(POST_ARGS
);
75 static int pre_bd(PRE_ARGS
);
76 static int pre_dl(PRE_ARGS
);
78 static const struct actions mdoc_actions
[MDOC_MAX
] = {
79 { NULL
, NULL
}, /* Ap */
80 { NULL
, post_dd
}, /* Dd */
81 { NULL
, post_dt
}, /* Dt */
82 { NULL
, post_os
}, /* Os */
83 { NULL
, post_sh
}, /* Sh */
84 { NULL
, NULL
}, /* Ss */
85 { NULL
, NULL
}, /* Pp */
86 { NULL
, NULL
}, /* D1 */
87 { pre_dl
, post_display
}, /* Dl */
88 { pre_bd
, post_display
}, /* Bd */
89 { NULL
, NULL
}, /* Ed */
90 { NULL
, post_bl
}, /* Bl */
91 { NULL
, NULL
}, /* El */
92 { NULL
, NULL
}, /* It */
93 { NULL
, NULL
}, /* Ad */
94 { NULL
, NULL
}, /* An */
95 { NULL
, post_ar
}, /* Ar */
96 { NULL
, NULL
}, /* Cd */
97 { NULL
, NULL
}, /* Cm */
98 { NULL
, NULL
}, /* Dv */
99 { NULL
, NULL
}, /* Er */
100 { NULL
, NULL
}, /* Ev */
101 { NULL
, post_std
}, /* Ex */
102 { NULL
, NULL
}, /* Fa */
103 { NULL
, NULL
}, /* Fd */
104 { NULL
, NULL
}, /* Fl */
105 { NULL
, NULL
}, /* Fn */
106 { NULL
, NULL
}, /* Ft */
107 { NULL
, NULL
}, /* Ic */
108 { NULL
, NULL
}, /* In */
109 { NULL
, post_li
}, /* Li */
110 { NULL
, NULL
}, /* Nd */
111 { NULL
, post_nm
}, /* Nm */
112 { NULL
, NULL
}, /* Op */
113 { NULL
, NULL
}, /* Ot */
114 { NULL
, post_pa
}, /* Pa */
115 { NULL
, post_std
}, /* Rv */
116 { NULL
, post_st
}, /* St */
117 { NULL
, NULL
}, /* Va */
118 { NULL
, NULL
}, /* Vt */
119 { NULL
, NULL
}, /* Xr */
120 { NULL
, NULL
}, /* %A */
121 { NULL
, NULL
}, /* %B */
122 { NULL
, NULL
}, /* %D */
123 { NULL
, NULL
}, /* %I */
124 { NULL
, NULL
}, /* %J */
125 { NULL
, NULL
}, /* %N */
126 { NULL
, NULL
}, /* %O */
127 { NULL
, NULL
}, /* %P */
128 { NULL
, NULL
}, /* %R */
129 { NULL
, NULL
}, /* %T */
130 { NULL
, NULL
}, /* %V */
131 { NULL
, NULL
}, /* Ac */
132 { NULL
, NULL
}, /* Ao */
133 { NULL
, NULL
}, /* Aq */
134 { NULL
, post_at
}, /* At */
135 { NULL
, NULL
}, /* Bc */
136 { NULL
, NULL
}, /* Bf */
137 { NULL
, NULL
}, /* Bo */
138 { NULL
, NULL
}, /* Bq */
139 { NULL
, NULL
}, /* Bsx */
140 { NULL
, NULL
}, /* Bx */
141 { NULL
, NULL
}, /* Db */
142 { NULL
, NULL
}, /* Dc */
143 { NULL
, NULL
}, /* Do */
144 { NULL
, NULL
}, /* Dq */
145 { NULL
, NULL
}, /* Ec */
146 { NULL
, NULL
}, /* Ef */
147 { NULL
, NULL
}, /* Em */
148 { NULL
, NULL
}, /* Eo */
149 { NULL
, NULL
}, /* Fx */
150 { NULL
, NULL
}, /* Ms */
151 { NULL
, NULL
}, /* No */
152 { NULL
, NULL
}, /* Ns */
153 { NULL
, NULL
}, /* Nx */
154 { NULL
, NULL
}, /* Ox */
155 { NULL
, NULL
}, /* Pc */
156 { NULL
, NULL
}, /* Pf */
157 { NULL
, NULL
}, /* Po */
158 { NULL
, NULL
}, /* Pq */
159 { NULL
, NULL
}, /* Qc */
160 { NULL
, NULL
}, /* Ql */
161 { NULL
, NULL
}, /* Qo */
162 { NULL
, NULL
}, /* Qq */
163 { NULL
, NULL
}, /* Re */
164 { NULL
, post_rs
}, /* Rs */
165 { NULL
, NULL
}, /* Sc */
166 { NULL
, NULL
}, /* So */
167 { NULL
, NULL
}, /* Sq */
168 { NULL
, NULL
}, /* Sm */
169 { NULL
, NULL
}, /* Sx */
170 { NULL
, NULL
}, /* Sy */
171 { NULL
, NULL
}, /* Tn */
172 { NULL
, NULL
}, /* Ux */
173 { NULL
, NULL
}, /* Xc */
174 { NULL
, NULL
}, /* Xo */
175 { NULL
, NULL
}, /* Fo */
176 { NULL
, NULL
}, /* Fc */
177 { NULL
, NULL
}, /* Oo */
178 { NULL
, NULL
}, /* Oc */
179 { NULL
, NULL
}, /* Bk */
180 { NULL
, NULL
}, /* Ek */
181 { NULL
, NULL
}, /* Bt */
182 { NULL
, NULL
}, /* Hf */
183 { NULL
, NULL
}, /* Fr */
184 { NULL
, NULL
}, /* Ud */
185 { NULL
, post_lb
}, /* Lb */
186 { NULL
, NULL
}, /* Lp */
187 { NULL
, NULL
}, /* Lk */
188 { NULL
, NULL
}, /* Mt */
189 { NULL
, NULL
}, /* Brq */
190 { NULL
, NULL
}, /* Bro */
191 { NULL
, NULL
}, /* Brc */
192 { NULL
, NULL
}, /* %C */
193 { NULL
, NULL
}, /* Es */
194 { NULL
, NULL
}, /* En */
195 { NULL
, NULL
}, /* Dx */
196 { NULL
, NULL
}, /* %Q */
197 { NULL
, NULL
}, /* br */
198 { NULL
, NULL
}, /* sp */
199 { NULL
, NULL
}, /* %U */
200 { NULL
, NULL
}, /* Ta */
205 static const enum mdoct rsord
[RSORD_MAX
] = {
224 mdoc_action_pre(struct mdoc
*m
, struct mdoc_node
*n
)
236 if (NULL
== mdoc_actions
[n
->tok
].pre
)
238 return((*mdoc_actions
[n
->tok
].pre
)(m
, n
));
243 mdoc_action_post(struct mdoc
*m
)
246 if (MDOC_ACTED
& m
->last
->flags
)
248 m
->last
->flags
|= MDOC_ACTED
;
250 switch (m
->last
->type
) {
259 if (NULL
== mdoc_actions
[m
->last
->tok
].post
)
261 return((*mdoc_actions
[m
->last
->tok
].post
)(m
, m
->last
));
266 * Concatenate sibling nodes together. All siblings must be of type
267 * MDOC_TEXT or an assertion is raised. Concatenation is separated by a
271 concat(struct mdoc
*m
, char *p
, const struct mdoc_node
*n
, size_t sz
)
276 for ( ; n
; n
= n
->next
) {
277 assert(MDOC_TEXT
== n
->type
);
279 * XXX: yes, these can technically be resized, but it's
280 * highly unlikely that we're going to get here, so let
283 if (strlcat(p
, n
->string
, sz
) >= sz
) {
284 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
289 if (strlcat(p
, " ", sz
) >= sz
) {
290 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
300 * Macros accepting `-std' as an argument have the name of the current
301 * document (`Nm') filled in as the argument if it's not provided.
306 struct mdoc_node
*nn
;
310 if (NULL
== m
->meta
.name
)
314 m
->next
= MDOC_NEXT_CHILD
;
316 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, m
->meta
.name
))
324 * The `Nm' macro's first use sets the name of the document. See also
334 if ( ! concat(m
, buf
, n
->child
, BUFSIZ
))
336 m
->meta
.name
= mandoc_strdup(buf
);
342 * Look up the value of `Lb' for matching predefined strings. If it has
343 * one, then substitute the current value for the formatted value. Note
344 * that the lookup may fail (we can provide arbitrary strings).
354 assert(MDOC_TEXT
== n
->child
->type
);
355 p
= mdoc_a2lib(n
->child
->string
);
358 free(n
->child
->string
);
359 n
->child
->string
= mandoc_strdup(p
);
363 sz
= strlen(n
->child
->string
) +
364 2 + strlen("\\(lqlibrary\\(rq");
365 buf
= mandoc_malloc(sz
);
366 snprintf(buf
, sz
, "library \\(lq%s\\(rq", n
->child
->string
);
367 free(n
->child
->string
);
368 n
->child
->string
= buf
;
374 * Substitute the value of `St' for the corresponding formatted string.
375 * We're guaranteed that this exists (it's been verified during the
384 assert(MDOC_TEXT
== n
->child
->type
);
385 p
= mdoc_a2st(n
->child
->string
);
387 free(n
->child
->string
);
388 n
->child
->string
= mandoc_strdup(p
);
395 * Look up the standard string in a table. We know that it exists from
396 * the validation phase, so assert on failure. If a standard key wasn't
397 * supplied, supply the default ``AT&T UNIX''.
402 struct mdoc_node
*nn
;
408 assert(MDOC_TEXT
== n
->child
->type
);
409 p
= mdoc_a2att(n
->child
->string
);
411 free(n
->child
->string
);
412 n
->child
->string
= mandoc_strdup(p
);
415 q
= n
->child
->string
;
416 sz
= strlen(p
) + strlen(q
) + 1;
417 buf
= mandoc_malloc(sz
);
420 free(n
->child
->string
);
421 n
->child
->string
= buf
;
427 m
->next
= MDOC_NEXT_CHILD
;
428 if ( ! mdoc_word_alloc(m
, nn
->line
, nn
->pos
, "AT&T UNIX"))
436 * Mark the current section. The ``named'' section (lastnamed) is set
437 * whenever the current section isn't a custom section--we use this to
438 * keep track of section ordering. Also check that the section is
439 * allowed within the document's manual section.
447 if (MDOC_HEAD
!= n
->type
)
450 if ( ! concat(m
, buf
, n
->child
, BUFSIZ
))
452 sec
= mdoc_str2sec(buf
);
454 * The first section should always make us move into a non-new
457 if (SEC_NONE
== m
->lastnamed
|| SEC_CUSTOM
!= sec
)
461 * Switch the parser's SYNOPSIS mode, to be copied
462 * into individual nodes when creating them.
463 * Note that this mode can also be set and unset
464 * using the roff nS register.
466 if (SEC_SYNOPSIS
== sec
)
467 m
->flags
|= MDOC_SYNOPSIS
;
469 m
->flags
&= ~MDOC_SYNOPSIS
;
471 /* Some sections only live in certain manual sections. */
473 switch ((m
->lastsec
= sec
)) {
474 case (SEC_RETURN_VALUES
):
477 assert(m
->meta
.msec
);
478 if (*m
->meta
.msec
== '2')
480 if (*m
->meta
.msec
== '3')
482 if (*m
->meta
.msec
== '9')
484 return(mdoc_nmsg(m
, n
, MANDOCERR_SECMSEC
));
493 * Parse out the contents of `Dt'. See in-line documentation for how we
494 * handle the various fields of this macro.
499 struct mdoc_node
*nn
;
509 m
->meta
.title
= m
->meta
.vol
= m
->meta
.arch
= NULL
;
511 * --> title = unknown, volume = local, msec = 0, arch = NULL
514 if (NULL
== (nn
= n
->child
)) {
515 /* XXX: make these macro values. */
516 /* FIXME: warn about missing values. */
517 m
->meta
.title
= mandoc_strdup("UNKNOWN");
518 m
->meta
.vol
= mandoc_strdup("LOCAL");
519 m
->meta
.msec
= mandoc_strdup("1");
520 return(post_prol(m
, n
));
523 /* Handles: `.Dt TITLE'
524 * --> title = TITLE, volume = local, msec = 0, arch = NULL
527 m
->meta
.title
= mandoc_strdup
528 ('\0' == nn
->string
[0] ? "UNKNOWN" : nn
->string
);
530 if (NULL
== (nn
= nn
->next
)) {
531 /* FIXME: warn about missing msec. */
532 /* XXX: make this a macro value. */
533 m
->meta
.vol
= mandoc_strdup("LOCAL");
534 m
->meta
.msec
= mandoc_strdup("1");
535 return(post_prol(m
, n
));
538 /* Handles: `.Dt TITLE SEC'
539 * --> title = TITLE, volume = SEC is msec ?
540 * format(msec) : SEC,
541 * msec = SEC is msec ? atoi(msec) : 0,
545 cp
= mdoc_a2msec(nn
->string
);
547 m
->meta
.vol
= mandoc_strdup(cp
);
548 m
->meta
.msec
= mandoc_strdup(nn
->string
);
549 } else if (mdoc_nmsg(m
, n
, MANDOCERR_BADMSEC
)) {
550 m
->meta
.vol
= mandoc_strdup(nn
->string
);
551 m
->meta
.msec
= mandoc_strdup(nn
->string
);
555 if (NULL
== (nn
= nn
->next
))
556 return(post_prol(m
, n
));
558 /* Handles: `.Dt TITLE SEC VOL'
559 * --> title = TITLE, volume = VOL is vol ?
561 * VOL is arch ? format(arch) :
565 cp
= mdoc_a2vol(nn
->string
);
568 m
->meta
.vol
= mandoc_strdup(cp
);
570 /* FIXME: warn about bad arch. */
571 cp
= mdoc_a2arch(nn
->string
);
574 m
->meta
.vol
= mandoc_strdup(nn
->string
);
576 m
->meta
.arch
= mandoc_strdup(cp
);
579 /* Ignore any subsequent parameters... */
580 /* FIXME: warn about subsequent parameters. */
582 return(post_prol(m
, n
));
587 * Set the operating system by way of the `Os' macro. Note that if an
588 * argument isn't provided and -DOSNAME="\"foo\"" is provided during
589 * compilation, this value will be used instead of filling in "sysname
590 * release" from uname().
597 struct utsname utsname
;
603 if ( ! concat(m
, buf
, n
->child
, BUFSIZ
))
606 /* XXX: yes, these can all be dynamically-adjusted buffers, but
607 * it's really not worth the extra hackery.
610 if ('\0' == buf
[0]) {
612 if (strlcat(buf
, OSNAME
, BUFSIZ
) >= BUFSIZ
) {
613 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
617 if (-1 == uname(&utsname
))
618 return(mdoc_nmsg(m
, n
, MANDOCERR_UTSNAME
));
620 if (strlcat(buf
, utsname
.sysname
, BUFSIZ
) >= BUFSIZ
) {
621 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
624 if (strlcat(buf
, " ", 64) >= BUFSIZ
) {
625 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
628 if (strlcat(buf
, utsname
.release
, BUFSIZ
) >= BUFSIZ
) {
629 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
635 m
->meta
.os
= mandoc_strdup(buf
);
636 return(post_prol(m
, n
));
641 * Calculate the -width for a `Bl -tag' list if it hasn't been provided.
642 * Uses the first head macro. NOTE AGAIN: this is ONLY if the -width
643 * argument has NOT been provided. See post_bl_width() for converting
647 post_bl_tagwidth(POST_ARGS
)
649 struct mdoc_node
*nn
;
656 for (nn
= n
->body
->child
; nn
; nn
= nn
->next
) {
657 if (MDOC_It
!= nn
->tok
)
660 assert(MDOC_BLOCK
== nn
->type
);
661 nn
= nn
->head
->child
;
663 if (MDOC_TEXT
== nn
->type
) {
664 sz
= strlen(nn
->string
) + 1;
668 if (0 != (ssz
= mdoc_macro2len(nn
->tok
)))
670 else if ( ! mdoc_nmsg(m
, n
, MANDOCERR_NOWIDTHARG
))
676 /* Defaults to ten ens. */
678 snprintf(buf
, NUMSIZ
, "%zun", sz
);
681 * We have to dynamically add this to the macro's argument list.
682 * We're guaranteed that a MDOC_Width doesn't already exist.
686 i
= (int)(n
->args
->argc
)++;
688 n
->args
->argv
= mandoc_realloc(n
->args
->argv
,
689 n
->args
->argc
* sizeof(struct mdoc_argv
));
691 n
->args
->argv
[i
].arg
= MDOC_Width
;
692 n
->args
->argv
[i
].line
= n
->line
;
693 n
->args
->argv
[i
].pos
= n
->pos
;
694 n
->args
->argv
[i
].sz
= 1;
695 n
->args
->argv
[i
].value
= mandoc_malloc(sizeof(char *));
696 n
->args
->argv
[i
].value
[0] = mandoc_strdup(buf
);
699 n
->data
.Bl
->width
= n
->args
->argv
[i
].value
[0];
705 * Calculate the real width of a list from the -width string, which may
706 * contain a macro (with a known default width), a literal string, or a
710 post_bl_width(POST_ARGS
)
718 * If the value to -width is a macro, then we re-write it to be
719 * the macro's width as set in share/tmac/mdoc/doc-common.
722 if (0 == strcmp(n
->data
.Bl
->width
, "Ds"))
724 else if (MDOC_MAX
== (tok
= mdoc_hash_find(n
->data
.Bl
->width
)))
726 else if (0 == (width
= mdoc_macro2len(tok
)))
727 return(mdoc_nmsg(m
, n
, MANDOCERR_BADWIDTH
));
729 /* The value already exists: free and reallocate it. */
733 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
734 if (MDOC_Width
== n
->args
->argv
[i
].arg
)
737 assert(i
< (int)n
->args
->argc
);
739 snprintf(buf
, NUMSIZ
, "%zun", width
);
740 free(n
->args
->argv
[i
].value
[0]);
741 n
->args
->argv
[i
].value
[0] = mandoc_strdup(buf
);
744 n
->data
.Bl
->width
= n
->args
->argv
[i
].value
[0];
750 * Do processing for -column lists, which can have two distinct styles
751 * of invocation. Merge this two styles into a consistent form.
755 post_bl_head(POST_ARGS
)
758 struct mdoc_node
*np
, *nn
, *nnp
;
760 if (LIST_column
!= n
->data
.Bl
->type
)
762 else if (NULL
== n
->child
)
768 for (c
= 0; c
< (int)np
->args
->argc
; c
++)
769 if (MDOC_Column
== np
->args
->argv
[c
].arg
)
772 assert(c
< (int)np
->args
->argc
);
773 assert(0 == np
->args
->argv
[c
].sz
);
776 * Accomodate for new-style groff column syntax. Shuffle the
777 * child nodes, all of which must be TEXT, as arguments for the
778 * column field. Then, delete the head children.
781 np
->args
->argv
[c
].sz
= (size_t)n
->nchild
;
782 np
->args
->argv
[c
].value
= mandoc_malloc
783 ((size_t)n
->nchild
* sizeof(char *));
785 n
->data
.Bl
->ncols
= np
->args
->argv
[c
].sz
;
786 n
->data
.Bl
->cols
= (const char **)np
->args
->argv
[c
].value
;
788 for (i
= 0, nn
= n
->child
; nn
; i
++) {
789 np
->args
->argv
[c
].value
[i
] = nn
->string
;
793 mdoc_node_delete(NULL
, nnp
);
806 if (MDOC_HEAD
== n
->type
)
807 return(post_bl_head(m
, n
));
808 if (MDOC_BLOCK
!= n
->type
)
812 * These are fairly complicated, so we've broken them into two
813 * functions. post_bl_tagwidth() is called when a -tag is
814 * specified, but no -width (it must be guessed). The second
815 * when a -width is specified (macro indicators must be
816 * rewritten into real lengths).
819 if (LIST_tag
== n
->data
.Bl
->type
&& NULL
== n
->data
.Bl
->width
) {
820 if ( ! post_bl_tagwidth(m
, n
))
822 } else if (NULL
!= n
->data
.Bl
->width
) {
823 if ( ! post_bl_width(m
, n
))
828 assert(n
->data
.Bl
->width
);
834 * The `Pa' macro defaults to a tilde if no value is provided as an
840 struct mdoc_node
*np
;
846 m
->next
= MDOC_NEXT_CHILD
;
847 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "~"))
855 * Empty `Li' macros get an empty string to make front-ends add an extra
861 struct mdoc_node
*np
;
867 m
->next
= MDOC_NEXT_CHILD
;
868 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, ""))
876 * The `Ar' macro defaults to two strings "file ..." if no value is
877 * provided as an argument.
882 struct mdoc_node
*np
;
888 m
->next
= MDOC_NEXT_CHILD
;
889 /* XXX: make into macro values. */
890 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "file"))
892 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "..."))
900 * Parse the date field in `Dd'.
907 if ( ! concat(m
, buf
, n
->child
, DATESIZ
))
910 m
->meta
.date
= mandoc_a2time
911 (MTIME_MDOCDATE
| MTIME_CANONICAL
, buf
);
913 if (0 == m
->meta
.date
) {
914 if ( ! mdoc_nmsg(m
, n
, MANDOCERR_BADDATE
))
916 m
->meta
.date
= time(NULL
);
919 return(post_prol(m
, n
));
924 * Remove prologue macros from the document after they're processed.
925 * The final document uses mdoc_meta for these values and discards the
932 mdoc_node_delete(m
, n
);
933 if (m
->meta
.title
&& m
->meta
.date
&& m
->meta
.os
)
934 m
->flags
|= MDOC_PBODY
;
940 * Trigger a literal context.
946 if (MDOC_BODY
== n
->type
)
947 m
->flags
|= MDOC_LITERAL
;
956 if (MDOC_BODY
!= n
->type
)
960 if (DISP_literal
== n
->data
.Bd
->type
)
961 m
->flags
|= MDOC_LITERAL
;
962 if (DISP_unfilled
== n
->data
.Bd
->type
)
963 m
->flags
|= MDOC_LITERAL
;
970 post_display(POST_ARGS
)
973 if (MDOC_BODY
== n
->type
)
974 m
->flags
&= ~MDOC_LITERAL
;
980 order_rs(enum mdoct t
)
984 for (i
= 0; i
< (int)RSORD_MAX
; i
++)
997 struct mdoc_node
*nn
, *next
, *prev
;
1000 if (MDOC_BLOCK
!= n
->type
)
1003 assert(n
->body
->child
);
1004 for (next
= NULL
, nn
= n
->body
->child
->next
; nn
; nn
= next
) {
1005 o
= order_rs(nn
->tok
);
1007 /* Remove `nn' from the chain. */
1010 next
->prev
= nn
->prev
;
1014 prev
->next
= nn
->next
;
1016 nn
->prev
= nn
->next
= NULL
;
1019 * Scan back until we reach a node that's ordered before
1020 * us, then set ourselves as being the next.
1022 for ( ; prev
; prev
= prev
->prev
)
1023 if (order_rs(prev
->tok
) <= o
)
1029 prev
->next
->prev
= nn
;
1030 nn
->next
= prev
->next
;
1035 n
->body
->child
->prev
= nn
;
1036 nn
->next
= n
->body
->child
;
1037 n
->body
->child
= nn
;