Mstdlib-1.24.0

Typedefs

typedef struct M_ini M_ini_t
 
typedef struct M_ini_settings M_ini_settings_t
 
typedef M_bool(* M_ini_merge_resolver_t) (const char *key, const char *val_cur, const char *val_new)
 

Enumerations

enum  M_ini_dupkvs_t {
  M_INI_DUPKVS_COMMENT_PREV = 0 ,
  M_INI_DUPKVS_REMOVE_PREV ,
  M_INI_DUPKVS_COMMENT ,
  M_INI_DUPKVS_REMOVE ,
  M_INI_DUPKVS_COLLECT
}
 
enum  M_ini_padding_t {
  M_INI_PADDING_NONE = 0 ,
  M_INI_PADDING_BEFORE_KV_DELIM = 1 << 0 ,
  M_INI_PADDING_AFTER_KV_DELIM = 1 << 1 ,
  M_INI_PADDING_AFTER_KV_VAL = 1 << 2 ,
  M_INI_PADDING_AFTER_COMMENT_CHAR = 1 << 3
}
 
enum  M_ini_multivals_t {
  M_INI_MULTIVALS_USE_LAST = 0 ,
  M_INI_MULTIVALS_USE_FIRST ,
  M_INI_MULTIVALS_KEEP_EXISTING ,
  M_INI_MULTIVALS_MAINTAIN_ORDER
}
 
enum  M_ini_merge_conflict_t {
  M_INI_MERGE_CALLBACK_FUNC = 0 ,
  M_INI_MERGE_NEW_REMOVED_KEEP = 1 << 0 ,
  M_INI_MERGE_NEW_CHANGED_USE_CUR = 1 << 1 ,
  M_INI_MERGE_MULTI_NEW_REMOVED_KEEP = 1 << 3
}
 

Functions

char * M_ini_full_key (const char *section, const char *key) M_MALLOC
 
void M_ini_split_key (const char *s, char **section, char **key)
 
M_ini_settings_tM_ini_settings_create (void) M_MALLOC
 
void M_ini_settings_destroy (M_ini_settings_t *info) M_FREE(1)
 
unsigned char M_ini_settings_get_element_delim_char (const M_ini_settings_t *info)
 
unsigned char M_ini_settings_get_quote_char (const M_ini_settings_t *info)
 
unsigned char M_ini_settings_get_escape_char (const M_ini_settings_t *info)
 
unsigned char M_ini_settings_get_comment_char (const M_ini_settings_t *info)
 
unsigned char M_ini_settings_get_kv_delim_char (const M_ini_settings_t *info)
 
M_uint32 M_ini_settings_get_padding (const M_ini_settings_t *info)
 
M_ini_dupkvs_t M_ini_settings_reader_get_dupkvs_handling (const M_ini_settings_t *info)
 
M_ini_multivals_t M_ini_settings_writer_get_multivals_handling (const M_ini_settings_t *info)
 
const char * M_ini_settings_writer_get_line_ending (const M_ini_settings_t *info)
 
M_uint32 M_ini_settings_merger_get_conflict_flags (const M_ini_settings_t *info)
 
M_ini_merge_resolver_t M_ini_settings_merger_get_resolver (const M_ini_settings_t *info)
 
void M_ini_settings_set_element_delim_char (M_ini_settings_t *info, unsigned char val)
 
void M_ini_settings_set_quote_char (M_ini_settings_t *info, unsigned char val)
 
void M_ini_settings_set_escape_char (M_ini_settings_t *info, unsigned char val)
 
void M_ini_settings_set_comment_char (M_ini_settings_t *info, unsigned char val)
 
void M_ini_settings_set_kv_delim_char (M_ini_settings_t *info, unsigned char val)
 
void M_ini_settings_set_padding (M_ini_settings_t *info, M_uint32 val)
 
void M_ini_settings_reader_set_dupkvs_handling (M_ini_settings_t *info, M_ini_dupkvs_t val)
 
void M_ini_settings_writer_set_multivals_handling (M_ini_settings_t *info, M_ini_multivals_t val)
 
void M_ini_settings_writer_set_line_ending (M_ini_settings_t *info, const char *val)
 
