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
|
#ifndef KEYWORD_H
#define KEYWORD_H
#include <stddef.h>
#include <time.h>
typedef enum keyword_type keyword_type;
typedef struct delimiter delimiter;
typedef struct keyword keyword;
typedef union keyword_val keyword_val;
typedef int (set_keyword_cb)(void *ctx, void *ret, const keyword *key, keyword_val val);
typedef int (get_keyword_cb)(void *ctx, void *data, const keyword *key, keyword_val *val);
typedef int (parse_callback)(void **ret, void *ctx, char *buf);
enum keyword_type {
TYPE_NONE,
TYPE_INT,
TYPE_STRING,
TYPE_FLOAT,
TYPE_BOOL,
TYPE_TIME,
TYPE_COUNT,
};
struct delimiter {
char *delm;
int lead_space;
int trail_space;
};
struct keyword {
const char *key;
const char *desc;
const char *time_fmt;
keyword_type type;
size_t *offsets;
set_keyword_cb *set_callback;
get_keyword_cb *get_callback;
};
union keyword_val {
int i;
time_t t;
char *str;
float f;
};
extern void *get_keyword_offset_ptr(const keyword *key, void *ptr);
extern keyword_val get_keyword_value(const keyword *key, char *value, int *error);
extern keyword_val get_keyword(const keyword *key, void *data, void *ctx, int *error);
extern int set_keyword(const keyword *key, keyword_val val, void *ret, void *ctx);
extern keyword_val parse_keyword(const keyword *key, char *key_str, char *value, int *error);
extern int parse_keywords(const keyword **keys, char *key, char *value, void *ret, void *ctx);
extern int parse_key_value_file(void *ret, void *ctx, const keyword **keywords, char *buf, const char *delm, parse_callback *parse_cb);
extern char *create_key_value_str(const keyword *key, keyword_val val, const delimiter *start_delm, const delimiter *end_delm);
extern char *create_key_value_file(void *data, void *ctx, const keyword **keywords, const delimiter *start_delm, const delimiter *end_delm);
#endif
|