[BACK]Return to mdoc.h CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Annotation of mandoc/mdoc.h, Revision 1.137

1.137   ! schwarze    1: /*     $Id: mdoc.h,v 1.136 2015/02/12 12:24:33 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.137   ! schwarze   10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
1.56      kristaps   11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1.137   ! schwarze   12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
1.56      kristaps   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:
1.129     schwarze  177: /*
1.105     kristaps  178:  * Section (named/unnamed) of `Sh'.   Note that these appear in the
1.121     kristaps  179:  * conventional order imposed by mdoc.7.  In the case of SEC_NONE, no
                    180:  * section has been invoked (this shouldn't happen).  SEC_CUSTOM refers
                    181:  * to other sections.
1.105     kristaps  182:  */
                    183: enum   mdoc_sec {
1.121     kristaps  184:        SEC_NONE = 0,
                    185:        SEC_NAME, /* NAME */
                    186:        SEC_LIBRARY, /* LIBRARY */
                    187:        SEC_SYNOPSIS, /* SYNOPSIS */
                    188:        SEC_DESCRIPTION, /* DESCRIPTION */
1.128     schwarze  189:        SEC_CONTEXT, /* CONTEXT */
1.121     kristaps  190:        SEC_IMPLEMENTATION, /* IMPLEMENTATION NOTES */
                    191:        SEC_RETURN_VALUES, /* RETURN VALUES */
                    192:        SEC_ENVIRONMENT,  /* ENVIRONMENT */
                    193:        SEC_FILES, /* FILES */
                    194:        SEC_EXIT_STATUS, /* EXIT STATUS */
                    195:        SEC_EXAMPLES, /* EXAMPLES */
                    196:        SEC_DIAGNOSTICS, /* DIAGNOSTICS */
                    197:        SEC_COMPATIBILITY, /* COMPATIBILITY */
                    198:        SEC_ERRORS, /* ERRORS */
                    199:        SEC_SEE_ALSO, /* SEE ALSO */
                    200:        SEC_STANDARDS, /* STANDARDS */
                    201:        SEC_HISTORY, /* HISTORY */
                    202:        SEC_AUTHORS, /* AUTHORS */
                    203:        SEC_CAVEATS, /* CAVEATS */
                    204:        SEC_BUGS, /* BUGS */
                    205:        SEC_SECURITY, /* SECURITY */
1.129     schwarze  206:        SEC_CUSTOM,
1.105     kristaps  207:        SEC__MAX
                    208: };
                    209:
                    210: struct mdoc_meta {
                    211:        char             *msec; /* `Dt' section (1, 3p, etc.) */
                    212:        char             *vol; /* `Dt' volume (implied) */
                    213:        char             *arch; /* `Dt' arch (i386, etc.) */
1.118     schwarze  214:        char             *date; /* `Dd' normalised date */
1.105     kristaps  215:        char             *title; /* `Dt' title (FOO, etc.) */
                    216:        char             *os; /* `Os' system (OpenBSD, etc.) */
                    217:        char             *name; /* leading `Nm' name */
                    218: };
                    219:
1.129     schwarze  220: /*
                    221:  * An argument to a macro (multiple values = `-column xxx yyy').
1.105     kristaps  222:  */
                    223: struct mdoc_argv {
1.129     schwarze  224:        enum mdocargt     arg; /* type of argument */
1.105     kristaps  225:        int               line;
                    226:        int               pos;
                    227:        size_t            sz; /* elements in "value" */
                    228:        char            **value; /* argument strings */
                    229: };
                    230:
1.33      kristaps  231: /*
1.105     kristaps  232:  * Reference-counted macro arguments.  These are refcounted because
                    233:  * blocks have multiple instances of the same arguments spread across
                    234:  * the HEAD, BODY, TAIL, and BLOCK node types.
1.33      kristaps  235:  */
1.129     schwarze  236: struct mdoc_arg {
1.105     kristaps  237:        size_t            argc;
                    238:        struct mdoc_argv *argv;
                    239:        unsigned int      refcnt;
                    240: };
1.1       kristaps  241:
1.105     kristaps  242: /*
                    243:  * Indicates that a BODY's formatting has ended, but the scope is still
                    244:  * open.  Used for syntax-broken blocks.
                    245:  */
                    246: enum   mdoc_endbody {
                    247:        ENDBODY_NOT = 0,
                    248:        ENDBODY_SPACE, /* is broken: append a space */
                    249:        ENDBODY_NOSPACE /* is broken: don't append a space */
                    250: };
                    251:
                    252: enum   mdoc_list {
                    253:        LIST__NONE = 0,
1.121     kristaps  254:        LIST_bullet, /* -bullet */
                    255:        LIST_column, /* -column */
                    256:        LIST_dash, /* -dash */
                    257:        LIST_diag, /* -diag */
                    258:        LIST_enum, /* -enum */
                    259:        LIST_hang, /* -hang */
                    260:        LIST_hyphen, /* -hyphen */
                    261:        LIST_inset, /* -inset */
                    262:        LIST_item, /* -item */
                    263:        LIST_ohang, /* -ohang */
                    264:        LIST_tag, /* -tag */
1.106     kristaps  265:        LIST_MAX
1.105     kristaps  266: };
                    267:
                    268: enum   mdoc_disp {
                    269:        DISP__NONE = 0,
1.131     schwarze  270:        DISP_centered, /* -centered */
1.121     kristaps  271:        DISP_ragged, /* -ragged */
                    272:        DISP_unfilled, /* -unfilled */
                    273:        DISP_filled, /* -filled */
                    274:        DISP_literal /* -literal */
1.105     kristaps  275: };
                    276:
                    277: enum   mdoc_auth {
                    278:        AUTH__NONE = 0,
1.121     kristaps  279:        AUTH_split, /* -split */
                    280:        AUTH_nosplit /* -nosplit */
1.105     kristaps  281: };
1.60      kristaps  282:
1.105     kristaps  283: enum   mdoc_font {
                    284:        FONT__NONE = 0,
1.121     kristaps  285:        FONT_Em, /* Em, -emphasis */
                    286:        FONT_Li, /* Li, -literal */
                    287:        FONT_Sy /* Sy, -symbolic */
1.105     kristaps  288: };
                    289:
                    290: struct mdoc_bd {
                    291:        const char       *offs; /* -offset */
                    292:        enum mdoc_disp    type; /* -ragged, etc. */
                    293:        int               comp; /* -compact */
                    294: };
                    295:
                    296: struct mdoc_bl {
                    297:        const char       *width; /* -width */
                    298:        const char       *offs; /* -offset */
                    299:        enum mdoc_list    type; /* -tag, -enum, etc. */
                    300:        int               comp; /* -compact */
                    301:        size_t            ncols; /* -column arg count */
                    302:        const char      **cols; /* -column val ptr */
1.123     schwarze  303:        int               count; /* -enum counter */
1.105     kristaps  304: };
                    305:
                    306: struct mdoc_bf {
                    307:        enum mdoc_font    font; /* font */
                    308: };
                    309:
                    310: struct mdoc_an {
                    311:        enum mdoc_auth    auth; /* -split, etc. */
                    312: };
                    313:
1.111     kristaps  314: struct mdoc_rs {
1.115     kristaps  315:        int               quote_T; /* whether to quote %T */
1.111     kristaps  316: };
                    317:
1.105     kristaps  318: /*
                    319:  * Consists of normalised node arguments.  These should be used instead
                    320:  * of iterating through the mdoc_arg pointers of a node: defaults are
                    321:  * provided, etc.
                    322:  */
1.109     kristaps  323: union  mdoc_data {
1.129     schwarze  324:        struct mdoc_an    An;
1.109     kristaps  325:        struct mdoc_bd    Bd;
                    326:        struct mdoc_bf    Bf;
                    327:        struct mdoc_bl    Bl;
1.130     schwarze  328:        struct mdoc_node *Es;
1.111     kristaps  329:        struct mdoc_rs    Rs;
1.109     kristaps  330: };
                    331:
1.129     schwarze  332: /*
                    333:  * Single node in tree-linked AST.
1.105     kristaps  334:  */
                    335: struct mdoc_node {
                    336:        struct mdoc_node *parent; /* parent AST node */
                    337:        struct mdoc_node *child; /* first child AST node */
1.107     kristaps  338:        struct mdoc_node *last; /* last child AST node */
1.105     kristaps  339:        struct mdoc_node *next; /* sibling AST node */
                    340:        struct mdoc_node *prev; /* prior sibling AST node */
                    341:        int               nchild; /* number children */
                    342:        int               line; /* parse line */
                    343:        int               pos; /* parse column */
                    344:        enum mdoct        tok; /* tok or MDOC__MAX if none */
                    345:        int               flags;
                    346: #define        MDOC_VALID       (1 << 0) /* has been validated */
1.136     schwarze  347: #define        MDOC_ENDED       (1 << 1) /* gone past body end mark */
1.105     kristaps  348: #define        MDOC_EOS         (1 << 2) /* at sentence boundary */
                    349: #define        MDOC_LINE        (1 << 3) /* first macro/text on line */
                    350: #define        MDOC_SYNPRETTY   (1 << 4) /* SYNOPSIS-style formatting */
1.136     schwarze  351: #define        MDOC_BROKEN      (1 << 5) /* must validate parent when ending */
1.122     kristaps  352: #define        MDOC_DELIMO      (1 << 6)
                    353: #define        MDOC_DELIMC      (1 << 7)
1.137   ! schwarze  354:        enum roff_type    type; /* AST node type */
1.105     kristaps  355:        enum mdoc_sec     sec; /* current named section */
1.110     kristaps  356:        union mdoc_data  *norm; /* normalised args */
1.134     schwarze  357:        int               prev_font; /* before entering this node */
1.105     kristaps  358:        /* FIXME: these can be union'd to shave a few bytes. */
                    359:        struct mdoc_arg  *args; /* BLOCK/ELEM */
                    360:        struct mdoc_node *head; /* BLOCK */
1.136     schwarze  361:        struct mdoc_node *body; /* BLOCK/ENDBODY */
1.105     kristaps  362:        struct mdoc_node *tail; /* BLOCK */
                    363:        char             *string; /* TEXT */
1.114     kristaps  364:        const struct tbl_span *span; /* TBL */
1.117     kristaps  365:        const struct eqn *eqn; /* EQN */
1.105     kristaps  366:        enum mdoc_endbody end; /* BODY */
                    367: };
                    368:
1.121     kristaps  369: /* Names of macros.  Index is enum mdoct. */
1.1       kristaps  370: extern const char *const *mdoc_macronames;
1.105     kristaps  371:
1.121     kristaps  372: /* Names of macro args.  Index is enum mdocargt. */
1.1       kristaps  373: extern const char *const *mdoc_argnames;
                    374:
                    375: __BEGIN_DECLS
                    376:
                    377: struct mdoc;
1.60      kristaps  378:
1.32      kristaps  379: const struct mdoc_node *mdoc_node(const struct mdoc *);
                    380: const struct mdoc_meta *mdoc_meta(const struct mdoc *);
1.126     schwarze  381: void mdoc_deroff(char **, const struct mdoc_node *);
1.1       kristaps  382:
                    383: __END_DECLS

CVSweb