]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_action.c
1 /* $Id: mdoc_action.c,v 1.62 2010/05/29 18:58:52 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_li(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_rs(POST_ARGS
);
66 static int post_sh(POST_ARGS
);
67 static int post_st(POST_ARGS
);
68 static int post_std(POST_ARGS
);
70 static int pre_bd(PRE_ARGS
);
71 static int pre_bl(PRE_ARGS
);
72 static int pre_dl(PRE_ARGS
);
73 static int pre_offset(PRE_ARGS
);
75 static const struct actions mdoc_actions
[MDOC_MAX
] = {
76 { NULL
, NULL
}, /* Ap */
77 { NULL
, post_dd
}, /* Dd */
78 { NULL
, post_dt
}, /* Dt */
79 { NULL
, post_os
}, /* Os */
80 { NULL
, post_sh
}, /* Sh */
81 { NULL
, NULL
}, /* Ss */
82 { NULL
, NULL
}, /* Pp */
83 { NULL
, NULL
}, /* D1 */
84 { pre_dl
, post_display
}, /* Dl */
85 { pre_bd
, post_display
}, /* Bd */
86 { NULL
, NULL
}, /* Ed */
87 { pre_bl
, post_bl
}, /* Bl */
88 { NULL
, NULL
}, /* El */
89 { NULL
, NULL
}, /* It */
90 { NULL
, NULL
}, /* Ad */
91 { NULL
, NULL
}, /* An */
92 { NULL
, post_ar
}, /* Ar */
93 { NULL
, NULL
}, /* Cd */
94 { NULL
, NULL
}, /* Cm */
95 { NULL
, NULL
}, /* Dv */
96 { NULL
, NULL
}, /* Er */
97 { NULL
, NULL
}, /* Ev */
98 { NULL
, post_std
}, /* Ex */
99 { NULL
, NULL
}, /* Fa */
100 { NULL
, NULL
}, /* Fd */
101 { NULL
, NULL
}, /* Fl */
102 { NULL
, NULL
}, /* Fn */
103 { NULL
, NULL
}, /* Ft */
104 { NULL
, NULL
}, /* Ic */
105 { NULL
, NULL
}, /* In */
106 { NULL
, post_li
}, /* Li */
107 { NULL
, NULL
}, /* Nd */
108 { NULL
, post_nm
}, /* Nm */
109 { NULL
, NULL
}, /* Op */
110 { NULL
, NULL
}, /* Ot */
111 { NULL
, post_pa
}, /* Pa */
112 { NULL
, post_std
}, /* Rv */
113 { NULL
, post_st
}, /* St */
114 { NULL
, NULL
}, /* Va */
115 { NULL
, NULL
}, /* Vt */
116 { NULL
, NULL
}, /* Xr */
117 { NULL
, NULL
}, /* %A */
118 { NULL
, NULL
}, /* %B */
119 { NULL
, NULL
}, /* %D */
120 { NULL
, NULL
}, /* %I */
121 { NULL
, NULL
}, /* %J */
122 { NULL
, NULL
}, /* %N */
123 { NULL
, NULL
}, /* %O */
124 { NULL
, NULL
}, /* %P */
125 { NULL
, NULL
}, /* %R */
126 { NULL
, NULL
}, /* %T */
127 { NULL
, NULL
}, /* %V */
128 { NULL
, NULL
}, /* Ac */
129 { NULL
, NULL
}, /* Ao */
130 { NULL
, NULL
}, /* Aq */
131 { NULL
, post_at
}, /* At */
132 { NULL
, NULL
}, /* Bc */
133 { NULL
, NULL
}, /* Bf */
134 { NULL
, NULL
}, /* Bo */
135 { NULL
, NULL
}, /* Bq */
136 { NULL
, NULL
}, /* Bsx */
137 { NULL
, NULL
}, /* Bx */
138 { NULL
, NULL
}, /* Db */
139 { NULL
, NULL
}, /* Dc */
140 { NULL
, NULL
}, /* Do */
141 { NULL
, NULL
}, /* Dq */
142 { NULL
, NULL
}, /* Ec */
143 { NULL
, NULL
}, /* Ef */
144 { NULL
, NULL
}, /* Em */
145 { NULL
, NULL
}, /* Eo */
146 { NULL
, NULL
}, /* Fx */
147 { NULL
, NULL
}, /* Ms */
148 { NULL
, NULL
}, /* No */
149 { NULL
, NULL
}, /* Ns */
150 { NULL
, NULL
}, /* Nx */
151 { NULL
, NULL
}, /* Ox */
152 { NULL
, NULL
}, /* Pc */
153 { NULL
, NULL
}, /* Pf */
154 { NULL
, NULL
}, /* Po */
155 { NULL
, NULL
}, /* Pq */
156 { NULL
, NULL
}, /* Qc */
157 { NULL
, NULL
}, /* Ql */
158 { NULL
, NULL
}, /* Qo */
159 { NULL
, NULL
}, /* Qq */
160 { NULL
, NULL
}, /* Re */
161 { NULL
, post_rs
}, /* Rs */
162 { NULL
, NULL
}, /* Sc */
163 { NULL
, NULL
}, /* So */
164 { NULL
, NULL
}, /* Sq */
165 { NULL
, NULL
}, /* Sm */
166 { NULL
, NULL
}, /* Sx */
167 { NULL
, NULL
}, /* Sy */
168 { NULL
, NULL
}, /* Tn */
169 { NULL
, NULL
}, /* Ux */
170 { NULL
, NULL
}, /* Xc */
171 { NULL
, NULL
}, /* Xo */
172 { NULL
, NULL
}, /* Fo */
173 { NULL
, NULL
}, /* Fc */
174 { NULL
, NULL
}, /* Oo */
175 { NULL
, NULL
}, /* Oc */
176 { NULL
, NULL
}, /* Bk */
177 { NULL
, NULL
}, /* Ek */
178 { NULL
, NULL
}, /* Bt */
179 { NULL
, NULL
}, /* Hf */
180 { NULL
, NULL
}, /* Fr */
181 { NULL
, NULL
}, /* Ud */
182 { NULL
, post_lb
}, /* Lb */
183 { NULL
, NULL
}, /* Lp */
184 { NULL
, NULL
}, /* Lk */
185 { NULL
, NULL
}, /* Mt */
186 { NULL
, NULL
}, /* Brq */
187 { NULL
, NULL
}, /* Bro */
188 { NULL
, NULL
}, /* Brc */
189 { NULL
, NULL
}, /* %C */
190 { NULL
, NULL
}, /* Es */
191 { NULL
, NULL
}, /* En */
192 { NULL
, NULL
}, /* Dx */
193 { NULL
, NULL
}, /* %Q */
194 { NULL
, NULL
}, /* br */
195 { NULL
, NULL
}, /* sp */
196 { NULL
, NULL
}, /* %U */
201 static const enum mdoct rsord
[RSORD_MAX
] = {
220 mdoc_action_pre(struct mdoc
*m
, struct mdoc_node
*n
)
232 if (NULL
== mdoc_actions
[n
->tok
].pre
)
234 return((*mdoc_actions
[n
->tok
].pre
)(m
, n
));
239 mdoc_action_post(struct mdoc
*m
)
242 if (MDOC_ACTED
& m
->last
->flags
)
244 m
->last
->flags
|= MDOC_ACTED
;
246 switch (m
->last
->type
) {
255 if (NULL
== mdoc_actions
[m
->last
->tok
].post
)
257 return((*mdoc_actions
[m
->last
->tok
].post
)(m
, m
->last
));
262 * Concatenate sibling nodes together. All siblings must be of type
263 * MDOC_TEXT or an assertion is raised. Concatenation is separated by a
267 concat(struct mdoc
*m
, char *p
, const struct mdoc_node
*n
, size_t sz
)
272 for ( ; n
; n
= n
->next
) {
273 assert(MDOC_TEXT
== n
->type
);
275 * XXX: yes, these can technically be resized, but it's
276 * highly unlikely that we're going to get here, so let
279 if (strlcat(p
, n
->string
, sz
) >= sz
) {
280 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
285 if (strlcat(p
, " ", sz
) >= sz
) {
286 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
296 * Macros accepting `-std' as an argument have the name of the current
297 * document (`Nm') filled in as the argument if it's not provided.
302 struct mdoc_node
*nn
;
306 if (NULL
== m
->meta
.name
)
310 m
->next
= MDOC_NEXT_CHILD
;
312 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, m
->meta
.name
))
320 * The `Nm' macro's first use sets the name of the document. See also
330 if ( ! concat(m
, buf
, n
->child
, BUFSIZ
))
332 m
->meta
.name
= mandoc_strdup(buf
);
338 * Look up the value of `Lb' for matching predefined strings. If it has
339 * one, then substitute the current value for the formatted value. Note
340 * that the lookup may fail (we can provide arbitrary strings).
350 assert(MDOC_TEXT
== n
->child
->type
);
351 p
= mdoc_a2lib(n
->child
->string
);
354 free(n
->child
->string
);
355 n
->child
->string
= mandoc_strdup(p
);
359 sz
= strlen(n
->child
->string
) +
360 2 + strlen("\\(lqlibrary\\(rq");
361 buf
= mandoc_malloc(sz
);
362 snprintf(buf
, sz
, "library \\(lq%s\\(rq", n
->child
->string
);
363 free(n
->child
->string
);
364 n
->child
->string
= buf
;
370 * Substitute the value of `St' for the corresponding formatted string.
371 * We're guaranteed that this exists (it's been verified during the
380 assert(MDOC_TEXT
== n
->child
->type
);
381 p
= mdoc_a2st(n
->child
->string
);
383 free(n
->child
->string
);
384 n
->child
->string
= mandoc_strdup(p
);
391 * Look up the standard string in a table. We know that it exists from
392 * the validation phase, so assert on failure. If a standard key wasn't
393 * supplied, supply the default ``AT&T UNIX''.
398 struct mdoc_node
*nn
;
404 assert(MDOC_TEXT
== n
->child
->type
);
405 p
= mdoc_a2att(n
->child
->string
);
407 free(n
->child
->string
);
408 n
->child
->string
= mandoc_strdup(p
);
411 q
= n
->child
->string
;
412 sz
= strlen(p
) + strlen(q
) + 1;
413 buf
= mandoc_malloc(sz
);
416 free(n
->child
->string
);
417 n
->child
->string
= buf
;
423 m
->next
= MDOC_NEXT_CHILD
;
424 if ( ! mdoc_word_alloc(m
, nn
->line
, nn
->pos
, "AT&T UNIX"))
432 * Mark the current section. The ``named'' section (lastnamed) is set
433 * whenever the current section isn't a custom section--we use this to
434 * keep track of section ordering. Also check that the section is
435 * allowed within the document's manual section.
443 if (MDOC_HEAD
!= n
->type
)
446 if ( ! concat(m
, buf
, n
->child
, BUFSIZ
))
448 sec
= mdoc_str2sec(buf
);
450 * The first section should always make us move into a non-new
453 if (SEC_NONE
== m
->lastnamed
|| SEC_CUSTOM
!= sec
)
456 /* Some sections only live in certain manual sections. */
458 switch ((m
->lastsec
= sec
)) {
459 case (SEC_RETURN_VALUES
):
462 assert(m
->meta
.msec
);
463 if (*m
->meta
.msec
== '2')
465 if (*m
->meta
.msec
== '3')
467 if (*m
->meta
.msec
== '9')
469 return(mdoc_nmsg(m
, n
, MANDOCERR_SECMSEC
));
478 * Parse out the contents of `Dt'. See in-line documentation for how we
479 * handle the various fields of this macro.
484 struct mdoc_node
*nn
;
494 m
->meta
.title
= m
->meta
.vol
= m
->meta
.arch
= NULL
;
496 * --> title = unknown, volume = local, msec = 0, arch = NULL
499 if (NULL
== (nn
= n
->child
)) {
500 /* XXX: make these macro values. */
501 /* FIXME: warn about missing values. */
502 m
->meta
.title
= mandoc_strdup("unknown");
503 m
->meta
.vol
= mandoc_strdup("local");
504 m
->meta
.msec
= mandoc_strdup("1");
505 return(post_prol(m
, n
));
508 /* Handles: `.Dt TITLE'
509 * --> title = TITLE, volume = local, msec = 0, arch = NULL
512 m
->meta
.title
= mandoc_strdup(nn
->string
);
514 if (NULL
== (nn
= nn
->next
)) {
515 /* FIXME: warn about missing msec. */
516 /* XXX: make this a macro value. */
517 m
->meta
.vol
= mandoc_strdup("local");
518 m
->meta
.msec
= mandoc_strdup("1");
519 return(post_prol(m
, n
));
522 /* Handles: `.Dt TITLE SEC'
523 * --> title = TITLE, volume = SEC is msec ?
524 * format(msec) : SEC,
525 * msec = SEC is msec ? atoi(msec) : 0,
529 cp
= mdoc_a2msec(nn
->string
);
531 m
->meta
.vol
= mandoc_strdup(cp
);
532 m
->meta
.msec
= mandoc_strdup(nn
->string
);
533 } else if (mdoc_nmsg(m
, n
, MANDOCERR_BADMSEC
)) {
534 m
->meta
.vol
= mandoc_strdup(nn
->string
);
535 m
->meta
.msec
= mandoc_strdup(nn
->string
);
539 if (NULL
== (nn
= nn
->next
))
540 return(post_prol(m
, n
));
542 /* Handles: `.Dt TITLE SEC VOL'
543 * --> title = TITLE, volume = VOL is vol ?
545 * VOL is arch ? format(arch) :
549 cp
= mdoc_a2vol(nn
->string
);
552 m
->meta
.vol
= mandoc_strdup(cp
);
554 /* FIXME: warn about bad arch. */
555 cp
= mdoc_a2arch(nn
->string
);
558 m
->meta
.vol
= mandoc_strdup(nn
->string
);
560 m
->meta
.arch
= mandoc_strdup(cp
);
563 /* Ignore any subsequent parameters... */
564 /* FIXME: warn about subsequent parameters. */
566 return(post_prol(m
, n
));
571 * Set the operating system by way of the `Os' macro. Note that if an
572 * argument isn't provided and -DOSNAME="\"foo\"" is provided during
573 * compilation, this value will be used instead of filling in "sysname
574 * release" from uname().
581 struct utsname utsname
;
587 if ( ! concat(m
, buf
, n
->child
, BUFSIZ
))
590 /* XXX: yes, these can all be dynamically-adjusted buffers, but
591 * it's really not worth the extra hackery.
594 if ('\0' == buf
[0]) {
596 if (strlcat(buf
, OSNAME
, BUFSIZ
) >= BUFSIZ
) {
597 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
601 if (-1 == uname(&utsname
))
602 return(mdoc_nmsg(m
, n
, MANDOCERR_UTSNAME
));
604 if (strlcat(buf
, utsname
.sysname
, BUFSIZ
) >= BUFSIZ
) {
605 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
608 if (strlcat(buf
, " ", 64) >= BUFSIZ
) {
609 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
612 if (strlcat(buf
, utsname
.release
, BUFSIZ
) >= BUFSIZ
) {
613 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
619 m
->meta
.os
= mandoc_strdup(buf
);
620 return(post_prol(m
, n
));
625 * Calculate the -width for a `Bl -tag' list if it hasn't been provided.
626 * Uses the first head macro. NOTE AGAIN: this is ONLY if the -width
627 * argument has NOT been provided. See post_bl_width() for converting
631 post_bl_tagwidth(POST_ARGS
)
633 struct mdoc_node
*nn
;
638 /* Defaults to ten ens. */
640 sz
= 10; /* XXX: make this a macro value. */
642 for (nn
= n
->body
->child
; nn
; nn
= nn
->next
) {
643 if (MDOC_It
== nn
->tok
)
648 assert(MDOC_BLOCK
== nn
->type
);
649 nn
= nn
->head
->child
;
650 if (MDOC_TEXT
!= nn
->type
) {
651 sz
= mdoc_macro2len(nn
->tok
);
653 if ( ! mdoc_nmsg(m
, n
, MANDOCERR_NOWIDTHARG
))
658 sz
= strlen(nn
->string
) + 1;
661 snprintf(buf
, NUMSIZ
, "%zun", sz
);
664 * We have to dynamically add this to the macro's argument list.
665 * We're guaranteed that a MDOC_Width doesn't already exist.
670 i
= (int)(nn
->args
->argc
)++;
672 nn
->args
->argv
= mandoc_realloc(nn
->args
->argv
,
673 nn
->args
->argc
* sizeof(struct mdoc_argv
));
675 nn
->args
->argv
[i
].arg
= MDOC_Width
;
676 nn
->args
->argv
[i
].line
= n
->line
;
677 nn
->args
->argv
[i
].pos
= n
->pos
;
678 nn
->args
->argv
[i
].sz
= 1;
679 nn
->args
->argv
[i
].value
= mandoc_malloc(sizeof(char *));
680 nn
->args
->argv
[i
].value
[0] = mandoc_strdup(buf
);
686 * Calculate the real width of a list from the -width string, which may
687 * contain a macro (with a known default width), a literal string, or a
691 post_bl_width(POST_ARGS
)
702 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
703 if (MDOC_Width
== n
->args
->argv
[i
].arg
)
706 if (i
== (int)n
->args
->argc
)
708 p
= n
->args
->argv
[i
].value
[0];
711 * If the value to -width is a macro, then we re-write it to be
712 * the macro's width as set in share/tmac/mdoc/doc-common.
715 if (0 == strcmp(p
, "Ds"))
717 else if (MDOC_MAX
== (tok
= mdoc_hash_find(p
)))
719 else if (0 == (width
= mdoc_macro2len(tok
)))
720 return(mdoc_nmsg(m
, n
, MANDOCERR_BADWIDTH
));
722 /* The value already exists: free and reallocate it. */
724 snprintf(buf
, NUMSIZ
, "%zun", width
);
725 free(n
->args
->argv
[i
].value
[0]);
726 n
->args
->argv
[i
].value
[0] = mandoc_strdup(buf
);
732 * Do processing for -column lists, which can have two distinct styles
733 * of invocation. Merge this two styles into a consistent form.
737 post_bl_head(POST_ARGS
)
740 struct mdoc_node
*np
, *nn
, *nnp
;
742 if (NULL
== n
->child
)
748 for (c
= 0; c
< (int)np
->args
->argc
; c
++)
749 if (MDOC_Column
== np
->args
->argv
[c
].arg
)
752 if (c
== (int)np
->args
->argc
)
754 assert(0 == np
->args
->argv
[c
].sz
);
757 * Accomodate for new-style groff column syntax. Shuffle the
758 * child nodes, all of which must be TEXT, as arguments for the
759 * column field. Then, delete the head children.
762 np
->args
->argv
[c
].sz
= (size_t)n
->nchild
;
763 np
->args
->argv
[c
].value
= mandoc_malloc
764 ((size_t)n
->nchild
* sizeof(char *));
766 for (i
= 0, nn
= n
->child
; nn
; i
++) {
767 np
->args
->argv
[c
].value
[i
] = nn
->string
;
771 mdoc_node_delete(NULL
, nnp
);
785 if (MDOC_HEAD
== n
->type
)
786 return(post_bl_head(m
, n
));
787 if (MDOC_BLOCK
!= n
->type
)
791 * These are fairly complicated, so we've broken them into two
792 * functions. post_bl_tagwidth() is called when a -tag is
793 * specified, but no -width (it must be guessed). The second
794 * when a -width is specified (macro indicators must be
795 * rewritten into real lengths).
798 len
= (int)(n
->args
? n
->args
->argc
: 0);
800 for (r
= i
= 0; i
< len
; i
++) {
801 if (MDOC_Tag
== n
->args
->argv
[i
].arg
)
803 if (MDOC_Width
== n
->args
->argv
[i
].arg
)
807 if (r
& (1 << 0) && ! (r
& (1 << 1))) {
808 if ( ! post_bl_tagwidth(m
, n
))
810 } else if (r
& (1 << 1))
811 if ( ! post_bl_width(m
, n
))
819 * The `Pa' macro defaults to a tilde if no value is provided as an
825 struct mdoc_node
*np
;
831 m
->next
= MDOC_NEXT_CHILD
;
832 /* XXX: make into macro value. */
833 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "~"))
841 * Empty `Li' macros get an empty string to make front-ends add an extra
847 struct mdoc_node
*np
;
853 m
->next
= MDOC_NEXT_CHILD
;
854 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, ""))
862 * The `Ar' macro defaults to two strings "file ..." if no value is
863 * provided as an argument.
868 struct mdoc_node
*np
;
874 m
->next
= MDOC_NEXT_CHILD
;
875 /* XXX: make into macro values. */
876 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "file"))
878 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "..."))
886 * Parse the date field in `Dd'.
893 if ( ! concat(m
, buf
, n
->child
, DATESIZ
))
896 m
->meta
.date
= mandoc_a2time
897 (MTIME_MDOCDATE
| MTIME_CANONICAL
, buf
);
899 if (0 == m
->meta
.date
) {
900 if ( ! mdoc_nmsg(m
, n
, MANDOCERR_BADDATE
))
902 m
->meta
.date
= time(NULL
);
905 return(post_prol(m
, n
));
910 * Remove prologue macros from the document after they're processed.
911 * The final document uses mdoc_meta for these values and discards the
918 mdoc_node_delete(m
, n
);
919 if (m
->meta
.title
&& m
->meta
.date
&& m
->meta
.os
)
920 m
->flags
|= MDOC_PBODY
;
926 * Trigger a literal context.
932 if (MDOC_BODY
== n
->type
)
933 m
->flags
|= MDOC_LITERAL
;
945 * Make sure that an empty offset produces an 8n length space as
946 * stipulated by mdoc.samples.
950 for (i
= 0; i
< (int)n
->args
->argc
; i
++) {
951 if (MDOC_Offset
!= n
->args
->argv
[i
].arg
)
953 if (n
->args
->argv
[i
].sz
)
955 assert(1 == n
->args
->refcnt
);
956 /* If no value set, length of <string>. */
957 n
->args
->argv
[i
].sz
++;
958 n
->args
->argv
[i
].value
= mandoc_malloc(sizeof(char *));
959 n
->args
->argv
[i
].value
[0] = mandoc_strdup("8n");
972 if (MDOC_BLOCK
!= n
->type
) {
974 assert(MDOC_BLOCK
== n
->parent
->type
);
975 assert(MDOC_Bl
== n
->parent
->tok
);
976 assert(LIST__NONE
!= n
->parent
->data
.list
);
977 n
->data
.list
= n
->parent
->data
.list
;
981 assert(LIST__NONE
== n
->data
.list
);
983 for (pos
= 0; pos
< (int)n
->args
->argc
; pos
++) {
984 switch (n
->args
->argv
[pos
].arg
) {
986 n
->data
.list
= LIST_bullet
;
989 n
->data
.list
= LIST_dash
;
992 n
->data
.list
= LIST_enum
;
995 n
->data
.list
= LIST_hyphen
;
998 n
->data
.list
= LIST_item
;
1001 n
->data
.list
= LIST_tag
;
1004 n
->data
.list
= LIST_diag
;
1007 n
->data
.list
= LIST_hang
;
1010 n
->data
.list
= LIST_ohang
;
1013 n
->data
.list
= LIST_inset
;
1016 n
->data
.list
= LIST_column
;
1021 if (LIST__NONE
!= n
->data
.list
)
1025 assert(LIST__NONE
!= n
->data
.list
);
1026 return(pre_offset(m
, n
));
1035 if (MDOC_BLOCK
== n
->type
)
1036 return(pre_offset(m
, n
));
1037 if (MDOC_BODY
!= n
->type
)
1040 /* Enter literal context if `Bd -literal' or `-unfilled'. */
1042 for (n
= n
->parent
, i
= 0; i
< (int)n
->args
->argc
; i
++)
1043 if (MDOC_Literal
== n
->args
->argv
[i
].arg
)
1044 m
->flags
|= MDOC_LITERAL
;
1045 else if (MDOC_Unfilled
== n
->args
->argv
[i
].arg
)
1046 m
->flags
|= MDOC_LITERAL
;
1053 post_display(POST_ARGS
)
1056 if (MDOC_BODY
== n
->type
)
1057 m
->flags
&= ~MDOC_LITERAL
;
1063 order_rs(enum mdoct t
)
1067 for (i
= 0; i
< (int)RSORD_MAX
; i
++)
1080 struct mdoc_node
*nn
, *next
, *prev
;
1083 if (MDOC_BLOCK
!= n
->type
)
1086 assert(n
->body
->child
);
1087 for (next
= NULL
, nn
= n
->body
->child
->next
; nn
; nn
= next
) {
1088 o
= order_rs(nn
->tok
);
1090 /* Remove `nn' from the chain. */
1093 next
->prev
= nn
->prev
;
1097 prev
->next
= nn
->next
;
1099 nn
->prev
= nn
->next
= NULL
;
1102 * Scan back until we reach a node that's ordered before
1103 * us, then set ourselves as being the next.
1105 for ( ; prev
; prev
= prev
->prev
)
1106 if (order_rs(prev
->tok
) <= o
)
1112 prev
->next
->prev
= nn
;
1113 nn
->next
= prev
->next
;
1118 n
->body
->child
->prev
= nn
;
1119 nn
->next
= n
->body
->child
;
1120 n
->body
->child
= nn
;