1*95c635efSGarrett D'Amore /* $Id: libmdoc.h,v 1.78 2011/12/02 01:37:14 schwarze Exp $ */ 2*95c635efSGarrett D'Amore /* 3*95c635efSGarrett D'Amore * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> 4*95c635efSGarrett D'Amore * 5*95c635efSGarrett D'Amore * Permission to use, copy, modify, and distribute this software for any 6*95c635efSGarrett D'Amore * purpose with or without fee is hereby granted, provided that the above 7*95c635efSGarrett D'Amore * copyright notice and this permission notice appear in all copies. 8*95c635efSGarrett D'Amore * 9*95c635efSGarrett D'Amore * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10*95c635efSGarrett D'Amore * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11*95c635efSGarrett D'Amore * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12*95c635efSGarrett D'Amore * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13*95c635efSGarrett D'Amore * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14*95c635efSGarrett D'Amore * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15*95c635efSGarrett D'Amore * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16*95c635efSGarrett D'Amore */ 17*95c635efSGarrett D'Amore #ifndef LIBMDOC_H 18*95c635efSGarrett D'Amore #define LIBMDOC_H 19*95c635efSGarrett D'Amore 20*95c635efSGarrett D'Amore enum mdoc_next { 21*95c635efSGarrett D'Amore MDOC_NEXT_SIBLING = 0, 22*95c635efSGarrett D'Amore MDOC_NEXT_CHILD 23*95c635efSGarrett D'Amore }; 24*95c635efSGarrett D'Amore 25*95c635efSGarrett D'Amore struct mdoc { 26*95c635efSGarrett D'Amore struct mparse *parse; /* parse pointer */ 27*95c635efSGarrett D'Amore int flags; /* parse flags */ 28*95c635efSGarrett D'Amore #define MDOC_HALT (1 << 0) /* error in parse: halt */ 29*95c635efSGarrett D'Amore #define MDOC_LITERAL (1 << 1) /* in a literal scope */ 30*95c635efSGarrett D'Amore #define MDOC_PBODY (1 << 2) /* in the document body */ 31*95c635efSGarrett D'Amore #define MDOC_NEWLINE (1 << 3) /* first macro/text in a line */ 32*95c635efSGarrett D'Amore #define MDOC_PHRASELIT (1 << 4) /* literal within a partila phrase */ 33*95c635efSGarrett D'Amore #define MDOC_PPHRASE (1 << 5) /* within a partial phrase */ 34*95c635efSGarrett D'Amore #define MDOC_FREECOL (1 << 6) /* `It' invocation should close */ 35*95c635efSGarrett D'Amore #define MDOC_SYNOPSIS (1 << 7) /* SYNOPSIS-style formatting */ 36*95c635efSGarrett D'Amore enum mdoc_next next; /* where to put the next node */ 37*95c635efSGarrett D'Amore struct mdoc_node *last; /* the last node parsed */ 38*95c635efSGarrett D'Amore struct mdoc_node *first; /* the first node parsed */ 39*95c635efSGarrett D'Amore struct mdoc_meta meta; /* document meta-data */ 40*95c635efSGarrett D'Amore enum mdoc_sec lastnamed; 41*95c635efSGarrett D'Amore enum mdoc_sec lastsec; 42*95c635efSGarrett D'Amore struct roff *roff; 43*95c635efSGarrett D'Amore }; 44*95c635efSGarrett D'Amore 45*95c635efSGarrett D'Amore #define MACRO_PROT_ARGS struct mdoc *m, \ 46*95c635efSGarrett D'Amore enum mdoct tok, \ 47*95c635efSGarrett D'Amore int line, \ 48*95c635efSGarrett D'Amore int ppos, \ 49*95c635efSGarrett D'Amore int *pos, \ 50*95c635efSGarrett D'Amore char *buf 51*95c635efSGarrett D'Amore 52*95c635efSGarrett D'Amore struct mdoc_macro { 53*95c635efSGarrett D'Amore int (*fp)(MACRO_PROT_ARGS); 54*95c635efSGarrett D'Amore int flags; 55*95c635efSGarrett D'Amore #define MDOC_CALLABLE (1 << 0) 56*95c635efSGarrett D'Amore #define MDOC_PARSED (1 << 1) 57*95c635efSGarrett D'Amore #define MDOC_EXPLICIT (1 << 2) 58*95c635efSGarrett D'Amore #define MDOC_PROLOGUE (1 << 3) 59*95c635efSGarrett D'Amore #define MDOC_IGNDELIM (1 << 4) 60*95c635efSGarrett D'Amore /* Reserved words in arguments treated as text. */ 61*95c635efSGarrett D'Amore }; 62*95c635efSGarrett D'Amore 63*95c635efSGarrett D'Amore enum margserr { 64*95c635efSGarrett D'Amore ARGS_ERROR, 65*95c635efSGarrett D'Amore ARGS_EOLN, /* end-of-line */ 66*95c635efSGarrett D'Amore ARGS_WORD, /* normal word */ 67*95c635efSGarrett D'Amore ARGS_PUNCT, /* series of punctuation */ 68*95c635efSGarrett D'Amore ARGS_QWORD, /* quoted word */ 69*95c635efSGarrett D'Amore ARGS_PHRASE, /* Ta'd phrase (-column) */ 70*95c635efSGarrett D'Amore ARGS_PPHRASE, /* tabbed phrase (-column) */ 71*95c635efSGarrett D'Amore ARGS_PEND /* last phrase (-column) */ 72*95c635efSGarrett D'Amore }; 73*95c635efSGarrett D'Amore 74*95c635efSGarrett D'Amore enum margverr { 75*95c635efSGarrett D'Amore ARGV_ERROR, 76*95c635efSGarrett D'Amore ARGV_EOLN, /* end of line */ 77*95c635efSGarrett D'Amore ARGV_ARG, /* valid argument */ 78*95c635efSGarrett D'Amore ARGV_WORD /* normal word (or bad argument---same thing) */ 79*95c635efSGarrett D'Amore }; 80*95c635efSGarrett D'Amore 81*95c635efSGarrett D'Amore /* 82*95c635efSGarrett D'Amore * A punctuation delimiter is opening, closing, or "middle mark" 83*95c635efSGarrett D'Amore * punctuation. These govern spacing. 84*95c635efSGarrett D'Amore * Opening punctuation (e.g., the opening parenthesis) suppresses the 85*95c635efSGarrett D'Amore * following space; closing punctuation (e.g., the closing parenthesis) 86*95c635efSGarrett D'Amore * suppresses the leading space; middle punctuation (e.g., the vertical 87*95c635efSGarrett D'Amore * bar) can do either. The middle punctuation delimiter bends the rules 88*95c635efSGarrett D'Amore * depending on usage. 89*95c635efSGarrett D'Amore */ 90*95c635efSGarrett D'Amore enum mdelim { 91*95c635efSGarrett D'Amore DELIM_NONE = 0, 92*95c635efSGarrett D'Amore DELIM_OPEN, 93*95c635efSGarrett D'Amore DELIM_MIDDLE, 94*95c635efSGarrett D'Amore DELIM_CLOSE, 95*95c635efSGarrett D'Amore DELIM_MAX 96*95c635efSGarrett D'Amore }; 97*95c635efSGarrett D'Amore 98*95c635efSGarrett D'Amore extern const struct mdoc_macro *const mdoc_macros; 99*95c635efSGarrett D'Amore 100*95c635efSGarrett D'Amore __BEGIN_DECLS 101*95c635efSGarrett D'Amore 102*95c635efSGarrett D'Amore #define mdoc_pmsg(m, l, p, t) \ 103*95c635efSGarrett D'Amore mandoc_msg((t), (m)->parse, (l), (p), NULL) 104*95c635efSGarrett D'Amore #define mdoc_nmsg(m, n, t) \ 105*95c635efSGarrett D'Amore mandoc_msg((t), (m)->parse, (n)->line, (n)->pos, NULL) 106*95c635efSGarrett D'Amore int mdoc_macro(MACRO_PROT_ARGS); 107*95c635efSGarrett D'Amore int mdoc_word_alloc(struct mdoc *, 108*95c635efSGarrett D'Amore int, int, const char *); 109*95c635efSGarrett D'Amore int mdoc_elem_alloc(struct mdoc *, int, int, 110*95c635efSGarrett D'Amore enum mdoct, struct mdoc_arg *); 111*95c635efSGarrett D'Amore int mdoc_block_alloc(struct mdoc *, int, int, 112*95c635efSGarrett D'Amore enum mdoct, struct mdoc_arg *); 113*95c635efSGarrett D'Amore int mdoc_head_alloc(struct mdoc *, int, int, enum mdoct); 114*95c635efSGarrett D'Amore int mdoc_tail_alloc(struct mdoc *, int, int, enum mdoct); 115*95c635efSGarrett D'Amore int mdoc_body_alloc(struct mdoc *, int, int, enum mdoct); 116*95c635efSGarrett D'Amore int mdoc_endbody_alloc(struct mdoc *m, int line, int pos, 117*95c635efSGarrett D'Amore enum mdoct tok, struct mdoc_node *body, 118*95c635efSGarrett D'Amore enum mdoc_endbody end); 119*95c635efSGarrett D'Amore void mdoc_node_delete(struct mdoc *, struct mdoc_node *); 120*95c635efSGarrett D'Amore void mdoc_hash_init(void); 121*95c635efSGarrett D'Amore enum mdoct mdoc_hash_find(const char *); 122*95c635efSGarrett D'Amore const char *mdoc_a2att(const char *); 123*95c635efSGarrett D'Amore const char *mdoc_a2lib(const char *); 124*95c635efSGarrett D'Amore const char *mdoc_a2st(const char *); 125*95c635efSGarrett D'Amore const char *mdoc_a2arch(const char *); 126*95c635efSGarrett D'Amore const char *mdoc_a2vol(const char *); 127*95c635efSGarrett D'Amore int mdoc_valid_pre(struct mdoc *, struct mdoc_node *); 128*95c635efSGarrett D'Amore int mdoc_valid_post(struct mdoc *); 129*95c635efSGarrett D'Amore enum margverr mdoc_argv(struct mdoc *, int, enum mdoct, 130*95c635efSGarrett D'Amore struct mdoc_arg **, int *, char *); 131*95c635efSGarrett D'Amore void mdoc_argv_free(struct mdoc_arg *); 132*95c635efSGarrett D'Amore enum margserr mdoc_args(struct mdoc *, int, 133*95c635efSGarrett D'Amore int *, char *, enum mdoct, char **); 134*95c635efSGarrett D'Amore enum margserr mdoc_zargs(struct mdoc *, int, 135*95c635efSGarrett D'Amore int *, char *, char **); 136*95c635efSGarrett D'Amore int mdoc_macroend(struct mdoc *); 137*95c635efSGarrett D'Amore enum mdelim mdoc_isdelim(const char *); 138*95c635efSGarrett D'Amore 139*95c635efSGarrett D'Amore __END_DECLS 140*95c635efSGarrett D'Amore 141*95c635efSGarrett D'Amore #endif /*!LIBMDOC_H*/ 142