void M_ini_settings_merger_set_conflict_flags (M_ini_settings_t *info, M_uint32 val)
 
void M_ini_settings_merger_set_resolver (M_ini_settings_t *info, M_ini_merge_resolver_t val)
 
M_ini_tM_ini_create (M_bool ignore_whitespace) M_MALLOC
 
M_ini_tM_ini_duplicate (const M_ini_t *ini)
 
void M_ini_destroy (M_ini_t *ini) M_FREE(1)
 
M_ini_tM_ini_read (const char *s, const M_ini_settings_t *info, M_bool ignore_whitespace, size_t *err_line) M_MALLOC
 
M_ini_tM_ini_read_file (const char *path, const M_ini_settings_t *info, M_bool ignore_whitespace, size_t *err_line, size_t max_read) M_MALLOC
 
M_bool M_ini_kv_has_key (const M_ini_t *ini, const char *key)
 
M_list_str_tM_ini_kv_keys (const M_ini_t *ini) M_MALLOC
 
M_list_str_tM_ini_kv_sections (const M_ini_t *ini) M_MALLOC
 
M_bool M_ini_kv_rename (M_ini_t *ini, const char *key, const char *new_key)
 
M_bool M_ini_kv_add_key (M_ini_t *ini, const char *key)
 
M_bool M_ini_kv_set (M_ini_t *ini, const char *key, const char *val)
 
M_bool M_ini_kv_insert (M_ini_t *ini, const char *key, const char *val)
 
M_bool M_ini_kv_remove (M_ini_t *ini, const char *key)
 
M_bool M_ini_kv_remove_vals (M_ini_t *ini, const char *key)
 
M_bool M_ini_kv_remove_val_at (M_ini_t *ini, const char *key, size_t idx)
 
size_t M_ini_kv_len (const M_ini_t *ini, const char *key)
 
M_bool M_ini_kv_get (const M_ini_t *ini, const char *key, size_t idx, const char **val)
 
const char * M_ini_kv_get_direct (const M_ini_t *ini, const char *key, size_t idx)
 
M_list_str_tM_ini_kv_get_vals (const M_ini_t *ini, const char *key)
 
char * M_ini_write (M_ini_t *ini, const M_ini_settings_t *info)
 
M_fs_error_t M_ini_write_file (M_ini_t *ini, const char *path, const M_ini_settings_t *info)
 
M_ini_tM_ini_merge (const M_ini_t *cur_ini, const M_ini_t *new_ini, const M_ini_t *orig_ini, const M_ini_settings_t *info)
 

Detailed Description

Configurable handling for various formats. Such as # vs ; comment identifiers.

For easier access functions that do not take a section use the key form 'section/key'. If multiple '/' characters are in the combined key the section is only up until the first '/'. Meaning: 'section/key/key_part'

Can handle multiple or single values under a single key.

Section names and keys cannot include the comment character. Values can, if they are quoted.

Supports:

Example:

M_ini_t *ini = NULL;
M_ini_settings_t *info = NULL;
char *out;
size_t errln = 0;
ini = M_ini_read_file("file.ini", info, M_TRUE, &errln, 0);
if (ini == NULL) {
M_printf("ini could not be parsed. Error line: %zu\n", errln);
return M_FALSE;
}
M_ini_kv_set(ini, "s1/key1", "yes");
out = M_ini_write(ini, info);
M_printf("new ini=\n%s\n", out);
M_free(out);
ssize_t M_printf(const char *fmt,...)
void M_ini_settings_destroy(M_ini_settings_t *info) M_FREE(1)
void M_ini_settings_set_quote_char(M_ini_settings_t *info, unsigned char val)
void M_ini_settings_writer_set_multivals_handling(M_ini_settings_t *info, M_ini_multivals_t val)
M_bool M_ini_kv_set(M_ini_t *ini, const char *key, const char *val)
void M_ini_settings_set_escape_char(M_ini_settings_t *info, unsigned char val)
void M_ini_settings_reader_set_dupkvs_handling(M_ini_settings_t *info, M_ini_dupkvs_t val)
void M_ini_destroy(M_ini_t *ini) M_FREE(1)
M_ini_t * M_ini_read_file(const char *path, const M_ini_settings_t *info, M_bool ignore_whitespace, size_t *err_line, size_t max_read) M_MALLOC
struct M_ini_settings M_ini_settings_t
Definition: m_ini.h:95
M_ini_settings_t * M_ini_settings_create(void) M_MALLOC
char * M_ini_write(M_ini_t *ini, const M_ini_settings_t *info)
struct M_ini M_ini_t
Definition: m_ini.h:92
void M_ini_settings_set_padding(M_ini_settings_t *info, M_uint32 val)
@ M_INI_PADDING_AFTER_COMMENT_CHAR
Definition: m_ini.h:134
@ M_INI_DUPKVS_REMOVE
Definition: m_ini.h:122
@ M_INI_MULTIVALS_USE_LAST
Definition: m_ini.h:140
void M_free(void *ptr) M_FREE(1)

