]> git.cameronkatri.com Git - mandoc.git/blob - private.h
Clean-ups & documentation.
[mandoc.git] / private.h
1 /* $Id: private.h,v 1.65 2009/01/16 12:23:25 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
8 * copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 */
19 #ifndef PRIVATE_H
20 #define PRIVATE_H
21
22 #include "mdoc.h"
23
24 enum mdoc_next {
25 MDOC_NEXT_SIBLING = 0,
26 MDOC_NEXT_CHILD
27 };
28
29 struct mdoc {
30 void *data;
31 struct mdoc_cb cb;
32 void *htab;
33 int flags;
34 #define MDOC_HALT (1 << 0)
35 enum mdoc_next next;
36 struct mdoc_node *last;
37 struct mdoc_node *first;
38 struct mdoc_meta meta;
39 enum mdoc_sec sec_lastn;
40 enum mdoc_sec sec_last;
41 };
42
43
44 /* FIXME: it's 9 (this isn't used properly). */
45
46 #define MDOC_LINEARG_MAX 12
47
48 #define MACRO_PROT_ARGS struct mdoc *mdoc, int tok, int line, \
49 int ppos, int *pos, char *buf
50
51 struct mdoc_macro {
52 int (*fp)(MACRO_PROT_ARGS);
53 int flags;
54 #define MDOC_CALLABLE (1 << 0)
55 #define MDOC_PARSED (1 << 1)
56 #define MDOC_EXPLICIT (1 << 2)
57 #define MDOC_QUOTABLE (1 << 3)
58 #define MDOC_PROLOGUE (1 << 4)
59 #define MDOC_TABSEP (1 << 5)
60 };
61
62 #define mdoc_nwarn(mdoc, node, type, fmt, ...) \
63 mdoc_vwarn((mdoc), (node)->line, \
64 (node)->pos, (type), (fmt), ##__VA_ARGS__)
65
66 #define mdoc_nerr(mdoc, node, fmt, ...) \
67 mdoc_verr((mdoc), (node)->line, \
68 (node)->pos, (fmt), ##__VA_ARGS__)
69
70 #define mdoc_warn(mdoc, type, fmt, ...) \
71 mdoc_vwarn((mdoc), (mdoc)->last->line, \
72 (mdoc)->last->pos, (type), (fmt), ##__VA_ARGS__)
73
74 #define mdoc_err(mdoc, fmt, ...) \
75 mdoc_verr((mdoc), (mdoc)->last->line, \
76 (mdoc)->last->pos, (fmt), ##__VA_ARGS__)
77
78 #define mdoc_msg(mdoc, fmt, ...) \
79 mdoc_vmsg((mdoc), (mdoc)->last->line, \
80 (mdoc)->last->pos, (fmt), ##__VA_ARGS__)
81
82 #define mdoc_pmsg(mdoc, line, pos, fmt, ...) \
83 mdoc_vmsg((mdoc), (line), \
84 (pos), (fmt), ##__VA_ARGS__)
85
86 #define mdoc_pwarn(mdoc, line, pos, type, fmt, ...) \
87 mdoc_vwarn((mdoc), (line), \
88 (pos), (type), (fmt), ##__VA_ARGS__)
89
90 #define mdoc_perr(mdoc, line, pos, fmt, ...) \
91 mdoc_verr((mdoc), (line), \
92 (pos), (fmt), ##__VA_ARGS__)
93
94 extern const struct mdoc_macro *const mdoc_macros;
95
96 __BEGIN_DECLS
97
98 int mdoc_vwarn(struct mdoc *, int, int,
99 enum mdoc_warn, const char *, ...);
100 void mdoc_vmsg(struct mdoc *, int, int,
101 const char *, ...);
102 int mdoc_verr(struct mdoc *, int, int,
103 const char *, ...);
104
105 int mdoc_macro(MACRO_PROT_ARGS);
106 int mdoc_find(const struct mdoc *, const char *);
107 int mdoc_word_alloc(struct mdoc *,
108 int, int, const char *);
109 int mdoc_elem_alloc(struct mdoc *, int, int,
110 int, size_t, const struct mdoc_arg *);
111 int mdoc_block_alloc(struct mdoc *, int, int,
112 int, size_t, const struct mdoc_arg *);
113 int mdoc_root_alloc(struct mdoc *);
114 int mdoc_head_alloc(struct mdoc *, int, int, int);
115 int mdoc_tail_alloc(struct mdoc *, int, int, int);
116 int mdoc_body_alloc(struct mdoc *, int, int, int);
117 void mdoc_node_free(struct mdoc_node *);
118 void mdoc_sibling(struct mdoc *, int, struct mdoc_node **,
119 struct mdoc_node **, struct mdoc_node *);
120 void *mdoc_tokhash_alloc(void);
121 int mdoc_tokhash_find(const void *, const char *);
122 void mdoc_tokhash_free(void *);
123 int mdoc_isdelim(const char *);
124 int mdoc_iscdelim(char);
125 enum mdoc_sec mdoc_atosec(size_t, const char **);
126 enum mdoc_msec mdoc_atomsec(const char *);
127 enum mdoc_vol mdoc_atovol(const char *);
128 enum mdoc_arch mdoc_atoarch(const char *);
129 enum mdoc_att mdoc_atoatt(const char *);
130 time_t mdoc_atotime(const char *);
131
132 int mdoc_valid_pre(struct mdoc *, struct mdoc_node *);
133 int mdoc_valid_post(struct mdoc *);
134 int mdoc_action_pre(struct mdoc *, struct mdoc_node *);
135 int mdoc_action_post(struct mdoc *);
136
137 int mdoc_argv(struct mdoc *, int, int,
138 struct mdoc_arg *, int *, char *);
139 #define ARGV_ERROR (-1)
140 #define ARGV_EOLN (0)
141 #define ARGV_ARG (1)
142 #define ARGV_WORD (2)
143 void mdoc_argv_free(int, struct mdoc_arg *);
144 int mdoc_args(struct mdoc *, int,
145 int *, char *, int, char **);
146 #define ARGS_ERROR (-1)
147 #define ARGS_EOLN (0)
148 #define ARGS_WORD (1)
149 #define ARGS_PUNCT (2)
150
151 #define ARGS_QUOTED (1 << 0)
152 #define ARGS_DELIM (1 << 1)
153 #define ARGS_TABSEP (1 << 2)
154
155 int xstrlcat(char *, const char *, size_t);
156 int xstrlcpy(char *, const char *, size_t);
157 int xstrcmp(const char *, const char *);
158 void *xcalloc(size_t, size_t);
159 char *xstrdup(const char *);
160
161 int macro_obsolete(MACRO_PROT_ARGS);
162 int macro_constant(MACRO_PROT_ARGS);
163 int macro_constant_scoped(MACRO_PROT_ARGS);
164 int macro_constant_delimited(MACRO_PROT_ARGS);
165 int macro_text(MACRO_PROT_ARGS);
166 int macro_scoped(MACRO_PROT_ARGS);
167 int macro_scoped_close(MACRO_PROT_ARGS);
168 int macro_scoped_line(MACRO_PROT_ARGS);
169 int macro_prologue(MACRO_PROT_ARGS);
170 int macro_end(struct mdoc *);
171
172 __END_DECLS
173
174 #endif /*!PRIVATE_H*/