From 44e48ddc2785b037abd202a8d38b2ef2e8c36600 Mon Sep 17 00:00:00 2001 From: quou Date: Sat, 14 Dec 2024 23:15:34 +1100 Subject: initial commit --- cfg/cfgparse.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 cfg/cfgparse.h (limited to 'cfg/cfgparse.h') diff --git a/cfg/cfgparse.h b/cfg/cfgparse.h new file mode 100644 index 0000000..4865b48 --- /dev/null +++ b/cfg/cfgparse.h @@ -0,0 +1,62 @@ +#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 +); +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 +); +const char* find_string_default( + const cfg_Object* obj, + const char* name, + const char* def +); + +#endif -- cgit v1.2.3-54-g00ecf