Typedef Documentation

◆ M_ini_t

typedef struct M_ini M_ini_t

◆ M_ini_settings_t

typedef struct M_ini_settings M_ini_settings_t

◆ M_ini_merge_resolver_t

typedef M_bool(* M_ini_merge_resolver_t) (const char *key, const char *val_cur, const char *val_new)

Conflict handler function prototype.

Ini merging can have conflicts resolved using a callback function. The use of the resolution callback is dependent on the appropriate merge flag being set.

Parameters
[in]keyThe key. If key is NULL then the values are they key. In this case if the value is NULL then the key doesn't exist for that location.
[in]val_curThe value in the current ini.
[in]val_newThe new value.
Returns
M_TRUE if the current value should be used. Otherwise, M_FALSE if the new value should be used.

Enumeration Type Documentation

◆ M_ini_dupkvs_t

Duplicate key, value pair handling where a key is encountered multiple times.

Enumerator
M_INI_DUPKVS_COMMENT_PREV 

Turn previous kv into comments. Last wins.

M_INI_DUPKVS_REMOVE_PREV 

Remove previous kv from the tree. Last wins.

M_INI_DUPKVS_COMMENT 

Turn the current kv into a comment. First wins.

M_INI_DUPKVS_REMOVE 

Remove the current kv from the tree. First wins.

M_INI_DUPKVS_COLLECT 

Multiple kv are allowed and their values should be collected. All win.

◆ M_ini_padding_t

Control padding when between parts of elements. Primarily used for writing but also used for reading when a comment duplicate key flag is used.

Enumerator
M_INI_PADDING_NONE 

No padding.

M_INI_PADDING_BEFORE_KV_DELIM 

Put a space before the kv delimiter.

M_INI_PADDING_AFTER_KV_DELIM 

Put a space after the kv delimiter.

M_INI_PADDING_AFTER_KV_VAL 

Put a space after the kv val if followed by a comment.

M_INI_PADDING_AFTER_COMMENT_CHAR 

Put a space after the comment character.

◆ M_ini_multivals_t

Control how muli value keys are written.

Enumerator
M_INI_MULTIVALS_USE_LAST 

Multi-value keys are not supported. Use the last value.

M_INI_MULTIVALS_USE_FIRST 

Multi-value keys are not supported. Use the first value.

M_INI_MULTIVALS_KEEP_EXISTING 

Multi-value keys are supported. Keep existing values in the same location and place new values after.

M_INI_MULTIVALS_MAINTAIN_ORDER 

Multi-value keys are supported. Remove all existing keys and write them all together maintaining the current value order.

◆ M_ini_merge_conflict_t

Control how conflicts are handled during merge.

These values all override the default behavior. Default behavior:

  • When a key is in new but not in cur and orig remove the key.
  • When the value (single) of cur is the same as orig but different than new use the new value.
  • When a key with multiple values has a value that is in cur and orig but not in new remove the value.
Enumerator
M_INI_MERGE_CALLBACK_FUNC 

Use a conflict resolution callback function to determine how to handle conflicts. A callback function must be set otherwise the default handling will be used.

M_INI_MERGE_NEW_REMOVED_KEEP 

When a key is not in new but in cur and orig keep the key. The default is to remove the key.

