]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_action.c
1 /* $Id: mdoc_action.c,v 1.44 2009/10/26 04:09:45 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.
18 #include <sys/utsname.h>
30 #define POST_ARGS struct mdoc *m, struct mdoc_node *n
31 #define PRE_ARGS struct mdoc *m, const struct mdoc_node *n
35 int (*post
)(POST_ARGS
);
38 static int concat(struct mdoc
*,
39 const struct mdoc_node
*,
41 static inline int order_rs(int);
44 extern size_t strlcat(char *, const char *, size_t);
47 static int post_ar(POST_ARGS
);
48 static int post_at(POST_ARGS
);
49 static int post_bl(POST_ARGS
);
50 static int post_bl_head(POST_ARGS
);
51 static int post_bl_tagwidth(POST_ARGS
);
52 static int post_bl_width(POST_ARGS
);
53 static int post_dd(POST_ARGS
);
54 static int post_display(POST_ARGS
);
55 static int post_dt(POST_ARGS
);
56 static int post_lb(POST_ARGS
);
57 static int post_nm(POST_ARGS
);
58 static int post_os(POST_ARGS
);
59 static int post_prol(POST_ARGS
);
60 static int post_rs(POST_ARGS
);
61 static int post_sh(POST_ARGS
);
62 static int post_st(POST_ARGS
);
63 static int post_std(POST_ARGS
);
64 static int post_tilde(POST_ARGS
);
66 static int pre_bd(PRE_ARGS
);
67 static int pre_bl(PRE_ARGS
);
68 static int pre_dl(PRE_ARGS
);
69 static int pre_offset(PRE_ARGS
);
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
, post_sh
}, /* 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 { pre_bl
, post_bl
}, /* Bl */
84 { NULL
, NULL
}, /* El */
85 { NULL
, NULL
}, /* It */
86 { NULL
, NULL
}, /* Ad */
87 { NULL
, NULL
}, /* An */
88 { NULL
, post_ar
}, /* 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_tilde
}, /* 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
, post_at
}, /* 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
, post_rs
}, /* 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
, post_lb
}, /* 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 */
197 static const int rsord
[RSORD_MAX
] = {
215 mdoc_action_pre(struct mdoc
*m
, const struct mdoc_node
*n
)
227 if (NULL
== mdoc_actions
[n
->tok
].pre
)
229 return((*mdoc_actions
[n
->tok
].pre
)(m
, n
));
234 mdoc_action_post(struct mdoc
*m
)
237 if (MDOC_ACTED
& m
->last
->flags
)
239 m
->last
->flags
|= MDOC_ACTED
;
241 switch (m
->last
->type
) {
250 if (NULL
== mdoc_actions
[m
->last
->tok
].post
)
252 return((*mdoc_actions
[m
->last
->tok
].post
)(m
, m
->last
));
257 concat(struct mdoc
*m
, const struct mdoc_node
*n
,
258 char *buf
, size_t sz
)
261 for ( ; n
; n
= n
->next
) {
262 assert(MDOC_TEXT
== n
->type
);
263 if (strlcat(buf
, n
->string
, sz
) >= sz
)
264 return(mdoc_nerr(m
, n
, ETOOLONG
));
267 if (strlcat(buf
, " ", sz
) >= sz
)
268 return(mdoc_nerr(m
, n
, ETOOLONG
));
278 struct mdoc_node
*nn
;
284 m
->next
= MDOC_NEXT_CHILD
;
285 assert(m
->meta
.name
);
286 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, m
->meta
.name
))
303 if ( ! concat(m
, n
->child
, buf
, sizeof(buf
)))
305 if (NULL
== (m
->meta
.name
= strdup(buf
)))
306 return(mdoc_nerr(m
, n
, EMALLOC
));
319 assert(MDOC_TEXT
== n
->child
->type
);
320 p
= mdoc_a2lib(n
->child
->string
);
322 sz
= strlen(n
->child
->string
) +
323 2 + strlen("\\(lqlibrary\\(rq");
326 return(mdoc_nerr(m
, n
, EMALLOC
));
327 (void)snprintf(buf
, sz
, "library \\(lq%s\\(rq",
329 free(n
->child
->string
);
330 n
->child
->string
= buf
;
334 free(n
->child
->string
);
335 n
->child
->string
= strdup(p
);
336 if (NULL
== n
->child
->string
)
337 return(mdoc_nerr(m
, n
, EMALLOC
));
348 assert(MDOC_TEXT
== n
->child
->type
);
349 p
= mdoc_a2st(n
->child
->string
);
351 free(n
->child
->string
);
352 n
->child
->string
= strdup(p
);
353 if (NULL
== n
->child
->string
)
354 return(mdoc_nerr(m
, n
, EMALLOC
));
363 struct mdoc_node
*nn
;
367 assert(MDOC_TEXT
== n
->child
->type
);
368 p
= mdoc_a2att(n
->child
->string
);
370 free(n
->child
->string
);
371 n
->child
->string
= strdup(p
);
372 if (NULL
== n
->child
->string
)
373 return(mdoc_nerr(m
, n
, EMALLOC
));
378 m
->next
= MDOC_NEXT_CHILD
;
380 if ( ! mdoc_word_alloc(m
, nn
->line
, nn
->pos
, "AT&T UNIX"))
395 * We keep track of the current section /and/ the "named"
396 * section, which is one of the conventional ones, in order to
400 if (MDOC_HEAD
!= n
->type
)
404 if ( ! concat(m
, n
->child
, buf
, sizeof(buf
)))
406 if (SEC_CUSTOM
!= (sec
= mdoc_atosec(buf
)))
409 switch ((m
->lastsec
= sec
)) {
410 case (SEC_RETURN_VALUES
):
413 switch (m
->meta
.msec
) {
421 return(mdoc_nwarn(m
, n
, EBADSEC
));
434 struct mdoc_node
*nn
;
446 m
->meta
.title
= m
->meta
.vol
= m
->meta
.arch
= NULL
;
450 * --> title = unknown, volume = local, msec = 0, arch = NULL
453 if (NULL
== (nn
= n
->child
)) {
454 if (NULL
== (m
->meta
.title
= strdup("unknown")))
455 return(mdoc_nerr(m
, n
, EMALLOC
));
456 if (NULL
== (m
->meta
.vol
= strdup("local")))
457 return(mdoc_nerr(m
, n
, EMALLOC
));
458 return(post_prol(m
, n
));
461 /* Handles: `.Dt TITLE'
462 * --> title = TITLE, volume = local, msec = 0, arch = NULL
465 if (NULL
== (m
->meta
.title
= strdup(nn
->string
)))
466 return(mdoc_nerr(m
, n
, EMALLOC
));
468 if (NULL
== (nn
= nn
->next
)) {
469 if (NULL
== (m
->meta
.vol
= strdup("local")))
470 return(mdoc_nerr(m
, n
, EMALLOC
));
471 return(post_prol(m
, n
));
474 /* Handles: `.Dt TITLE SEC'
475 * --> title = TITLE, volume = SEC is msec ?
476 * format(msec) : SEC,
477 * msec = SEC is msec ? atoi(msec) : 0,
481 cp
= mdoc_a2msec(nn
->string
);
483 if (NULL
== (m
->meta
.vol
= strdup(cp
)))
484 return(mdoc_nerr(m
, n
, EMALLOC
));
486 lval
= strtol(nn
->string
, &ep
, 10);
487 if (nn
->string
[0] != '\0' && *ep
== '\0')
488 m
->meta
.msec
= (int)lval
;
489 } else if (NULL
== (m
->meta
.vol
= strdup(nn
->string
)))
490 return(mdoc_nerr(m
, n
, EMALLOC
));
492 if (NULL
== (nn
= nn
->next
))
493 return(post_prol(m
, n
));
495 /* Handles: `.Dt TITLE SEC VOL'
496 * --> title = TITLE, volume = VOL is vol ?
498 * VOL is arch ? format(arch) :
502 cp
= mdoc_a2vol(nn
->string
);
505 if (NULL
== (m
->meta
.vol
= strdup(cp
)))
506 return(mdoc_nerr(m
, n
, EMALLOC
));
508 cp
= mdoc_a2arch(nn
->string
);
511 if (NULL
== (m
->meta
.vol
= strdup(nn
->string
)))
512 return(mdoc_nerr(m
, n
, EMALLOC
));
513 } else if (NULL
== (m
->meta
.arch
= strdup(cp
)))
514 return(mdoc_nerr(m
, n
, EMALLOC
));
517 /* Ignore any subsequent parameters... */
519 return(post_prol(m
, n
));
528 struct utsname utsname
;
532 * Setting OSNAME to be the name of the target operating system,
533 * e.g., "OpenBSD 4.4", will result in the compile-time constant
534 * by supplied instead of the value in uname().
541 if ( ! concat(m
, n
->child
, buf
, sizeof(buf
)))
546 if (strlcat(buf
, OSNAME
, 64) >= 64)
547 return(mdoc_nerr(m
, n
, EUTSNAME
));
549 if (-1 == uname(&utsname
))
550 return(mdoc_nerr(m
, n
, EUTSNAME
));
551 if (strlcat(buf
, utsname
.sysname
, 64) >= 64)
552 return(mdoc_nerr(m
, n
, ETOOLONG
));
553 if (strlcat(buf
, " ", 64) >= 64)
554 return(mdoc_nerr(m
, n
, ETOOLONG
));
555 if (strlcat(buf
, utsname
.release
, 64) >= 64)
556 return(mdoc_nerr(m
, n
, ETOOLONG
));
560 if (NULL
== (m
->meta
.os
= strdup(buf
)))
561 return(mdoc_nerr(m
, n
, EMALLOC
));
563 return(post_prol(m
, n
));
568 * Calculate the -width for a `Bl -tag' list if it hasn't been provided.
569 * Uses the first head macro.
572 post_bl_tagwidth(POST_ARGS
)
574 struct mdoc_node
*nn
;
579 * Use the text width, if a text node, or the default macro
585 assert(MDOC_BLOCK
== nn
->type
);
586 assert(MDOC_It
== nn
->tok
);
587 nn
= nn
->head
->child
;
590 sz
= 10; /* Default size. */
593 if (MDOC_TEXT
!= nn
->type
) {
594 if (0 == (sz
= (int)mdoc_macro2len(nn
->tok
)))
595 if ( ! mdoc_nwarn(m
, n
, ENOWIDTH
))
598 sz
= (int)strlen(nn
->string
) + 1;
601 if (-1 == snprintf(buf
, sizeof(buf
), "%dn", sz
))
602 return(mdoc_nerr(m
, n
, ENUMFMT
));
605 * We have to dynamically add this to the macro's argument list.
606 * We're guaranteed that a MDOC_Width doesn't already exist.
611 sz
= (int)(nn
->args
->argc
)++;
613 nn
->args
->argv
= realloc(nn
->args
->argv
,
614 nn
->args
->argc
* sizeof(struct mdoc_argv
));
616 if (NULL
== nn
->args
->argv
)
617 return(mdoc_nerr(m
, n
, EMALLOC
));
619 nn
->args
->argv
[sz
].arg
= MDOC_Width
;
620 nn
->args
->argv
[sz
].line
= n
->line
;
621 nn
->args
->argv
[sz
].pos
= n
->pos
;
622 nn
->args
->argv
[sz
].sz
= 1;
623 nn
->args
->argv
[sz
].value
= calloc(1, sizeof(char *));
625 if (NULL
== nn
->args
->argv
[sz
].value
)
626 return(mdoc_nerr(m
, n
, EMALLOC
));
627 if (NULL
== (nn
->args
->argv
[sz
].value
[0] = strdup(buf
)))
628 return(mdoc_nerr(m
, n
, EMALLOC
));
635 post_bl_width(POST_ARGS
)
645 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
646 if (MDOC_Width
== n
->args
->argv
[i
].arg
)
649 if (i
== (int)n
->args
->argc
)
651 p
= n
->args
->argv
[i
].value
[0];
654 * If the value to -width is a macro, then we re-write it to be
655 * the macro's width as set in share/tmac/mdoc/doc-common.
658 if (0 == strcmp(p
, "Ds"))
660 else if (MDOC_MAX
== (tok
= mdoc_hash_find(p
)))
662 else if (0 == (width
= mdoc_macro2len(tok
)))
663 return(mdoc_nwarn(m
, n
, ENOWIDTH
));
665 /* The value already exists: free and reallocate it. */
667 if (-1 == snprintf(buf
, sizeof(buf
), "%zun", width
))
668 return(mdoc_nerr(m
, n
, ENUMFMT
));
670 free(n
->args
->argv
[i
].value
[0]);
671 n
->args
->argv
[i
].value
[0] = strdup(buf
);
672 if (NULL
== n
->args
->argv
[i
].value
[0])
673 return(mdoc_nerr(m
, n
, EMALLOC
));
681 post_bl_head(POST_ARGS
)
684 struct mdoc_node
*np
, *nn
, *nnp
;
686 if (NULL
== n
->child
)
692 for (c
= 0; c
< (int)np
->args
->argc
; c
++)
693 if (MDOC_Column
== np
->args
->argv
[c
].arg
)
696 /* Only process -column. */
698 if (c
== (int)np
->args
->argc
)
701 assert(0 == np
->args
->argv
[c
].sz
);
704 * Accomodate for new-style groff column syntax. Shuffle the
705 * child nodes, all of which must be TEXT, as arguments for the
706 * column field. Then, delete the head children.
709 np
->args
->argv
[c
].sz
= (size_t)n
->nchild
;
710 np
->args
->argv
[c
].value
= malloc
711 ((size_t)n
->nchild
* sizeof(char *));
713 for (i
= 0, nn
= n
->child
; nn
; i
++) {
714 np
->args
->argv
[c
].value
[i
] = nn
->string
;
733 if (MDOC_HEAD
== n
->type
)
734 return(post_bl_head(m
, n
));
735 if (MDOC_BLOCK
!= n
->type
)
739 * These are fairly complicated, so we've broken them into two
740 * functions. post_bl_tagwidth() is called when a -tag is
741 * specified, but no -width (it must be guessed). The second
742 * when a -width is specified (macro indicators must be
743 * rewritten into real lengths).
746 len
= (int)(n
->args
? n
->args
->argc
: 0);
748 for (r
= i
= 0; i
< len
; i
++) {
749 if (MDOC_Tag
== n
->args
->argv
[i
].arg
)
751 if (MDOC_Width
== n
->args
->argv
[i
].arg
)
755 if (r
& (1 << 0) && ! (r
& (1 << 1))) {
756 if ( ! post_bl_tagwidth(m
, n
))
758 } else if (r
& (1 << 1))
759 if ( ! post_bl_width(m
, n
))
767 post_tilde(POST_ARGS
)
769 struct mdoc_node
*np
;
775 m
->next
= MDOC_NEXT_CHILD
;
777 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "~"))
788 struct mdoc_node
*np
;
794 m
->next
= MDOC_NEXT_CHILD
;
795 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "file"))
797 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "..."))
811 if ( ! concat(m
, n
->child
, buf
, sizeof(buf
)))
814 if (0 == (m
->meta
.date
= mdoc_atotime(buf
))) {
815 if ( ! mdoc_nwarn(m
, n
, EBADDATE
))
817 m
->meta
.date
= time(NULL
);
820 return(post_prol(m
, n
));
827 struct mdoc_node
*np
;
829 /* Remove prologue macros from AST. */
831 if (n
->parent
->child
== n
)
832 n
->parent
->child
= n
->prev
;
834 n
->prev
->next
= NULL
;
837 assert(NULL
== n
->next
);
841 m
->next
= MDOC_NEXT_SIBLING
;
844 m
->next
= MDOC_NEXT_CHILD
;
847 mdoc_node_freelist(np
);
849 if (m
->meta
.title
&& m
->meta
.date
&& m
->meta
.os
)
850 m
->flags
|= MDOC_PBODY
;
860 if (MDOC_BODY
== n
->type
)
861 m
->flags
|= MDOC_LITERAL
;
872 * Make sure that an empty offset produces an 8n length space as
873 * stipulated by mdoc.samples.
877 for (i
= 0; i
< (int)n
->args
->argc
; i
++) {
878 if (MDOC_Offset
!= n
->args
->argv
[i
].arg
)
880 if (n
->args
->argv
[i
].sz
)
882 assert(1 == n
->args
->refcnt
);
883 /* If no value set, length of <string>. */
884 n
->args
->argv
[i
].value
=
885 calloc(1, sizeof(char *));
886 if (NULL
== n
->args
->argv
[i
].value
)
887 return(mdoc_nerr(m
, n
, EMALLOC
));
888 n
->args
->argv
[i
].sz
++;
889 n
->args
->argv
[i
].value
[0] = strdup("8n");
890 if (NULL
== n
->args
->argv
[i
].value
[0])
891 return(mdoc_nerr(m
, n
, EMALLOC
));
903 return(MDOC_BLOCK
== n
->type
? pre_offset(m
, n
) : 1);
912 if (MDOC_BLOCK
== n
->type
)
913 return(pre_offset(m
, n
));
914 if (MDOC_BODY
!= n
->type
)
917 /* Enter literal context if `Bd -literal' or `-unfilled'. */
919 for (n
= n
->parent
, i
= 0; i
< (int)n
->args
->argc
; i
++)
920 if (MDOC_Literal
== n
->args
->argv
[i
].arg
)
921 m
->flags
|= MDOC_LITERAL
;
922 else if (MDOC_Unfilled
== n
->args
->argv
[i
].arg
)
923 m
->flags
|= MDOC_LITERAL
;
930 post_display(POST_ARGS
)
933 if (MDOC_BODY
== n
->type
)
934 m
->flags
&= ~MDOC_LITERAL
;
944 for (i
= 0; i
< RSORD_MAX
; i
++)
957 struct mdoc_node
*nn
, *next
, *prev
;
960 if (MDOC_BLOCK
!= n
->type
)
963 assert(n
->body
->child
);
964 for (next
= NULL
, nn
= n
->body
->child
->next
; nn
; nn
= next
) {
965 o
= order_rs(nn
->tok
);
967 /* Remove `nn' from the chain. */
970 next
->prev
= nn
->prev
;
974 prev
->next
= nn
->next
;
976 nn
->prev
= nn
->next
= NULL
;
979 * Scan back until we reach a node that's ordered before
980 * us, then set ourselves as being the next.
982 for ( ; prev
; prev
= prev
->prev
)
983 if (order_rs(prev
->tok
) <= o
)
989 prev
->next
->prev
= nn
;
990 nn
->next
= prev
->next
;
995 n
->body
->child
->prev
= nn
;
996 nn
->next
= n
->body
->child
;