-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparseconf.h
75 lines (63 loc) · 2.11 KB
/
parseconf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* parseconf.h
* Copyright (C) 2007 Tillmann Werner <[email protected]>
*
* This file is free software; as a special exception the author gives
* unlimited permission to copy and/or distribute it, with or without
* modifications, as long as this notice is preserved.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef __HONEYTRAP_PARSECONF_H
#define __HONEYTRAP_PARSECONF_H 1
#define LCFG_BUFSIZ 0xff
struct lcfg {
char error[LCFG_BUFSIZ];
struct lcfg_parser *parser;
};
enum lcfg_status {
lcfg_status_ok,
lcfg_status_error
};
typedef enum lcfg_status (* lcfg_visitor_function) (const char *key, void *data, size_t size, void *user_data);
enum lcfg_token_type {
lcfg_null_token = 0,
lcfg_identifier,
lcfg_equals,
lcfg_string,
lcfg_sbracket_open,
lcfg_sbracket_close,
lcfg_comma,
lcfg_brace_open,
lcfg_brace_close
};
extern const char *lcfg_token_map[];
struct lcfg_token {
enum lcfg_token_type type;
struct lcfg_string *string;
short line;
short col;
};
struct lcfg_string {
char *str;
unsigned int size;
unsigned int capacity;
};
struct lcfg_string *lcfg_string_new();
struct lcfg_string *lcfg_string_new_copy(struct lcfg_string *);
int lcfg_string_set(struct lcfg_string *, const char *);
int lcfg_string_cat_char(struct lcfg_string *, char);
int lcfg_string_cat_cstr(struct lcfg_string *, const char *);
int lcfg_string_cat_uint(struct lcfg_string *, unsigned int);
int lcfg_string_find(struct lcfg_string *, char);
int lcfg_string_rfind(struct lcfg_string *, char);
void lcfg_string_trunc(struct lcfg_string *, unsigned int);
inline const char *lcfg_string_cstr(struct lcfg_string *);
inline unsigned int lcfg_string_len(struct lcfg_string *);
void lcfg_string_delete(struct lcfg_string *);
void lcfg_error_set(struct lcfg *c, const char *fmt, ...);
enum lcfg_status lcfg_accept(struct lcfg *c, lcfg_visitor_function fn, void *user_data);
void lcfg_delete(struct lcfg *c);
struct lcfg *parse_config_file(const char *filename);
#endif