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
76
77
78
79
|
#ifndef cfgparse_h
#define cfgparse_h
#include "memory.h"
typedef enum {
cfg_type_int,
cfg_type_float,
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 {
float flt;
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
);
const cfg_Object* find_child(
const cfg_Object* obj,
const char* name
);
int find_int_default(
const cfg_Object* obj,
const char* name,
int def
);
float find_float_default(
const cfg_Object* obj,
const char* name,
float def
);
float find_num_default(
const cfg_Object* obj,
const char* name,
float def
);
const char* find_string_default(
const cfg_Object* obj,
const char* name,
const char* def
);
unsigned find_colour_default(
const cfg_Object* obj,
const char* name,
const char* def
);
#endif
|