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 } |
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:
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) |
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.
[in] | key | The 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_cur | The value in the current ini. |
[in] | val_new | The new value. |
enum M_ini_dupkvs_t |
Duplicate key, value pair handling where a key is encountered multiple times.
enum 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.
enum M_ini_multivals_t |
Control how muli value keys are written.
Control how conflicts are handled during merge.
These values all override the default behavior. Default behavior:
char * M_ini_full_key | ( | const char * | section, |
const char * | key | ||
) |
Create a full key from individual parts.
[in] | section | The section the key belongs to. Can be NULL if referencing a key not in a section. |
[in] | key | The key within the section. Can be NULL if referencing a section only. |
void M_ini_split_key | ( | const char * | s, |
char ** | section, | ||
char ** | key | ||
) |
Split a full key into it's individual parts.
[in] | s | The full key. |
[out] | section | The section part. Optional, pass NULL if not needed. May be returned as NULL. |
[out] | key | The key part. Optional, pass NULL if not needed. May be returned as NULL. |
M_ini_settings_t * M_ini_settings_create | ( | void | ) |
Create an ini settings object.
void M_ini_settings_destroy | ( | M_ini_settings_t * | info | ) |
Destroy an ini settings object.
[in] | info | The settings object to destroy. |
unsigned char M_ini_settings_get_element_delim_char | ( | const M_ini_settings_t * | info | ) |
Get the element delimiter character.
[in] | info | The settings. |
unsigned char M_ini_settings_get_quote_char | ( | const M_ini_settings_t * | info | ) |
Get the quote character.
[in] | info | The settings. |
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.
[in] | info | The settings. |
unsigned char M_ini_settings_get_comment_char | ( | const M_ini_settings_t * | info | ) |
Get the comment character.
[in] | info | The settings. |
unsigned char M_ini_settings_get_kv_delim_char | ( | const M_ini_settings_t * | info | ) |
Get the key, value delimiter character.
[in] | info | The settings. |
M_uint32 M_ini_settings_get_padding | ( | const M_ini_settings_t * | info | ) |
Get the padding flags.
[in] | info | The settings. |
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.
[in] | info | The settings. |
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.
[in] | info | The settings. |
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.
[in] | info | The settings. |
M_uint32 M_ini_settings_merger_get_conflict_flags | ( | const M_ini_settings_t * | info | ) |
Get the conflict resolution flags used for merging.
[in] | info | The settings. |
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.
[in] | info | The settings. |
void M_ini_settings_set_element_delim_char | ( | M_ini_settings_t * | info, |
unsigned char | val | ||
) |
Set the element delimiter character.
[in,out] | info | The settings. |
[in] | val | The value to set. |
void M_ini_settings_set_quote_char | ( | M_ini_settings_t * | info, |
unsigned char | val | ||
) |
Set the quote character.
[in,out] | info | The settings. |
[in] | val | The value to set. |
void M_ini_settings_set_escape_char | ( | M_ini_settings_t * | info, |
unsigned char | val | ||
) |
Set the escape character.
[in,out] | info | The settings. |
[in] | val | The value to set. |
void M_ini_settings_set_comment_char | ( | M_ini_settings_t * | info, |
unsigned char | val | ||
) |
Set the comment character.
[in,out] | info | The settings. |
[in] | val | The value to set. |
void M_ini_settings_set_kv_delim_char | ( | M_ini_settings_t * | info, |
unsigned char | val | ||
) |
Set the key value delimiter character.
[in,out] | info | The settings. |
[in] | val | The value to set. |
void M_ini_settings_set_padding | ( | M_ini_settings_t * | info, |
M_uint32 | val | ||
) |
Set the padding flags.
[in,out] | info | The settings. |
[in] | val | The value to set. |
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.
[in,out] | info | The settings. |
[in] | val | The value to set. |
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..
[in,out] | info | The settings. |
[in] | val | The value to set. |
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.
[in,out] | info | The settings. |
[in] | val | The value to set. |
void M_ini_settings_merger_set_conflict_flags | ( | M_ini_settings_t * | info, |
M_uint32 | val | ||
) |
Set the conflict resolution flags used for merging.
[in,out] | info | The settings. |
[in] | val | The value to set. |
void M_ini_settings_merger_set_resolver | ( | M_ini_settings_t * | info, |
M_ini_merge_resolver_t | val | ||
) |
Set the conflict resolution function.
[in,out] | info | The settings. |
[in] | val | The value to set. |
M_ini_t * M_ini_create | ( | M_bool | ignore_whitespace | ) |
Create a new ini object.
[in] | ignore_whitespace | Should whitespace be ignored when comparing section and key names. |
Duplicate an ini.
[in] | ini | The ini to duplicate |
void M_ini_destroy | ( | M_ini_t * | ini | ) |
Destroy the ini.
[in] | ini | The ini to destroy. |
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.
[in] | s | The string to parse. |
[in] | info | The ini settings that control how the ini is structured and should be read. |
[in] | ignore_whitespace | Should whitespace be ignored for section and key comparison. |
[out] | err_line | If an error occurs the line the error is present on. Optional, pass NULL if not needed. |
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.
[in] | path | The full file path to read. |
[in] | info | The ini settings that control how the ini is structured and should be read. |
[in] | ignore_whitespace | Should whitespace be ignored for section and key comparison. |
[out] | err_line | If an error occurs the line the error is present on. Optional, pass NULL if not needed. |
[in] | max_read | The maximum number of bytes to read. |
M_bool M_ini_kv_has_key | ( | const M_ini_t * | ini, |
const char * | key | ||
) |
Does the ini contain a given key.
[in] | ini | The ini. |
[in] | key | The key to check. |
M_list_str_t * M_ini_kv_keys | ( | const M_ini_t * | ini | ) |
Get a list of all keys contained in the ini.
[in] | ini | The ini. |
M_list_str_t * M_ini_kv_sections | ( | const M_ini_t * | ini | ) |
Get a list of sections contained in the ini.
[in] | ini | The ini. |
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.
[in,out] | ini | The ini. |
[in] | key | The section or key to rename. |
[in] | new_key | The new name. |
M_bool M_ini_kv_add_key | ( | M_ini_t * | ini, |
const char * | key | ||
) |
Add a key (without value) to the ini.
[in,out] | ini | The ini. |
key | The key to add. |
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.
[in,out] | ini | The ini. |
[in] | key | The key. |
[in] | val | The vaule. |
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.
[in,out] | ini | The ini. |
[in] | key | The key. |
[in] | val | The vaule. |
M_bool M_ini_kv_remove | ( | M_ini_t * | ini, |
const char * | key | ||
) |
Remove the key from the ini.
[in,out] | ini | The ini. |
[in] | key | The key. |
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.
[in,out] | ini | The ini. |
[in] | key | The key. |
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.
[in,out] | ini | The ini. |
[in] | key | The key. |
[in] | idx | The index of the value to remove. |
size_t M_ini_kv_len | ( | const M_ini_t * | ini, |
const char * | key | ||
) |
Get the number of values for a given key.
[in] | ini | The ini. |
[in] | key | The key. |
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.
[in] | ini | The ini. |
[in] | key | The key. |
[in] | idx | The index of the value to get. |
[out] | val | The 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. |
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.
[in] | ini | The ini. |
[in] | key | The key. |
[in] | idx | The index of the value to get. |
M_list_str_t * M_ini_kv_get_vals | ( | const M_ini_t * | ini, |
const char * | key | ||
) |
Get all values for the key.
[in] | ini | The ini. |
[in] | key | The key. |
char * M_ini_write | ( | M_ini_t * | ini, |
const M_ini_settings_t * | info | ||
) |
Write the ini to a string.
[in,out] | ini | The ini. |
[in] | info | Settings controlling how the ini should be written. |
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.
[in,out] | ini | The ini. |
[in] | path | The file path to write the ini to. This will overwrite the data in the file at path if path is an existing file. |
[in] | info | Settings controlling how the ini should be written. |
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:
[in] | cur_ini | The current ini. Contains user changes that differ from the original ini. |
[in] | new_ini | The new ini. |
[in] | orig_ini | The original ini that cur_ini is based on. |
[in] | info | Settings controlling how the ini should be merged. |