-
Notifications
You must be signed in to change notification settings - Fork 1
/
node.h
273 lines (261 loc) · 6.06 KB
/
node.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/* $Id: node.h,v 1.37 2019/05/01 12:52:05 schwarze Exp $ */
/*
* Copyright (c) 2014 Kristaps Dzonsons <[email protected]>
* Copyright (c) 2019 Ingo Schwarze <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <bsdqueue.h>
/*
* The interface of the DocBook syntax tree.
*/
/*
* How the output from each node behaves
* with respect to mdoc(7) structure.
*/
enum nodeclass {
CLASS_VOID = 0, /* No output at all, children are skipped. */
CLASS_TEXT, /* Node prints only text, no macros. */
CLASS_TRANS, /* Transparent: only the children are shown. */
CLASS_LINE, /* Generates only simple in-line macros. */
CLASS_ENCL, /* Explicit or implicit partial blocks. */
CLASS_BLOCK, /* Output linebreak before and after. */
CLASS_NOFILL /* Block preserving leading whitespace. */
};
/*
* All node types used for formatting purposes.
* More DocBook XML elements are recognized, but remapped or discarded.
*/
enum nodeid {
NODE_ABSTRACT,
NODE_APPENDIX,
NODE_ARG,
NODE_AUTHOR,
NODE_AUTHORGROUP,
NODE_BLOCKQUOTE,
NODE_BOOKINFO,
NODE_CAUTION,
NODE_CITEREFENTRY,
NODE_CITETITLE,
NODE_CMDSYNOPSIS,
NODE_COLSPEC,
NODE_COMMAND,
NODE_CONSTANT,
NODE_CONTRIB,
NODE_COPYRIGHT,
NODE_DATE,
NODE_DOCTYPE,
NODE_EDITOR,
NODE_EMAIL,
NODE_EMPHASIS,
NODE_ENTITY,
NODE_ENTRY,
NODE_ENVAR,
NODE_ERRORNAME,
NODE_FIELDSYNOPSIS,
NODE_FILENAME,
NODE_FIRSTTERM,
NODE_FOOTNOTE,
NODE_FUNCDEF,
NODE_FUNCPARAMS,
NODE_FUNCPROTOTYPE,
NODE_FUNCSYNOPSIS,
NODE_FUNCSYNOPSISINFO,
NODE_FUNCTION,
NODE_GLOSSTERM,
NODE_GROUP,
NODE_IMAGEDATA,
NODE_INCLUDE,
NODE_INDEX,
NODE_INFO,
NODE_INFORMALEQUATION,
NODE_INLINEEQUATION,
NODE_ITEMIZEDLIST,
NODE_KEYSYM,
NODE_LEGALNOTICE,
NODE_LINK,
NODE_LISTITEM,
NODE_LITERAL,
NODE_LITERALLAYOUT,
NODE_MANVOLNUM,
NODE_MARKUP,
NODE_MEMBER,
NODE_MML_MATH,
NODE_MML_MFENCED,
NODE_MML_MFRAC,
NODE_MML_MI,
NODE_MML_MN,
NODE_MML_MO,
NODE_MML_MROW,
NODE_MML_MSUB,
NODE_MML_MSUP,
NODE_MODIFIER,
NODE_NOTE,
NODE_OLINK,
NODE_OPTION,
NODE_ORDEREDLIST,
NODE_PARA,
NODE_PARAMDEF,
NODE_PARAMETER,
NODE_PERSONNAME,
NODE_PREFACE,
NODE_PRODUCTNAME,
NODE_PROGRAMLISTING,
NODE_PROMPT,
NODE_PUBDATE,
NODE_QUOTE,
NODE_REFCLASS,
NODE_REFDESCRIPTOR,
NODE_REFENTRY,
NODE_REFENTRYINFO,
NODE_REFENTRYTITLE,
NODE_REFMETA,
NODE_REFMETAINFO,
NODE_REFMISCINFO,
NODE_REFNAME,
NODE_REFNAMEDIV,
NODE_REFPURPOSE,
NODE_REFSYNOPSISDIV,
NODE_REPLACEABLE,
NODE_ROW,
NODE_SBR,
NODE_SCREEN,
NODE_SECTION,
NODE_SIMPLELIST,
NODE_SIMPLESECT,
NODE_SPANSPEC,
NODE_SUBSCRIPT,
NODE_SUBTITLE,
NODE_SUPERSCRIPT,
NODE_SYNOPSIS,
NODE_SYSTEMITEM,
NODE_TABLE,
NODE_TBODY,
NODE_TERM,
NODE_TFOOT,
NODE_TGROUP,
NODE_THEAD,
NODE_TIP,
NODE_TITLE,
NODE_TYPE,
NODE_VARIABLELIST,
NODE_VARLISTENTRY,
NODE_VARNAME,
NODE_VOID,
NODE_WARNING,
NODE_WORDASWORD,
NODE_XREF,
NODE_YEAR,
NODE_UNKNOWN,
NODE_TEXT,
NODE_ESCAPE,
NODE_IGNORE,
NODE_DELETE,
NODE_DELETE_WARN
};
/*
* All recognised attribute keys.
* Other attributes are discarded.
*/
enum attrkey {
/* Alpha-order... */
ATTRKEY_CHOICE = 0,
ATTRKEY_CLASS,
ATTRKEY_CLOSE,
ATTRKEY_COLS,
ATTRKEY_DEFINITION,
ATTRKEY_ENDTERM,
ATTRKEY_ENTITYREF,
ATTRKEY_FILEREF,
ATTRKEY_HREF,
ATTRKEY_ID,
ATTRKEY_LINKEND,
ATTRKEY_LOCALINFO,
ATTRKEY_NAME,
ATTRKEY_OPEN,
ATTRKEY_PUBLIC,
ATTRKEY_REP,
ATTRKEY_SYSTEM,
ATTRKEY_TARGETDOC,
ATTRKEY_TARGETPTR,
ATTRKEY_URL,
ATTRKEY_XLINK_HREF,
ATTRKEY__MAX
};
/*
* All explicitly recognised attribute values.
* If an attribute has ATTRVAL__MAX, it is treated as free-form.
*/
enum attrval {
/* Alpha-order... */
ATTRVAL_EVENT,
ATTRVAL_IPADDRESS,
ATTRVAL_MONOSPACED,
ATTRVAL_NOREPEAT,
ATTRVAL_OPT,
ATTRVAL_PLAIN,
ATTRVAL_REPEAT,
ATTRVAL_REQ,
ATTRVAL_SYSTEMNAME,
ATTRVAL__MAX
};
TAILQ_HEAD(pnodeq, pnode);
TAILQ_HEAD(pattrq, pattr);
/*
* One DocBook XML element attribute.
*/
struct pattr {
enum attrkey key;
enum attrval val;
char *rawval;
TAILQ_ENTRY(pattr) child;
};
/*
* One DocBook XML element.
*/
struct pnode {
enum nodeid node; /* Node type. */
char *b; /* String value. */
struct pnode *parent; /* Parent node or NULL. */
int flags;
#define NFLAG_LINE (1 << 0) /* New line before this node. */
#define NFLAG_SPC (1 << 1) /* Whitespace before this node. */
struct pnodeq childq; /* Queue of children. */
struct pattrq attrq; /* Attributes of the node. */
TAILQ_ENTRY(pnode) child;
};
/*
* The parse result for one complete DocBook XML document.
*/
struct ptree {
struct pnode *root; /* The document element. */
int flags;
#define TREE_ERROR (1 << 0) /* A parse error occurred. */
#define TREE_WARN (1 << 1) /* A parser warning occurred. */
#define TREE_CLOSED (1 << 3) /* The document element was closed. */
};
enum attrkey attrkey_parse(const char *);
const char *attrkey_name(enum attrkey);
enum attrval attrval_parse(const char *);
const char *attr_getval(const struct pattr *a);
enum nodeid pnode_parse(const char *name);
const char *pnode_name(enum nodeid);
enum nodeclass pnode_class(enum nodeid);
struct pnode *pnode_alloc(struct pnode *);
struct pnode *pnode_alloc_text(struct pnode *, const char *);
void pnode_unlink(struct pnode *);
void pnode_unlinksub(struct pnode *);
enum attrval pnode_getattr(struct pnode *, enum attrkey);
const char *pnode_getattr_raw(struct pnode *, enum attrkey, const char *);
struct pnode *pnode_findfirst(struct pnode *, enum nodeid);
struct pnode *pnode_takefirst(struct pnode *, enum nodeid);