Files
86Box/src/include/86box/ini.h

129 lines
6.6 KiB
C
Raw Normal View History

2022-09-10 13:32:46 +02:00
/*
* 86Box A hypervisor and IBM PC system emulator that specializes in
* running old operating systems and software designed for IBM
* PC systems and compatibles from 1981 through fairly recent
* system designs based on the PCI bus.
2022-09-10 13:32:46 +02:00
*
* This file is part of the 86Box distribution.
2022-09-10 13:32:46 +02:00
*
* Configuration file handler header.
2022-09-10 13:32:46 +02:00
*
*
*
2023-01-06 15:36:29 -05:00
* Authors: Sarah Walker, <https://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
* Fred N. van Kempen, <decwiz@yahoo.com>
* Overdoze,
2022-09-10 13:32:46 +02:00
*
* Copyright 2008-2017 Sarah Walker.
2023-01-06 15:36:29 -05:00
* Copyright 2016-2017 Miran Grca.
2022-09-10 13:32:46 +02:00
*
*/
#ifndef EMU_INI_H
#define EMU_INI_H
#ifdef __cplusplus
extern "C" {
#endif
typedef void *ini_t;
typedef void *ini_section_t;
extern ini_t ini_new(void);
extern ini_t ini_read(const char *fn);
extern void ini_write(ini_t ini, const char *fn);
2022-09-10 13:32:46 +02:00
extern void ini_dump(ini_t ini);
extern void ini_close(ini_t ini);
extern void ini_section_delete_var(ini_section_t section, const char *name);
extern int ini_section_get_int(ini_section_t section, const char *name, int def);
extern uint32_t ini_section_get_uint(ini_section_t section, const char *name, uint32_t def);
#if 0
extern float ini_section_get_float(ini_section_t section, const char *name, float def);
#endif
extern double ini_section_get_double(ini_section_t section, const char *name, double def);
extern int ini_section_get_hex16(ini_section_t section, const char *name, int def);
extern int ini_section_get_hex20(ini_section_t section, const char *name, int def);
extern int ini_section_get_mac(ini_section_t section, const char *name, int def);
extern char *ini_section_get_string(ini_section_t section, const char *name, char *def);
extern wchar_t *ini_section_get_wstring(ini_section_t section, const char *name, wchar_t *def);
extern void ini_section_set_int(ini_section_t section, const char *name, int val);
extern void ini_section_set_uint(ini_section_t section, const char *name, uint32_t val);
#if 0
extern void ini_section_set_float(ini_section_t section, const char *name, float val);
#endif
extern void ini_section_set_double(ini_section_t section, const char *name, double val);
extern void ini_section_set_hex16(ini_section_t section, const char *name, int val);
extern void ini_section_set_hex20(ini_section_t section, const char *name, int val);
extern void ini_section_set_mac(ini_section_t section, const char *name, int val);
2022-11-06 15:55:16 -05:00
extern void ini_section_set_string(ini_section_t section, const char *name, const char *val);
extern void ini_section_set_wstring(ini_section_t section, const char *name, wchar_t *val);
2025-03-08 02:13:14 +06:00
extern int ini_has_entry(ini_section_t self, const char *name);
2022-09-10 13:32:46 +02:00
#define ini_delete_var(ini, head, name) ini_section_delete_var(ini_find_section(ini, head), name)
#define ini_get_int(ini, head, name, def) ini_section_get_int(ini_find_section(ini, head), name, def)
#define ini_get_uint(ini, head, name, def) ini_section_get_uint(ini_find_section(ini, head), name, def)
#if 0
#define ini_get_float(ini, head, name, def) ini_section_get_float(ini_find_section(ini, head), name, def)
#endif
2022-09-10 13:32:46 +02:00
#define ini_get_double(ini, head, name, def) ini_section_get_double(ini_find_section(ini, head), name, def)
#define ini_get_hex16(ini, head, name, def) ini_section_get_hex16(ini_find_section(ini, head), name, def)
#define ini_get_hex20(ini, head, name, def) ini_section_get_hex20(ini_find_section(ini, head), name, def)
#define ini_get_mac(ini, head, name, def) ini_section_get_mac(ini_find_section(ini, head), name, def)
#define ini_get_string(ini, head, name, def) ini_section_get_string(ini_find_section(ini, head), name, def)
#define ini_get_wstring(ini, head, name, def) ini_section_get_wstring(ini_find_section(ini, head), name, def)
#define ini_set_int(ini, head, name, val) ini_section_set_int(ini_find_or_create_section(ini, head), name, val)
#define ini_set_uint(ini, head, name, val) ini_section_set_uint(ini_find_or_create_section(ini, head), name, val)
#if 0
#define ini_set_float(ini, head, name, val) ini_section_set_float(ini_find_or_create_section(ini, head), name, val)
#endif
2022-09-10 13:32:46 +02:00
#define ini_set_double(ini, head, name, val) ini_section_set_double(ini_find_or_create_section(ini, head), name, val)
#define ini_set_hex16(ini, head, name, val) ini_section_set_hex16(ini_find_or_create_section(ini, head), name, val)
#define ini_set_hex20(ini, head, name, val) ini_section_set_hex20(ini_find_or_create_section(ini, head), name, val)
#define ini_set_mac(ini, head, name, val) ini_section_set_mac(ini_find_or_create_section(ini, head), name, val)
#define ini_set_string(ini, head, name, val) ini_section_set_string(ini_find_or_create_section(ini, head), name, val)
#define ini_set_wstring(ini, head, name, val) ini_section_set_wstring(ini_find_or_create_section(ini, head), name, val)
extern ini_section_t ini_find_section(ini_t ini, const char *name);
extern ini_section_t ini_find_or_create_section(ini_t ini, const char *name);
extern void ini_rename_section(ini_section_t section, const char *name);
2022-09-10 13:32:46 +02:00
extern void ini_delete_section_if_empty(ini_t ini, ini_section_t section);
2025-03-09 01:39:07 +06:00
static inline void *wx_config_load(const char *path) { return (void*) ini_read(path); }
2025-03-08 02:13:14 +06:00
static inline int wx_config_get_string(void *config, const char *name, char *dst, int size, const char *defVal) {
int res = ini_has_entry(ini_find_or_create_section((ini_t)config, ""), name);
char* str = ini_get_string((ini_t)config, "", name, (char*)defVal);
if (size == 0)
return res;
2025-03-09 01:39:07 +06:00
if (str != NULL)
strncpy(dst, str, size - 1);
else
dst[0] = 0;
2025-03-08 02:13:14 +06:00
return res;
}
static inline int wx_config_get_int(void *config, const char *name, int *dst, int defVal) {
int res = ini_has_entry(ini_find_or_create_section((ini_t)config, ""), name);
*dst = ini_get_int((ini_t)config, "", name, defVal);
return res;
}
static inline int wx_config_get_float(void *config, const char *name, float *dst, float defVal) {
int res = ini_has_entry(ini_find_or_create_section((ini_t)config, ""), name);
*dst = (float)ini_get_double((ini_t)config, "", name, defVal);
return res;
}
static inline int wx_config_get_bool(void *config, const char *name, int *dst, int defVal) {
int res = ini_has_entry(ini_find_or_create_section((ini_t)config, ""), name);
*dst = !!ini_get_int((ini_t)config, "", name, defVal);
return res;
}
static inline int wx_config_has_entry(void *config, const char *name) { return ini_has_entry(ini_find_or_create_section((ini_t)config, ""), name); }
static inline void wx_config_free(void *config) { ini_close(config); };
2022-09-10 13:32:46 +02:00
#ifdef __cplusplus
}
#endif
#endif