]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc.c
1 /* $Id: mdoc.c,v 1.212 2014/03/30 19:47:48 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
] = {
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",
50 "Xr", "%A", "%B", "%D",
52 "%I", "%J", "%N", "%O",
54 "%P", "%R", "%T", "%V",
55 "Ac", "Ao", "Aq", "At",
56 "Bc", "Bf", "Bo", "Bq",
57 "Bsx", "Bx", "Db", "Dc",
58 "Do", "Dq", "Ec", "Ef",
59 "Em", "Eo", "Fx", "Ms",
60 "No", "Ns", "Nx", "Ox",
61 "Pc", "Pf", "Po", "Pq",
62 "Qc", "Ql", "Qo", "Qq",
63 "Re", "Rs", "Sc", "So",
64 "Sq", "Sm", "Sx", "Sy",
65 "Tn", "Ux", "Xc", "Xo",
66 "Fo", "Fc", "Oo", "Oc",
67 "Bk", "Ek", "Bt", "Hf",
68 "Fr", "Ud", "Lb", "Lp",
69 "Lk", "Mt", "Brq", "Bro",
71 "Brc", "%C", "Es", "En",
73 "Dx", "%Q", "br", "sp",
78 const char *const __mdoc_argnames
[MDOC_ARG_MAX
] = {
79 "split", "nosplit", "ragged",
80 "unfilled", "literal", "file",
81 "offset", "bullet", "dash",
82 "hyphen", "item", "enum",
83 "tag", "diag", "hang",
84 "ohang", "inset", "column",
85 "width", "compact", "std",
86 "filled", "words", "emphasis",
87 "symbolic", "nested", "centered"
90 const char * const *mdoc_macronames
= __mdoc_macronames
;
91 const char * const *mdoc_argnames
= __mdoc_argnames
;
93 static void mdoc_node_free(struct mdoc_node
*);
94 static void mdoc_node_unlink(struct mdoc
*,
96 static void mdoc_free1(struct mdoc
*);
97 static void mdoc_alloc1(struct mdoc
*);
98 static struct mdoc_node
*node_alloc(struct mdoc
*, int, int,
99 enum mdoct
, enum mdoc_type
);
100 static int node_append(struct mdoc
*,
103 static int mdoc_preptext(struct mdoc
*, int, char *, int);
105 static int mdoc_ptext(struct mdoc
*, int, char *, int);
106 static int mdoc_pmacro(struct mdoc
*, int, char *, int);
108 const struct mdoc_node
*
109 mdoc_node(const struct mdoc
*mdoc
)
112 assert( ! (MDOC_HALT
& mdoc
->flags
));
117 const struct mdoc_meta
*
118 mdoc_meta(const struct mdoc
*mdoc
)
121 assert( ! (MDOC_HALT
& mdoc
->flags
));
127 * Frees volatile resources (parse tree, meta-data, fields).
130 mdoc_free1(struct mdoc
*mdoc
)
134 mdoc_node_delete(mdoc
, mdoc
->first
);
135 if (mdoc
->meta
.title
)
136 free(mdoc
->meta
.title
);
140 free(mdoc
->meta
.name
);
142 free(mdoc
->meta
.arch
);
144 free(mdoc
->meta
.vol
);
146 free(mdoc
->meta
.msec
);
148 free(mdoc
->meta
.date
);
153 * Allocate all volatile resources (parse tree, meta-data, fields).
156 mdoc_alloc1(struct mdoc
*mdoc
)
159 memset(&mdoc
->meta
, 0, sizeof(struct mdoc_meta
));
161 mdoc
->lastnamed
= mdoc
->lastsec
= SEC_NONE
;
162 mdoc
->last
= mandoc_calloc(1, sizeof(struct mdoc_node
));
163 mdoc
->first
= mdoc
->last
;
164 mdoc
->last
->type
= MDOC_ROOT
;
165 mdoc
->last
->tok
= MDOC_MAX
;
166 mdoc
->next
= MDOC_NEXT_CHILD
;
171 * Free up volatile resources (see mdoc_free1()) then re-initialises the
172 * data with mdoc_alloc1(). After invocation, parse data has been reset
173 * and the parser is ready for re-invocation on a new tree; however,
174 * cross-parse non-volatile data is kept intact.
177 mdoc_reset(struct mdoc
*mdoc
)
186 * Completely free up all volatile and non-volatile parse resources.
187 * After invocation, the pointer is no longer usable.
190 mdoc_free(struct mdoc
*mdoc
)
199 * Allocate volatile and non-volatile parse resources.
202 mdoc_alloc(struct roff
*roff
, struct mparse
*parse
,
203 char *defos
, int quick
)
207 p
= mandoc_calloc(1, sizeof(struct mdoc
));
221 * Climb back up the parse tree, validating open scopes. Mostly calls
222 * through to macro_end() in macro.c.
225 mdoc_endparse(struct mdoc
*mdoc
)
228 assert( ! (MDOC_HALT
& mdoc
->flags
));
229 if (mdoc_macroend(mdoc
))
231 mdoc
->flags
|= MDOC_HALT
;
236 mdoc_addeqn(struct mdoc
*mdoc
, const struct eqn
*ep
)
240 assert( ! (MDOC_HALT
& mdoc
->flags
));
242 /* No text before an initial macro. */
244 if (SEC_NONE
== mdoc
->lastnamed
) {
245 mdoc_pmsg(mdoc
, ep
->ln
, ep
->pos
, MANDOCERR_NOTEXT
);
249 n
= node_alloc(mdoc
, ep
->ln
, ep
->pos
, MDOC_MAX
, MDOC_EQN
);
252 if ( ! node_append(mdoc
, n
))
255 mdoc
->next
= MDOC_NEXT_SIBLING
;
260 mdoc_addspan(struct mdoc
*mdoc
, const struct tbl_span
*sp
)
264 assert( ! (MDOC_HALT
& mdoc
->flags
));
266 /* No text before an initial macro. */
268 if (SEC_NONE
== mdoc
->lastnamed
) {
269 mdoc_pmsg(mdoc
, sp
->line
, 0, MANDOCERR_NOTEXT
);
273 n
= node_alloc(mdoc
, sp
->line
, 0, MDOC_MAX
, MDOC_TBL
);
276 if ( ! node_append(mdoc
, n
))
279 mdoc
->next
= MDOC_NEXT_SIBLING
;
285 * Main parse routine. Parses a single line -- really just hands off to
286 * the macro (mdoc_pmacro()) or text parser (mdoc_ptext()).
289 mdoc_parseln(struct mdoc
*mdoc
, int ln
, char *buf
, int offs
)
292 assert( ! (MDOC_HALT
& mdoc
->flags
));
294 mdoc
->flags
|= MDOC_NEWLINE
;
297 * Let the roff nS register switch SYNOPSIS mode early,
298 * such that the parser knows at all times
299 * whether this mode is on or off.
300 * Note that this mode is also switched by the Sh macro.
302 if (roff_getreg(mdoc
->roff
, "nS"))
303 mdoc
->flags
|= MDOC_SYNOPSIS
;
305 mdoc
->flags
&= ~MDOC_SYNOPSIS
;
307 return(roff_getcontrol(mdoc
->roff
, buf
, &offs
) ?
308 mdoc_pmacro(mdoc
, ln
, buf
, offs
) :
309 mdoc_ptext(mdoc
, ln
, buf
, offs
));
313 mdoc_macro(MACRO_PROT_ARGS
)
315 assert(tok
< MDOC_MAX
);
317 /* If we're in the body, deny prologue calls. */
319 if (MDOC_PROLOGUE
& mdoc_macros
[tok
].flags
&&
320 MDOC_PBODY
& mdoc
->flags
) {
321 mdoc_pmsg(mdoc
, line
, ppos
, MANDOCERR_BADBODY
);
325 /* If we're in the prologue, deny "body" macros. */
327 if ( ! (MDOC_PROLOGUE
& mdoc_macros
[tok
].flags
) &&
328 ! (MDOC_PBODY
& mdoc
->flags
)) {
329 mdoc_pmsg(mdoc
, line
, ppos
, MANDOCERR_BADPROLOG
);
330 if (NULL
== mdoc
->meta
.msec
)
331 mdoc
->meta
.msec
= mandoc_strdup("1");
332 if (NULL
== mdoc
->meta
.title
)
333 mdoc
->meta
.title
= mandoc_strdup("UNKNOWN");
334 if (NULL
== mdoc
->meta
.vol
)
335 mdoc
->meta
.vol
= mandoc_strdup("LOCAL");
336 if (NULL
== mdoc
->meta
.os
)
337 mdoc
->meta
.os
= mandoc_strdup("LOCAL");
338 if (NULL
== mdoc
->meta
.date
)
339 mdoc
->meta
.date
= mandoc_normdate
340 (mdoc
->parse
, NULL
, line
, ppos
);
341 mdoc
->flags
|= MDOC_PBODY
;
344 return((*mdoc_macros
[tok
].fp
)(mdoc
, tok
, line
, ppos
, pos
, buf
));
349 node_append(struct mdoc
*mdoc
, struct mdoc_node
*p
)
354 assert(MDOC_ROOT
!= p
->type
);
356 switch (mdoc
->next
) {
357 case (MDOC_NEXT_SIBLING
):
358 mdoc
->last
->next
= p
;
359 p
->prev
= mdoc
->last
;
360 p
->parent
= mdoc
->last
->parent
;
362 case (MDOC_NEXT_CHILD
):
363 mdoc
->last
->child
= p
;
364 p
->parent
= mdoc
->last
;
374 * Copy over the normalised-data pointer of our parent. Not
375 * everybody has one, but copying a null pointer is fine.
380 if (ENDBODY_NOT
!= p
->end
)
386 p
->norm
= p
->parent
->norm
;
392 if ( ! mdoc_valid_pre(mdoc
, p
))
397 assert(MDOC_BLOCK
== p
->parent
->type
);
401 assert(MDOC_BLOCK
== p
->parent
->type
);
407 assert(MDOC_BLOCK
== p
->parent
->type
);
420 if ( ! mdoc_valid_post(mdoc
))
431 static struct mdoc_node
*
432 node_alloc(struct mdoc
*mdoc
, int line
, int pos
,
433 enum mdoct tok
, enum mdoc_type type
)
437 p
= mandoc_calloc(1, sizeof(struct mdoc_node
));
438 p
->sec
= mdoc
->lastsec
;
447 if (MDOC_SYNOPSIS
& mdoc
->flags
)
448 p
->flags
|= MDOC_SYNPRETTY
;
450 p
->flags
&= ~MDOC_SYNPRETTY
;
451 if (MDOC_NEWLINE
& mdoc
->flags
)
452 p
->flags
|= MDOC_LINE
;
453 mdoc
->flags
&= ~MDOC_NEWLINE
;
460 mdoc_tail_alloc(struct mdoc
*mdoc
, int line
, int pos
, enum mdoct tok
)
464 p
= node_alloc(mdoc
, line
, pos
, tok
, MDOC_TAIL
);
465 if ( ! node_append(mdoc
, p
))
467 mdoc
->next
= MDOC_NEXT_CHILD
;
473 mdoc_head_alloc(struct mdoc
*mdoc
, int line
, int pos
, enum mdoct tok
)
480 p
= node_alloc(mdoc
, line
, pos
, tok
, MDOC_HEAD
);
481 if ( ! node_append(mdoc
, p
))
483 mdoc
->next
= MDOC_NEXT_CHILD
;
489 mdoc_body_alloc(struct mdoc
*mdoc
, int line
, int pos
, enum mdoct tok
)
493 p
= node_alloc(mdoc
, line
, pos
, tok
, MDOC_BODY
);
494 if ( ! node_append(mdoc
, p
))
496 mdoc
->next
= MDOC_NEXT_CHILD
;
502 mdoc_endbody_alloc(struct mdoc
*mdoc
, int line
, int pos
, enum mdoct tok
,
503 struct mdoc_node
*body
, enum mdoc_endbody end
)
507 p
= node_alloc(mdoc
, line
, pos
, tok
, MDOC_BODY
);
509 p
->norm
= body
->norm
;
511 if ( ! node_append(mdoc
, p
))
513 mdoc
->next
= MDOC_NEXT_SIBLING
;
519 mdoc_block_alloc(struct mdoc
*mdoc
, int line
, int pos
,
520 enum mdoct tok
, struct mdoc_arg
*args
)
524 p
= node_alloc(mdoc
, line
, pos
, tok
, MDOC_BLOCK
);
537 p
->norm
= mandoc_calloc(1, sizeof(union mdoc_data
));
543 if ( ! node_append(mdoc
, p
))
545 mdoc
->next
= MDOC_NEXT_CHILD
;
551 mdoc_elem_alloc(struct mdoc
*mdoc
, int line
, int pos
,
552 enum mdoct tok
, struct mdoc_arg
*args
)
556 p
= node_alloc(mdoc
, line
, pos
, tok
, MDOC_ELEM
);
563 p
->norm
= mandoc_calloc(1, sizeof(union mdoc_data
));
569 if ( ! node_append(mdoc
, p
))
571 mdoc
->next
= MDOC_NEXT_CHILD
;
576 mdoc_word_alloc(struct mdoc
*mdoc
, int line
, int pos
, const char *p
)
580 n
= node_alloc(mdoc
, line
, pos
, MDOC_MAX
, MDOC_TEXT
);
581 n
->string
= roff_strdup(mdoc
->roff
, p
);
583 if ( ! node_append(mdoc
, n
))
586 mdoc
->next
= MDOC_NEXT_SIBLING
;
591 mdoc_word_append(struct mdoc
*mdoc
, const char *p
)
594 char *addstr
, *newstr
;
597 addstr
= roff_strdup(mdoc
->roff
, p
);
598 mandoc_asprintf(&newstr
, "%s %s", n
->string
, addstr
);
602 mdoc
->next
= MDOC_NEXT_SIBLING
;
606 mdoc_node_free(struct mdoc_node
*p
)
609 if (MDOC_BLOCK
== p
->type
|| MDOC_ELEM
== p
->type
)
614 mdoc_argv_free(p
->args
);
620 mdoc_node_unlink(struct mdoc
*mdoc
, struct mdoc_node
*n
)
623 /* Adjust siblings. */
626 n
->prev
->next
= n
->next
;
628 n
->next
->prev
= n
->prev
;
634 if (n
->parent
->child
== n
)
635 n
->parent
->child
= n
->prev
? n
->prev
: n
->next
;
636 if (n
->parent
->last
== n
)
637 n
->parent
->last
= n
->prev
? n
->prev
: NULL
;
640 /* Adjust parse point, if applicable. */
642 if (mdoc
&& mdoc
->last
== n
) {
644 mdoc
->last
= n
->prev
;
645 mdoc
->next
= MDOC_NEXT_SIBLING
;
647 mdoc
->last
= n
->parent
;
648 mdoc
->next
= MDOC_NEXT_CHILD
;
652 if (mdoc
&& mdoc
->first
== n
)
658 mdoc_node_delete(struct mdoc
*mdoc
, struct mdoc_node
*p
)
663 mdoc_node_delete(mdoc
, p
->child
);
665 assert(0 == p
->nchild
);
667 mdoc_node_unlink(mdoc
, p
);
672 mdoc_node_relink(struct mdoc
*mdoc
, struct mdoc_node
*p
)
675 mdoc_node_unlink(mdoc
, p
);
676 return(node_append(mdoc
, p
));
681 * Pre-treat a text line.
682 * Text lines can consist of equations, which must be handled apart from
684 * Thus, use this function to step through a line checking if it has any
685 * equations embedded in it.
686 * This must handle multiple equations AND equations that do not end at
687 * the end-of-line, i.e., will re-enter in the next roff parse.
690 mdoc_preptext(struct mdoc
*mdoc
, int line
, char *buf
, int offs
)
695 while ('\0' != buf
[offs
]) {
696 /* Mark starting position if eqn is set. */
698 if ('\0' != (delim
= roff_eqndelim(mdoc
->roff
)))
699 if (NULL
!= (start
= strchr(buf
+ offs
, delim
)))
702 /* Parse text as normal. */
703 if ( ! mdoc_ptext(mdoc
, line
, buf
, offs
))
706 /* Continue only if an equation exists. */
710 /* Read past the end of the equation. */
711 offs
+= start
- (buf
+ offs
);
712 assert(start
== &buf
[offs
]);
713 if (NULL
!= (end
= strchr(buf
+ offs
, delim
))) {
719 /* Parse the equation itself. */
720 roff_openeqn(mdoc
->roff
, NULL
, line
, offs
, buf
);
722 /* Process a finished equation? */
723 if (roff_closeeqn(mdoc
->roff
))
724 if ( ! mdoc_addeqn(mdoc
, roff_eqn(mdoc
->roff
)))
726 offs
+= (end
- (buf
+ offs
));
734 * Parse free-form text, that is, a line that does not begin with the
738 mdoc_ptext(struct mdoc
*mdoc
, int line
, char *buf
, int offs
)
743 /* No text before an initial macro. */
745 if (SEC_NONE
== mdoc
->lastnamed
) {
746 mdoc_pmsg(mdoc
, line
, offs
, MANDOCERR_NOTEXT
);
754 * Divert directly to list processing if we're encountering a
755 * columnar MDOC_BLOCK with or without a prior MDOC_BLOCK entry
756 * (a MDOC_BODY means it's already open, in which case we should
757 * process within its context in the normal way).
760 if (MDOC_Bl
== n
->tok
&& MDOC_BODY
== n
->type
&&
761 LIST_column
== n
->norm
->Bl
.type
) {
762 /* `Bl' is open without any children. */
763 mdoc
->flags
|= MDOC_FREECOL
;
764 return(mdoc_macro(mdoc
, MDOC_It
, line
, offs
, &offs
, buf
));
767 if (MDOC_It
== n
->tok
&& MDOC_BLOCK
== n
->type
&&
769 MDOC_Bl
== n
->parent
->tok
&&
770 LIST_column
== n
->parent
->norm
->Bl
.type
) {
771 /* `Bl' has block-level `It' children. */
772 mdoc
->flags
|= MDOC_FREECOL
;
773 return(mdoc_macro(mdoc
, MDOC_It
, line
, offs
, &offs
, buf
));
777 * Search for the beginning of unescaped trailing whitespace (ws)
778 * and for the first character not to be output (end).
781 /* FIXME: replace with strcspn(). */
783 for (c
= end
= buf
+ offs
; *c
; c
++) {
791 * Always warn about trailing tabs,
792 * even outside literal context,
793 * where they should be put on the next line.
798 * Strip trailing tabs in literal context only;
799 * outside, they affect the next line.
801 if (MDOC_LITERAL
& mdoc
->flags
)
805 /* Skip the escaped character, too, if any. */
818 mdoc_pmsg(mdoc
, line
, (int)(ws
-buf
), MANDOCERR_EOLNSPACE
);
820 if ('\0' == buf
[offs
] && ! (MDOC_LITERAL
& mdoc
->flags
)) {
821 mdoc_pmsg(mdoc
, line
, (int)(c
-buf
), MANDOCERR_NOBLANKLN
);
824 * Insert a `sp' in the case of a blank line. Technically,
825 * blank lines aren't allowed, but enough manuals assume this
826 * behaviour that we want to work around it.
828 if ( ! mdoc_elem_alloc(mdoc
, line
, offs
, MDOC_sp
, NULL
))
831 mdoc
->next
= MDOC_NEXT_SIBLING
;
833 return(mdoc_valid_post(mdoc
));
836 if ( ! mdoc_word_alloc(mdoc
, line
, offs
, buf
+offs
))
839 if (MDOC_LITERAL
& mdoc
->flags
)
843 * End-of-sentence check. If the last character is an unescaped
844 * EOS character, then flag the node as being the end of a
845 * sentence. The front-end will know how to interpret this.
850 if (mandoc_eos(buf
+offs
, (size_t)(end
-buf
-offs
)))
851 mdoc
->last
->flags
|= MDOC_EOS
;
858 * Parse a macro line, that is, a line beginning with the control
862 mdoc_pmacro(struct mdoc
*mdoc
, int ln
, char *buf
, int offs
)
869 /* Empty post-control lines are ignored. */
871 if ('"' == buf
[offs
]) {
872 mdoc_pmsg(mdoc
, ln
, offs
, MANDOCERR_BADCOMMENT
);
874 } else if ('\0' == buf
[offs
])
880 * Copy the first word into a nil-terminated buffer.
881 * Stop copying when a tab, space, or eoln is encountered.
885 while (i
< 4 && '\0' != buf
[offs
] &&
886 ' ' != buf
[offs
] && '\t' != buf
[offs
])
887 mac
[i
++] = buf
[offs
++];
891 tok
= (i
> 1 || i
< 4) ? mdoc_hash_find(mac
) : MDOC_MAX
;
893 if (MDOC_MAX
== tok
) {
894 mandoc_vmsg(MANDOCERR_MACRO
, mdoc
->parse
,
895 ln
, sv
, "%s", buf
+ sv
- 1);
899 /* Disregard the first trailing tab, if applicable. */
901 if ('\t' == buf
[offs
])
904 /* Jump to the next non-whitespace word. */
906 while (buf
[offs
] && ' ' == buf
[offs
])
910 * Trailing whitespace. Note that tabs are allowed to be passed
911 * into the parser as "text", so we only warn about spaces here.
914 if ('\0' == buf
[offs
] && ' ' == buf
[offs
- 1])
915 mdoc_pmsg(mdoc
, ln
, offs
- 1, MANDOCERR_EOLNSPACE
);
918 * If an initial macro or a list invocation, divert directly
919 * into macro processing.
922 if (NULL
== mdoc
->last
|| MDOC_It
== tok
|| MDOC_El
== tok
) {
923 if ( ! mdoc_macro(mdoc
, tok
, ln
, sv
, &offs
, buf
))
932 * If the first macro of a `Bl -column', open an `It' block
933 * context around the parsed macro.
936 if (MDOC_Bl
== n
->tok
&& MDOC_BODY
== n
->type
&&
937 LIST_column
== n
->norm
->Bl
.type
) {
938 mdoc
->flags
|= MDOC_FREECOL
;
939 if ( ! mdoc_macro(mdoc
, MDOC_It
, ln
, sv
, &sv
, buf
))
945 * If we're following a block-level `It' within a `Bl -column'
946 * context (perhaps opened in the above block or in ptext()),
947 * then open an `It' block context around the parsed macro.
950 if (MDOC_It
== n
->tok
&& MDOC_BLOCK
== n
->type
&&
952 MDOC_Bl
== n
->parent
->tok
&&
953 LIST_column
== n
->parent
->norm
->Bl
.type
) {
954 mdoc
->flags
|= MDOC_FREECOL
;
955 if ( ! mdoc_macro(mdoc
, MDOC_It
, ln
, sv
, &sv
, buf
))
960 /* Normal processing of a macro. */
962 if ( ! mdoc_macro(mdoc
, tok
, ln
, sv
, &offs
, buf
))
965 /* In quick mode (for mandocdb), abort after the NAME section. */
967 if (mdoc
->quick
&& MDOC_Sh
== tok
&&
968 SEC_NAME
!= mdoc
->last
->sec
)
973 err
: /* Error out. */
975 mdoc
->flags
|= MDOC_HALT
;
980 mdoc_isdelim(const char *p
)
993 return(DELIM_MIDDLE
);
1009 return(DELIM_CLOSE
);
1017 if (0 == strcmp(p
+ 1, "."))
1018 return(DELIM_CLOSE
);
1019 if (0 == strcmp(p
+ 1, "fR|\\fP"))
1020 return(DELIM_MIDDLE
);
1026 mdoc_deroff(char **dest
, const struct mdoc_node
*n
)
1031 if (MDOC_TEXT
!= n
->type
) {
1032 for (n
= n
->child
; n
; n
= n
->next
)
1033 mdoc_deroff(dest
, n
);
1037 /* Skip leading whitespace. */
1039 for (cp
= n
->string
; '\0' != *cp
; cp
++)
1040 if (0 == isspace((unsigned char)*cp
))
1043 /* Skip trailing whitespace. */
1045 for (sz
= strlen(cp
); sz
; sz
--)
1046 if (0 == isspace((unsigned char)cp
[sz
-1]))
1049 /* Skip empty strings. */
1054 if (NULL
== *dest
) {
1055 *dest
= mandoc_strndup(cp
, sz
);
1059 mandoc_asprintf(&cp
, "%s %*s", *dest
, (int)sz
, cp
);