summaryrefslogtreecommitdiff
path: root/cfgparse.h
blob: f8eeedb558f67c02dd075b0ef48d3be5eff7c372 (plain) (blame)
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
#ifndef cfgparse_h
#define cfgparse_h

#include "memory.h"

typedef enum {
	cfg_type_int,
	cfg_type_string,
	cfg_type_data,
	cfg_type_none
} cfg_Type;

typedef struct {
	int size;
	char* data;
} cfg_Data;

typedef struct cfg_Prop {
	char name[28];
	cfg_Type type;
	union {
		int num;
		cfg_Data data;
		char* str;
	} as;
	struct cfg_Prop* next;
} cfg_Prop;

typedef struct cfg_Object {
	char name[28];
	int prop_count;
	cfg_Prop* props;
	struct cfg_Object* next;
} cfg_Object;

cfg_Object* cfg_parse(const char* src, Arena* arena);
const cfg_Prop* find_prop(
	const cfg_Object* obj,
	const char* name
);
const cfg_Prop* find_prop_of(
	const cfg_Object* obj,
	const char* name,
	cfg_Type type
);

int find_int_default(
	const cfg_Object* obj,
	const char* name,
	int def
);
const char* find_string_default(
	const cfg_Object* obj,
	const char* name,
	const char* def
);

#endif