M_INI_MERGE_NEW_CHANGED_USE_CUR 

When the value of cur is the same as orig but different than new use the value from cur. Meaning the default value is set but has changed. The default is to use the new value.

M_INI_MERGE_MULTI_NEW_REMOVED_KEEP 

When a key with multiple values has a value that is in cur and orig but not in new keep the value. The default is to remove the value.

Function Documentation

◆ M_ini_full_key()

char * M_ini_full_key ( const char *  section,
const char *  key 
)

Create a full key from individual parts.

Parameters
[in]sectionThe section the key belongs to. Can be NULL if referencing a key not in a section.
[in]keyThe key within the section. Can be NULL if referencing a section only.
Returns
A string with the full key.

◆ M_ini_split_key()

void M_ini_split_key ( const char *  s,
char **  section,
char **  key 
)

Split a full key into it's individual parts.

Parameters
[in]sThe full key.
[out]sectionThe section part. Optional, pass NULL if not needed. May be returned as NULL.
[out]keyThe key part. Optional, pass NULL if not needed. May be returned as NULL.

◆ M_ini_settings_create()

M_ini_settings_t * M_ini_settings_create ( void  )

Create an ini settings object.

Returns
an ini settings object.

◆ M_ini_settings_destroy()

void M_ini_settings_destroy ( M_ini_settings_t info)

Destroy an ini settings object.

Parameters
[in]infoThe settings object to destroy.

◆ M_ini_settings_get_element_delim_char()

unsigned char M_ini_settings_get_element_delim_char ( const M_ini_settings_t info)

Get the element delimiter character.

Parameters
[in]infoThe settings.
Returns
The element delimiter character. Default is "\n".

◆ M_ini_settings_get_quote_char()

unsigned char M_ini_settings_get_quote_char ( const M_ini_settings_t info)

Get the quote character.

Parameters
[in]infoThe settings.
Returns
The quote character. 0 if not set.

◆ M_ini_settings_get_escape_char()

unsigned char M_ini_settings_get_escape_char ( const M_ini_settings_t info)

Get the quoting escape character.

This can be the same character as the quote character which suggests CSV style quoting.

Parameters
[in]infoThe settings.
Returns
The escape character. 0 if not set.

◆ M_ini_settings_get_comment_char()

unsigned char M_ini_settings_get_comment_char ( const M_ini_settings_t info)

Get the comment character.

Parameters
[in]infoThe settings.
Returns
The comment character. Default is "#".

◆ M_ini_settings_get_kv_delim_char()

unsigned char M_ini_settings_get_kv_delim_char ( const M_ini_settings_t info)

Get the key, value delimiter character.

Parameters
[in]infoThe settings.
Returns
The key, value delimiter character. Default is "=".

◆ M_ini_settings_get_padding()

M_uint32 M_ini_settings_get_padding ( const M_ini_settings_t info)

Get the padding flags.

Parameters
[in]infoThe settings.
Returns
The padding flags.

◆ M_ini_settings_reader_get_dupkvs_handling()

M_ini_dupkvs_t M_ini_settings_reader_get_dupkvs_handling ( const M_ini_settings_t info)

Get the duplicate key handling value used during reading.

Parameters
[in]infoThe settings.
Returns
The duplicate key handling value.

◆ M_ini_settings_writer_get_multivals_handling()

M_ini_multivals_t M_ini_settings_writer_get_multivals_handling ( const M_ini_settings_t info)

Get the multiple value handling value used during writing.

Parameters
[in]infoThe settings.
Returns
The multiple value handing value.

◆ M_ini_settings_writer_get_line_ending()

const char * M_ini_settings_writer_get_line_ending ( const M_ini_settings_t info)

Get the line ending used when writing the ini.

This is to allow multiple character line endings (Windows "\r\n"). This is an override of the element delim character that will be used if set. The line ending string will not be used when determining if quoting is necessary. The element delim is still used for this purpose even when the line ending is set.

Parameters
[in]infoThe settings.
Returns
The line ending characters.

◆ M_ini_settings_merger_get_conflict_flags()

M_uint32 M_ini_settings_merger_get_conflict_flags ( const M_ini_settings_t info)

