[BACK]Return to libmdoc.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / mandoc

Annotation of src/usr.bin/mandoc/libmdoc.h, Revision 1.45

1.45    ! schwarze    1: /*     $Id: libmdoc.h,v 1.44 2011/04/21 22:59:54 schwarze Exp $ */
1.1       kristaps    2: /*
1.45    ! 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.3       schwarze    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.3       schwarze    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: #ifndef LIBMDOC_H
                     18: #define LIBMDOC_H
                     19:
                     20: enum   mdoc_next {
                     21:        MDOC_NEXT_SIBLING = 0,
                     22:        MDOC_NEXT_CHILD
                     23: };
                     24:
                     25: struct mdoc {
1.45    ! schwarze   26:        struct mparse    *parse; /* parse pointer */
        !            27:        int               flags; /* parse flags */
1.30      schwarze   28: #define        MDOC_HALT        (1 << 0) /* error in parse: halt */
                     29: #define        MDOC_LITERAL     (1 << 1) /* in a literal scope */
                     30: #define        MDOC_PBODY       (1 << 2) /* in the document body */
                     31: #define        MDOC_NEWLINE     (1 << 3) /* first macro/text in a line */
1.32      schwarze   32: #define        MDOC_PHRASELIT   (1 << 4) /* literal within a partila phrase */
                     33: #define        MDOC_PPHRASE     (1 << 5) /* within a partial phrase */
1.37      schwarze   34: #define        MDOC_FREECOL     (1 << 6) /* `It' invocation should close */
1.40      schwarze   35: #define        MDOC_SYNOPSIS    (1 << 7) /* SYNOPSIS-style formatting */
1.38      schwarze   36:        enum mdoc_next    next; /* where to put the next node */
                     37:        struct mdoc_node *last; /* the last node parsed */
                     38:        struct mdoc_node *first; /* the first node parsed */
                     39:        struct mdoc_meta  meta; /* document meta-data */
1.1       kristaps   40:        enum mdoc_sec     lastnamed;
                     41:        enum mdoc_sec     lastsec;
1.38      schwarze   42:        struct regset    *regs; /* registers */
1.1       kristaps   43: };
                     44:
1.38      schwarze   45: #define        MACRO_PROT_ARGS struct mdoc *m, \
                     46:                        enum mdoct tok, \
                     47:                        int line, \
                     48:                        int ppos, \
                     49:                        int *pos, \
                     50:                        char *buf
1.1       kristaps   51:
                     52: struct mdoc_macro {
                     53:        int             (*fp)(MACRO_PROT_ARGS);
                     54:        int               flags;
                     55: #define        MDOC_CALLABLE    (1 << 0)
                     56: #define        MDOC_PARSED      (1 << 1)
                     57: #define        MDOC_EXPLICIT    (1 << 2)
                     58: #define        MDOC_PROLOGUE    (1 << 3)
                     59: #define        MDOC_IGNDELIM    (1 << 4)
                     60:        /* Reserved words in arguments treated as text. */
                     61: };
                     62:
1.29      schwarze   63: enum   margserr {
                     64:        ARGS_ERROR,
                     65:        ARGS_EOLN,
                     66:        ARGS_WORD,
                     67:        ARGS_PUNCT,
                     68:        ARGS_QWORD,
                     69:        ARGS_PHRASE,
1.30      schwarze   70:        ARGS_PPHRASE,
                     71:        ARGS_PEND
1.29      schwarze   72: };
                     73:
                     74: enum   margverr {
                     75:        ARGV_ERROR,
                     76:        ARGV_EOLN,
                     77:        ARGV_ARG,
                     78:        ARGV_WORD
                     79: };
                     80:
