37 lines
1.5 KiB
C
37 lines
1.5 KiB
C
// dvxPrefs.h — INI-based preferences system
|
|
//
|
|
// Loads a configuration file at startup and provides typed accessors
|
|
// with caller-supplied defaults. The INI file is read-only at runtime;
|
|
// values are queried by section + key. If the file is missing or a key
|
|
// is absent, the default is returned silently.
|
|
//
|
|
// The underlying parser is rxi/ini (thirdparty/ini/src).
|
|
|
|
#ifndef DVX_PREFS_H
|
|
#define DVX_PREFS_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
// Load an INI file into memory. Returns true on success, false if the
|
|
// file could not be opened (all getters will return their defaults).
|
|
// Only one file may be loaded at a time; calling again frees the previous.
|
|
bool prefsLoad(const char *filename);
|
|
|
|
// Release all memory held by the loaded INI file.
|
|
void prefsFree(void);
|
|
|
|
// Retrieve a string value. Returns defaultVal if the section/key pair
|
|
// is not present. The returned pointer is valid until prefsFree().
|
|
const char *prefsGetString(const char *section, const char *key, const char *defaultVal);
|
|
|
|
// Retrieve an integer value. Returns defaultVal if the section/key pair
|
|
// is not present or cannot be parsed.
|
|
int32_t prefsGetInt(const char *section, const char *key, int32_t defaultVal);
|
|
|
|
// Retrieve a boolean value. Recognises "true", "yes", "1" as true and
|
|
// "false", "no", "0" as false (case-insensitive). Returns defaultVal
|
|
// for anything else or if the key is missing.
|
|
bool prefsGetBool(const char *section, const char *key, bool defaultVal);
|
|
|
|
#endif
|