Get the conflict resolution flags used for merging.

Parameters
[in]infoThe settings.
Returns
The conflict resolution flags. If 0 then either the default handing is going to be used or a custom resolution callback has been registered. Check if the call back is not NULL to know if the default handling will be used.

◆ M_ini_settings_merger_get_resolver()

M_ini_merge_resolver_t M_ini_settings_merger_get_resolver ( const M_ini_settings_t info)

Get the conflict resolution function used for merging when the conflict flags are set to use a custom resolution callback.

Parameters
[in]infoThe settings.
Returns
the resolution function. NULL if not set.

◆ M_ini_settings_set_element_delim_char()

void M_ini_settings_set_element_delim_char ( M_ini_settings_t info,
unsigned char  val 
)

Set the element delimiter character.

Parameters
[in,out]infoThe settings.
[in]valThe value to set.

◆ M_ini_settings_set_quote_char()

void M_ini_settings_set_quote_char ( M_ini_settings_t info,
unsigned char  val 
)

Set the quote character.

Parameters
[in,out]infoThe settings.
[in]valThe value to set.

◆ M_ini_settings_set_escape_char()

void M_ini_settings_set_escape_char ( M_ini_settings_t info,
unsigned char  val 
)

Set the escape character.

Parameters
[in,out]infoThe settings.
[in]valThe value to set.

◆ M_ini_settings_set_comment_char()

void M_ini_settings_set_comment_char ( M_ini_settings_t info,
unsigned char  val 
)

Set the comment character.

Parameters
[in,out]infoThe settings.
[in]valThe value to set.

◆ M_ini_settings_set_kv_delim_char()

void M_ini_settings_set_kv_delim_char ( M_ini_settings_t info,
unsigned char  val 
)

Set the key value delimiter character.

Parameters
[in,out]infoThe settings.
[in]valThe value to set.

◆ M_ini_settings_set_padding()

void M_ini_settings_set_padding ( M_ini_settings_t info,
M_uint32  val 
)

Set the padding flags.

Parameters
[in,out]infoThe settings.
[in]valThe value to set.

◆ M_ini_settings_reader_set_dupkvs_handling()

void M_ini_settings_reader_set_dupkvs_handling ( M_ini_settings_t info,
M_ini_dupkvs_t  val 
)

Set the duplicate key flags used for reading.

Parameters
[in,out]infoThe settings.
[in]valThe value to set.

◆ M_ini_settings_writer_set_multivals_handling()

void M_ini_settings_writer_set_multivals_handling ( M_ini_settings_t info,
M_ini_multivals_t  val 
)

Set the multiple value handling flags used for writing..

Parameters
[in,out]infoThe settings.
[in]valThe value to set.

◆ M_ini_settings_writer_set_line_ending()

void M_ini_settings_writer_set_line_ending ( M_ini_settings_t info,
const char *  val 
)

Set the line ending used when writing the ini.

This is to allow multiple character line endings (Windows "\r\n"). This is an override of the element delim character that will be used if set. The line ending string will not be used when determining if quoting is necessary. The element delim is still used for this purpose even when the line ending is set.

Parameters
[in,out]infoThe settings.
[in]valThe value to set.

◆ M_ini_settings_merger_set_conflict_flags()

void M_ini_settings_merger_set_conflict_flags ( M_ini_settings_t info,
M_uint32  val 
)

Set the conflict resolution flags used for merging.

Parameters
[in,out]infoThe settings.
[in]valThe value to set.

◆ M_ini_settings_merger_set_resolver()

void M_ini_settings_merger_set_resolver ( M_ini_settings_t info,
M_ini_merge_resolver_t  val 
)

Set the conflict resolution function.

Parameters
[in,out]infoThe settings.
[in]valThe value to set.

◆ M_ini_create()

M_ini_t * M_ini_create ( M_bool  ignore_whitespace)

Create a new ini object.

Parameters
[in]ignore_whitespaceShould whitespace be ignored when comparing section and key names.
Returns
A new ini object.

◆ M_ini_duplicate()

M_ini_t * M_ini_duplicate ( const M_ini_t ini)

Duplicate an ini.

