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