]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_action.c
1 /* $Id: mdoc_action.c,v 1.60 2010/05/17 23:57:06 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>
33 #include "libmandoc.h"
35 #define POST_ARGS struct mdoc *m, struct mdoc_node *n
36 #define PRE_ARGS struct mdoc *m, struct mdoc_node *n
43 int (*post
)(POST_ARGS
);
46 static int concat(struct mdoc
*, char *,
47 const struct mdoc_node
*, size_t);
48 static inline int order_rs(enum mdoct
);
50 static int post_ar(POST_ARGS
);
51 static int post_at(POST_ARGS
);
52 static int post_bl(POST_ARGS
);
53 static int post_bl_head(POST_ARGS
);
54 static int post_bl_tagwidth(POST_ARGS
);
55 static int post_bl_width(POST_ARGS
);
56 static int post_dd(POST_ARGS
);
57 static int post_display(POST_ARGS
);
58 static int post_dt(POST_ARGS
);
59 static int post_lb(POST_ARGS
);
60 static int post_nm(POST_ARGS
);
61 static int post_os(POST_ARGS
);
62 static int post_pa(POST_ARGS
);
63 static int post_prol(POST_ARGS
);
64 static int post_rs(POST_ARGS
);
65 static int post_sh(POST_ARGS
);
66 static int post_st(POST_ARGS
);
67 static int post_std(POST_ARGS
);
69 static int pre_bd(PRE_ARGS
);
70 static int pre_bl(PRE_ARGS
);
71 static int pre_dl(PRE_ARGS
);
72 static int pre_offset(PRE_ARGS
);
74 static const struct actions mdoc_actions
[MDOC_MAX
] = {
75 { NULL
, NULL
}, /* Ap */
76 { NULL
, post_dd
}, /* Dd */
77 { NULL
, post_dt
}, /* Dt */
78 { NULL
, post_os
}, /* Os */
79 { NULL
, post_sh
}, /* Sh */
80 { NULL
, NULL
}, /* Ss */
81 { NULL
, NULL
}, /* Pp */
82 { NULL
, NULL
}, /* D1 */
83 { pre_dl
, post_display
}, /* Dl */
84 { pre_bd
, post_display
}, /* Bd */
85 { NULL
, NULL
}, /* Ed */
86 { pre_bl
, post_bl
}, /* Bl */
87 { NULL
, NULL
}, /* El */
88 { NULL
, NULL
}, /* It */
89 { NULL
, NULL
}, /* Ad */
90 { NULL
, NULL
}, /* An */
91 { NULL
, post_ar
}, /* Ar */
92 { NULL
, NULL
}, /* Cd */
93 { NULL
, NULL
}, /* Cm */
94 { NULL
, NULL
}, /* Dv */
95 { NULL
, NULL
}, /* Er */
96 { NULL
, NULL
}, /* Ev */
97 { NULL
, post_std
}, /* Ex */
98 { NULL
, NULL
}, /* Fa */
99 { NULL
, NULL
}, /* Fd */
100 { NULL
, NULL
}, /* Fl */
101 { NULL
, NULL
}, /* Fn */
102 { NULL
, NULL
}, /* Ft */
103 { NULL
, NULL
}, /* Ic */
104 { NULL
, NULL
}, /* In */
105 { NULL
, NULL
}, /* Li */
106 { NULL
, NULL
}, /* Nd */
107 { NULL
, post_nm
}, /* Nm */
108 { NULL
, NULL
}, /* Op */
109 { NULL
, NULL
}, /* Ot */
110 { NULL
, post_pa
}, /* Pa */
111 { NULL
, post_std
}, /* Rv */
112 { NULL
, post_st
}, /* St */
113 { NULL
, NULL
}, /* Va */
114 { NULL
, NULL
}, /* Vt */
115 { NULL
, NULL
}, /* Xr */
116 { NULL
, NULL
}, /* %A */
117 { NULL
, NULL
}, /* %B */
118 { NULL
, NULL
}, /* %D */
119 { NULL
, NULL
}, /* %I */
120 { NULL
, NULL
}, /* %J */
121 { NULL
, NULL
}, /* %N */
122 { NULL
, NULL
}, /* %O */
123 { NULL
, NULL
}, /* %P */
124 { NULL
, NULL
}, /* %R */
125 { NULL
, NULL
}, /* %T */
126 { NULL
, NULL
}, /* %V */
127 { NULL
, NULL
}, /* Ac */
128 { NULL
, NULL
}, /* Ao */
129 { NULL
, NULL
}, /* Aq */
130 { NULL
, post_at
}, /* At */
131 { NULL
, NULL
}, /* Bc */
132 { NULL
, NULL
}, /* Bf */
133 { NULL
, NULL
}, /* Bo */
134 { NULL
, NULL
}, /* Bq */
135 { NULL
, NULL
}, /* Bsx */
136 { NULL
, NULL
}, /* Bx */
137 { NULL
, NULL
}, /* Db */
138 { NULL
, NULL
}, /* Dc */
139 { NULL
, NULL
}, /* Do */
140 { NULL
, NULL
}, /* Dq */
141 { NULL
, NULL
}, /* Ec */
142 { NULL
, NULL
}, /* Ef */
143 { NULL
, NULL
}, /* Em */
144 { NULL
, NULL
}, /* Eo */
145 { NULL
, NULL
}, /* Fx */
146 { NULL
, NULL
}, /* Ms */
147 { NULL
, NULL
}, /* No */
148 { NULL
, NULL
}, /* Ns */
149 { NULL
, NULL
}, /* Nx */
150 { NULL
, NULL
}, /* Ox */
151 { NULL
, NULL
}, /* Pc */
152 { NULL
, NULL
}, /* Pf */
153 { NULL
, NULL
}, /* Po */
154 { NULL
, NULL
}, /* Pq */
155 { NULL
, NULL
}, /* Qc */
156 { NULL
, NULL
}, /* Ql */
157 { NULL
, NULL
}, /* Qo */
158 { NULL
, NULL
}, /* Qq */
159 { NULL
, NULL
}, /* Re */
160 { NULL
, post_rs
}, /* Rs */
161 { NULL
, NULL
}, /* Sc */
162 { NULL
, NULL
}, /* So */
163 { NULL
, NULL
}, /* Sq */
164 { NULL
, NULL
}, /* Sm */
165 { NULL
, NULL
}, /* Sx */
166 { NULL
, NULL
}, /* Sy */
167 { NULL
, NULL
}, /* Tn */
168 { NULL
, NULL
}, /* Ux */
169 { NULL
, NULL
}, /* Xc */
170 { NULL
, NULL
}, /* Xo */
171 { NULL
, NULL
}, /* Fo */
172 { NULL
, NULL
}, /* Fc */
173 { NULL
, NULL
}, /* Oo */
174 { NULL
, NULL
}, /* Oc */
175 { NULL
, NULL
}, /* Bk */
176 { NULL
, NULL
}, /* Ek */
177 { NULL
, NULL
}, /* Bt */
178 { NULL
, NULL
}, /* Hf */
179 { NULL
, NULL
}, /* Fr */
180 { NULL
, NULL
}, /* Ud */
181 { NULL
, post_lb
}, /* Lb */
182 { NULL
, NULL
}, /* Lp */
183 { NULL
, NULL
}, /* Lk */
184 { NULL
, NULL
}, /* Mt */
185 { NULL
, NULL
}, /* Brq */
186 { NULL
, NULL
}, /* Bro */
187 { NULL
, NULL
}, /* Brc */
188 { NULL
, NULL
}, /* %C */
189 { NULL
, NULL
}, /* Es */
190 { NULL
, NULL
}, /* En */
191 { NULL
, NULL
}, /* Dx */
192 { NULL
, NULL
}, /* %Q */
193 { NULL
, NULL
}, /* br */
194 { NULL
, NULL
}, /* sp */
195 { NULL
, NULL
}, /* %U */
200 static const enum mdoct rsord
[RSORD_MAX
] = {
219 mdoc_action_pre(struct mdoc
*m
, struct mdoc_node
*n
)
231 if (NULL
== mdoc_actions
[n
->tok
].pre
)
233 return((*mdoc_actions
[n
->tok
].pre
)(m
, n
));
238 mdoc_action_post(struct mdoc
*m
)
241 if (MDOC_ACTED
& m
->last
->flags
)
243 m
->last
->flags
|= MDOC_ACTED
;
245 switch (m
->last
->type
) {
254 if (NULL
== mdoc_actions
[m
->last
->tok
].post
)
256 return((*mdoc_actions
[m
->last
->tok
].post
)(m
, m
->last
));
261 * Concatenate sibling nodes together. All siblings must be of type
262 * MDOC_TEXT or an assertion is raised. Concatenation is separated by a
266 concat(struct mdoc
*m
, char *p
, const struct mdoc_node
*n
, size_t sz
)
271 for ( ; n
; n
= n
->next
) {
272 assert(MDOC_TEXT
== n
->type
);
274 * XXX: yes, these can technically be resized, but it's
275 * highly unlikely that we're going to get here, so let
278 if (strlcat(p
, n
->string
, sz
) >= sz
) {
279 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
284 if (strlcat(p
, " ", sz
) >= sz
) {
285 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
295 * Macros accepting `-std' as an argument have the name of the current
296 * document (`Nm') filled in as the argument if it's not provided.
301 struct mdoc_node
*nn
;
305 if (NULL
== m
->meta
.name
)
309 m
->next
= MDOC_NEXT_CHILD
;
311 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, m
->meta
.name
))
319 * The `Nm' macro's first use sets the name of the document. See also
329 if ( ! concat(m
, buf
, n
->child
, BUFSIZ
))
331 m
->meta
.name
= mandoc_strdup(buf
);
337 * Look up the value of `Lb' for matching predefined strings. If it has
338 * one, then substitute the current value for the formatted value. Note
339 * that the lookup may fail (we can provide arbitrary strings).
349 assert(MDOC_TEXT
== n
->child
->type
);
350 p
= mdoc_a2lib(n
->child
->string
);
353 free(n
->child
->string
);
354 n
->child
->string
= mandoc_strdup(p
);
358 sz
= strlen(n
->child
->string
) +
359 2 + strlen("\\(lqlibrary\\(rq");
360 buf
= mandoc_malloc(sz
);
361 snprintf(buf
, sz
, "library \\(lq%s\\(rq", n
->child
->string
);
362 free(n
->child
->string
);
363 n
->child
->string
= buf
;
369 * Substitute the value of `St' for the corresponding formatted string.
370 * We're guaranteed that this exists (it's been verified during the
379 assert(MDOC_TEXT
== n
->child
->type
);
380 p
= mdoc_a2st(n
->child
->string
);
382 free(n
->child
->string
);
383 n
->child
->string
= mandoc_strdup(p
);
390 * Look up the standard string in a table. We know that it exists from
391 * the validation phase, so assert on failure. If a standard key wasn't
392 * supplied, supply the default ``AT&T UNIX''.
397 struct mdoc_node
*nn
;
403 assert(MDOC_TEXT
== n
->child
->type
);
404 p
= mdoc_a2att(n
->child
->string
);
406 free(n
->child
->string
);
407 n
->child
->string
= mandoc_strdup(p
);
410 q
= n
->child
->string
;
411 sz
= strlen(p
) + strlen(q
) + 1;
412 buf
= mandoc_malloc(sz
);
415 free(n
->child
->string
);
416 n
->child
->string
= buf
;
422 m
->next
= MDOC_NEXT_CHILD
;
423 if ( ! mdoc_word_alloc(m
, nn
->line
, nn
->pos
, "AT&T UNIX"))
431 * Mark the current section. The ``named'' section (lastnamed) is set
432 * whenever the current section isn't a custom section--we use this to
433 * keep track of section ordering. Also check that the section is
434 * allowed within the document's manual section.
442 if (MDOC_HEAD
!= n
->type
)
445 if ( ! concat(m
, buf
, n
->child
, BUFSIZ
))
447 sec
= mdoc_str2sec(buf
);
449 * The first section should always make us move into a non-new
452 if (SEC_NONE
== m
->lastnamed
|| SEC_CUSTOM
!= sec
)
455 /* Some sections only live in certain manual sections. */
457 switch ((m
->lastsec
= sec
)) {
458 case (SEC_RETURN_VALUES
):
461 assert(m
->meta
.msec
);
462 if (*m
->meta
.msec
== '2')
464 if (*m
->meta
.msec
== '3')
466 if (*m
->meta
.msec
== '9')
468 return(mdoc_nmsg(m
, n
, MANDOCERR_SECMSEC
));
477 * Parse out the contents of `Dt'. See in-line documentation for how we
478 * handle the various fields of this macro.
483 struct mdoc_node
*nn
;
493 m
->meta
.title
= m
->meta
.vol
= m
->meta
.arch
= NULL
;
495 * --> title = unknown, volume = local, msec = 0, arch = NULL
498 if (NULL
== (nn
= n
->child
)) {
499 /* XXX: make these macro values. */
500 /* FIXME: warn about missing values. */
501 m
->meta
.title
= mandoc_strdup("unknown");
502 m
->meta
.vol
= mandoc_strdup("local");
503 m
->meta
.msec
= mandoc_strdup("1");
504 return(post_prol(m
, n
));
507 /* Handles: `.Dt TITLE'
508 * --> title = TITLE, volume = local, msec = 0, arch = NULL
511 m
->meta
.title
= mandoc_strdup(nn
->string
);
513 if (NULL
== (nn
= nn
->next
)) {
514 /* FIXME: warn about missing msec. */
515 /* XXX: make this a macro value. */
516 m
->meta
.vol
= mandoc_strdup("local");
517 m
->meta
.msec
= mandoc_strdup("1");
518 return(post_prol(m
, n
));
521 /* Handles: `.Dt TITLE SEC'
522 * --> title = TITLE, volume = SEC is msec ?
523 * format(msec) : SEC,
524 * msec = SEC is msec ? atoi(msec) : 0,
528 cp
= mdoc_a2msec(nn
->string
);
530 m
->meta
.vol
= mandoc_strdup(cp
);
531 m
->meta
.msec
= mandoc_strdup(nn
->string
);
532 } else if (mdoc_nmsg(m
, n
, MANDOCERR_BADMSEC
)) {
533 m
->meta
.vol
= mandoc_strdup(nn
->string
);
534 m
->meta
.msec
= mandoc_strdup(nn
->string
);
538 if (NULL
== (nn
= nn
->next
))
539 return(post_prol(m
, n
));
541 /* Handles: `.Dt TITLE SEC VOL'
542 * --> title = TITLE, volume = VOL is vol ?
544 * VOL is arch ? format(arch) :
548 cp
= mdoc_a2vol(nn
->string
);
551 m
->meta
.vol
= mandoc_strdup(cp
);
553 /* FIXME: warn about bad arch. */
554 cp
= mdoc_a2arch(nn
->string
);
557 m
->meta
.vol
= mandoc_strdup(nn
->string
);
559 m
->meta
.arch
= mandoc_strdup(cp
);
562 /* Ignore any subsequent parameters... */
563 /* FIXME: warn about subsequent parameters. */
565 return(post_prol(m
, n
));
570 * Set the operating system by way of the `Os' macro. Note that if an
571 * argument isn't provided and -DOSNAME="\"foo\"" is provided during
572 * compilation, this value will be used instead of filling in "sysname
573 * release" from uname().
580 struct utsname utsname
;
586 if ( ! concat(m
, buf
, n
->child
, BUFSIZ
))
589 /* XXX: yes, these can all be dynamically-adjusted buffers, but
590 * it's really not worth the extra hackery.
593 if ('\0' == buf
[0]) {
595 if (strlcat(buf
, OSNAME
, BUFSIZ
) >= BUFSIZ
) {
596 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
600 if (-1 == uname(&utsname
))
601 return(mdoc_nmsg(m
, n
, MANDOCERR_UTSNAME
));
603 if (strlcat(buf
, utsname
.sysname
, BUFSIZ
) >= BUFSIZ
) {
604 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
607 if (strlcat(buf
, " ", 64) >= BUFSIZ
) {
608 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
611 if (strlcat(buf
, utsname
.release
, BUFSIZ
) >= BUFSIZ
) {
612 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
618 m
->meta
.os
= mandoc_strdup(buf
);
619 return(post_prol(m
, n
));
624 * Calculate the -width for a `Bl -tag' list if it hasn't been provided.
625 * Uses the first head macro. NOTE AGAIN: this is ONLY if the -width
626 * argument has NOT been provided. See post_bl_width() for converting
630 post_bl_tagwidth(POST_ARGS
)
632 struct mdoc_node
*nn
;
637 /* Defaults to ten ens. */
639 sz
= 10; /* XXX: make this a macro value. */
643 assert(MDOC_BLOCK
== nn
->type
);
644 assert(MDOC_It
== nn
->tok
);
645 nn
= nn
->head
->child
;
646 if (MDOC_TEXT
!= nn
->type
) {
647 sz
= mdoc_macro2len(nn
->tok
);
649 if ( ! mdoc_nmsg(m
, n
, MANDOCERR_NOWIDTHARG
))
654 sz
= strlen(nn
->string
) + 1;
657 snprintf(buf
, NUMSIZ
, "%zun", sz
);
660 * We have to dynamically add this to the macro's argument list.
661 * We're guaranteed that a MDOC_Width doesn't already exist.
666 i
= (int)(nn
->args
->argc
)++;
668 nn
->args
->argv
= mandoc_realloc(nn
->args
->argv
,
669 nn
->args
->argc
* sizeof(struct mdoc_argv
));
671 nn
->args
->argv
[i
].arg
= MDOC_Width
;
672 nn
->args
->argv
[i
].line
= n
->line
;
673 nn
->args
->argv
[i
].pos
= n
->pos
;
674 nn
->args
->argv
[i
].sz
= 1;
675 nn
->args
->argv
[i
].value
= mandoc_malloc(sizeof(char *));
676 nn
->args
->argv
[i
].value
[0] = mandoc_strdup(buf
);
682 * Calculate the real width of a list from the -width string, which may
683 * contain a macro (with a known default width), a literal string, or a
687 post_bl_width(POST_ARGS
)
698 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
699 if (MDOC_Width
== n
->args
->argv
[i
].arg
)
702 if (i
== (int)n
->args
->argc
)
704 p
= n
->args
->argv
[i
].value
[0];
707 * If the value to -width is a macro, then we re-write it to be
708 * the macro's width as set in share/tmac/mdoc/doc-common.
711 if (0 == strcmp(p
, "Ds"))
713 else if (MDOC_MAX
== (tok
= mdoc_hash_find(p
)))
715 else if (0 == (width
= mdoc_macro2len(tok
)))
716 return(mdoc_nmsg(m
, n
, MANDOCERR_BADWIDTH
));
718 /* The value already exists: free and reallocate it. */
720 snprintf(buf
, NUMSIZ
, "%zun", width
);
721 free(n
->args
->argv
[i
].value
[0]);
722 n
->args
->argv
[i
].value
[0] = mandoc_strdup(buf
);
728 * Do processing for -column lists, which can have two distinct styles
729 * of invocation. Merge this two styles into a consistent form.
733 post_bl_head(POST_ARGS
)
736 struct mdoc_node
*np
, *nn
, *nnp
;
738 if (NULL
== n
->child
)
744 for (c
= 0; c
< (int)np
->args
->argc
; c
++)
745 if (MDOC_Column
== np
->args
->argv
[c
].arg
)
748 if (c
== (int)np
->args
->argc
)
750 assert(0 == np
->args
->argv
[c
].sz
);
753 * Accomodate for new-style groff column syntax. Shuffle the
754 * child nodes, all of which must be TEXT, as arguments for the
755 * column field. Then, delete the head children.
758 np
->args
->argv
[c
].sz
= (size_t)n
->nchild
;
759 np
->args
->argv
[c
].value
= mandoc_malloc
760 ((size_t)n
->nchild
* sizeof(char *));
762 for (i
= 0, nn
= n
->child
; nn
; i
++) {
763 np
->args
->argv
[c
].value
[i
] = nn
->string
;
767 mdoc_node_delete(NULL
, nnp
);
781 if (MDOC_HEAD
== n
->type
)
782 return(post_bl_head(m
, n
));
783 if (MDOC_BLOCK
!= n
->type
)
787 * These are fairly complicated, so we've broken them into two
788 * functions. post_bl_tagwidth() is called when a -tag is
789 * specified, but no -width (it must be guessed). The second
790 * when a -width is specified (macro indicators must be
791 * rewritten into real lengths).
794 len
= (int)(n
->args
? n
->args
->argc
: 0);
796 for (r
= i
= 0; i
< len
; i
++) {
797 if (MDOC_Tag
== n
->args
->argv
[i
].arg
)
799 if (MDOC_Width
== n
->args
->argv
[i
].arg
)
803 if (r
& (1 << 0) && ! (r
& (1 << 1))) {
804 if ( ! post_bl_tagwidth(m
, n
))
806 } else if (r
& (1 << 1))
807 if ( ! post_bl_width(m
, n
))
815 * The `Pa' macro defaults to a tilde if no value is provided as an
821 struct mdoc_node
*np
;
827 m
->next
= MDOC_NEXT_CHILD
;
828 /* XXX: make into macro value. */
829 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "~"))
837 * The `Ar' macro defaults to two strings "file ..." if no value is
838 * provided as an argument.
843 struct mdoc_node
*np
;
849 m
->next
= MDOC_NEXT_CHILD
;
850 /* XXX: make into macro values. */
851 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "file"))
853 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "..."))
861 * Parse the date field in `Dd'.
868 if ( ! concat(m
, buf
, n
->child
, DATESIZ
))
871 m
->meta
.date
= mandoc_a2time
872 (MTIME_MDOCDATE
| MTIME_CANONICAL
, buf
);
874 if (0 == m
->meta
.date
) {
875 if ( ! mdoc_nmsg(m
, n
, MANDOCERR_BADDATE
))
877 m
->meta
.date
= time(NULL
);
880 return(post_prol(m
, n
));
885 * Remove prologue macros from the document after they're processed.
886 * The final document uses mdoc_meta for these values and discards the
893 mdoc_node_delete(m
, n
);
894 if (m
->meta
.title
&& m
->meta
.date
&& m
->meta
.os
)
895 m
->flags
|= MDOC_PBODY
;
901 * Trigger a literal context.
907 if (MDOC_BODY
== n
->type
)
908 m
->flags
|= MDOC_LITERAL
;
920 * Make sure that an empty offset produces an 8n length space as
921 * stipulated by mdoc.samples.
925 for (i
= 0; i
< (int)n
->args
->argc
; i
++) {
926 if (MDOC_Offset
!= n
->args
->argv
[i
].arg
)
928 if (n
->args
->argv
[i
].sz
)
930 assert(1 == n
->args
->refcnt
);
931 /* If no value set, length of <string>. */
932 n
->args
->argv
[i
].sz
++;
933 n
->args
->argv
[i
].value
= mandoc_malloc(sizeof(char *));
934 n
->args
->argv
[i
].value
[0] = mandoc_strdup("8n");
947 if (MDOC_BLOCK
!= n
->type
) {
949 assert(MDOC_BLOCK
== n
->parent
->type
);
950 assert(MDOC_Bl
== n
->parent
->tok
);
951 assert(LIST__NONE
!= n
->parent
->data
.list
);
952 n
->data
.list
= n
->parent
->data
.list
;
956 assert(LIST__NONE
== n
->data
.list
);
958 for (pos
= 0; pos
< (int)n
->args
->argc
; pos
++) {
959 switch (n
->args
->argv
[pos
].arg
) {
961 n
->data
.list
= LIST_bullet
;
964 n
->data
.list
= LIST_dash
;
967 n
->data
.list
= LIST_enum
;
970 n
->data
.list
= LIST_hyphen
;
973 n
->data
.list
= LIST_item
;
976 n
->data
.list
= LIST_tag
;
979 n
->data
.list
= LIST_diag
;
982 n
->data
.list
= LIST_hang
;
985 n
->data
.list
= LIST_ohang
;
988 n
->data
.list
= LIST_inset
;
991 n
->data
.list
= LIST_column
;
996 if (LIST__NONE
!= n
->data
.list
)
1000 assert(LIST__NONE
!= n
->data
.list
);
1001 return(pre_offset(m
, n
));
1010 if (MDOC_BLOCK
== n
->type
)
1011 return(pre_offset(m
, n
));
1012 if (MDOC_BODY
!= n
->type
)
1015 /* Enter literal context if `Bd -literal' or `-unfilled'. */
1017 for (n
= n
->parent
, i
= 0; i
< (int)n
->args
->argc
; i
++)
1018 if (MDOC_Literal
== n
->args
->argv
[i
].arg
)
1019 m
->flags
|= MDOC_LITERAL
;
1020 else if (MDOC_Unfilled
== n
->args
->argv
[i
].arg
)
1021 m
->flags
|= MDOC_LITERAL
;
1028 post_display(POST_ARGS
)
1031 if (MDOC_BODY
== n
->type
)
1032 m
->flags
&= ~MDOC_LITERAL
;
1038 order_rs(enum mdoct t
)
1042 for (i
= 0; i
< (int)RSORD_MAX
; i
++)
1055 struct mdoc_node
*nn
, *next
, *prev
;
1058 if (MDOC_BLOCK
!= n
->type
)
1061 assert(n
->body
->child
);
1062 for (next
= NULL
, nn
= n
->body
->child
->next
; nn
; nn
= next
) {
1063 o
= order_rs(nn
->tok
);
1065 /* Remove `nn' from the chain. */
1068 next
->prev
= nn
->prev
;
1072 prev
->next
= nn
->next
;
1074 nn
->prev
= nn
->next
= NULL
;
1077 * Scan back until we reach a node that's ordered before
1078 * us, then set ourselves as being the next.
1080 for ( ; prev
; prev
= prev
->prev
)
1081 if (order_rs(prev
->tok
) <= o
)
1087 prev
->next
->prev
= nn
;
1088 nn
->next
= prev
->next
;
1093 n
->body
->child
->prev
= nn
;
1094 nn
->next
= n
->body
->child
;
1095 n
->body
->child
= nn
;