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

Annotation of mandoc/roff.h, Revision 1.39

1.39    ! schwarze    1: /*     $Id: roff.h,v 1.38 2017/01/10 12:53:08 schwarze Exp $   */
1.1       kristaps    2: /*
1.28      schwarze    3:  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
1.38      schwarze    4:  * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
1.1       kristaps    5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
1.12      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.28      schwarze   10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
1.12      kristaps   11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1.28      schwarze   12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
1.12      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.29      schwarze   19: struct mdoc_arg;
                     20: union  mdoc_data;
                     21:
1.32      schwarze   22: enum   roff_macroset {
                     23:        MACROSET_NONE = 0,
                     24:        MACROSET_MDOC,
                     25:        MACROSET_MAN
                     26: };
                     27:
1.29      schwarze   28: enum   roff_sec {
                     29:        SEC_NONE = 0,
                     30:        SEC_NAME,
                     31:        SEC_LIBRARY,
                     32:        SEC_SYNOPSIS,
                     33:        SEC_DESCRIPTION,
                     34:        SEC_CONTEXT,
                     35:        SEC_IMPLEMENTATION,     /* IMPLEMENTATION NOTES */
                     36:        SEC_RETURN_VALUES,
                     37:        SEC_ENVIRONMENT,
                     38:        SEC_FILES,
                     39:        SEC_EXIT_STATUS,
                     40:        SEC_EXAMPLES,
                     41:        SEC_DIAGNOSTICS,
                     42:        SEC_COMPATIBILITY,
                     43:        SEC_ERRORS,
                     44:        SEC_SEE_ALSO,
                     45:        SEC_STANDARDS,
                     46:        SEC_HISTORY,
                     47:        SEC_AUTHORS,
                     48:        SEC_CAVEATS,
                     49:        SEC_BUGS,
                     50:        SEC_SECURITY,
                     51:        SEC_CUSTOM,
                     52:        SEC__MAX
                     53: };
                     54:
1.28      schwarze   55: enum   roff_type {
                     56:        ROFFT_ROOT,
                     57:        ROFFT_BLOCK,
                     58:        ROFFT_HEAD,
                     59:        ROFFT_BODY,
                     60:        ROFFT_TAIL,
                     61:        ROFFT_ELEM,
                     62:        ROFFT_TEXT,
                     63:        ROFFT_TBL,
                     64:        ROFFT_EQN
1.29      schwarze   65: };
                     66:
1.31      schwarze   67: enum   roff_next {
                     68:        ROFF_NEXT_SIBLING = 0,
                     69:        ROFF_NEXT_CHILD
                     70: };
                     71:
1.29      schwarze   72: /*
                     73:  * Indicates that a BODY's formatting has ended, but
                     74:  * the scope is still open.  Used for badly nested blocks.
                     75:  */
                     76: enum   mdoc_endbody {
                     77:        ENDBODY_NOT = 0,
                     78:        ENDBODY_SPACE,  /* Is broken: append a space. */
                     79:        ENDBODY_NOSPACE /* Is broken: don't append a space. */
                     80: };
                     81:
                     82: struct roff_node {
                     83:        struct roff_node *parent;  /* Parent AST node. */
                     84:        struct roff_node *child;   /* First child AST node. */
                     85:        struct roff_node *last;    /* Last child AST node. */
                     86:        struct roff_node *next;    /* Sibling AST node. */
                     87:        struct roff_node *prev;    /* Prior sibling AST node. */
                     88:        struct roff_node *head;    /* BLOCK */
                     89:        struct roff_node *body;    /* BLOCK/ENDBODY */
                     90:        struct roff_node *tail;    /* BLOCK */
                     91:        struct mdoc_arg  *args;    /* BLOCK/ELEM */
                     92:        union mdoc_data  *norm;    /* Normalized arguments. */
                     93:        char             *string;  /* TEXT */
                     94:        const struct tbl_span *span; /* TBL */
                     95:        const struct eqn *eqn;     /* EQN */
                     96:        int               line;    /* Input file line number. */
                     97:        int               pos;     /* Input file column number. */
                     98:        int               tok;     /* Request or macro ID. */
1.33      schwarze   99: #define        TOKEN_NONE       (-1)      /* No request or macro. */
1.29      schwarze  100:        int               flags;
1.39    ! schwarze  101: #define        NODE_VALID       (1 << 0)  /* Has been validated. */
        !           102: #define        NODE_ENDED       (1 << 1)  /* Gone past body end mark. */
        !           103: #define        NODE_EOS         (1 << 2)  /* At sentence boundary. */
        !           104: #define        NODE_LINE        (1 << 3)  /* First macro/text on line. */
        !           105: #define        NODE_SYNPRETTY   (1 << 4)  /* SYNOPSIS-style formatting. */
        !           106: #define        NODE_BROKEN      (1 << 5)  /* Must validate parent when ending. */
        !           107: #define        NODE_DELIMO      (1 << 6)
        !           108: #define        NODE_DELIMC      (1 << 7)
1.38      schwarze  109: #define        NODE_NOSRC       (1 << 8)  /* Generated node, not in input file. */
                    110: #define        NODE_NOPRT       (1 << 9)  /* Shall not print anything. */
1.29      schwarze  111:        int               prev_font; /* Before entering this node. */
                    112:        int               aux;     /* Decoded node data, type-dependent. */
                    113:        enum roff_type    type;    /* AST node type. */
                    114:        enum roff_sec     sec;     /* Current named section. */
                    115:        enum mdoc_endbody end;     /* BODY */
1.28      schwarze  116: };
1.30      schwarze  117:
                    118: struct roff_meta {
                    119:        char             *msec;    /* Manual section, usually a digit. */
                    120:        char             *vol;     /* Manual volume title. */
                    121:        char             *os;      /* Operating system. */
                    122:        char             *arch;    /* Machine architecture. */
                    123:        char             *title;   /* Manual title, usually CAPS. */
                    124:        char             *name;    /* Leading manual name. */
                    125:        char             *date;    /* Normalized date. */
                    126:        int               hasbody; /* Document is not empty. */
1.31      schwarze  127: };
                    128:
                    129: struct roff_man {
                    130:        struct roff_meta  meta;    /* Document meta-data. */
                    131:        struct mparse    *parse;   /* Parse pointer. */
                    132:        struct roff      *roff;    /* Roff parser state data. */
                    133:        const char       *defos;   /* Default operating system. */
                    134:        struct roff_node *first;   /* The first node parsed. */
                    135:        struct roff_node *last;    /* The last node parsed. */
                    136:        struct roff_node *last_es; /* The most recent Es node. */
                    137:        int               quick;   /* Abort parse early. */
                    138:        int               flags;   /* Parse flags. */
                    139: #define        MDOC_LITERAL     (1 << 1)  /* In a literal scope. */
                    140: #define        MDOC_PBODY       (1 << 2)  /* In the document body. */
                    141: #define        MDOC_NEWLINE     (1 << 3)  /* First macro/text in a line. */
1.35      schwarze  142: #define        MDOC_PHRASE      (1 << 4)  /* In a Bl -column phrase. */
                    143: #define        MDOC_PHRASELIT   (1 << 5)  /* Literal within a phrase. */
1.31      schwarze  144: #define        MDOC_FREECOL     (1 << 6)  /* `It' invocation should close. */
                    145: #define        MDOC_SYNOPSIS    (1 << 7)  /* SYNOPSIS-style formatting. */
                    146: #define        MDOC_KEEP        (1 << 8)  /* In a word keep. */
                    147: #define        MDOC_SMOFF       (1 << 9)  /* Spacing is off. */
                    148: #define        MDOC_NODELIMC    (1 << 10) /* Disable closing delimiter handling. */
                    149: #define        MAN_ELINE        (1 << 11) /* Next-line element scope. */
                    150: #define        MAN_BLINE        (1 << 12) /* Next-line block scope. */
1.35      schwarze  151: #define        MDOC_PHRASEQF    (1 << 13) /* Quote first word encountered. */
                    152: #define        MDOC_PHRASEQL    (1 << 14) /* Quote last word of this phrase. */
                    153: #define        MDOC_PHRASEQN    (1 << 15) /* Quote first word of the next phrase. */
1.31      schwarze  154: #define        MAN_LITERAL       MDOC_LITERAL
                    155: #define        MAN_NEWLINE       MDOC_NEWLINE
1.32      schwarze  156:        enum roff_macroset macroset; /* Kind of high-level macros used. */
1.31      schwarze  157:        enum roff_sec     lastsec; /* Last section seen. */
                    158:        enum roff_sec     lastnamed; /* Last standard section seen. */
                    159:        enum roff_next    next;    /* Where to put the next node. */
1.30      schwarze  160: };
1.34      schwarze  161:
                    162:
                    163: void            deroff(char **, const struct roff_node *);

CVSweb