]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_action.c
1 /* $Id: mdoc_action.c,v 1.57 2010/05/14 16:02:29 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
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>
32 #include "libmandoc.h"
34 #define POST_ARGS struct mdoc *m, struct mdoc_node *n
35 #define PRE_ARGS struct mdoc *m, const struct mdoc_node *n
42 int (*post
)(POST_ARGS
);
45 static int concat(struct mdoc
*, char *,
46 const struct mdoc_node
*, size_t);
47 static inline int order_rs(enum mdoct
);
49 static int post_ar(POST_ARGS
);
50 static int post_at(POST_ARGS
);
51 static int post_bl(POST_ARGS
);
52 static int post_bl_head(POST_ARGS
);
53 static int post_bl_tagwidth(POST_ARGS
);
54 static int post_bl_width(POST_ARGS
);
55 static int post_dd(POST_ARGS
);
56 static int post_display(POST_ARGS
);
57 static int post_dt(POST_ARGS
);
58 static int post_lb(POST_ARGS
);
59 static int post_nm(POST_ARGS
);
60 static int post_os(POST_ARGS
);
61 static int post_pa(POST_ARGS
);
62 static int post_prol(POST_ARGS
);
63 static int post_rs(POST_ARGS
);
64 static int post_sh(POST_ARGS
);
65 static int post_st(POST_ARGS
);
66 static int post_std(POST_ARGS
);
68 static int pre_bd(PRE_ARGS
);
69 static int pre_bl(PRE_ARGS
);
70 static int pre_dl(PRE_ARGS
);
71 static int pre_offset(PRE_ARGS
);
73 static const struct actions mdoc_actions
[MDOC_MAX
] = {
74 { NULL
, NULL
}, /* Ap */
75 { NULL
, post_dd
}, /* Dd */
76 { NULL
, post_dt
}, /* Dt */
77 { NULL
, post_os
}, /* Os */
78 { NULL
, post_sh
}, /* Sh */
79 { NULL
, NULL
}, /* Ss */
80 { NULL
, NULL
}, /* Pp */
81 { NULL
, NULL
}, /* D1 */
82 { pre_dl
, post_display
}, /* Dl */
83 { pre_bd
, post_display
}, /* Bd */
84 { NULL
, NULL
}, /* Ed */
85 { pre_bl
, post_bl
}, /* Bl */
86 { NULL
, NULL
}, /* El */
87 { NULL
, NULL
}, /* It */
88 { NULL
, NULL
}, /* Ad */
89 { NULL
, NULL
}, /* An */
90 { NULL
, post_ar
}, /* Ar */
91 { NULL
, NULL
}, /* Cd */
92 { NULL
, NULL
}, /* Cm */
93 { NULL
, NULL
}, /* Dv */
94 { NULL
, NULL
}, /* Er */
95 { NULL
, NULL
}, /* Ev */
96 { NULL
, post_std
}, /* Ex */
97 { NULL
, NULL
}, /* Fa */
98 { NULL
, NULL
}, /* Fd */
99 { NULL
, NULL
}, /* Fl */
100 { NULL
, NULL
}, /* Fn */
101 { NULL
, NULL
}, /* Ft */
102 { NULL
, NULL
}, /* Ic */
103 { NULL
, NULL
}, /* In */
104 { NULL
, NULL
}, /* Li */
105 { NULL
, NULL
}, /* Nd */
106 { NULL
, post_nm
}, /* Nm */
107 { NULL
, NULL
}, /* Op */
108 { NULL
, NULL
}, /* Ot */
109 { NULL
, post_pa
}, /* Pa */
110 { NULL
, post_std
}, /* Rv */
111 { NULL
, post_st
}, /* St */
112 { NULL
, NULL
}, /* Va */
113 { NULL
, NULL
}, /* Vt */
114 { NULL
, NULL
}, /* Xr */
115 { NULL
, NULL
}, /* %A */
116 { NULL
, NULL
}, /* %B */
117 { NULL
, NULL
}, /* %D */
118 { NULL
, NULL
}, /* %I */
119 { NULL
, NULL
}, /* %J */
120 { NULL
, NULL
}, /* %N */
121 { NULL
, NULL
}, /* %O */
122 { NULL
, NULL
}, /* %P */
123 { NULL
, NULL
}, /* %R */
124 { NULL
, NULL
}, /* %T */
125 { NULL
, NULL
}, /* %V */
126 { NULL
, NULL
}, /* Ac */
127 { NULL
, NULL
}, /* Ao */
128 { NULL
, NULL
}, /* Aq */
129 { NULL
, post_at
}, /* At */
130 { NULL
, NULL
}, /* Bc */
131 { NULL
, NULL
}, /* Bf */
132 { NULL
, NULL
}, /* Bo */
133 { NULL
, NULL
}, /* Bq */
134 { NULL
, NULL
}, /* Bsx */
135 { NULL
, NULL
}, /* Bx */
136 { NULL
, NULL
}, /* Db */
137 { NULL
, NULL
}, /* Dc */
138 { NULL
, NULL
}, /* Do */
139 { NULL
, NULL
}, /* Dq */
140 { NULL
, NULL
}, /* Ec */
141 { NULL
, NULL
}, /* Ef */
142 { NULL
, NULL
}, /* Em */
143 { NULL
, NULL
}, /* Eo */
144 { NULL
, NULL
}, /* Fx */
145 { NULL
, NULL
}, /* Ms */
146 { NULL
, NULL
}, /* No */
147 { NULL
, NULL
}, /* Ns */
148 { NULL
, NULL
}, /* Nx */
149 { NULL
, NULL
}, /* Ox */
150 { NULL
, NULL
}, /* Pc */
151 { NULL
, NULL
}, /* Pf */
152 { NULL
, NULL
}, /* Po */
153 { NULL
, NULL
}, /* Pq */
154 { NULL
, NULL
}, /* Qc */
155 { NULL
, NULL
}, /* Ql */
156 { NULL
, NULL
}, /* Qo */
157 { NULL
, NULL
}, /* Qq */
158 { NULL
, NULL
}, /* Re */
159 { NULL
, post_rs
}, /* Rs */
160 { NULL
, NULL
}, /* Sc */
161 { NULL
, NULL
}, /* So */
162 { NULL
, NULL
}, /* Sq */
163 { NULL
, NULL
}, /* Sm */
164 { NULL
, NULL
}, /* Sx */
165 { NULL
, NULL
}, /* Sy */
166 { NULL
, NULL
}, /* Tn */
167 { NULL
, NULL
}, /* Ux */
168 { NULL
, NULL
}, /* Xc */
169 { NULL
, NULL
}, /* Xo */
170 { NULL
, NULL
}, /* Fo */
171 { NULL
, NULL
}, /* Fc */
172 { NULL
, NULL
}, /* Oo */
173 { NULL
, NULL
}, /* Oc */
174 { NULL
, NULL
}, /* Bk */
175 { NULL
, NULL
}, /* Ek */
176 { NULL
, NULL
}, /* Bt */
177 { NULL
, NULL
}, /* Hf */
178 { NULL
, NULL
}, /* Fr */
179 { NULL
, NULL
}, /* Ud */
180 { NULL
, post_lb
}, /* Lb */
181 { NULL
, NULL
}, /* Lp */
182 { NULL
, NULL
}, /* Lk */
183 { NULL
, NULL
}, /* Mt */
184 { NULL
, NULL
}, /* Brq */
185 { NULL
, NULL
}, /* Bro */
186 { NULL
, NULL
}, /* Brc */
187 { NULL
, NULL
}, /* %C */
188 { NULL
, NULL
}, /* Es */
189 { NULL
, NULL
}, /* En */
190 { NULL
, NULL
}, /* Dx */
191 { NULL
, NULL
}, /* %Q */
192 { NULL
, NULL
}, /* br */
193 { NULL
, NULL
}, /* sp */
194 { NULL
, NULL
}, /* %U */
199 static const enum mdoct rsord
[RSORD_MAX
] = {
218 mdoc_action_pre(struct mdoc
*m
, const struct mdoc_node
*n
)
230 if (NULL
== mdoc_actions
[n
->tok
].pre
)
232 return((*mdoc_actions
[n
->tok
].pre
)(m
, n
));
237 mdoc_action_post(struct mdoc
*m
)
240 if (MDOC_ACTED
& m
->last
->flags
)
242 m
->last
->flags
|= MDOC_ACTED
;
244 switch (m
->last
->type
) {
253 if (NULL
== mdoc_actions
[m
->last
->tok
].post
)
255 return((*mdoc_actions
[m
->last
->tok
].post
)(m
, m
->last
));
260 * Concatenate sibling nodes together. All siblings must be of type
261 * MDOC_TEXT or an assertion is raised. Concatenation is separated by a
265 concat(struct mdoc
*m
, char *p
, const struct mdoc_node
*n
, size_t sz
)
270 for ( ; n
; n
= n
->next
) {
271 assert(MDOC_TEXT
== n
->type
);
272 if (strlcat(p
, n
->string
, sz
) >= sz
)
273 return(mdoc_nerr(m
, n
, ETOOLONG
));
276 if (strlcat(p
, " ", sz
) >= sz
)
277 return(mdoc_nerr(m
, n
, ETOOLONG
));
285 * Macros accepting `-std' as an argument have the name of the current
286 * document (`Nm') filled in as the argument if it's not provided.
291 struct mdoc_node
*nn
;
297 m
->next
= MDOC_NEXT_CHILD
;
298 assert(m
->meta
.name
);
299 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, m
->meta
.name
))
307 * The `Nm' macro's first use sets the name of the document. See also
317 if ( ! concat(m
, buf
, n
->child
, BUFSIZ
))
319 m
->meta
.name
= mandoc_strdup(buf
);
325 * Look up the value of `Lb' for matching predefined strings. If it has
326 * one, then substitute the current value for the formatted value. Note
327 * that the lookup may fail (we can provide arbitrary strings).
337 assert(MDOC_TEXT
== n
->child
->type
);
338 p
= mdoc_a2lib(n
->child
->string
);
341 free(n
->child
->string
);
342 n
->child
->string
= mandoc_strdup(p
);
346 sz
= strlen(n
->child
->string
) +
347 2 + strlen("\\(lqlibrary\\(rq");
348 buf
= mandoc_malloc(sz
);
349 snprintf(buf
, sz
, "library \\(lq%s\\(rq", n
->child
->string
);
350 free(n
->child
->string
);
351 n
->child
->string
= buf
;
357 * Substitute the value of `St' for the corresponding formatted string.
358 * We're guaranteed that this exists (it's been verified during the
367 assert(MDOC_TEXT
== n
->child
->type
);
368 p
= mdoc_a2st(n
->child
->string
);
370 free(n
->child
->string
);
371 n
->child
->string
= mandoc_strdup(p
);
378 * Look up the standard string in a table. We know that it exists from
379 * the validation phase, so assert on failure. If a standard key wasn't
380 * supplied, supply the default ``AT&T UNIX''.
385 struct mdoc_node
*nn
;
391 assert(MDOC_TEXT
== n
->child
->type
);
392 p
= mdoc_a2att(n
->child
->string
);
394 free(n
->child
->string
);
395 n
->child
->string
= mandoc_strdup(p
);
398 q
= n
->child
->string
;
399 sz
= strlen(p
) + strlen(q
) + 1;
400 buf
= mandoc_malloc(sz
);
403 free(n
->child
->string
);
404 n
->child
->string
= buf
;
410 m
->next
= MDOC_NEXT_CHILD
;
411 if ( ! mdoc_word_alloc(m
, nn
->line
, nn
->pos
, "AT&T UNIX"))
419 * Mark the current section. The ``named'' section (lastnamed) is set
420 * whenever the current section isn't a custom section--we use this to
421 * keep track of section ordering. Also check that the section is
422 * allowed within the document's manual section.
430 if (MDOC_HEAD
!= n
->type
)
433 if ( ! concat(m
, buf
, n
->child
, BUFSIZ
))
435 sec
= mdoc_str2sec(buf
);
437 * The first section should always make us move into a non-new
440 if (SEC_NONE
== m
->lastnamed
|| SEC_CUSTOM
!= sec
)
443 /* Some sections only live in certain manual sections. */
445 switch ((m
->lastsec
= sec
)) {
446 case (SEC_RETURN_VALUES
):
449 switch (m
->meta
.msec
) {
457 return(mdoc_nwarn(m
, n
, EBADSEC
));
468 * Parse out the contents of `Dt'. See in-line documentation for how we
469 * handle the various fields of this macro.
474 struct mdoc_node
*nn
;
486 m
->meta
.title
= m
->meta
.vol
= m
->meta
.arch
= NULL
;
490 * --> title = unknown, volume = local, msec = 0, arch = NULL
493 if (NULL
== (nn
= n
->child
)) {
494 /* XXX: make these macro values. */
495 m
->meta
.title
= mandoc_strdup("unknown");
496 m
->meta
.vol
= mandoc_strdup("local");
497 return(post_prol(m
, n
));
500 /* Handles: `.Dt TITLE'
501 * --> title = TITLE, volume = local, msec = 0, arch = NULL
504 m
->meta
.title
= mandoc_strdup(nn
->string
);
506 if (NULL
== (nn
= nn
->next
)) {
507 /* XXX: make this a macro value. */
508 m
->meta
.vol
= mandoc_strdup("local");
509 return(post_prol(m
, n
));
512 /* Handles: `.Dt TITLE SEC'
513 * --> title = TITLE, volume = SEC is msec ?
514 * format(msec) : SEC,
515 * msec = SEC is msec ? atoi(msec) : 0,
519 cp
= mdoc_a2msec(nn
->string
);
521 /* FIXME: where is strtonum!? */
522 m
->meta
.vol
= mandoc_strdup(cp
);
523 lval
= strtol(nn
->string
, &ep
, 10);
524 if (nn
->string
[0] != '\0' && *ep
== '\0')
525 m
->meta
.msec
= (int)lval
;
527 m
->meta
.vol
= mandoc_strdup(nn
->string
);
529 if (NULL
== (nn
= nn
->next
))
530 return(post_prol(m
, n
));
532 /* Handles: `.Dt TITLE SEC VOL'
533 * --> title = TITLE, volume = VOL is vol ?
535 * VOL is arch ? format(arch) :
539 cp
= mdoc_a2vol(nn
->string
);
542 m
->meta
.vol
= mandoc_strdup(cp
);
544 cp
= mdoc_a2arch(nn
->string
);
547 m
->meta
.vol
= mandoc_strdup(nn
->string
);
549 m
->meta
.arch
= mandoc_strdup(cp
);
552 /* Ignore any subsequent parameters... */
553 /* FIXME: warn about subsequent parameters. */
555 return(post_prol(m
, n
));
560 * Set the operating system by way of the `Os' macro. Note that if an
561 * argument isn't provided and -DOSNAME="\"foo\"" is provided during
562 * compilation, this value will be used instead of filling in "sysname
563 * release" from uname().
570 struct utsname utsname
;
576 if ( ! concat(m
, buf
, n
->child
, BUFSIZ
))
579 if ('\0' == buf
[0]) {
581 if (strlcat(buf
, OSNAME
, BUFSIZ
) >= BUFSIZ
)
582 return(mdoc_nerr(m
, n
, EUTSNAME
));
584 if (-1 == uname(&utsname
))
585 return(mdoc_nerr(m
, n
, EUTSNAME
));
586 if (strlcat(buf
, utsname
.sysname
, BUFSIZ
) >= BUFSIZ
)
587 return(mdoc_nerr(m
, n
, ETOOLONG
));
588 if (strlcat(buf
, " ", 64) >= BUFSIZ
)
589 return(mdoc_nerr(m
, n
, ETOOLONG
));
590 if (strlcat(buf
, utsname
.release
, BUFSIZ
) >= BUFSIZ
)
591 return(mdoc_nerr(m
, n
, ETOOLONG
));
595 m
->meta
.os
= mandoc_strdup(buf
);
596 return(post_prol(m
, n
));
601 * Calculate the -width for a `Bl -tag' list if it hasn't been provided.
602 * Uses the first head macro. NOTE AGAIN: this is ONLY if the -width
603 * argument has NOT been provided. See post_bl_width() for converting
607 post_bl_tagwidth(POST_ARGS
)
609 struct mdoc_node
*nn
;
614 /* Defaults to ten ens. */
616 sz
= 10; /* XXX: make this a macro value. */
620 assert(MDOC_BLOCK
== nn
->type
);
621 assert(MDOC_It
== nn
->tok
);
622 nn
= nn
->head
->child
;
623 if (MDOC_TEXT
!= nn
->type
) {
624 sz
= mdoc_macro2len(nn
->tok
);
626 if ( ! mdoc_nwarn(m
, n
, ENOWIDTH
))
631 sz
= strlen(nn
->string
) + 1;
634 snprintf(buf
, NUMSIZ
, "%zun", sz
);
637 * We have to dynamically add this to the macro's argument list.
638 * We're guaranteed that a MDOC_Width doesn't already exist.
643 i
= (int)(nn
->args
->argc
)++;
645 nn
->args
->argv
= mandoc_realloc(nn
->args
->argv
,
646 nn
->args
->argc
* sizeof(struct mdoc_argv
));
648 nn
->args
->argv
[i
].arg
= MDOC_Width
;
649 nn
->args
->argv
[i
].line
= n
->line
;
650 nn
->args
->argv
[i
].pos
= n
->pos
;
651 nn
->args
->argv
[i
].sz
= 1;
652 nn
->args
->argv
[i
].value
= mandoc_malloc(sizeof(char *));
653 nn
->args
->argv
[i
].value
[0] = mandoc_strdup(buf
);
659 * Calculate the real width of a list from the -width string, which may
660 * contain a macro (with a known default width), a literal string, or a
664 post_bl_width(POST_ARGS
)
675 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
676 if (MDOC_Width
== n
->args
->argv
[i
].arg
)
679 if (i
== (int)n
->args
->argc
)
681 p
= n
->args
->argv
[i
].value
[0];
684 * If the value to -width is a macro, then we re-write it to be
685 * the macro's width as set in share/tmac/mdoc/doc-common.
688 if (0 == strcmp(p
, "Ds"))
689 /* XXX: make into a macro. */
691 else if (MDOC_MAX
== (tok
= mdoc_hash_find(p
)))
693 else if (0 == (width
= mdoc_macro2len(tok
)))
694 return(mdoc_nwarn(m
, n
, ENOWIDTH
));
696 /* The value already exists: free and reallocate it. */
698 snprintf(buf
, NUMSIZ
, "%zun", width
);
699 free(n
->args
->argv
[i
].value
[0]);
700 n
->args
->argv
[i
].value
[0] = mandoc_strdup(buf
);
706 * Do processing for -column lists, which can have two distinct styles
707 * of invocation. Merge this two styles into a consistent form.
711 post_bl_head(POST_ARGS
)
714 struct mdoc_node
*np
, *nn
, *nnp
;
716 if (NULL
== n
->child
)
722 for (c
= 0; c
< (int)np
->args
->argc
; c
++)
723 if (MDOC_Column
== np
->args
->argv
[c
].arg
)
726 if (c
== (int)np
->args
->argc
)
728 assert(0 == np
->args
->argv
[c
].sz
);
731 * Accomodate for new-style groff column syntax. Shuffle the
732 * child nodes, all of which must be TEXT, as arguments for the
733 * column field. Then, delete the head children.
736 np
->args
->argv
[c
].sz
= (size_t)n
->nchild
;
737 np
->args
->argv
[c
].value
= mandoc_malloc
738 ((size_t)n
->nchild
* sizeof(char *));
740 for (i
= 0, nn
= n
->child
; nn
; i
++) {
741 np
->args
->argv
[c
].value
[i
] = nn
->string
;
745 mdoc_node_delete(NULL
, nnp
);
759 if (MDOC_HEAD
== n
->type
)
760 return(post_bl_head(m
, n
));
761 if (MDOC_BLOCK
!= n
->type
)
765 * These are fairly complicated, so we've broken them into two
766 * functions. post_bl_tagwidth() is called when a -tag is
767 * specified, but no -width (it must be guessed). The second
768 * when a -width is specified (macro indicators must be
769 * rewritten into real lengths).
772 len
= (int)(n
->args
? n
->args
->argc
: 0);
774 for (r
= i
= 0; i
< len
; i
++) {
775 if (MDOC_Tag
== n
->args
->argv
[i
].arg
)
777 if (MDOC_Width
== n
->args
->argv
[i
].arg
)
781 if (r
& (1 << 0) && ! (r
& (1 << 1))) {
782 if ( ! post_bl_tagwidth(m
, n
))
784 } else if (r
& (1 << 1))
785 if ( ! post_bl_width(m
, n
))
793 * The `Pa' macro defaults to a tilde if no value is provided as an
799 struct mdoc_node
*np
;
805 m
->next
= MDOC_NEXT_CHILD
;
806 /* XXX: make into macro value. */
807 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "~"))
815 * The `Ar' macro defaults to two strings "file ..." if no value is
816 * provided as an argument.
821 struct mdoc_node
*np
;
827 m
->next
= MDOC_NEXT_CHILD
;
828 /* XXX: make into macro values. */
829 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "file"))
831 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "..."))
839 * Parse the date field in `Dd'.
846 if ( ! concat(m
, buf
, n
->child
, DATESIZ
))
849 m
->meta
.date
= mandoc_a2time
850 (MTIME_MDOCDATE
| MTIME_CANONICAL
, buf
);
852 if (0 == m
->meta
.date
) {
853 if ( ! mdoc_nwarn(m
, n
, EBADDATE
))
855 m
->meta
.date
= time(NULL
);
858 return(post_prol(m
, n
));
863 * Remove prologue macros from the document after they're processed.
864 * The final document uses mdoc_meta for these values and discards the
871 mdoc_node_delete(m
, n
);
872 if (m
->meta
.title
&& m
->meta
.date
&& m
->meta
.os
)
873 m
->flags
|= MDOC_PBODY
;
879 * Trigger a literal context.
885 if (MDOC_BODY
== n
->type
)
886 m
->flags
|= MDOC_LITERAL
;
898 * Make sure that an empty offset produces an 8n length space as
899 * stipulated by mdoc.samples.
903 for (i
= 0; i
< (int)n
->args
->argc
; i
++) {
904 if (MDOC_Offset
!= n
->args
->argv
[i
].arg
)
906 if (n
->args
->argv
[i
].sz
)
908 assert(1 == n
->args
->refcnt
);
909 /* If no value set, length of <string>. */
910 n
->args
->argv
[i
].sz
++;
911 n
->args
->argv
[i
].value
= mandoc_malloc(sizeof(char *));
912 n
->args
->argv
[i
].value
[0] = mandoc_strdup("8n");
924 return(MDOC_BLOCK
== n
->type
? pre_offset(m
, n
) : 1);
933 if (MDOC_BLOCK
== n
->type
)
934 return(pre_offset(m
, n
));
935 if (MDOC_BODY
!= n
->type
)
938 /* Enter literal context if `Bd -literal' or `-unfilled'. */
940 for (n
= n
->parent
, i
= 0; i
< (int)n
->args
->argc
; i
++)
941 if (MDOC_Literal
== n
->args
->argv
[i
].arg
)
942 m
->flags
|= MDOC_LITERAL
;
943 else if (MDOC_Unfilled
== n
->args
->argv
[i
].arg
)
944 m
->flags
|= MDOC_LITERAL
;
951 post_display(POST_ARGS
)
954 if (MDOC_BODY
== n
->type
)
955 m
->flags
&= ~MDOC_LITERAL
;
961 order_rs(enum mdoct t
)
965 for (i
= 0; i
< (int)RSORD_MAX
; i
++)
978 struct mdoc_node
*nn
, *next
, *prev
;
981 if (MDOC_BLOCK
!= n
->type
)
984 assert(n
->body
->child
);
985 for (next
= NULL
, nn
= n
->body
->child
->next
; nn
; nn
= next
) {
986 o
= order_rs(nn
->tok
);
988 /* Remove `nn' from the chain. */
991 next
->prev
= nn
->prev
;
995 prev
->next
= nn
->next
;
997 nn
->prev
= nn
->next
= NULL
;
1000 * Scan back until we reach a node that's ordered before
1001 * us, then set ourselves as being the next.
1003 for ( ; prev
; prev
= prev
->prev
)
1004 if (order_rs(prev
->tok
) <= o
)
1010 prev
->next
->prev
= nn
;
1011 nn
->next
= prev
->next
;
1016 n
->body
->child
->prev
= nn
;
1017 nn
->next
= n
->body
->child
;
1018 n
->body
->child
= nn
;