X_INI_VERSION_MAJOR
#define X_INI_VERSION_MAJOR 1
STDX - Minimal INI parser Part of the STDX General Purpose C Library by marciovmf License: MIT https://github.com/marciovmf/stdx
One flat string pool owns all normalized C strings (section names, keys, values). Sections and entries are indexed by arrays for direct and iterative access.
To compile the implementation, define X_IMPL_INI
in one source file before including this header.
To customize how this module allocates memory, define
X_INI_ALLOC / X_INI_REALLOC / X_INI_FREE before including.
#define X_INI_VERSION_MAJOR 1
#define X_INI_VERSION_MINOR 1
#define X_INI_VERSION_PATCH 0
#define X_INI_VERSION(X_INI_VERSION_MAJOR *10000+X_INI_VERSION_MINOR *100+X_INI_VERSION_PATCH)
#define X_INI_DEFAULT_SECTIONS_CAP 16
#define X_INI_DEFAULT_ENTRIES_CAP 64
#define X_INI_MAX_LINE 4096
Ini parsing status.
typedef enum XIniErrorCode{
XINI_OK=0,
XINI_ERR_IO,
XINI_ERR_MEMORY,
XINI_ERR_SYNTAX,
XINI_ERR_EXPECT_EQUALS,
XINI_ERR_EXPECT_RBRACKET,
XINI_ERR_UNTERMINATED_STRING
}XIniErrorCode;
Ini error information
typedef struct XIniError{
XIniErrorCode code;
int line;
int column;
const char *message;
}XIniError;
Ini section information
typedef struct XIniSection{
const char *name;
int first_entry;
}XIniSection;
Ini Entry
typedef struct XIniEntry{
int section;
const char *key;
const char *value;
}XIniEntry;
Represents a parsed INI source
typedef struct XIni{
char *pool;
size_t pool_size;
size_t pool_cap;
XIniSection *sections;
int sections_count;
int sections_cap;
XIniEntry *entries;
int entries_count;
int entries_cap;
int global_section;
}XIni;
Load and parse an INI file from disk.
X_INI_API bool x_ini_load_file(
const char *path,
XIni *out_ini,
XIniError *err
);
True on success, false on failure.
Load and parse INI data from a memory buffer.
X_INI_API bool x_ini_load_mem(
const void *data,
size_t size,
XIni *out_ini,
XIniError *err
);
True on success, false on failure.
Free all resources associated with an INI structure.
X_INI_API void x_ini_free(XIni *ini);
XIni *iniNothing.
Get a human-readable string for an INI error code.
X_INI_API const char * x_ini_err_str(XIniErrorCode code);
XIniErrorCode codePointer to a static, thread-safe error string.
Retrieve a string value from the INI data.
X_INI_API const char * x_ini_get(
const XIni *ini,
const char *section,
const char *key,
const char *def_value
);
const XIni *iniconst char *sectionconst char *keyconst char *def_valuePointer to the value string, or def_value if not found.
Retrieve a 32-bit integer value from the INI data.
X_INI_API int32_t x_ini_get_i32(
const XIni *ini,
const char *section,
const char *key,
int32_t def_value
);
const XIni *iniconst char *sectionconst char *keyint32_t def_valueParsed integer value, or def_value on failure.
Retrieve a 32-bit floating-point value from the INI data.
X_INI_API float x_ini_get_f32(
const XIni *ini,
const char *section,
const char *key,
float def_value
);
const XIni *iniconst char *sectionconst char *keyfloat def_valueParsed floating-point value, or def_value on failure.
Retrieve a boolean value from the INI data.
X_INI_API bool x_ini_get_bool(
const XIni *ini,
const char *section,
const char *key,
bool def_value
);
const XIni *iniconst char *sectionconst char *keybool def_valueParsed boolean value, or def_value on failure.
Get the number of sections in the INI data.
X_INI_API int x_ini_section_count(const XIni *ini);
const XIni *iniNumber of sections.
Get the name of a section by index.
X_INI_API const char * x_ini_section_name(
const XIni *ini,
int section_index
);
const XIni *iniint section_indexSection name string.
Get the number of keys in a section.
X_INI_API int x_ini_key_count(
const XIni *ini,
int section_index
);
const XIni *iniint section_indexNumber of keys in the section.
Get the name of a key by section and key index.
X_INI_API const char * x_ini_key_name(
const XIni *ini,
int section_index,
int key_index
);
const XIni *iniint section_indexint key_indexKey name string.
Get the value of a key by section and key index.
X_INI_API const char * x_ini_value_at(
const XIni *ini,
int section_index,
int key_index
);
const XIni *iniint section_indexint key_indexValue string at the specified position.
Internal macro for allocating memory. To override how this header allocates memory, define this macro with a different implementation before including this header.
#define X_INI_ALLOC(sz) malloc(sz)
szInternal macro for resizing memory. To override how this header resizes memory, define this macro with a different implementation before including this header.
#define X_INI_REALLOC(p, sz) realloc((p), (sz))
szInternal macro for freeing memory. To override how this header frees memory, define this macro with a different implementation before including this header.
#define X_INI_FREE(p) free(p)
p