Print this page
Update to 1.12.3.
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mandoc/mdoc.h
+++ new/usr/src/cmd/mandoc/mdoc.h
1 -/* $Id: mdoc.h,v 1.122 2011/03/22 14:05:45 kristaps Exp $ */
1 +/* $Id: mdoc.h,v 1.125 2013/12/24 19:11:45 schwarze Exp $ */
2 2 /*
3 3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 4 *
5 5 * Permission to use, copy, modify, and distribute this software for any
6 6 * purpose with or without fee is hereby granted, provided that the above
7 7 * copyright notice and this permission notice appear in all copies.
8 8 *
9 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 16 */
17 17 #ifndef MDOC_H
18 18 #define MDOC_H
19 19
20 20 enum mdoct {
21 21 MDOC_Ap = 0,
22 22 MDOC_Dd,
23 23 MDOC_Dt,
24 24 MDOC_Os,
25 25 MDOC_Sh,
26 26 MDOC_Ss,
27 27 MDOC_Pp,
28 28 MDOC_D1,
29 29 MDOC_Dl,
30 30 MDOC_Bd,
31 31 MDOC_Ed,
32 32 MDOC_Bl,
33 33 MDOC_El,
34 34 MDOC_It,
35 35 MDOC_Ad,
36 36 MDOC_An,
37 37 MDOC_Ar,
38 38 MDOC_Cd,
39 39 MDOC_Cm,
40 40 MDOC_Dv,
41 41 MDOC_Er,
42 42 MDOC_Ev,
43 43 MDOC_Ex,
44 44 MDOC_Fa,
45 45 MDOC_Fd,
46 46 MDOC_Fl,
47 47 MDOC_Fn,
48 48 MDOC_Ft,
49 49 MDOC_Ic,
50 50 MDOC_In,
51 51 MDOC_Li,
52 52 MDOC_Nd,
53 53 MDOC_Nm,
54 54 MDOC_Op,
55 55 MDOC_Ot,
56 56 MDOC_Pa,
57 57 MDOC_Rv,
58 58 MDOC_St,
59 59 MDOC_Va,
60 60 MDOC_Vt,
61 61 MDOC_Xr,
62 62 MDOC__A,
63 63 MDOC__B,
64 64 MDOC__D,
65 65 MDOC__I,
66 66 MDOC__J,
67 67 MDOC__N,
68 68 MDOC__O,
69 69 MDOC__P,
70 70 MDOC__R,
71 71 MDOC__T,
72 72 MDOC__V,
73 73 MDOC_Ac,
74 74 MDOC_Ao,
75 75 MDOC_Aq,
76 76 MDOC_At,
77 77 MDOC_Bc,
78 78 MDOC_Bf,
79 79 MDOC_Bo,
80 80 MDOC_Bq,
81 81 MDOC_Bsx,
82 82 MDOC_Bx,
83 83 MDOC_Db,
84 84 MDOC_Dc,
85 85 MDOC_Do,
86 86 MDOC_Dq,
87 87 MDOC_Ec,
88 88 MDOC_Ef,
89 89 MDOC_Em,
90 90 MDOC_Eo,
91 91 MDOC_Fx,
92 92 MDOC_Ms,
93 93 MDOC_No,
94 94 MDOC_Ns,
95 95 MDOC_Nx,
96 96 MDOC_Ox,
97 97 MDOC_Pc,
98 98 MDOC_Pf,
99 99 MDOC_Po,
100 100 MDOC_Pq,
101 101 MDOC_Qc,
102 102 MDOC_Ql,
103 103 MDOC_Qo,
104 104 MDOC_Qq,
105 105 MDOC_Re,
106 106 MDOC_Rs,
107 107 MDOC_Sc,
108 108 MDOC_So,
109 109 MDOC_Sq,
110 110 MDOC_Sm,
111 111 MDOC_Sx,
112 112 MDOC_Sy,
113 113 MDOC_Tn,
114 114 MDOC_Ux,
115 115 MDOC_Xc,
116 116 MDOC_Xo,
117 117 MDOC_Fo,
118 118 MDOC_Fc,
119 119 MDOC_Oo,
120 120 MDOC_Oc,
121 121 MDOC_Bk,
122 122 MDOC_Ek,
123 123 MDOC_Bt,
124 124 MDOC_Hf,
125 125 MDOC_Fr,
126 126 MDOC_Ud,
127 127 MDOC_Lb,
128 128 MDOC_Lp,
129 129 MDOC_Lk,
130 130 MDOC_Mt,
131 131 MDOC_Brq,
132 132 MDOC_Bro,
133 133 MDOC_Brc,
134 134 MDOC__C,
135 135 MDOC_Es,
136 136 MDOC_En,
137 137 MDOC_Dx,
138 138 MDOC__Q,
139 139 MDOC_br,
140 140 MDOC_sp,
141 141 MDOC__U,
142 142 MDOC_Ta,
143 143 MDOC_MAX
144 144 };
145 145
146 146 enum mdocargt {
147 147 MDOC_Split, /* -split */
148 148 MDOC_Nosplit, /* -nospli */
149 149 MDOC_Ragged, /* -ragged */
150 150 MDOC_Unfilled, /* -unfilled */
151 151 MDOC_Literal, /* -literal */
152 152 MDOC_File, /* -file */
153 153 MDOC_Offset, /* -offset */
154 154 MDOC_Bullet, /* -bullet */
155 155 MDOC_Dash, /* -dash */
156 156 MDOC_Hyphen, /* -hyphen */
157 157 MDOC_Item, /* -item */
158 158 MDOC_Enum, /* -enum */
159 159 MDOC_Tag, /* -tag */
160 160 MDOC_Diag, /* -diag */
161 161 MDOC_Hang, /* -hang */
162 162 MDOC_Ohang, /* -ohang */
163 163 MDOC_Inset, /* -inset */
164 164 MDOC_Column, /* -column */
165 165 MDOC_Width, /* -width */
166 166 MDOC_Compact, /* -compact */
167 167 MDOC_Std, /* -std */
168 168 MDOC_Filled, /* -filled */
169 169 MDOC_Words, /* -words */
170 170 MDOC_Emphasis, /* -emphasis */
171 171 MDOC_Symbolic, /* -symbolic */
172 172 MDOC_Nested, /* -nested */
173 173 MDOC_Centred, /* -centered */
174 174 MDOC_ARG_MAX
175 175 };
176 176
177 177 enum mdoc_type {
178 178 MDOC_TEXT,
179 179 MDOC_ELEM,
180 180 MDOC_HEAD,
181 181 MDOC_TAIL,
182 182 MDOC_BODY,
183 183 MDOC_BLOCK,
184 184 MDOC_TBL,
185 185 MDOC_EQN,
186 186 MDOC_ROOT
187 187 };
188 188
189 189 /*
190 190 * Section (named/unnamed) of `Sh'. Note that these appear in the
191 191 * conventional order imposed by mdoc.7. In the case of SEC_NONE, no
192 192 * section has been invoked (this shouldn't happen). SEC_CUSTOM refers
193 193 * to other sections.
194 194 */
195 195 enum mdoc_sec {
196 196 SEC_NONE = 0,
197 197 SEC_NAME, /* NAME */
198 198 SEC_LIBRARY, /* LIBRARY */
199 199 SEC_SYNOPSIS, /* SYNOPSIS */
200 200 SEC_DESCRIPTION, /* DESCRIPTION */
201 201 SEC_IMPLEMENTATION, /* IMPLEMENTATION NOTES */
202 202 SEC_RETURN_VALUES, /* RETURN VALUES */
203 203 SEC_ENVIRONMENT, /* ENVIRONMENT */
204 204 SEC_FILES, /* FILES */
205 205 SEC_EXIT_STATUS, /* EXIT STATUS */
206 206 SEC_EXAMPLES, /* EXAMPLES */
207 207 SEC_DIAGNOSTICS, /* DIAGNOSTICS */
208 208 SEC_COMPATIBILITY, /* COMPATIBILITY */
209 209 SEC_ERRORS, /* ERRORS */
210 210 SEC_SEE_ALSO, /* SEE ALSO */
211 211 SEC_STANDARDS, /* STANDARDS */
212 212 SEC_HISTORY, /* HISTORY */
213 213 SEC_AUTHORS, /* AUTHORS */
214 214 SEC_CAVEATS, /* CAVEATS */
215 215 SEC_BUGS, /* BUGS */
216 216 SEC_SECURITY, /* SECURITY */
217 217 SEC_CUSTOM,
218 218 SEC__MAX
219 219 };
220 220
221 221 struct mdoc_meta {
222 222 char *msec; /* `Dt' section (1, 3p, etc.) */
223 223 char *vol; /* `Dt' volume (implied) */
224 224 char *arch; /* `Dt' arch (i386, etc.) */
225 225 char *date; /* `Dd' normalised date */
226 226 char *title; /* `Dt' title (FOO, etc.) */
227 227 char *os; /* `Os' system (OpenBSD, etc.) */
228 228 char *name; /* leading `Nm' name */
229 229 };
230 230
231 231 /*
232 232 * An argument to a macro (multiple values = `-column xxx yyy').
233 233 */
234 234 struct mdoc_argv {
235 235 enum mdocargt arg; /* type of argument */
236 236 int line;
237 237 int pos;
238 238 size_t sz; /* elements in "value" */
239 239 char **value; /* argument strings */
240 240 };
241 241
242 242 /*
243 243 * Reference-counted macro arguments. These are refcounted because
244 244 * blocks have multiple instances of the same arguments spread across
245 245 * the HEAD, BODY, TAIL, and BLOCK node types.
246 246 */
247 247 struct mdoc_arg {
248 248 size_t argc;
249 249 struct mdoc_argv *argv;
250 250 unsigned int refcnt;
251 251 };
252 252
253 253 /*
254 254 * Indicates that a BODY's formatting has ended, but the scope is still
255 255 * open. Used for syntax-broken blocks.
256 256 */
257 257 enum mdoc_endbody {
258 258 ENDBODY_NOT = 0,
259 259 ENDBODY_SPACE, /* is broken: append a space */
260 260 ENDBODY_NOSPACE /* is broken: don't append a space */
261 261 };
262 262
263 263 enum mdoc_list {
264 264 LIST__NONE = 0,
265 265 LIST_bullet, /* -bullet */
266 266 LIST_column, /* -column */
267 267 LIST_dash, /* -dash */
268 268 LIST_diag, /* -diag */
269 269 LIST_enum, /* -enum */
270 270 LIST_hang, /* -hang */
271 271 LIST_hyphen, /* -hyphen */
272 272 LIST_inset, /* -inset */
273 273 LIST_item, /* -item */
274 274 LIST_ohang, /* -ohang */
275 275 LIST_tag, /* -tag */
276 276 LIST_MAX
277 277 };
278 278
279 279 enum mdoc_disp {
280 280 DISP__NONE = 0,
281 281 DISP_centred, /* -centered */
282 282 DISP_ragged, /* -ragged */
283 283 DISP_unfilled, /* -unfilled */
284 284 DISP_filled, /* -filled */
285 285 DISP_literal /* -literal */
286 286 };
287 287
288 288 enum mdoc_auth {
289 289 AUTH__NONE = 0,
290 290 AUTH_split, /* -split */
291 291 AUTH_nosplit /* -nosplit */
292 292 };
293 293
294 294 enum mdoc_font {
295 295 FONT__NONE = 0,
296 296 FONT_Em, /* Em, -emphasis */
297 297 FONT_Li, /* Li, -literal */
298 298 FONT_Sy /* Sy, -symbolic */
299 299 };
300 300
301 301 struct mdoc_bd {
302 302 const char *offs; /* -offset */
303 303 enum mdoc_disp type; /* -ragged, etc. */
↓ open down ↓ |
292 lines elided |
↑ open up ↑ |
304 304 int comp; /* -compact */
305 305 };
306 306
307 307 struct mdoc_bl {
308 308 const char *width; /* -width */
309 309 const char *offs; /* -offset */
310 310 enum mdoc_list type; /* -tag, -enum, etc. */
311 311 int comp; /* -compact */
312 312 size_t ncols; /* -column arg count */
313 313 const char **cols; /* -column val ptr */
314 + int count; /* -enum counter */
314 315 };
315 316
316 317 struct mdoc_bf {
317 318 enum mdoc_font font; /* font */
318 319 };
319 320
320 321 struct mdoc_an {
321 322 enum mdoc_auth auth; /* -split, etc. */
322 323 };
323 324
324 325 struct mdoc_rs {
325 326 int quote_T; /* whether to quote %T */
326 327 };
327 328
328 329 /*
329 330 * Consists of normalised node arguments. These should be used instead
330 331 * of iterating through the mdoc_arg pointers of a node: defaults are
331 332 * provided, etc.
332 333 */
333 334 union mdoc_data {
334 335 struct mdoc_an An;
335 336 struct mdoc_bd Bd;
336 337 struct mdoc_bf Bf;
337 338 struct mdoc_bl Bl;
338 339 struct mdoc_rs Rs;
339 340 };
340 341
341 342 /*
342 343 * Single node in tree-linked AST.
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
343 344 */
344 345 struct mdoc_node {
345 346 struct mdoc_node *parent; /* parent AST node */
346 347 struct mdoc_node *child; /* first child AST node */
347 348 struct mdoc_node *last; /* last child AST node */
348 349 struct mdoc_node *next; /* sibling AST node */
349 350 struct mdoc_node *prev; /* prior sibling AST node */
350 351 int nchild; /* number children */
351 352 int line; /* parse line */
352 353 int pos; /* parse column */
354 + int lastline; /* the node ends on this line */
353 355 enum mdoct tok; /* tok or MDOC__MAX if none */
354 356 int flags;
355 357 #define MDOC_VALID (1 << 0) /* has been validated */
356 358 #define MDOC_EOS (1 << 2) /* at sentence boundary */
357 359 #define MDOC_LINE (1 << 3) /* first macro/text on line */
358 360 #define MDOC_SYNPRETTY (1 << 4) /* SYNOPSIS-style formatting */
359 361 #define MDOC_ENDED (1 << 5) /* rendering has been ended */
360 362 #define MDOC_DELIMO (1 << 6)
361 363 #define MDOC_DELIMC (1 << 7)
362 364 enum mdoc_type type; /* AST node type */
363 365 enum mdoc_sec sec; /* current named section */
364 366 union mdoc_data *norm; /* normalised args */
367 + const void *prev_font; /* before entering this node */
365 368 /* FIXME: these can be union'd to shave a few bytes. */
366 369 struct mdoc_arg *args; /* BLOCK/ELEM */
367 370 struct mdoc_node *pending; /* BLOCK */
368 371 struct mdoc_node *head; /* BLOCK */
369 372 struct mdoc_node *body; /* BLOCK */
370 373 struct mdoc_node *tail; /* BLOCK */
371 374 char *string; /* TEXT */
372 375 const struct tbl_span *span; /* TBL */
373 376 const struct eqn *eqn; /* EQN */
374 377 enum mdoc_endbody end; /* BODY */
375 378 };
376 379
377 380 /* Names of macros. Index is enum mdoct. */
378 381 extern const char *const *mdoc_macronames;
379 382
380 383 /* Names of macro args. Index is enum mdocargt. */
381 384 extern const char *const *mdoc_argnames;
382 385
383 386 __BEGIN_DECLS
384 387
385 388 struct mdoc;
386 389
387 390 const struct mdoc_node *mdoc_node(const struct mdoc *);
388 391 const struct mdoc_meta *mdoc_meta(const struct mdoc *);
389 392
390 393 __END_DECLS
391 394
392 395 #endif /*!MDOC_H*/
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX