]> git.cameronkatri.com Git - mandoc.git/blob - private.h
Noted lacking areas in mdocterm.1.
[mandoc.git] / private.h
1 /* $Id: private.h,v 1.84 2009/02/28 13:47:36 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 linetok;
34 int flags;
35 #define MDOC_HALT (1 << 0)
36 enum mdoc_next next;
37 struct mdoc_node *last;
38 struct mdoc_node *first;
39 struct mdoc_meta meta;
40 enum mdoc_sec lastnamed;
41 enum mdoc_sec lastsec;
42 };
43
44
45 /* Hard-limit of macro arguments. */
46
47 #define MDOC_LINEARG_MAX 9
48
49 /* Suggested limit of macro arguments. */
50
51 #define MDOC_LINEARG_SOFTMAX 9
52
53 #define MACRO_PROT_ARGS struct mdoc *mdoc, int tok, int line, \
54 int ppos, int *pos, char *buf
55
56 struct mdoc_macro {
57 int (*fp)(MACRO_PROT_ARGS);
58 int flags;
59 #define MDOC_CALLABLE (1 << 0)
60 #define MDOC_PARSED (1 << 1)
61 #define MDOC_EXPLICIT (1 << 2)
62 #define MDOC_PROLOGUE (1 << 3)
63 };
64
65 #define mdoc_nwarn(mdoc, node, type, fmt, ...) \
66 mdoc_vwarn((mdoc), (node)->line, \
67 (node)->pos, (type), (fmt), ##__VA_ARGS__)
68
69 #define mdoc_nerr(mdoc, node, fmt, ...) \
70 mdoc_verr((mdoc), (node)->line, \
71 (node)->pos, (fmt), ##__VA_ARGS__)
72
73 #define mdoc_warn(mdoc, type, fmt, ...) \
74 mdoc_vwarn((mdoc), (mdoc)->last->line, \
75 (mdoc)->last->pos, (type), (fmt), ##__VA_ARGS__)
76
77 #define mdoc_err(mdoc, fmt, ...) \
78 mdoc_verr((mdoc), (mdoc)->last->line, \
79 (mdoc)->last->pos, (fmt), ##__VA_ARGS__)
80
81 #define mdoc_msg(mdoc, fmt, ...) \
82 mdoc_vmsg((mdoc), (mdoc)->last->line, \
83 (mdoc)->last->pos, (fmt), ##__VA_ARGS__)
84
85 #define mdoc_pmsg(mdoc, line, pos, fmt, ...) \
86 mdoc_vmsg((mdoc), (line), \
87 (pos), (fmt), ##__VA_ARGS__)
88
89 #define mdoc_pwarn(mdoc, line, pos, type, fmt, ...) \
90 mdoc_vwarn((mdoc), (line), \
91 (pos), (type), (fmt), ##__VA_ARGS__)
92
93 #define mdoc_perr(mdoc, line, pos, fmt, ...) \
94 mdoc_verr((mdoc), (line), \
95 (pos), (fmt), ##__VA_ARGS__)
96
97 extern const struct mdoc_macro *const mdoc_macros;
98
99 __BEGIN_DECLS
100
101 int mdoc_vwarn(struct mdoc *, int, int,
102 enum mdoc_warn, const char *, ...);
103 void mdoc_vmsg(struct mdoc *, int, int,
104 const char *, ...);
105 int mdoc_verr(struct mdoc *, int, int,
106 const char *, ...);
107
108 int mdoc_macro(MACRO_PROT_ARGS);
109 int mdoc_find(const struct mdoc *, const char *);
110 int mdoc_word_alloc(struct mdoc *,
111 int, int, const char *);
112 int mdoc_elem_alloc(struct mdoc *, int, int,
113 int, size_t, const struct mdoc_arg *);
114 int mdoc_block_alloc(struct mdoc *, int, int,
115 int, size_t, const struct mdoc_arg *);
116 int mdoc_root_alloc(struct mdoc *);
117 int mdoc_head_alloc(struct mdoc *, int, int, int);
118 int mdoc_tail_alloc(struct mdoc *, int, int, int);
119 int mdoc_body_alloc(struct mdoc *, int, int, int);
120 void mdoc_node_free(struct mdoc_node *);
121 void mdoc_node_freelist(struct mdoc_node *);
122 void mdoc_sibling(struct mdoc *, int, struct mdoc_node **,
123 struct mdoc_node **, struct mdoc_node *);
124 void *mdoc_tokhash_alloc(void);
125 int mdoc_tokhash_find(const void *, const char *);
126 void mdoc_tokhash_free(void *);
127 int mdoc_iscdelim(char);
128 size_t mdoc_isescape(const char *);
129 enum mdoc_sec mdoc_atosec(const char *);
130 enum mdoc_msec mdoc_atomsec(const char *);
131 enum mdoc_vol mdoc_atovol(const char *);
132 enum mdoc_arch mdoc_atoarch(const char *);
133 time_t mdoc_atotime(const char *);
134 size_t mdoc_macro2len(int);
135
136 char *mdoc_type2a(enum mdoc_type);
137 char *mdoc_node2a(struct mdoc_node *);
138
139 int mdoc_valid_pre(struct mdoc *,
140 const struct mdoc_node *);
141 int mdoc_valid_post(struct mdoc *);
142 int mdoc_action_pre(struct mdoc *, struct mdoc_node *);
143 int mdoc_action_post(struct mdoc *);
144
145 int mdoc_argv(struct mdoc *, int, int,
146 struct mdoc_arg *, int *, char *);
147 #define ARGV_ERROR (-1)
148 #define ARGV_EOLN (0)
149 #define ARGV_ARG (1)
150 #define ARGV_WORD (2)
151 void mdoc_argv_free(int, struct mdoc_arg *);
152 int mdoc_args(struct mdoc *, int,
153 int *, char *, int, char **);
154 #define ARGS_ERROR (-1)
155 #define ARGS_EOLN (0)
156 #define ARGS_WORD (1)
157 #define ARGS_PUNCT (2)
158 #define ARGS_QWORD (3)
159 #define ARGS_PHRASE (4)
160
161 int xstrlcats(char *, const struct mdoc_node *, size_t);
162 int xstrlcat(char *, const char *, size_t);
163 int xstrlcpy(char *, const char *, size_t);
164 int xstrcmp(const char *, const char *);
165 int xstrncmp(const char *, const char *, size_t);
166 void *xcalloc(size_t, size_t);
167 void *xrealloc(void *, size_t);
168 char *xstrdup(const char *);
169
170 int macro_end(struct mdoc *);
171
172 __END_DECLS
173
174 #endif /*!PRIVATE_H*/