diff options
Diffstat (limited to 'src/grecs.hin')
-rw-r--r-- | src/grecs.hin | 584 |
1 files changed, 0 insertions, 584 deletions
diff --git a/src/grecs.hin b/src/grecs.hin deleted file mode 100644 index bfaaa49..0000000 --- a/src/grecs.hin +++ /dev/null | |||
@@ -1,584 +0,0 @@ | |||
1 | /* grecs - Gray's Extensible Configuration System -*- c -*- | ||
2 | Copyright (C) 2007-2016 Sergey Poznyakoff | ||
3 | |||
4 | Grecs is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU General Public License as published by the | ||
6 | Free Software Foundation; either version 3 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | Grecs is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with Grecs. If not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #ifndef _GRECS_H | ||
18 | #define _GRECS_H | ||
19 | |||
20 | #include <sys/types.h> | ||
21 | #include <unistd.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <stdio.h> | ||
24 | #include <stdarg.h> | ||
25 | |||
26 | #if ENABLE_NLS | ||
27 | # include "gettext.h" | ||
28 | #else | ||
29 | # ifndef gettext | ||
30 | # define gettext(msgid) msgid | ||
31 | # endif | ||
32 | #endif | ||
33 | #ifndef _ | ||
34 | # define _(msgid) gettext(msgid) | ||
35 | #endif | ||
36 | #ifndef N_ | ||
37 | # define N_(s) s | ||
38 | #endif | ||
39 | |||
40 | #define GRECS_VERSION_MAJOR 1 | ||
41 | #define GRECS_VERSION_MINOR 0 | ||
42 | |||
43 | #define GRECS_TREE_API @GRECS_TREE_API@ | ||
44 | #define GRECS_SOCKADDR_LIST @GRECS_SOCKADDR_LIST@ | ||
45 | |||
46 | struct grecs_version_info { | ||
47 | const char *package; | ||
48 | const char *version; | ||
49 | const char *id; | ||
50 | int major; | ||
51 | int minor; | ||
52 | int patch; | ||
53 | char *suffix; | ||
54 | char *buffer; | ||
55 | }; | ||
56 | |||
57 | struct grecs_locus_point { | ||
58 | char *file; | ||
59 | unsigned line; | ||
60 | unsigned col; | ||
61 | }; | ||
62 | |||
63 | #define grecs_locus_point_advance_line(loc) do { \ | ||
64 | (loc).line++; \ | ||
65 | (loc).col = 0; \ | ||
66 | } while (0) | ||
67 | |||
68 | #define GRECS_LOCUS_POINT_EQ(a,b) \ | ||
69 | ((strcmp((a)->file, (b)->file) == 0) && ((a)->line == (b)->line)) | ||
70 | |||
71 | typedef struct grecs_locus { | ||
72 | struct grecs_locus_point beg; | ||
73 | struct grecs_locus_point end; | ||
74 | } grecs_locus_t; | ||
75 | |||
76 | extern grecs_locus_t grecs_locus; | ||
77 | extern int grecs_adjust_string_locations; | ||
78 | |||
79 | enum grecs_data_type { | ||
80 | grecs_type_void, | ||
81 | grecs_type_string, | ||
82 | grecs_type_short, | ||
83 | grecs_type_ushort, | ||
84 | grecs_type_int, | ||
85 | grecs_type_uint, | ||
86 | grecs_type_long, | ||
87 | grecs_type_ulong, | ||
88 | grecs_type_size, | ||
89 | /* grecs_type_off,*/ | ||
90 | grecs_type_time, | ||
91 | grecs_type_bool, | ||
92 | grecs_type_ipv4, | ||
93 | grecs_type_cidr, | ||
94 | grecs_type_host, | ||
95 | grecs_type_sockaddr, | ||
96 | grecs_type_section, | ||
97 | grecs_type_null | ||
98 | }; | ||
99 | |||
100 | #define GRECS_DFLT 0x00 /* Default keyword flags */ | ||
101 | #define GRECS_AGGR 0x01 /* Multiple entries aggregate */ | ||
102 | #define GRECS_MULT 0x02 /* Statement can appear multiple times */ | ||
103 | #define GRECS_INAC 0x04 /* Inactive keyword */ | ||
104 | #define GRECS_LIST 0x08 /* Value is a list of declared type */ | ||
105 | #define GRECS_HIDDEN 0x10 /* Hidden keyword: don't display in help output */ | ||
106 | #define GRECS_CONST 0x20 /* For string types: initial value is constant, | ||
107 | don't try to free it before assigning new value. | ||
108 | This flag is cleared after the first assignment. | ||
109 | */ | ||
110 | |||
111 | enum grecs_callback_command { | ||
112 | grecs_callback_section_begin, | ||
113 | grecs_callback_section_end, | ||
114 | grecs_callback_set_value | ||
115 | }; | ||
116 | |||
117 | #define GRECS_TYPE_STRING 0 | ||
118 | #define GRECS_TYPE_LIST 1 | ||
119 | #define GRECS_TYPE_ARRAY 2 | ||
120 | |||
121 | struct grecs_list_entry { | ||
122 | struct grecs_list_entry *next, *prev; | ||
123 | void *data; | ||
124 | }; | ||
125 | |||
126 | struct grecs_list { | ||
127 | struct grecs_list_entry *head, *tail; | ||
128 | size_t count; | ||
129 | int (*cmp)(const void *, const void *); | ||
130 | void (*free_entry)(void *); | ||
131 | }; | ||
132 | |||
133 | typedef struct grecs_value { | ||
134 | int type; | ||
135 | grecs_locus_t locus; | ||
136 | union { | ||
137 | struct grecs_list *list; | ||
138 | char *string; | ||
139 | struct { | ||
140 | size_t c; | ||
141 | struct grecs_value **v; | ||
142 | } arg; | ||
143 | } v; | ||
144 | } grecs_value_t; | ||
145 | |||
146 | #define GRECS_VALUE_EMPTY_P(val) \ | ||
147 | (!(val) || \ | ||
148 | ((val)->type == GRECS_TYPE_STRING && (val)->v.string == NULL)) | ||
149 | |||
150 | enum grecs_node_type { | ||
151 | grecs_node_root, | ||
152 | grecs_node_stmt, | ||
153 | grecs_node_block | ||
154 | }; | ||
155 | |||
156 | typedef struct grecs_node { | ||
157 | enum grecs_node_type type; | ||
158 | grecs_locus_t locus; | ||
159 | struct grecs_node *up; | ||
160 | struct grecs_node *down; | ||
161 | struct grecs_node *next; | ||
162 | struct grecs_node *prev; | ||
163 | char *ident; | ||
164 | grecs_locus_t idloc; | ||
165 | union { | ||
166 | struct grecs_value *value; | ||
167 | struct grecs_symtab *texttab; | ||
168 | } v; | ||
169 | } grecs_node_t; | ||
170 | |||
171 | typedef int (*grecs_callback_fn)( | ||
172 | #if GRECS_TREE_API | ||
173 | enum grecs_callback_command cmd, | ||
174 | grecs_node_t * /* node */, | ||
175 | void * /* varptr */, | ||
176 | void * /* cb_data */ | ||
177 | #else | ||
178 | enum grecs_callback_command cmd, | ||
179 | grecs_locus_t * /* locus */, | ||
180 | void * /* varptr */, | ||
181 | grecs_value_t * /* value */, | ||
182 | void * /* cb_data */ | ||
183 | #endif | ||
184 | ); | ||
185 | |||
186 | struct grecs_keyword { | ||
187 | const char *ident; | ||
188 | const char *argname; | ||
189 | const char *docstring; | ||
190 | enum grecs_data_type type; | ||
191 | int flags; | ||
192 | void *varptr; | ||
193 | size_t offset; | ||
194 | grecs_callback_fn callback; | ||
195 | void *callback_data; | ||
196 | struct grecs_keyword *kwd; | ||
197 | }; | ||
198 | |||
199 | struct grecs_sockaddr { | ||
200 | #if GRECS_SOCKADDR_LIST | ||
201 | struct grecs_sockaddr *next; | ||
202 | #endif | ||
203 | int len; | ||
204 | struct sockaddr *sa; | ||
205 | }; | ||
206 | |||
207 | struct grecs_version_info *grecs_version(void); | ||
208 | int grecs_version_cmp(const char *vstr1, const char *vstr2, int *pres); | ||
209 | int grecs_version_ok(const char *vstr); | ||
210 | void grecs_version_info_free(struct grecs_version_info *pv); | ||
211 | struct grecs_version_info *grecs_version_split(const char *vstr); | ||
212 | int grecs_version_info_cmp(struct grecs_version_info *vx, | ||
213 | struct grecs_version_info *vy, | ||
214 | int *pres); | ||
215 | |||
216 | extern void *(*grecs_malloc_fun)(size_t size); | ||
217 | extern void *(*grecs_realloc_fun)(void *ptr, size_t size); | ||
218 | extern void (*grecs_alloc_die_fun)(void); | ||
219 | extern void (*grecs_free_fun)(void *ptr); | ||
220 | |||
221 | void *grecs_malloc(size_t size); | ||
222 | void *grecs_zalloc(size_t size); | ||
223 | void *grecs_calloc(size_t nmemb, size_t size); | ||
224 | void *grecs_realloc(void *ptr, size_t size); | ||
225 | void grecs_alloc_die(void); | ||
226 | char *grecs_strdup(const char *str); | ||
227 | void grecs_free(void *ptr); | ||
228 | |||
229 | grecs_value_t *grecs_value_ptr_from_static(grecs_value_t *input); | ||
230 | |||
231 | extern void (*grecs_print_diag_fun)(grecs_locus_t const *, int, int, const char*); | ||
232 | |||
233 | void grecs_warning(grecs_locus_t const *locus, | ||
234 | int errcode, const char *fmt, ...) | ||
235 | __attribute__ ((__format__ (__printf__, 3, 4))); | ||
236 | void grecs_error(grecs_locus_t const *locus, int errcode, | ||
237 | const char *fmt, ...) | ||
238 | __attribute__ ((__format__ (__printf__, 3, 4))); | ||
239 | |||
240 | int grecs_asprint_locus(char **locstr, size_t *size, | ||
241 | grecs_locus_t const *locus); | ||
242 | |||
243 | |||
244 | extern int grecs_trace_flags; | ||
245 | |||
246 | #define GRECS_TRACE_GRAM 0x01 | ||
247 | #define GRECS_TRACE_LEX 0x02 | ||
248 | void grecs_gram_trace(int n); | ||
249 | void grecs_lex_trace(int n); | ||
250 | |||
251 | void grecs_parse_line_directive(char *text, grecs_locus_t *ploc, |