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