3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2013, 2014, 2015 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 AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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.
35 SEC_IMPLEMENTATION
, /* IMPLEMENTATION NOTES */
68 ROFF_NEXT_SIBLING
= 0,
73 * Indicates that a BODY's formatting has ended, but
74 * the scope is still open. Used for badly nested blocks.
78 ENDBODY_SPACE
, /* Is broken: append a space. */
79 ENDBODY_NOSPACE
/* Is broken: don't append a space. */
83 struct roff_node
*parent
; /* Parent AST node. */
84 struct roff_node
*child
; /* First child AST node. */
85 struct roff_node
*last
; /* Last child AST node. */
86 struct roff_node
*next
; /* Sibling AST node. */
87 struct roff_node
*prev
; /* Prior sibling AST node. */
88 struct roff_node
*head
; /* BLOCK */
89 struct roff_node
*body
; /* BLOCK/ENDBODY */
90 struct roff_node
*tail
; /* BLOCK */
91 struct mdoc_arg
*args
; /* BLOCK/ELEM */
92 union mdoc_data
*norm
; /* Normalized arguments. */
93 char *string
; /* TEXT */
94 const struct tbl_span
*span
; /* TBL */
95 const struct eqn
*eqn
; /* EQN */
96 int line
; /* Input file line number. */
97 int pos
; /* Input file column number. */
98 int tok
; /* Request or macro ID. */
99 #define TOKEN_NONE (-1) /* No request or macro. */
101 #define MDOC_VALID (1 << 0) /* Has been validated. */
102 #define MDOC_ENDED (1 << 1) /* Gone past body end mark. */
103 #define MDOC_EOS (1 << 2) /* At sentence boundary. */
104 #define MDOC_LINE (1 << 3) /* First macro/text on line. */
105 #define MDOC_SYNPRETTY (1 << 4) /* SYNOPSIS-style formatting. */
106 #define MDOC_BROKEN (1 << 5) /* Must validate parent when ending. */
107 #define MDOC_DELIMO (1 << 6)
108 #define MDOC_DELIMC (1 << 7)
109 #define MAN_VALID MDOC_VALID
110 #define MAN_EOS MDOC_EOS
111 #define MAN_LINE MDOC_LINE
112 int prev_font
; /* Before entering this node. */
113 int aux
; /* Decoded node data, type-dependent. */
114 enum roff_type type
; /* AST node type. */
115 enum roff_sec sec
; /* Current named section. */
116 enum mdoc_endbody end
; /* BODY */
120 char *msec
; /* Manual section, usually a digit. */
121 char *vol
; /* Manual volume title. */
122 char *os
; /* Operating system. */
123 char *arch
; /* Machine architecture. */
124 char *title
; /* Manual title, usually CAPS. */
125 char *name
; /* Leading manual name. */
126 char *date
; /* Normalized date. */
127 int hasbody
; /* Document is not empty. */
131 struct roff_meta meta
; /* Document meta-data. */
132 struct mparse
*parse
; /* Parse pointer. */
133 struct roff
*roff
; /* Roff parser state data. */
134 const char *defos
; /* Default operating system. */
135 struct roff_node
*first
; /* The first node parsed. */
136 struct roff_node
*last
; /* The last node parsed. */
137 struct roff_node
*last_es
; /* The most recent Es node. */
138 int quick
; /* Abort parse early. */
139 int flags
; /* Parse flags. */
140 #define MDOC_LITERAL (1 << 1) /* In a literal scope. */
141 #define MDOC_PBODY (1 << 2) /* In the document body. */
142 #define MDOC_NEWLINE (1 << 3) /* First macro/text in a line. */
143 #define MDOC_PHRASE (1 << 4) /* In a Bl -column phrase. */
144 #define MDOC_PHRASELIT (1 << 5) /* Literal within a phrase. */
145 #define MDOC_FREECOL (1 << 6) /* `It' invocation should close. */
146 #define MDOC_SYNOPSIS (1 << 7) /* SYNOPSIS-style formatting. */
147 #define MDOC_KEEP (1 << 8) /* In a word keep. */
148 #define MDOC_SMOFF (1 << 9) /* Spacing is off. */
149 #define MDOC_NODELIMC (1 << 10) /* Disable closing delimiter handling. */
150 #define MAN_ELINE (1 << 11) /* Next-line element scope. */
151 #define MAN_BLINE (1 << 12) /* Next-line block scope. */
152 #define MDOC_PHRASEQF (1 << 13) /* Quote first word encountered. */
153 #define MDOC_PHRASEQL (1 << 14) /* Quote last word of this phrase. */
154 #define MDOC_PHRASEQN (1 << 15) /* Quote first word of the next phrase. */
155 #define MAN_LITERAL MDOC_LITERAL
156 #define MAN_NEWLINE MDOC_NEWLINE
157 enum roff_macroset macroset
; /* Kind of high-level macros used. */
158 enum roff_sec lastsec
; /* Last section seen. */
159 enum roff_sec lastnamed
; /* Last standard section seen. */
160 enum roff_next next
; /* Where to put the next node. */
164 void deroff(char **, const struct roff_node
*);