mdoc.h (260e9a87725c090ba5835b1f9f0b62fa2f96036f) | mdoc.h (371584c2eae4cf827fd406ba26c14f021adaaa70) |
---|---|
1/* $Id: mdoc.h,v 1.136 2015/02/12 12:24:33 schwarze Exp $ */ | 1/* $Id: mdoc.h,v 1.144 2015/11/07 14:01:16 schwarze Exp $ */ |
2/* 3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> 4 * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> 5 * 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. 9 * | 2/* 3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> 4 * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> 5 * 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. 9 * |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 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. 17 */ 18 | 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. 17 */ 18 |
19enum 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, 142 MDOC_ll, 143 MDOC_MAX 144}; | 19#define MDOC_Ap 0 20#define MDOC_Dd 1 21#define MDOC_Dt 2 22#define MDOC_Os 3 23#define MDOC_Sh 4 24#define MDOC_Ss 5 25#define MDOC_Pp 6 26#define MDOC_D1 7 27#define MDOC_Dl 8 28#define MDOC_Bd 9 29#define MDOC_Ed 10 30#define MDOC_Bl 11 31#define MDOC_El 12 32#define MDOC_It 13 33#define MDOC_Ad 14 34#define MDOC_An 15 35#define MDOC_Ar 16 36#define MDOC_Cd 17 37#define MDOC_Cm 18 38#define MDOC_Dv 19 39#define MDOC_Er 20 40#define MDOC_Ev 21 41#define MDOC_Ex 22 42#define MDOC_Fa 23 43#define MDOC_Fd 24 44#define MDOC_Fl 25 45#define MDOC_Fn 26 46#define MDOC_Ft 27 47#define MDOC_Ic 28 48#define MDOC_In 29 49#define MDOC_Li 30 50#define MDOC_Nd 31 51#define MDOC_Nm 32 52#define MDOC_Op 33 53#define MDOC_Ot 34 54#define MDOC_Pa 35 55#define MDOC_Rv 36 56#define MDOC_St 37 57#define MDOC_Va 38 58#define MDOC_Vt 39 59#define MDOC_Xr 40 60#define MDOC__A 41 61#define MDOC__B 42 62#define MDOC__D 43 63#define MDOC__I 44 64#define MDOC__J 45 65#define MDOC__N 46 66#define MDOC__O 47 67#define MDOC__P 48 68#define MDOC__R 49 69#define MDOC__T 50 70#define MDOC__V 51 71#define MDOC_Ac 52 72#define MDOC_Ao 53 73#define MDOC_Aq 54 74#define MDOC_At 55 75#define MDOC_Bc 56 76#define MDOC_Bf 57 77#define MDOC_Bo 58 78#define MDOC_Bq 59 79#define MDOC_Bsx 60 80#define MDOC_Bx 61 81#define MDOC_Db 62 82#define MDOC_Dc 63 83#define MDOC_Do 64 84#define MDOC_Dq 65 85#define MDOC_Ec 66 86#define MDOC_Ef 67 87#define MDOC_Em 68 88#define MDOC_Eo 69 89#define MDOC_Fx 70 90#define MDOC_Ms 71 91#define MDOC_No 72 92#define MDOC_Ns 73 93#define MDOC_Nx 74 94#define MDOC_Ox 75 95#define MDOC_Pc 76 96#define MDOC_Pf 77 97#define MDOC_Po 78 98#define MDOC_Pq 79 99#define MDOC_Qc 80 100#define MDOC_Ql 81 101#define MDOC_Qo 82 102#define MDOC_Qq 83 103#define MDOC_Re 84 104#define MDOC_Rs 85 105#define MDOC_Sc 86 106#define MDOC_So 87 107#define MDOC_Sq 88 108#define MDOC_Sm 89 109#define MDOC_Sx 90 110#define MDOC_Sy 91 111#define MDOC_Tn 92 112#define MDOC_Ux 93 113#define MDOC_Xc 94 114#define MDOC_Xo 95 115#define MDOC_Fo 96 116#define MDOC_Fc 97 117#define MDOC_Oo 98 118#define MDOC_Oc 99 119#define MDOC_Bk 100 120#define MDOC_Ek 101 121#define MDOC_Bt 102 122#define MDOC_Hf 103 123#define MDOC_Fr 104 124#define MDOC_Ud 105 125#define MDOC_Lb 106 126#define MDOC_Lp 107 127#define MDOC_Lk 108 128#define MDOC_Mt 109 129#define MDOC_Brq 110 130#define MDOC_Bro 111 131#define MDOC_Brc 112 132#define MDOC__C 113 133#define MDOC_Es 114 134#define MDOC_En 115 135#define MDOC_Dx 116 136#define MDOC__Q 117 137#define MDOC_br 118 138#define MDOC_sp 119 139#define MDOC__U 120 140#define MDOC_Ta 121 141#define MDOC_ll 122 142#define MDOC_MAX 123 |
145 146enum mdocargt { 147 MDOC_Split, /* -split */ 148 MDOC_Nosplit, /* -nospli */ 149 MDOC_Ragged, /* -ragged */ 150 MDOC_Unfilled, /* -unfilled */ 151 MDOC_Literal, /* -literal */ 152 MDOC_File, /* -file */ --- 16 unchanged lines hidden (view full) --- 169 MDOC_Words, /* -words */ 170 MDOC_Emphasis, /* -emphasis */ 171 MDOC_Symbolic, /* -symbolic */ 172 MDOC_Nested, /* -nested */ 173 MDOC_Centred, /* -centered */ 174 MDOC_ARG_MAX 175}; 176 | 143 144enum mdocargt { 145 MDOC_Split, /* -split */ 146 MDOC_Nosplit, /* -nospli */ 147 MDOC_Ragged, /* -ragged */ 148 MDOC_Unfilled, /* -unfilled */ 149 MDOC_Literal, /* -literal */ 150 MDOC_File, /* -file */ --- 16 unchanged lines hidden (view full) --- 167 MDOC_Words, /* -words */ 168 MDOC_Emphasis, /* -emphasis */ 169 MDOC_Symbolic, /* -symbolic */ 170 MDOC_Nested, /* -nested */ 171 MDOC_Centred, /* -centered */ 172 MDOC_ARG_MAX 173}; 174 |
177enum mdoc_type { 178 MDOC_TEXT, 179 MDOC_ELEM, 180 MDOC_HEAD, 181 MDOC_TAIL, 182 MDOC_BODY, 183 MDOC_BLOCK, 184 MDOC_TBL, 185 MDOC_EQN, 186 MDOC_ROOT 187}; 188 | |
189/* | 175/* |
190 * Section (named/unnamed) of `Sh'. Note that these appear in the 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. 194 */ 195enum mdoc_sec { 196 SEC_NONE = 0, 197 SEC_NAME, /* NAME */ 198 SEC_LIBRARY, /* LIBRARY */ 199 SEC_SYNOPSIS, /* SYNOPSIS */ 200 SEC_DESCRIPTION, /* DESCRIPTION */ 201 SEC_CONTEXT, /* CONTEXT */ 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 */ 218 SEC_CUSTOM, 219 SEC__MAX 220}; 221 222struct mdoc_meta { 223 char *msec; /* `Dt' section (1, 3p, etc.) */ 224 char *vol; /* `Dt' volume (implied) */ 225 char *arch; /* `Dt' arch (i386, etc.) */ 226 char *date; /* `Dd' normalised date */ 227 char *title; /* `Dt' title (FOO, etc.) */ 228 char *os; /* `Os' system (OpenBSD, etc.) */ 229 char *name; /* leading `Nm' name */ 230}; 231 232/* | |
233 * An argument to a macro (multiple values = `-column xxx yyy'). 234 */ 235struct mdoc_argv { 236 enum mdocargt arg; /* type of argument */ 237 int line; 238 int pos; 239 size_t sz; /* elements in "value" */ 240 char **value; /* argument strings */ --- 5 unchanged lines hidden (view full) --- 246 * the HEAD, BODY, TAIL, and BLOCK node types. 247 */ 248struct mdoc_arg { 249 size_t argc; 250 struct mdoc_argv *argv; 251 unsigned int refcnt; 252}; 253 | 176 * An argument to a macro (multiple values = `-column xxx yyy'). 177 */ 178struct mdoc_argv { 179 enum mdocargt arg; /* type of argument */ 180 int line; 181 int pos; 182 size_t sz; /* elements in "value" */ 183 char **value; /* argument strings */ --- 5 unchanged lines hidden (view full) --- 189 * the HEAD, BODY, TAIL, and BLOCK node types. 190 */ 191struct mdoc_arg { 192 size_t argc; 193 struct mdoc_argv *argv; 194 unsigned int refcnt; 195}; 196 |
254/* 255 * Indicates that a BODY's formatting has ended, but the scope is still 256 * open. Used for syntax-broken blocks. 257 */ 258enum 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 | |
264enum mdoc_list { 265 LIST__NONE = 0, 266 LIST_bullet, /* -bullet */ 267 LIST_column, /* -column */ 268 LIST_dash, /* -dash */ 269 LIST_diag, /* -diag */ 270 LIST_enum, /* -enum */ 271 LIST_hang, /* -hang */ --- 60 unchanged lines hidden (view full) --- 332 * of iterating through the mdoc_arg pointers of a node: defaults are 333 * provided, etc. 334 */ 335union mdoc_data { 336 struct mdoc_an An; 337 struct mdoc_bd Bd; 338 struct mdoc_bf Bf; 339 struct mdoc_bl Bl; | 197enum mdoc_list { 198 LIST__NONE = 0, 199 LIST_bullet, /* -bullet */ 200 LIST_column, /* -column */ 201 LIST_dash, /* -dash */ 202 LIST_diag, /* -diag */ 203 LIST_enum, /* -enum */ 204 LIST_hang, /* -hang */ --- 60 unchanged lines hidden (view full) --- 265 * of iterating through the mdoc_arg pointers of a node: defaults are 266 * provided, etc. 267 */ 268union mdoc_data { 269 struct mdoc_an An; 270 struct mdoc_bd Bd; 271 struct mdoc_bf Bf; 272 struct mdoc_bl Bl; |
340 struct mdoc_node *Es; | 273 struct roff_node *Es; |
341 struct mdoc_rs Rs; 342}; 343 | 274 struct mdoc_rs Rs; 275}; 276 |
344/* 345 * Single node in tree-linked AST. 346 */ 347struct mdoc_node { 348 struct mdoc_node *parent; /* parent AST node */ 349 struct mdoc_node *child; /* first child AST node */ 350 struct mdoc_node *last; /* last child AST node */ 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 */ 359#define MDOC_ENDED (1 << 1) /* gone past body end mark */ 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_BROKEN (1 << 5) /* must validate parent when ending */ 364#define MDOC_DELIMO (1 << 6) 365#define MDOC_DELIMC (1 << 7) 366 enum mdoc_type type; /* AST node type */ 367 enum mdoc_sec sec; /* current named section */ 368 union mdoc_data *norm; /* normalised args */ 369 int prev_font; /* before entering this node */ 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 */ 373 struct mdoc_node *body; /* BLOCK/ENDBODY */ 374 struct mdoc_node *tail; /* BLOCK */ 375 char *string; /* TEXT */ 376 const struct tbl_span *span; /* TBL */ 377 const struct eqn *eqn; /* EQN */ 378 enum mdoc_endbody end; /* BODY */ 379}; 380 381/* Names of macros. Index is enum mdoct. */ | 277/* Names of macros. */ |
382extern const char *const *mdoc_macronames; 383 384/* Names of macro args. Index is enum mdocargt. */ 385extern const char *const *mdoc_argnames; 386 | 278extern const char *const *mdoc_macronames; 279 280/* Names of macro args. Index is enum mdocargt. */ 281extern const char *const *mdoc_argnames; 282 |
387__BEGIN_DECLS | |
388 | 283 |
389struct mdoc; 390 391const struct mdoc_node *mdoc_node(const struct mdoc *); 392const struct mdoc_meta *mdoc_meta(const struct mdoc *); 393void mdoc_deroff(char **, const struct mdoc_node *); 394 395__END_DECLS | 284void mdoc_validate(struct roff_man *); |