1.45    ! schwarze   81: /*
        !            82:  * A punctuation delimiter is opening, closing, or "middle mark"
        !            83:  * punctuation.  These govern spacing.
        !            84:  * Opening punctuation (e.g., the opening parenthesis) suppresses the
        !            85:  * following space; closing punctuation (e.g., the closing parenthesis)
        !            86:  * suppresses the leading space; middle punctuation (e.g., the vertical
        !            87:  * bar) can do either.  The middle punctuation delimiter bends the rules
        !            88:  * depending on usage.
        !            89:  */
        !            90: enum   mdelim {
        !            91:        DELIM_NONE = 0,
        !            92:        DELIM_OPEN,
        !            93:        DELIM_MIDDLE,
        !            94:        DELIM_CLOSE,
        !            95:        DELIM_MAX
        !            96: };
        !            97:
1.1       kristaps   98: extern const struct mdoc_macro *const mdoc_macros;
                     99:
                    100: __BEGIN_DECLS
                    101:
1.35      schwarze  102: #define                  mdoc_pmsg(m, l, p, t) \
1.45    ! schwarze  103:                  mandoc_msg((t), (m)->parse, (l), (p), NULL)
1.35      schwarze  104: #define                  mdoc_nmsg(m, n, t) \
1.45    ! schwarze  105:                  mandoc_msg((t), (m)->parse, (n)->line, (n)->pos, NULL)
1.1       kristaps  106: int              mdoc_macro(MACRO_PROT_ARGS);
                    107: int              mdoc_word_alloc(struct mdoc *,
                    108:                        int, int, const char *);
                    109: int              mdoc_elem_alloc(struct mdoc *, int, int,
1.25      schwarze  110:                        enum mdoct, struct mdoc_arg *);
1.1       kristaps  111: int              mdoc_block_alloc(struct mdoc *, int, int,
1.25      schwarze  112:                        enum mdoct, struct mdoc_arg *);
                    113: int              mdoc_head_alloc(struct mdoc *, int, int, enum mdoct);
                    114: int              mdoc_tail_alloc(struct mdoc *, int, int, enum mdoct);
                    115: int              mdoc_body_alloc(struct mdoc *, int, int, enum mdoct);
1.39      schwarze  116: int              mdoc_endbody_alloc(struct mdoc *m, int line, int pos,
                    117:                        enum mdoct tok, struct mdoc_node *body,
                    118:                        enum mdoc_endbody end);
1.27      schwarze  119: void             mdoc_node_delete(struct mdoc *, struct mdoc_node *);
1.21      schwarze  120: void             mdoc_hash_init(void);
1.25      schwarze  121: enum mdoct       mdoc_hash_find(const char *);
1.15      schwarze  122: const char      *mdoc_a2att(const char *);
                    123: const char      *mdoc_a2lib(const char *);
                    124: const char      *mdoc_a2st(const char *);
1.1       kristaps  125: const char      *mdoc_a2arch(const char *);
                    126: const char      *mdoc_a2vol(const char *);
                    127: const char      *mdoc_a2msec(const char *);
1.37      schwarze  128: int              mdoc_valid_pre(struct mdoc *, struct mdoc_node *);
1.1       kristaps  129: int              mdoc_valid_post(struct mdoc *);
1.29      schwarze  130: enum margverr    mdoc_argv(struct mdoc *, int, enum mdoct,
1.1       kristaps  131:                        struct mdoc_arg **, int *, char *);
                    132: void             mdoc_argv_free(struct mdoc_arg *);
1.29      schwarze  133: enum margserr    mdoc_args(struct mdoc *, int,
1.25      schwarze  134:                        int *, char *, enum mdoct, char **);
1.29      schwarze  135: enum margserr    mdoc_zargs(struct mdoc *, int,
1.20      schwarze  136:                        int *, char *, int, char **);
1.32      schwarze  137: #define        ARGS_DELIM      (1 << 1)
                    138: #define        ARGS_TABSEP     (1 << 2)
                    139: #define        ARGS_NOWARN     (1 << 3)
1.29      schwarze  140:
1.1       kristaps  141: int              mdoc_macroend(struct mdoc *);
1.45    ! schwarze  142:
        !           143: #define        DELIMSZ   6 /* hint: max possible size of a delimiter */
        !           144: enum mdelim      mdoc_isdelim(const char *);
1.1       kristaps  145:
                    146: __END_DECLS
                    147:
                    148: #endif /*!LIBMDOC_H*/