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