summaryrefslogtreecommitdiff
path: root/keyword.h
blob: d4343b08da106604931a0d6a66e4995114813cdf (plain)
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
#ifndef KEYWORD_H
#define KEYWORD_H
#include <stddef.h>
#include <time.h>

typedef enum keyword_type keyword_type;
typedef struct keyword keyword;
typedef union keyword_val keyword_val;
typedef int (keyword_cb)(void *ctx, void *ret, const keyword *key, keyword_val val);

enum keyword_type {
	TYPE_NONE,
	TYPE_INT,
	TYPE_STRING,
	TYPE_FLOAT,
	TYPE_BOOL,
	TYPE_TIME,
	TYPE_COUNT,
};

struct keyword {
	const char *key;	/* Keyword. */
	const char *desc;	/* Description of the keyword. */
	const char *time_fmt;	/* Format string used to parse a timestamp (if needed). */
	keyword_type type;	/* Datatype of the keyword. */
	size_t *offsets;	/* Offset(s) of member(s) in a struct (if needed). */
	keyword_cb *callback;	/* Callback to keyword specific parsing function (if needed). */
};

union keyword_val {
	int i;		/* Integer. */
	time_t t;	/* Time. */
	char *str;	/* String. */
	float f;	/* Float. */
};

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 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);
#endif