]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_action.c
1 /* $Id: mdoc_action.c,v 1.65 2010/06/03 13:44:36 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 */
197 { NULL
, NULL
}, /* Ta */
202 static const enum mdoct rsord
[RSORD_MAX
] = {
221 mdoc_action_pre(struct mdoc
*m
, struct mdoc_node
*n
)
233 if (NULL
== mdoc_actions
[n
->tok
].pre
)
235 return((*mdoc_actions
[n
->tok
].pre
)(m
, n
));
240 mdoc_action_post(struct mdoc
*m
)
243 if (MDOC_ACTED
& m
->last
->flags
)
245 m
->last
->flags
|= MDOC_ACTED
;
247 switch (m
->last
->type
) {
256 if (NULL
== mdoc_actions
[m
->last
->tok
].post
)
258 return((*mdoc_actions
[m
->last
->tok
].post
)(m
, m
->last
));
263 * Concatenate sibling nodes together. All siblings must be of type
264 * MDOC_TEXT or an assertion is raised. Concatenation is separated by a
268 concat(struct mdoc
*m
, char *p
, const struct mdoc_node
*n
, size_t sz
)
273 for ( ; n
; n
= n
->next
) {
274 assert(MDOC_TEXT
== n
->type
);
276 * XXX: yes, these can technically be resized, but it's
277 * highly unlikely that we're going to get here, so let
280 if (strlcat(p
, n
->string
, sz
) >= sz
) {
281 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
286 if (strlcat(p
, " ", sz
) >= sz
) {
287 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
297 * Macros accepting `-std' as an argument have the name of the current
298 * document (`Nm') filled in as the argument if it's not provided.
303 struct mdoc_node
*nn
;
307 if (NULL
== m
->meta
.name
)
311 m
->next
= MDOC_NEXT_CHILD
;
313 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, m
->meta
.name
))
321 * The `Nm' macro's first use sets the name of the document. See also
331 if ( ! concat(m
, buf
, n
->child
, BUFSIZ
))
333 m
->meta
.name
= mandoc_strdup(buf
);
339 * Look up the value of `Lb' for matching predefined strings. If it has
340 * one, then substitute the current value for the formatted value. Note
341 * that the lookup may fail (we can provide arbitrary strings).
351 assert(MDOC_TEXT
== n
->child
->type
);
352 p
= mdoc_a2lib(n
->child
->string
);
355 free(n
->child
->string
);
356 n
->child
->string
= mandoc_strdup(p
);
360 sz
= strlen(n
->child
->string
) +
361 2 + strlen("\\(lqlibrary\\(rq");
362 buf
= mandoc_malloc(sz
);
363 snprintf(buf
, sz
, "library \\(lq%s\\(rq", n
->child
->string
);
364 free(n
->child
->string
);
365 n
->child
->string
= buf
;
371 * Substitute the value of `St' for the corresponding formatted string.
372 * We're guaranteed that this exists (it's been verified during the
381 assert(MDOC_TEXT
== n
->child
->type
);
382 p
= mdoc_a2st(n
->child
->string
);
384 free(n
->child
->string
);
385 n
->child
->string
= mandoc_strdup(p
);
392 * Look up the standard string in a table. We know that it exists from
393 * the validation phase, so assert on failure. If a standard key wasn't
394 * supplied, supply the default ``AT&T UNIX''.
399 struct mdoc_node
*nn
;
405 assert(MDOC_TEXT
== n
->child
->type
);
406 p
= mdoc_a2att(n
->child
->string
);
408 free(n
->child
->string
);
409 n
->child
->string
= mandoc_strdup(p
);
412 q
= n
->child
->string
;
413 sz
= strlen(p
) + strlen(q
) + 1;
414 buf
= mandoc_malloc(sz
);
417 free(n
->child
->string
);
418 n
->child
->string
= buf
;
424 m
->next
= MDOC_NEXT_CHILD
;
425 if ( ! mdoc_word_alloc(m
, nn
->line
, nn
->pos
, "AT&T UNIX"))
433 * Mark the current section. The ``named'' section (lastnamed) is set
434 * whenever the current section isn't a custom section--we use this to
435 * keep track of section ordering. Also check that the section is
436 * allowed within the document's manual section.
444 if (MDOC_HEAD
!= n
->type
)
447 if ( ! concat(m
, buf
, n
->child
, BUFSIZ
))
449 sec
= mdoc_str2sec(buf
);
451 * The first section should always make us move into a non-new
454 if (SEC_NONE
== m
->lastnamed
|| SEC_CUSTOM
!= sec
)
457 /* Some sections only live in certain manual sections. */
459 switch ((m
->lastsec
= sec
)) {
460 case (SEC_RETURN_VALUES
):
463 assert(m
->meta
.msec
);
464 if (*m
->meta
.msec
== '2')
466 if (*m
->meta
.msec
== '3')
468 if (*m
->meta
.msec
== '9')
470 return(mdoc_nmsg(m
, n
, MANDOCERR_SECMSEC
));
479 * Parse out the contents of `Dt'. See in-line documentation for how we
480 * handle the various fields of this macro.
485 struct mdoc_node
*nn
;
495 m
->meta
.title
= m
->meta
.vol
= m
->meta
.arch
= NULL
;
497 * --> title = unknown, volume = local, msec = 0, arch = NULL
500 if (NULL
== (nn
= n
->child
)) {
501 /* XXX: make these macro values. */
502 /* FIXME: warn about missing values. */
503 m
->meta
.title
= mandoc_strdup("UNKNOWN");
504 m
->meta
.vol
= mandoc_strdup("LOCAL");
505 m
->meta
.msec
= mandoc_strdup("1");
506 return(post_prol(m
, n
));
509 /* Handles: `.Dt TITLE'
510 * --> title = TITLE, volume = local, msec = 0, arch = NULL
513 m
->meta
.title
= mandoc_strdup
514 ('\0' == nn
->string
[0] ? "UNKNOWN" : nn
->string
);
516 if (NULL
== (nn
= nn
->next
)) {
517 /* FIXME: warn about missing msec. */
518 /* XXX: make this a macro value. */
519 m
->meta
.vol
= mandoc_strdup("LOCAL");
520 m
->meta
.msec
= mandoc_strdup("1");
521 return(post_prol(m
, n
));
524 /* Handles: `.Dt TITLE SEC'
525 * --> title = TITLE, volume = SEC is msec ?
526 * format(msec) : SEC,
527 * msec = SEC is msec ? atoi(msec) : 0,
531 cp
= mdoc_a2msec(nn
->string
);
533 m
->meta
.vol
= mandoc_strdup(cp
);
534 m
->meta
.msec
= mandoc_strdup(nn
->string
);
535 } else if (mdoc_nmsg(m
, n
, MANDOCERR_BADMSEC
)) {
536 m
->meta
.vol
= mandoc_strdup(nn
->string
);
537 m
->meta
.msec
= mandoc_strdup(nn
->string
);
541 if (NULL
== (nn
= nn
->next
))
542 return(post_prol(m
, n
));
544 /* Handles: `.Dt TITLE SEC VOL'
545 * --> title = TITLE, volume = VOL is vol ?
547 * VOL is arch ? format(arch) :
551 cp
= mdoc_a2vol(nn
->string
);
554 m
->meta
.vol
= mandoc_strdup(cp
);
556 /* FIXME: warn about bad arch. */
557 cp
= mdoc_a2arch(nn
->string
);
560 m
->meta
.vol
= mandoc_strdup(nn
->string
);
562 m
->meta
.arch
= mandoc_strdup(cp
);
565 /* Ignore any subsequent parameters... */
566 /* FIXME: warn about subsequent parameters. */
568 return(post_prol(m
, n
));
573 * Set the operating system by way of the `Os' macro. Note that if an
574 * argument isn't provided and -DOSNAME="\"foo\"" is provided during
575 * compilation, this value will be used instead of filling in "sysname
576 * release" from uname().
583 struct utsname utsname
;
589 if ( ! concat(m
, buf
, n
->child
, BUFSIZ
))
592 /* XXX: yes, these can all be dynamically-adjusted buffers, but
593 * it's really not worth the extra hackery.
596 if ('\0' == buf
[0]) {
598 if (strlcat(buf
, OSNAME
, BUFSIZ
) >= BUFSIZ
) {
599 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
603 if (-1 == uname(&utsname
))
604 return(mdoc_nmsg(m
, n
, MANDOCERR_UTSNAME
));
606 if (strlcat(buf
, utsname
.sysname
, BUFSIZ
) >= BUFSIZ
) {
607 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
610 if (strlcat(buf
, " ", 64) >= BUFSIZ
) {
611 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
614 if (strlcat(buf
, utsname
.release
, BUFSIZ
) >= BUFSIZ
) {
615 mdoc_nmsg(m
, n
, MANDOCERR_MEM
);
621 m
->meta
.os
= mandoc_strdup(buf
);
622 return(post_prol(m
, n
));
627 * Calculate the -width for a `Bl -tag' list if it hasn't been provided.
628 * Uses the first head macro. NOTE AGAIN: this is ONLY if the -width
629 * argument has NOT been provided. See post_bl_width() for converting
633 post_bl_tagwidth(POST_ARGS
)
635 struct mdoc_node
*nn
;
640 /* Defaults to ten ens. */
642 sz
= 10; /* XXX: make this a macro value. */
644 for (nn
= n
->body
->child
; nn
; nn
= nn
->next
) {
645 if (MDOC_It
== nn
->tok
)
650 assert(MDOC_BLOCK
== nn
->type
);
651 nn
= nn
->head
->child
;
652 if (MDOC_TEXT
!= nn
->type
) {
653 sz
= mdoc_macro2len(nn
->tok
);
655 if ( ! mdoc_nmsg(m
, n
, MANDOCERR_NOWIDTHARG
))
660 sz
= strlen(nn
->string
) + 1;
663 snprintf(buf
, NUMSIZ
, "%zun", sz
);
666 * We have to dynamically add this to the macro's argument list.
667 * We're guaranteed that a MDOC_Width doesn't already exist.
672 i
= (int)(nn
->args
->argc
)++;
674 nn
->args
->argv
= mandoc_realloc(nn
->args
->argv
,
675 nn
->args
->argc
* sizeof(struct mdoc_argv
));
677 nn
->args
->argv
[i
].arg
= MDOC_Width
;
678 nn
->args
->argv
[i
].line
= n
->line
;
679 nn
->args
->argv
[i
].pos
= n
->pos
;
680 nn
->args
->argv
[i
].sz
= 1;
681 nn
->args
->argv
[i
].value
= mandoc_malloc(sizeof(char *));
682 nn
->args
->argv
[i
].value
[0] = mandoc_strdup(buf
);
688 * Calculate the real width of a list from the -width string, which may
689 * contain a macro (with a known default width), a literal string, or a
693 post_bl_width(POST_ARGS
)
704 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
705 if (MDOC_Width
== n
->args
->argv
[i
].arg
)
708 if (i
== (int)n
->args
->argc
)
710 p
= n
->args
->argv
[i
].value
[0];
713 * If the value to -width is a macro, then we re-write it to be
714 * the macro's width as set in share/tmac/mdoc/doc-common.
717 if (0 == strcmp(p
, "Ds"))
719 else if (MDOC_MAX
== (tok
= mdoc_hash_find(p
)))
721 else if (0 == (width
= mdoc_macro2len(tok
)))
722 return(mdoc_nmsg(m
, n
, MANDOCERR_BADWIDTH
));
724 /* The value already exists: free and reallocate it. */
726 snprintf(buf
, NUMSIZ
, "%zun", width
);
727 free(n
->args
->argv
[i
].value
[0]);
728 n
->args
->argv
[i
].value
[0] = mandoc_strdup(buf
);
734 * Do processing for -column lists, which can have two distinct styles
735 * of invocation. Merge this two styles into a consistent form.
739 post_bl_head(POST_ARGS
)
742 struct mdoc_node
*np
, *nn
, *nnp
;
744 if (NULL
== n
->child
)
750 for (c
= 0; c
< (int)np
->args
->argc
; c
++)
751 if (MDOC_Column
== np
->args
->argv
[c
].arg
)
754 if (c
== (int)np
->args
->argc
)
756 assert(0 == np
->args
->argv
[c
].sz
);
759 * Accomodate for new-style groff column syntax. Shuffle the
760 * child nodes, all of which must be TEXT, as arguments for the
761 * column field. Then, delete the head children.
764 np
->args
->argv
[c
].sz
= (size_t)n
->nchild
;
765 np
->args
->argv
[c
].value
= mandoc_malloc
766 ((size_t)n
->nchild
* sizeof(char *));
768 for (i
= 0, nn
= n
->child
; nn
; i
++) {
769 np
->args
->argv
[c
].value
[i
] = nn
->string
;
773 mdoc_node_delete(NULL
, nnp
);
787 if (MDOC_HEAD
== n
->type
)
788 return(post_bl_head(m
, n
));
789 if (MDOC_BLOCK
!= n
->type
)
793 * These are fairly complicated, so we've broken them into two
794 * functions. post_bl_tagwidth() is called when a -tag is
795 * specified, but no -width (it must be guessed). The second
796 * when a -width is specified (macro indicators must be
797 * rewritten into real lengths).
800 len
= (int)(n
->args
? n
->args
->argc
: 0);
802 for (r
= i
= 0; i
< len
; i
++) {
803 if (MDOC_Tag
== n
->args
->argv
[i
].arg
)
805 if (MDOC_Width
== n
->args
->argv
[i
].arg
)
809 if (r
& (1 << 0) && ! (r
& (1 << 1))) {
810 if ( ! post_bl_tagwidth(m
, n
))
812 } else if (r
& (1 << 1))
813 if ( ! post_bl_width(m
, n
))
821 * The `Pa' macro defaults to a tilde if no value is provided as an
827 struct mdoc_node
*np
;
833 m
->next
= MDOC_NEXT_CHILD
;
834 /* XXX: make into macro value. */
835 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "~"))
843 * Empty `Li' macros get an empty string to make front-ends add an extra
849 struct mdoc_node
*np
;
855 m
->next
= MDOC_NEXT_CHILD
;
856 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, ""))
864 * The `Ar' macro defaults to two strings "file ..." if no value is
865 * provided as an argument.
870 struct mdoc_node
*np
;
876 m
->next
= MDOC_NEXT_CHILD
;
877 /* XXX: make into macro values. */
878 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "file"))
880 if ( ! mdoc_word_alloc(m
, n
->line
, n
->pos
, "..."))
888 * Parse the date field in `Dd'.
895 if ( ! concat(m
, buf
, n
->child
, DATESIZ
))
898 m
->meta
.date
= mandoc_a2time
899 (MTIME_MDOCDATE
| MTIME_CANONICAL
, buf
);
901 if (0 == m
->meta
.date
) {
902 if ( ! mdoc_nmsg(m
, n
, MANDOCERR_BADDATE
))
904 m
->meta
.date
= time(NULL
);
907 return(post_prol(m
, n
));
912 * Remove prologue macros from the document after they're processed.
913 * The final document uses mdoc_meta for these values and discards the
920 mdoc_node_delete(m
, n
);
921 if (m
->meta
.title
&& m
->meta
.date
&& m
->meta
.os
)
922 m
->flags
|= MDOC_PBODY
;
928 * Trigger a literal context.
934 if (MDOC_BODY
== n
->type
)
935 m
->flags
|= MDOC_LITERAL
;
947 * Make sure that an empty offset produces an 8n length space as
948 * stipulated by mdoc.samples.
951 for (i
= 0; n
->args
&& i
< (int)n
->args
->argc
; i
++) {
952 if (MDOC_Offset
!= n
->args
->argv
[i
].arg
)
954 if (n
->args
->argv
[i
].sz
)
956 assert(1 == n
->args
->refcnt
);
957 /* If no value set, length of <string>. */
958 n
->args
->argv
[i
].sz
++;
959 n
->args
->argv
[i
].value
= mandoc_malloc(sizeof(char *));
960 n
->args
->argv
[i
].value
[0] = mandoc_strdup("8n");
972 if (MDOC_BLOCK
== n
->type
)
973 return(pre_offset(m
, n
));
983 if (MDOC_BLOCK
== n
->type
)
984 return(pre_offset(m
, n
));
985 if (MDOC_BODY
!= n
->type
)
988 /* Enter literal context if `Bd -literal' or `-unfilled'. */
990 for (n
= n
->parent
, i
= 0; i
< (int)n
->args
->argc
; i
++)
991 if (MDOC_Literal
== n
->args
->argv
[i
].arg
)
992 m
->flags
|= MDOC_LITERAL
;
993 else if (MDOC_Unfilled
== n
->args
->argv
[i
].arg
)
994 m
->flags
|= MDOC_LITERAL
;
1001 post_display(POST_ARGS
)
1004 if (MDOC_BODY
== n
->type
)
1005 m
->flags
&= ~MDOC_LITERAL
;
1011 order_rs(enum mdoct t
)
1015 for (i
= 0; i
< (int)RSORD_MAX
; i
++)
1028 struct mdoc_node
*nn
, *next
, *prev
;
1031 if (MDOC_BLOCK
!= n
->type
)
1034 assert(n
->body
->child
);
1035 for (next
= NULL
, nn
= n
->body
->child
->next
; nn
; nn
= next
) {
1036 o
= order_rs(nn
->tok
);
1038 /* Remove `nn' from the chain. */
1041 next
->prev
= nn
->prev
;
1045 prev
->next
= nn
->next
;
1047 nn
->prev
= nn
->next
= NULL
;
1050 * Scan back until we reach a node that's ordered before
1051 * us, then set ourselves as being the next.
1053 for ( ; prev
; prev
= prev
->prev
)
1054 if (order_rs(prev
->tok
) <= o
)
1060 prev
->next
->prev
= nn
;
1061 nn
->next
= prev
->next
;
1066 n
->body
->child
->prev
= nn
;
1067 nn
->next
= n
->body
->child
;
1068 n
->body
->child
= nn
;