vn/code/vn_config.h

89 lines
2.1 KiB
C
Raw Permalink Normal View History

2023-06-17 21:06:25 +00:00
/* date = June 17th 2023 10:48 pm */
#ifndef VN_CONFIG_H
#define VN_CONFIG_H
2023-07-19 15:09:41 +00:00
////////////////////////////////
//~ sixten: Config Types
2023-06-18 10:09:36 +00:00
enum config_entry_type
{
Config_Entry_S32,
Config_Entry_S64,
Config_Entry_B32,
};
2023-06-17 21:06:25 +00:00
struct config_entry
{
string Name;
2023-06-18 10:09:36 +00:00
void *Target;
config_entry_type Type;
2023-06-17 21:06:25 +00:00
config_entry *Next;
config_entry *Prev;
2023-06-19 17:12:26 +00:00
config_entry *NextInternal;
2023-06-17 21:06:25 +00:00
};
2023-06-18 10:09:36 +00:00
struct config_entry_bucket
2023-06-17 21:06:25 +00:00
{
config_entry *First;
config_entry *Last;
};
2023-06-18 10:09:36 +00:00
struct config
{
arena *Arena;
2023-06-18 10:09:36 +00:00
config_entry_bucket EntryBuckets[32];
2023-06-19 17:12:26 +00:00
// sixten(NOTE): Keeps track of the order in which the entries were declared. (Used during saving)
config_entry *FirstInternal;
config_entry *LastInternal;
2023-06-18 10:09:36 +00:00
};
2023-07-19 15:09:41 +00:00
////////////////////////////////
//~ sixten: Config Parse Types
enum config_parse_mode
{
ConfigParseMode_Main,
ConfigParseMode_ScanForCurlyOpenOrEquals,
ConfigParseMode_ScanForValue,
ConfigParseMode_ScanForSemicolon,
};
struct config_parse_node
{
config_parse_node *Next;
config_parse_node *Prev;
string Name;
};
struct config_parse_list
{
config_parse_node *First;
config_parse_node *Last;
s64 TotalCountPlusOne;
};
////////////////////////////////
//~ sixten: Config Type Functions
static config *CreateConfig(void);
2023-06-18 10:09:36 +00:00
static config_entry *Config_FindEntryByName(config *Config, string Name);
2023-06-19 17:12:26 +00:00
static void Config_BindEntry(config *Config, string Name, config_entry_type Type, void *Target);
inline void Config_BindS32(config *Config, string Name, s32 *Target, s32 Default);
inline void Config_BindS64(config *Config, string Name, s64 *Target, s64 Default);
inline void Config_BindB32(config *Config, string Name, b32 *Target, b32 Default);
2023-06-17 21:06:25 +00:00
static void Config_ReadFile(config *Config, string Path);
static void Config_WriteFile(config *Config);
2023-07-19 15:09:41 +00:00
////////////////////////////////
//~ sixten: Config Parse Type Functions
static void Config_ParseListPush(arena *Arena, config_parse_list *List, string Name);
2023-07-19 15:09:41 +00:00
static void Config_ParseListPop(config_parse_list *List);
static string Config_ParseListJoin(arena *Arena, config_parse_list *List);
2023-07-19 15:09:41 +00:00
2023-06-17 21:06:25 +00:00
#endif //VN_CONFIG_H