]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc.c
1 /* $Id: mdoc.c,v 1.220 2014/07/09 11:31:43 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include <sys/types.h>
34 #include "mandoc_aux.h"
36 #include "libmandoc.h"
38 const char *const __mdoc_macronames
[MDOC_MAX
+ 1] = {
39 "Ap", "Dd", "Dt", "Os",
40 "Sh", "Ss", "Pp", "D1",
41 "Dl", "Bd", "Ed", "Bl",
42 "El", "It", "Ad", "An",
43 "Ar", "Cd", "Cm", "Dv",
44 "Er", "Ev", "Ex", "Fa",
45 "Fd", "Fl", "Fn", "Ft",
46 "Ic", "In", "Li", "Nd",
47 "Nm", "Op", "Ot", "Pa",
48 "Rv", "St", "Va", "Vt",
49 "Xr", "%A", "%B", "%D",
50 "%I", "%J", "%N", "%O",
51 "%P", "%R", "%T", "%V",
52 "Ac", "Ao", "Aq", "At",
53 "Bc", "Bf", "Bo", "Bq",
54 "Bsx", "Bx", "Db", "Dc",
55 "Do", "Dq", "Ec", "Ef",
56 "Em", "Eo", "Fx", "Ms",
57 "No", "Ns", "Nx", "Ox",
58 "Pc", "Pf", "Po", "Pq",
59 "Qc", "Ql", "Qo", "Qq",
60 "Re", "Rs", "Sc", "So",
61 "Sq", "Sm", "Sx", "Sy",
62 "Tn", "Ux", "Xc", "Xo",
63 "Fo", "Fc", "Oo", "Oc",
64 "Bk", "Ek", "Bt", "Hf",
65 "Fr", "Ud", "Lb", "Lp",
66 "Lk", "Mt", "Brq", "Bro",
67 "Brc", "%C", "Es", "En",
68 "Dx", "%Q", "br", "sp",
69 "%U", "Ta", "ll", "text",
72 const char *const __mdoc_argnames
[MDOC_ARG_MAX
] = {
73 "split", "nosplit", "ragged",
74 "unfilled", "literal", "file",
75 "offset", "bullet", "dash",
76 "hyphen", "item", "enum",
77 "tag", "diag", "hang",
78 "ohang", "inset", "column",
79 "width", "compact", "std",
80 "filled", "words", "emphasis",
81 "symbolic", "nested", "centered"
84 const char * const *mdoc_macronames
= __mdoc_macronames
;
85 const char * const *mdoc_argnames
= __mdoc_argnames
;
87 static void mdoc_node_free(struct mdoc_node
*);
88 static void mdoc_node_unlink(struct mdoc
*,
90 static void mdoc_free1(struct mdoc
*);
91 static void mdoc_alloc1(struct mdoc
*);
92 static struct mdoc_node
*node_alloc(struct mdoc
*, int, int,
93 enum mdoct
, enum mdoc_type
);
94 static int node_append(struct mdoc
*,
97 static int mdoc_preptext(struct mdoc
*, int, char *, int);
99 static int mdoc_ptext(struct mdoc
*, int, char *, int);
100 static int mdoc_pmacro(struct mdoc
*, int, char *, int);
103 const struct mdoc_node
*
104 mdoc_node(const struct mdoc
*mdoc
)
107 assert( ! (MDOC_HALT
& mdoc
->flags
));
111 const struct mdoc_meta
*
112 mdoc_meta(const struct mdoc
*mdoc
)
115 assert( ! (MDOC_HALT
& mdoc
->flags
));
120 * Frees volatile resources (parse tree, meta-data, fields).
123 mdoc_free1(struct mdoc
*mdoc
)
127 mdoc_node_delete(mdoc
, mdoc
->first
);
128 if (mdoc
->meta
.title
)
129 free(mdoc
->meta
.title
);
133 free(mdoc
->meta
.name
);
135 free(mdoc
->meta
.arch
);
137 free(mdoc
->meta
.vol
);
139 free(mdoc
->meta
.msec
);
141 free(mdoc
->meta
.date
);
145 * Allocate all volatile resources (parse tree, meta-data, fields).
148 mdoc_alloc1(struct mdoc
*mdoc
)
151 memset(&mdoc
->meta
, 0, sizeof(struct mdoc_meta
));
153 mdoc
->lastnamed
= mdoc
->lastsec
= SEC_NONE
;
154 mdoc
->last
= mandoc_calloc(1, sizeof(struct mdoc_node
));
155 mdoc
->first
= mdoc
->last
;
156 mdoc
->last
->type
= MDOC_ROOT
;
157 mdoc
->last
->tok
= MDOC_MAX
;
158 mdoc
->next
= MDOC_NEXT_CHILD
;
162 * Free up volatile resources (see mdoc_free1()) then re-initialises the
163 * data with mdoc_alloc1(). After invocation, parse data has been reset
164 * and the parser is ready for re-invocation on a new tree; however,
165 * cross-parse non-volatile data is kept intact.
168 mdoc_reset(struct mdoc
*mdoc
)
176 * Completely free up all volatile and non-volatile parse resources.
177 * After invocation, the pointer is no longer usable.
180 mdoc_free(struct mdoc
*mdoc
)
188 * Allocate volatile and non-volatile parse resources.
191 mdoc_alloc(struct roff
*roff
, struct mparse
*parse
,
192 const char *defos
, int quick
)
196 p
= mandoc_calloc(1, sizeof(struct mdoc
));
209 * Climb back up the parse tree, validating open scopes. Mostly calls
210 * through to macro_end() in macro.c.
213 mdoc_endparse(struct mdoc
*mdoc
)
216 assert( ! (MDOC_HALT
& mdoc
->flags
));
217 if (mdoc_macroend(mdoc
))
219 mdoc
->flags
|= MDOC_HALT
;
224 mdoc_addeqn(struct mdoc
*mdoc
, const struct eqn
*ep
)
228 assert( ! (MDOC_HALT
& mdoc
->flags
));
230 n
= node_alloc(mdoc
, ep
->ln
, ep
->pos
, MDOC_MAX
, MDOC_EQN
);
233 if ( ! node_append(mdoc
, n
))
236 mdoc
->next
= MDOC_NEXT_SIBLING
;
241 mdoc_addspan(struct mdoc
*mdoc
, const struct tbl_span
*sp
)
245 assert( ! (MDOC_HALT
& mdoc
->flags
));
247 n
= node_alloc(mdoc
, sp
->line
, 0, MDOC_MAX
, MDOC_TBL
);
250 if ( ! node_append(mdoc
, n
))
253 mdoc
->next
= MDOC_NEXT_SIBLING
;
258 * Main parse routine. Parses a single line -- really just hands off to
259 * the macro (mdoc_pmacro()) or text parser (mdoc_ptext()).
262 mdoc_parseln(struct mdoc
*mdoc
, int ln
, char *buf
, int offs
)
265 assert( ! (MDOC_HALT
& mdoc
->flags
));
267 mdoc
->flags
|= MDOC_NEWLINE
;
270 * Let the roff nS register switch SYNOPSIS mode early,
271 * such that the parser knows at all times
272 * whether this mode is on or off.
273 * Note that this mode is also switched by the Sh macro.
275 if (roff_getreg(mdoc
->roff
, "nS"))
276 mdoc
->flags
|= MDOC_SYNOPSIS
;
278 mdoc
->flags
&= ~MDOC_SYNOPSIS
;
280 return(roff_getcontrol(mdoc
->roff
, buf
, &offs
) ?
281 mdoc_pmacro(mdoc
, ln
, buf
, offs
) :
282 mdoc_ptext(mdoc
, ln
, buf
, offs
));
286 mdoc_macro(MACRO_PROT_ARGS
)
288 assert(tok
< MDOC_MAX
);
290 /* If we're in the body, deny prologue calls. */
292 if (MDOC_PROLOGUE
& mdoc_macros
[tok
].flags
&&
293 MDOC_PBODY
& mdoc
->flags
) {
294 mandoc_vmsg(MANDOCERR_PROLOG_ONLY
, mdoc
->parse
,
295 line
, ppos
, "%s", mdoc_macronames
[tok
]);
299 /* If we're in the prologue, deny "body" macros. */
301 if ( ! (MDOC_PROLOGUE
& mdoc_macros
[tok
].flags
) &&
302 ! (MDOC_PBODY
& mdoc
->flags
)) {
303 mandoc_vmsg(MANDOCERR_PROLOG_BAD
, mdoc
->parse
,
304 line
, ppos
, "%s", mdoc_macronames
[tok
]);
305 if (NULL
== mdoc
->meta
.msec
)
306 mdoc
->meta
.msec
= mandoc_strdup("1");
307 if (NULL
== mdoc
->meta
.title
)
308 mdoc
->meta
.title
= mandoc_strdup("UNKNOWN");
309 if (NULL
== mdoc
->meta
.vol
)
310 mdoc
->meta
.vol
= mandoc_strdup("LOCAL");
311 if (NULL
== mdoc
->meta
.os
)
312 mdoc
->meta
.os
= mandoc_strdup("LOCAL");
313 if (NULL
== mdoc
->meta
.date
)
314 mdoc
->meta
.date
= mandoc_normdate
315 (mdoc
->parse
, NULL
, line
, ppos
);
316 mdoc
->flags
|= MDOC_PBODY
;
319 return((*mdoc_macros
[tok
].fp
)(mdoc
, tok
, line
, ppos
, pos
, buf
));
324 node_append(struct mdoc
*mdoc
, struct mdoc_node
*p
)
329 assert(MDOC_ROOT
!= p
->type
);
331 switch (mdoc
->next
) {
332 case MDOC_NEXT_SIBLING
:
333 mdoc
->last
->next
= p
;
334 p
->prev
= mdoc
->last
;
335 p
->parent
= mdoc
->last
->parent
;
337 case MDOC_NEXT_CHILD
:
338 mdoc
->last
->child
= p
;
339 p
->parent
= mdoc
->last
;
349 * Copy over the normalised-data pointer of our parent. Not
350 * everybody has one, but copying a null pointer is fine.
355 if (ENDBODY_NOT
!= p
->end
)
361 p
->norm
= p
->parent
->norm
;
367 if ( ! mdoc_valid_pre(mdoc
, p
))
372 assert(MDOC_BLOCK
== p
->parent
->type
);
376 assert(MDOC_BLOCK
== p
->parent
->type
);
382 assert(MDOC_BLOCK
== p
->parent
->type
);
395 if ( ! mdoc_valid_post(mdoc
))
405 static struct mdoc_node
*
406 node_alloc(struct mdoc
*mdoc
, int line
, int pos
,
407 enum mdoct tok
, enum mdoc_type type
)
411 p
= mandoc_calloc(1, sizeof(struct mdoc_node
));
412 p
->sec
= mdoc
->lastsec
;
421 if (MDOC_SYNOPSIS
& mdoc
->flags
)
422 p
->flags
|= MDOC_SYNPRETTY
;
424 p
->flags
&= ~MDOC_SYNPRETTY
;
425 if (MDOC_NEWLINE
& mdoc
->flags
)
426 p
->flags
|= MDOC_LINE
;
427 mdoc
->flags
&= ~MDOC_NEWLINE
;
433 mdoc_tail_alloc(struct mdoc
*mdoc
, int line
, int pos
, enum mdoct tok
)
437 p
= node_alloc(mdoc
, line
, pos
, tok
, MDOC_TAIL
);
438 if ( ! node_append(mdoc
, p
))
440 mdoc
->next
= MDOC_NEXT_CHILD
;
445 mdoc_head_alloc(struct mdoc
*mdoc
, int line
, int pos
, enum mdoct tok
)
452 p
= node_alloc(mdoc
, line
, pos
, tok
, MDOC_HEAD
);
453 if ( ! node_append(mdoc
, p
))
455 mdoc
->next
= MDOC_NEXT_CHILD
;
460 mdoc_body_alloc(struct mdoc
*mdoc
, int line
, int pos
, enum mdoct tok
)
464 p
= node_alloc(mdoc
, line
, pos
, tok
, MDOC_BODY
);
465 if ( ! node_append(mdoc
, p
))
467 mdoc
->next
= MDOC_NEXT_CHILD
;
472 mdoc_endbody_alloc(struct mdoc
*mdoc
, int line
, int pos
, enum mdoct tok
,
473 struct mdoc_node
*body
, enum mdoc_endbody end
)
477 p
= node_alloc(mdoc
, line
, pos
, tok
, MDOC_BODY
);
479 p
->norm
= body
->norm
;
481 if ( ! node_append(mdoc
, p
))
483 mdoc
->next
= MDOC_NEXT_SIBLING
;
488 mdoc_block_alloc(struct mdoc
*mdoc
, int line
, int pos
,
489 enum mdoct tok
, struct mdoc_arg
*args
)
493 p
= node_alloc(mdoc
, line
, pos
, tok
, MDOC_BLOCK
);
508 p
->norm
= mandoc_calloc(1, sizeof(union mdoc_data
));
514 if ( ! node_append(mdoc
, p
))
516 mdoc
->next
= MDOC_NEXT_CHILD
;
521 mdoc_elem_alloc(struct mdoc
*mdoc
, int line
, int pos
,
522 enum mdoct tok
, struct mdoc_arg
*args
)
526 p
= node_alloc(mdoc
, line
, pos
, tok
, MDOC_ELEM
);
533 p
->norm
= mandoc_calloc(1, sizeof(union mdoc_data
));
539 if ( ! node_append(mdoc
, p
))
541 mdoc
->next
= MDOC_NEXT_CHILD
;
546 mdoc_word_alloc(struct mdoc
*mdoc
, int line
, int pos
, const char *p
)
550 n
= node_alloc(mdoc
, line
, pos
, MDOC_MAX
, MDOC_TEXT
);
551 n
->string
= roff_strdup(mdoc
->roff
, p
);
553 if ( ! node_append(mdoc
, n
))
556 mdoc
->next
= MDOC_NEXT_SIBLING
;
561 mdoc_word_append(struct mdoc
*mdoc
, const char *p
)
564 char *addstr
, *newstr
;
567 addstr
= roff_strdup(mdoc
->roff
, p
);
568 mandoc_asprintf(&newstr
, "%s %s", n
->string
, addstr
);
572 mdoc
->next
= MDOC_NEXT_SIBLING
;
576 mdoc_node_free(struct mdoc_node
*p
)
579 if (MDOC_BLOCK
== p
->type
|| MDOC_ELEM
== p
->type
)
584 mdoc_argv_free(p
->args
);
589 mdoc_node_unlink(struct mdoc
*mdoc
, struct mdoc_node
*n
)
592 /* Adjust siblings. */
595 n
->prev
->next
= n
->next
;
597 n
->next
->prev
= n
->prev
;
603 if (n
->parent
->child
== n
)
604 n
->parent
->child
= n
->prev
? n
->prev
: n
->next
;
605 if (n
->parent
->last
== n
)
606 n
->parent
->last
= n
->prev
? n
->prev
: NULL
;
609 /* Adjust parse point, if applicable. */
611 if (mdoc
&& mdoc
->last
== n
) {
613 mdoc
->last
= n
->prev
;
614 mdoc
->next
= MDOC_NEXT_SIBLING
;
616 mdoc
->last
= n
->parent
;
617 mdoc
->next
= MDOC_NEXT_CHILD
;
621 if (mdoc
&& mdoc
->first
== n
)
626 mdoc_node_delete(struct mdoc
*mdoc
, struct mdoc_node
*p
)
631 mdoc_node_delete(mdoc
, p
->child
);
633 assert(0 == p
->nchild
);
635 mdoc_node_unlink(mdoc
, p
);
640 mdoc_node_relink(struct mdoc
*mdoc
, struct mdoc_node
*p
)
643 mdoc_node_unlink(mdoc
, p
);
644 return(node_append(mdoc
, p
));
649 * Pre-treat a text line.
650 * Text lines can consist of equations, which must be handled apart from
652 * Thus, use this function to step through a line checking if it has any
653 * equations embedded in it.
654 * This must handle multiple equations AND equations that do not end at
655 * the end-of-line, i.e., will re-enter in the next roff parse.
658 mdoc_preptext(struct mdoc
*mdoc
, int line
, char *buf
, int offs
)
663 while ('\0' != buf
[offs
]) {
664 /* Mark starting position if eqn is set. */
666 if ('\0' != (delim
= roff_eqndelim(mdoc
->roff
)))
667 if (NULL
!= (start
= strchr(buf
+ offs
, delim
)))
670 /* Parse text as normal. */
671 if ( ! mdoc_ptext(mdoc
, line
, buf
, offs
))
674 /* Continue only if an equation exists. */
678 /* Read past the end of the equation. */
679 offs
+= start
- (buf
+ offs
);
680 assert(start
== &buf
[offs
]);
681 if (NULL
!= (end
= strchr(buf
+ offs
, delim
))) {
687 /* Parse the equation itself. */
688 roff_openeqn(mdoc
->roff
, NULL
, line
, offs
, buf
);
690 /* Process a finished equation? */
691 if (roff_closeeqn(mdoc
->roff
))
692 if ( ! mdoc_addeqn(mdoc
, roff_eqn(mdoc
->roff
)))
694 offs
+= (end
- (buf
+ offs
));
702 * Parse free-form text, that is, a line that does not begin with the
706 mdoc_ptext(struct mdoc
*mdoc
, int line
, char *buf
, int offs
)
715 * Divert directly to list processing if we're encountering a
716 * columnar MDOC_BLOCK with or without a prior MDOC_BLOCK entry
717 * (a MDOC_BODY means it's already open, in which case we should
718 * process within its context in the normal way).
721 if (MDOC_Bl
== n
->tok
&& MDOC_BODY
== n
->type
&&
722 LIST_column
== n
->norm
->Bl
.type
) {
723 /* `Bl' is open without any children. */
724 mdoc
->flags
|= MDOC_FREECOL
;
725 return(mdoc_macro(mdoc
, MDOC_It
, line
, offs
, &offs
, buf
));
728 if (MDOC_It
== n
->tok
&& MDOC_BLOCK
== n
->type
&&
730 MDOC_Bl
== n
->parent
->tok
&&
731 LIST_column
== n
->parent
->norm
->Bl
.type
) {
732 /* `Bl' has block-level `It' children. */
733 mdoc
->flags
|= MDOC_FREECOL
;
734 return(mdoc_macro(mdoc
, MDOC_It
, line
, offs
, &offs
, buf
));
738 * Search for the beginning of unescaped trailing whitespace (ws)
739 * and for the first character not to be output (end).
742 /* FIXME: replace with strcspn(). */
744 for (c
= end
= buf
+ offs
; *c
; c
++) {
752 * Always warn about trailing tabs,
753 * even outside literal context,
754 * where they should be put on the next line.
759 * Strip trailing tabs in literal context only;
760 * outside, they affect the next line.
762 if (MDOC_LITERAL
& mdoc
->flags
)
766 /* Skip the escaped character, too, if any. */
779 mandoc_msg(MANDOCERR_SPACE_EOL
, mdoc
->parse
,
780 line
, (int)(ws
-buf
), NULL
);
782 if ('\0' == buf
[offs
] && ! (MDOC_LITERAL
& mdoc
->flags
)) {
783 mandoc_msg(MANDOCERR_FI_BLANK
, mdoc
->parse
,
784 line
, (int)(c
- buf
), NULL
);
787 * Insert a `sp' in the case of a blank line. Technically,
788 * blank lines aren't allowed, but enough manuals assume this
789 * behaviour that we want to work around it.
791 if ( ! mdoc_elem_alloc(mdoc
, line
, offs
, MDOC_sp
, NULL
))
794 mdoc
->next
= MDOC_NEXT_SIBLING
;
796 return(mdoc_valid_post(mdoc
));
799 if ( ! mdoc_word_alloc(mdoc
, line
, offs
, buf
+offs
))
802 if (MDOC_LITERAL
& mdoc
->flags
)
806 * End-of-sentence check. If the last character is an unescaped
807 * EOS character, then flag the node as being the end of a
808 * sentence. The front-end will know how to interpret this.
813 if (mandoc_eos(buf
+offs
, (size_t)(end
-buf
-offs
)))
814 mdoc
->last
->flags
|= MDOC_EOS
;
820 * Parse a macro line, that is, a line beginning with the control
824 mdoc_pmacro(struct mdoc
*mdoc
, int ln
, char *buf
, int offs
)
831 /* Empty post-control lines are ignored. */
833 if ('"' == buf
[offs
]) {
834 mandoc_msg(MANDOCERR_COMMENT_BAD
, mdoc
->parse
,
837 } else if ('\0' == buf
[offs
])
843 * Copy the first word into a nil-terminated buffer.
844 * Stop copying when a tab, space, or eoln is encountered.
848 while (i
< 4 && '\0' != buf
[offs
] && ' ' != buf
[offs
] &&
850 mac
[i
++] = buf
[offs
++];
854 tok
= (i
> 1 && i
< 4) ? mdoc_hash_find(mac
) : MDOC_MAX
;
856 if (MDOC_MAX
== tok
) {
857 mandoc_vmsg(MANDOCERR_MACRO
, mdoc
->parse
,
858 ln
, sv
, "%s", buf
+ sv
- 1);
862 /* Disregard the first trailing tab, if applicable. */
864 if ('\t' == buf
[offs
])
867 /* Jump to the next non-whitespace word. */
869 while (buf
[offs
] && ' ' == buf
[offs
])
873 * Trailing whitespace. Note that tabs are allowed to be passed
874 * into the parser as "text", so we only warn about spaces here.
877 if ('\0' == buf
[offs
] && ' ' == buf
[offs
- 1])
878 mandoc_msg(MANDOCERR_SPACE_EOL
, mdoc
->parse
,
882 * If an initial macro or a list invocation, divert directly
883 * into macro processing.
886 if (NULL
== mdoc
->last
|| MDOC_It
== tok
|| MDOC_El
== tok
) {
887 if ( ! mdoc_macro(mdoc
, tok
, ln
, sv
, &offs
, buf
))
896 * If the first macro of a `Bl -column', open an `It' block
897 * context around the parsed macro.
900 if (MDOC_Bl
== n
->tok
&& MDOC_BODY
== n
->type
&&
901 LIST_column
== n
->norm
->Bl
.type
) {
902 mdoc
->flags
|= MDOC_FREECOL
;
903 if ( ! mdoc_macro(mdoc
, MDOC_It
, ln
, sv
, &sv
, buf
))
909 * If we're following a block-level `It' within a `Bl -column'
910 * context (perhaps opened in the above block or in ptext()),
911 * then open an `It' block context around the parsed macro.
914 if (MDOC_It
== n
->tok
&& MDOC_BLOCK
== n
->type
&&
916 MDOC_Bl
== n
->parent
->tok
&&
917 LIST_column
== n
->parent
->norm
->Bl
.type
) {
918 mdoc
->flags
|= MDOC_FREECOL
;
919 if ( ! mdoc_macro(mdoc
, MDOC_It
, ln
, sv
, &sv
, buf
))
924 /* Normal processing of a macro. */
926 if ( ! mdoc_macro(mdoc
, tok
, ln
, sv
, &offs
, buf
))
929 /* In quick mode (for mandocdb), abort after the NAME section. */
931 if (mdoc
->quick
&& MDOC_Sh
== tok
&&
932 SEC_NAME
!= mdoc
->last
->sec
)
937 err
: /* Error out. */
939 mdoc
->flags
|= MDOC_HALT
;
944 mdoc_isdelim(const char *p
)
957 return(DELIM_MIDDLE
);
981 if (0 == strcmp(p
+ 1, "."))
983 if (0 == strcmp(p
+ 1, "fR|\\fP"))
984 return(DELIM_MIDDLE
);
990 mdoc_deroff(char **dest
, const struct mdoc_node
*n
)
995 if (MDOC_TEXT
!= n
->type
) {
996 for (n
= n
->child
; n
; n
= n
->next
)
997 mdoc_deroff(dest
, n
);
1001 /* Skip leading whitespace. */
1003 for (cp
= n
->string
; '\0' != *cp
; cp
++)
1004 if (0 == isspace((unsigned char)*cp
))
1007 /* Skip trailing whitespace. */
1009 for (sz
= strlen(cp
); sz
; sz
--)
1010 if (0 == isspace((unsigned char)cp
[sz
-1]))
1013 /* Skip empty strings. */
1018 if (NULL
== *dest
) {
1019 *dest
= mandoc_strndup(cp
, sz
);
1023 mandoc_asprintf(&cp
, "%s %*s", *dest
, (int)sz
, cp
);