Parameters
[in]iniThe ini to duplicate

◆ M_ini_destroy()

void M_ini_destroy ( M_ini_t ini)

Destroy the ini.

Parameters
[in]iniThe ini to destroy.

◆ M_ini_read()

M_ini_t * M_ini_read ( const char *  s,
const M_ini_settings_t info,
M_bool  ignore_whitespace,
size_t *  err_line 
)

Parse a string into an ini object.

Parameters
[in]sThe string to parse.
[in]infoThe ini settings that control how the ini is structured and should be read.
[in]ignore_whitespaceShould whitespace be ignored for section and key comparison.
[out]err_lineIf an error occurs the line the error is present on. Optional, pass NULL if not needed.
Returns
An ini object. NULL if data could not be parsed.

◆ M_ini_read_file()

M_ini_t * M_ini_read_file ( const char *  path,
const M_ini_settings_t info,
M_bool  ignore_whitespace,
size_t *  err_line,
size_t  max_read 
)

Read a file based on file name into an ini object.

Parameters
[in]pathThe full file path to read.
[in]infoThe ini settings that control how the ini is structured and should be read.
[in]ignore_whitespaceShould whitespace be ignored for section and key comparison.
[out]err_lineIf an error occurs the line the error is present on. Optional, pass NULL if not needed.
[in]max_readThe maximum number of bytes to read.
Returns
An ini object. NULL if the file could not be parsed.

◆ M_ini_kv_has_key()

M_bool M_ini_kv_has_key ( const M_ini_t ini,
const char *  key 
)

Does the ini contain a given key.

Parameters
[in]iniThe ini.
[in]keyThe key to check.
Returns
M_TRUE if the ini contains the key otherwise M_FALSE.

◆ M_ini_kv_keys()

M_list_str_t * M_ini_kv_keys ( const M_ini_t ini)

Get a list of all keys contained in the ini.

Parameters
[in]iniThe ini.
Returns
A list of keys contained in the ini.

◆ M_ini_kv_sections()

M_list_str_t * M_ini_kv_sections ( const M_ini_t ini)

Get a list of sections contained in the ini.

Parameters
[in]iniThe ini.
Returns
A list of sections contained in the ini.

◆ M_ini_kv_rename()

M_bool M_ini_kv_rename ( M_ini_t ini,
const char *  key,
const char *  new_key 
)

Rename a section or key in the ini.

Renaming a section can move all keys under it. Renaming a key will move it to the new location if the section portion is different.

Renaming will fail if the new name already exists. This applies to sections and keys.

This can also be used to rename the "pretty name" for a section or key when ignore white space is in use. Or when the case needs to be changed. E.g. "section_1" -> "Section 1". These are equivalent when ignore whitespace is enabled and renaming will simply change the pretty name.

Parameters
[in,out]iniThe ini.
[in]keyThe section or key to rename.
[in]new_keyThe new name.
Returns
M_TRUE on success otherwise M_FALSE.

◆ M_ini_kv_add_key()

M_bool M_ini_kv_add_key ( M_ini_t ini,
const char *  key 
)

Add a key (without value) to the ini.

Parameters
[in,out]iniThe ini.
keyThe key to add.
Returns
M_TRUE if added otherwise M_FALSE.

◆ M_ini_kv_set()

M_bool M_ini_kv_set ( M_ini_t ini,
const char *  key,
const char *  val 
)

Set the value for the key to this value only.

This will clear/replace any other values (even multiple) for the key.

Parameters
[in,out]iniThe ini.
[in]keyThe key.
[in]valThe vaule.
Returns
M_TRUE on success otherwise M_FALSE.

◆ M_ini_kv_insert()

M_bool M_ini_kv_insert ( M_ini_t ini,
const char *  key,
const char *  val 
)

Insert the value into the values for key.

This does not remove/replace the existing values for the key.

Parameters
[in,out]iniThe ini.
[in]keyThe key.
[in]valThe vaule.
Returns
M_TRUE on success otherwise M_FALSE.

◆ M_ini_kv_remove()

M_bool M_ini_kv_remove ( M_ini_t ini,
const char *  key 
)

