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

Annotation of mandoc/libmdoc.h, Revision 1.87

1.87    ! schwarze    1: /*     $Id: libmdoc.h,v 1.86 2014/07/09 11:31:43 schwarze Exp $ */
1.1       kristaps    2: /*
1.77      schwarze    3:  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
1.82      schwarze    4:  * Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org>
1.1       kristaps    5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
1.6       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.6       kristaps   10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
1.1       kristaps   17:  */
                     18: #ifndef LIBMDOC_H
                     19: #define LIBMDOC_H
                     20:
                     21: enum   mdoc_next {
                     22:        MDOC_NEXT_SIBLING = 0,
                     23:        MDOC_NEXT_CHILD
                     24: };
                     25:
                     26: struct mdoc {
1.69      kristaps   27:        struct mparse    *parse; /* parse pointer */
1.86      schwarze   28:        const char       *defos; /* default argument for .Os */
1.83      schwarze   29:        int               quick; /* abort parse early */
1.69      kristaps   30:        int               flags; /* parse flags */
1.42      kristaps   31: #define        MDOC_LITERAL     (1 << 1) /* in a literal scope */
                     32: #define        MDOC_PBODY       (1 << 2) /* in the document body */
                     33: #define        MDOC_NEWLINE     (1 << 3) /* first macro/text in a line */
1.45      kristaps   34: #define        MDOC_PHRASELIT   (1 << 4) /* literal within a partila phrase */
                     35: #define        MDOC_PPHRASE     (1 << 5) /* within a partial phrase */
1.51      kristaps   36: #define        MDOC_FREECOL     (1 << 6) /* `It' invocation should close */
1.59      schwarze   37: #define        MDOC_SYNOPSIS    (1 << 7) /* SYNOPSIS-style formatting */
1.82      schwarze   38: #define        MDOC_KEEP        (1 << 8) /* in a word keep */
                     39: #define        MDOC_SMOFF       (1 << 9) /* spacing is off */
1.56      kristaps   40:        enum mdoc_next    next; /* where to put the next node */
                     41:        struct mdoc_node *last; /* the last node parsed */
                     42:        struct mdoc_node *first; /* the first node parsed */
1.85      schwarze   43:        struct mdoc_node *last_es; /* the most recent Es node */
1.56      kristaps   44:        struct mdoc_meta  meta; /* document meta-data */
1.1       kristaps   45:        enum mdoc_sec     lastnamed;
                     46:        enum mdoc_sec     lastsec;
1.75      kristaps   47:        struct roff      *roff;
1.13      kristaps   48: };
1.1       kristaps   49:
1.81      schwarze   50: #define        MACRO_PROT_ARGS struct mdoc *mdoc, \
1.55      kristaps   51:                        enum mdoct tok, \
                     52:                        int line, \
                     53:                        int ppos, \
                     54:                        int *pos, \
                     55:                        char *buf
1.1       kristaps   56:
                     57: struct mdoc_macro {
                     58:        int             (*fp)(MACRO_PROT_ARGS);
                     59:        int               flags;
                     60: #define        MDOC_CALLABLE    (1 << 0)
                     61: #define        MDOC_PARSED      (1 << 1)
                     62: #define        MDOC_EXPLICIT    (1 << 2)
                     63: #define        MDOC_PROLOGUE    (1 << 3)
1.82      schwarze   64: #define        MDOC_IGNDELIM    (1 << 4)
                     65: #define        MDOC_JOIN        (1 << 5)
1.1       kristaps   66: };
                     67:
1.36      kristaps   68: enum   margserr {
1.35      kristaps   69:        ARGS_ERROR,
1.73      kristaps   70:        ARGS_EOLN, /* end-of-line */
                     71:        ARGS_WORD, /* normal word */
                     72:        ARGS_PUNCT, /* series of punctuation */
                     73:        ARGS_QWORD, /* quoted word */
                     74:        ARGS_PHRASE, /* Ta'd phrase (-column) */
                     75:        ARGS_PPHRASE, /* tabbed phrase (-column) */
                     76:        ARGS_PEND /* last phrase (-column) */
1.35      kristaps   77: };
                     78:
1.37      kristaps   79: enum   margverr {
                     80:        ARGV_ERROR,
1.73      kristaps   81:        ARGV_EOLN, /* end of line */
                     82:        ARGV_ARG, /* valid argument */
                     83:        ARGV_WORD /* normal word (or bad argument---same thing) */
1.37      kristaps   84: };
                     85:
1.70      kristaps   86: /*
                     87:  * A punctuation delimiter is opening, closing, or "middle mark"
                     88:  * punctuation.  These govern spacing.
                     89:  * Opening punctuation (e.g., the opening parenthesis) suppresses the
                     90:  * following space; closing punctuation (e.g., the closing parenthesis)
                     91:  * suppresses the leading space; middle punctuation (e.g., the vertical
                     92:  * bar) can do either.  The middle punctuation delimiter bends the rules
                     93:  * depending on usage.
                     94:  */
                     95: enum   mdelim {
                     96:        DELIM_NONE = 0,
                     97:        DELIM_OPEN,
                     98:        DELIM_MIDDLE,
                     99:        DELIM_CLOSE,
                    100:        DELIM_MAX
                    101: };
                    102:
1.1       kristaps  103: extern const struct mdoc_macro *const mdoc_macros;
                    104:
                    105: __BEGIN_DECLS
                    106:
1.81      schwarze  107: #define                  mdoc_pmsg(mdoc, l, p, t) \
                    108:                  mandoc_msg((t), (mdoc)->parse, (l), (p), NULL)
                    109: #define                  mdoc_nmsg(mdoc, n, t) \
                    110:                  mandoc_msg((t), (mdoc)->parse, (n)->line, (n)->pos, NULL)
1.1       kristaps  111: int              mdoc_macro(MACRO_PROT_ARGS);
1.84      schwarze  112: int              mdoc_word_alloc(struct mdoc *,
1.1       kristaps  113:                        int, int, const char *);
1.82      schwarze  114: void             mdoc_word_append(struct mdoc *, const char *);
1.84      schwarze  115: int              mdoc_elem_alloc(struct mdoc *, int, int,
1.31      kristaps  116:                        enum mdoct, struct mdoc_arg *);
1.84      schwarze  117: int              mdoc_block_alloc(struct mdoc *, int, int,
1.31      kristaps  118:                        enum mdoct, struct mdoc_arg *);
                    119: int              mdoc_head_alloc(struct mdoc *, int, int, enum mdoct);
                    120: int              mdoc_tail_alloc(struct mdoc *, int, int, enum mdoct);
                    121: int              mdoc_body_alloc(struct mdoc *, int, int, enum mdoct);
1.81      schwarze  122: int              mdoc_endbody_alloc(struct mdoc *, int, int, enum mdoct,
                    123:                        struct mdoc_node *, enum mdoc_endbody);
1.33      kristaps  124: void             mdoc_node_delete(struct mdoc *, struct mdoc_node *);
1.80      schwarze  125: int              mdoc_node_relink(struct mdoc *, struct mdoc_node *);
1.27      kristaps  126: void             mdoc_hash_init(void);
1.31      kristaps  127: enum mdoct       mdoc_hash_find(const char *);
1.16      kristaps  128: const char      *mdoc_a2att(const char *);
1.18      kristaps  129: const char      *mdoc_a2lib(const char *);
1.17      kristaps  130: const char      *mdoc_a2st(const char *);
1.1       kristaps  131: const char      *mdoc_a2arch(const char *);
                    132: const char      *mdoc_a2vol(const char *);
1.52      kristaps  133: int              mdoc_valid_pre(struct mdoc *, struct mdoc_node *);
1.1       kristaps  134: int              mdoc_valid_post(struct mdoc *);
1.37      kristaps  135: enum margverr    mdoc_argv(struct mdoc *, int, enum mdoct,
1.1       kristaps  136:                        struct mdoc_arg **, int *, char *);
                    137: void             mdoc_argv_free(struct mdoc_arg *);
1.36      kristaps  138: enum margserr    mdoc_args(struct mdoc *, int,
1.31      kristaps  139:                        int *, char *, enum mdoct, char **);
1.84      schwarze  140: enum margserr    mdoc_zargs(struct mdoc *, int,
1.74      kristaps  141:                        int *, char *, char **);
1.2       kristaps  142: int              mdoc_macroend(struct mdoc *);
1.70      kristaps  143: enum mdelim      mdoc_isdelim(const char *);
1.1       kristaps  144:
                    145: __END_DECLS
                    146:
                    147: #endif /*!LIBMDOC_H*/

CVSweb