1 /* $Id: private.h,v 1.71 2009/01/20 13:05:28 kristaps Exp $ */
3 * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
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
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.
25 MDOC_NEXT_SIBLING
= 0,
35 #define MDOC_HALT (1 << 0)
36 #define MDOC_BODYPARSE (1 << 1)
38 struct mdoc_node
*last
;
39 struct mdoc_node
*first
;
40 struct mdoc_meta meta
;
41 enum mdoc_sec sec_lastn
;
42 enum mdoc_sec sec_last
;
46 /* Hard-limit of macro arguments. */
48 #define MDOC_LINEARG_MAX 9
50 /* Suggested limit of macro arguments. */
52 #define MDOC_LINEARG_SOFTMAX 9
54 #define MACRO_PROT_ARGS struct mdoc *mdoc, int tok, int line, \
55 int ppos, int *pos, char *buf
58 int (*fp
)(MACRO_PROT_ARGS
);
60 #define MDOC_CALLABLE (1 << 0)
61 #define MDOC_PARSED (1 << 1)
62 #define MDOC_EXPLICIT (1 << 2)
63 #define MDOC_QUOTABLE (1 << 3)
64 #define MDOC_PROLOGUE (1 << 4)
65 #define MDOC_TABSEP (1 << 5)
68 #define mdoc_nwarn(mdoc, node, type, fmt, ...) \
69 mdoc_vwarn((mdoc), (node)->line, \
70 (node)->pos, (type), (fmt), ##__VA_ARGS__)
72 #define mdoc_nerr(mdoc, node, fmt, ...) \
73 mdoc_verr((mdoc), (node)->line, \
74 (node)->pos, (fmt), ##__VA_ARGS__)
76 #define mdoc_warn(mdoc, type, fmt, ...) \
77 mdoc_vwarn((mdoc), (mdoc)->last->line, \
78 (mdoc)->last->pos, (type), (fmt), ##__VA_ARGS__)
80 #define mdoc_err(mdoc, fmt, ...) \
81 mdoc_verr((mdoc), (mdoc)->last->line, \
82 (mdoc)->last->pos, (fmt), ##__VA_ARGS__)
84 #define mdoc_msg(mdoc, fmt, ...) \
85 mdoc_vmsg((mdoc), (mdoc)->last->line, \
86 (mdoc)->last->pos, (fmt), ##__VA_ARGS__)
88 #define mdoc_pmsg(mdoc, line, pos, fmt, ...) \
89 mdoc_vmsg((mdoc), (line), \
90 (pos), (fmt), ##__VA_ARGS__)
92 #define mdoc_pwarn(mdoc, line, pos, type, fmt, ...) \
93 mdoc_vwarn((mdoc), (line), \
94 (pos), (type), (fmt), ##__VA_ARGS__)
96 #define mdoc_perr(mdoc, line, pos, fmt, ...) \
97 mdoc_verr((mdoc), (line), \
98 (pos), (fmt), ##__VA_ARGS__)
100 extern const struct mdoc_macro
*const mdoc_macros
;
104 int mdoc_vwarn(struct mdoc
*, int, int,
105 enum mdoc_warn
, const char *, ...);
106 void mdoc_vmsg(struct mdoc
*, int, int,
108 int mdoc_verr(struct mdoc
*, int, int,
111 int mdoc_macro(MACRO_PROT_ARGS
);
112 int mdoc_find(const struct mdoc
*, const char *);
113 int mdoc_word_alloc(struct mdoc
*,
114 int, int, const char *);
115 int mdoc_elem_alloc(struct mdoc
*, int, int,
116 int, size_t, const struct mdoc_arg
*);
117 int mdoc_block_alloc(struct mdoc
*, int, int,
118 int, size_t, const struct mdoc_arg
*);
119 int mdoc_root_alloc(struct mdoc
*);
120 int mdoc_head_alloc(struct mdoc
*, int, int, int);
121 int mdoc_tail_alloc(struct mdoc
*, int, int, int);
122 int mdoc_body_alloc(struct mdoc
*, int, int, int);
123 void mdoc_node_free(struct mdoc_node
*);
124 void mdoc_node_freelist(struct mdoc_node
*);
125 void mdoc_sibling(struct mdoc
*, int, struct mdoc_node
**,
126 struct mdoc_node
**, struct mdoc_node
*);
127 void *mdoc_tokhash_alloc(void);
128 int mdoc_tokhash_find(const void *, const char *);
129 void mdoc_tokhash_free(void *);
130 int mdoc_isdelim(const char *);
131 int mdoc_iscdelim(char);
132 enum mdoc_sec
mdoc_atosec(const char *);
133 enum mdoc_msec
mdoc_atomsec(const char *);
134 enum mdoc_vol
mdoc_atovol(const char *);
135 enum mdoc_arch
mdoc_atoarch(const char *);
136 enum mdoc_att
mdoc_atoatt(const char *);
137 time_t mdoc_atotime(const char *);
139 char *mdoc_type2a(enum mdoc_type
);
140 char *mdoc_node2a(struct mdoc_node
*);
142 int mdoc_valid_pre(struct mdoc
*, struct mdoc_node
*);
143 int mdoc_valid_post(struct mdoc
*);
144 int mdoc_action_pre(struct mdoc
*, struct mdoc_node
*);
145 int mdoc_action_post(struct mdoc
*);
147 int mdoc_argv(struct mdoc
*, int, int,
148 struct mdoc_arg
*, int *, char *);
149 #define ARGV_ERROR (-1)
150 #define ARGV_EOLN (0)
152 #define ARGV_WORD (2)
153 void mdoc_argv_free(int, struct mdoc_arg
*);
154 int mdoc_args(struct mdoc
*, int,
155 int *, char *, int, char **);
156 #define ARGS_ERROR (-1)
157 #define ARGS_EOLN (0)
158 #define ARGS_WORD (1)
159 #define ARGS_PUNCT (2)
160 #define ARGS_QWORD (3)
162 #define ARGS_QUOTED (1 << 0)
163 #define ARGS_DELIM (1 << 1)
164 #define ARGS_TABSEP (1 << 2)
166 int xstrlcats(char *, const struct mdoc_node
*, size_t);
167 int xstrlcat(char *, const char *, size_t);
168 int xstrlcpy(char *, const char *, size_t);
169 int xstrcmp(const char *, const char *);
170 void *xcalloc(size_t, size_t);
171 char *xstrdup(const char *);
173 int macro_obsolete(MACRO_PROT_ARGS
);
174 int macro_constant(MACRO_PROT_ARGS
);
175 int macro_constant_scoped(MACRO_PROT_ARGS
);
176 int macro_constant_delimited(MACRO_PROT_ARGS
);
177 int macro_text(MACRO_PROT_ARGS
);
178 int macro_scoped(MACRO_PROT_ARGS
);
179 int macro_scoped_close(MACRO_PROT_ARGS
);
180 int macro_scoped_line(MACRO_PROT_ARGS
);
181 int macro_prologue(MACRO_PROT_ARGS
);
182 int macro_end(struct mdoc
*);
186 #endif /*!PRIVATE_H*/