Remove the key from the ini.

Parameters
[in,out]iniThe ini.
[in]keyThe key.
Returns
M_TRUE on success otherwise M_FALSE.

◆ M_ini_kv_remove_vals()

M_bool M_ini_kv_remove_vals ( M_ini_t ini,
const char *  key 
)

Remove all values for a key but leave the key as part of the ini.

Parameters
[in,out]iniThe ini.
[in]keyThe key.
Returns
M_TRUE on success otherwise M_FALSE.

◆ M_ini_kv_remove_val_at()

M_bool M_ini_kv_remove_val_at ( M_ini_t ini,
const char *  key,
size_t  idx 
)

Remove a specific value from the key.

Parameters
[in,out]iniThe ini.
[in]keyThe key.
[in]idxThe index of the value to remove.
Returns
M_TRUE on success otherwise M_FALSE.

◆ M_ini_kv_len()

size_t M_ini_kv_len ( const M_ini_t ini,
const char *  key 
)

Get the number of values for a given key.

Parameters
[in]iniThe ini.
[in]keyThe key.
Returns
The number of values for a given key.

◆ M_ini_kv_get()

M_bool M_ini_kv_get ( const M_ini_t ini,
const char *  key,
size_t  idx,
const char **  val 
)

Get the value at the given index for the key.

Parameters
[in]iniThe ini.
[in]keyThe key.
[in]idxThe index of the value to get.
[out]valThe value. Can be NULL to check for value existence. Use M_ini_kv_has_key to determine key existence because a key can be part of of the ini and not have a value.
Returns
M_TRUE if the value can be retrieved. Otherwise M_FALSE.

◆ M_ini_kv_get_direct()

const char * M_ini_kv_get_direct ( const M_ini_t ini,
const char *  key,
size_t  idx 
)

Get the value at the given index for the key.

Parameters
[in]iniThe ini.
[in]keyThe key.
[in]idxThe index of the value to get.
Returns
The value.

◆ M_ini_kv_get_vals()

M_list_str_t * M_ini_kv_get_vals ( const M_ini_t ini,
const char *  key 
)

Get all values for the key.

Parameters
[in]iniThe ini.
[in]keyThe key.
Returns
A string list of values or NULL.

◆ M_ini_write()

char * M_ini_write ( M_ini_t ini,
const M_ini_settings_t info 
)

Write the ini to a string.

Parameters
[in,out]iniThe ini.
[in]infoSettings controlling how the ini should be written.
Returns
The ini as a string.

◆ M_ini_write_file()

M_fs_error_t M_ini_write_file ( M_ini_t ini,
const char *  path,
const M_ini_settings_t info 
)

Write the ini directly to a file.

Parameters
[in,out]iniThe ini.
[in]pathThe file path to write the ini to. This will overwrite the data in the file at path if path is an existing file.
[in]infoSettings controlling how the ini should be written.
Returns
Result.

◆ M_ini_merge()

M_ini_t * M_ini_merge ( const M_ini_t cur_ini,
const M_ini_t new_ini,
const M_ini_t orig_ini,
const M_ini_settings_t info 
)

Merge a new ini into an existing ini.

The merge processes is similar to a three way diff. The current values are compared to the values in new and the original. The merge process is:

  1. Update keys. a. Only in new = in merged. b. Only in cur = in merged. c. In cur and new but not in orig = in merged. d. In orig and cur but not in new = flag handling (default: not in merged). e. In orig and new but not in cur = flag handling (default: not in merged). f. in cur, new and orig = in merged.
  2. Update vals. a. Cur and orig the same but new different = flag handling (default: use new). b. Cur and new the same but orig different = use cur/new. c. New and orig the same but cur different = use cur d. All there are the same = use cur/new/orig.
  3. Update multi-vals. a. In cur and new = use cur/new. b. Only in cur = use cur. c. In cur and orig but not in new = flag (default remove). d. In new but not in cur or orig = use new.
Parameters
[in]cur_iniThe current ini. Contains user changes that differ from the original ini.
[in]new_iniThe new ini.
[in]orig_iniThe original ini that cur_ini is based on.
[in]infoSettings controlling how the ini should be merged.