libconfini
Yet another INI parser
|
libconfini header More...
#include <stdio.h>
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | IniFormat |
24-bit bitfield representing the format of an INI file (INI dialect) More... | |
struct | IniStatistics |
Global statistics about an INI file. More... | |
struct | IniDispatch |
Dispatch of a single INI node. More... | |
Macros | |
#define | INIFORMAT_TABLE_AS(_____) |
Calls a user-given macro for each row of the table. More... | |
#define | INIFORMAT_HAS_NO_ESC(FORMAT) |
Checks whether a format does not support escape sequences. More... | |
#define | CONFINI_ERROR 252 |
Error mask (flags not present in user-generated interruptions) More... | |
Typedefs | |
typedef struct IniFormat | IniFormat |
24-bit bitfield representing the format of an INI file (INI dialect) More... | |
typedef struct IniStatistics | IniStatistics |
Global statistics about an INI file. More... | |
typedef struct IniDispatch | IniDispatch |
Dispatch of a single INI node. More... | |
typedef uint32_t | IniFormatNum |
The unique ID number of an INI format (24-bit maximum) More... | |
typedef int(* | IniStatsHandler) (IniStatistics *statistics, void *user_data) |
Callback function for handling an IniStatistics structure. More... | |
typedef int(* | IniDispHandler) (IniDispatch *dispatch, void *user_data) |
Callback function for handling an IniDispatch structure. More... | |
typedef int(* | IniStrHandler) (char *ini_string, size_t string_length, size_t string_num, IniFormat format, void *user_data) |
Callback function for handling an INI string. More... | |
typedef int(* | IniSubstrHandler) (const char *ini_string, size_t fragm_offset, size_t fragm_length, size_t fragm_num, IniFormat format, void *user_data) |
Callback function for handling a selected fragment of an INI string. More... | |
Functions | |
int | load_ini_file (FILE *const ini_file, const IniFormat format, const IniStatsHandler f_init, const IniDispHandler f_foreach, void *const user_data) |
Parses an INI file and dispatches its content using a FILE structure as argument. More... | |
int | load_ini_path (const char *const path, const IniFormat format, const IniStatsHandler f_init, const IniDispHandler f_foreach, void *const user_data) |
Parses an INI file and dispatches its content using a path as argument. More... | |
_Bool | ini_string_match_ss (const char *const simple_string_a, const char *const simple_string_b, const IniFormat format) |
Compares two simple strings and checks if they match. More... | |
_Bool | ini_string_match_si (const char *const simple_string, const char *const ini_string, const IniFormat format) |
Compares a simple string and an INI string and and checks if they match. More... | |
_Bool | ini_string_match_ii (const char *const ini_string_a, const char *const ini_string_b, const IniFormat format) |
Compares two INI strings and checks if they match. More... | |
_Bool | ini_array_match (const char *const ini_string_a, const char *const ini_string_b, const char delimiter, const IniFormat format) |
Compares two INI arrays and checks if they match. More... | |
size_t | ini_unquote (char *const ini_string, const IniFormat format) |
Unescapes \' , \" , and \\ and removes all unescaped quotes (if single/double quotes are considered metacharacters in respect to the format given) More... | |
size_t | ini_string_parse (char *const ini_string, const IniFormat format) |
Unescapes \' , \" , and \\ and removes all unescaped quotes (if single/double quotes are considered metacharacters in respect to the format given); if the format allows it, sequences of one or more spaces out of quotes will be collapsed. More... | |
size_t | ini_array_get_length (const char *const ini_string, const char delimiter, const IniFormat format) |
Gets the length of a stringified INI array in number of members. More... | |
int | ini_array_foreach (const char *const ini_string, const char delimiter, const IniFormat format, const IniSubstrHandler f_foreach, void *const user_data) |
Calls a custom function for each member of a stringified INI array, without modifying the content of the buffer – useful for read-only (const ) stringified arrays. More... | |
size_t | ini_array_shift (const char **const ini_strptr, const char delimiter, const IniFormat format) |
Shifts the location pointed by ini_strptr to the next member of the INI array (without modifying the content of the buffer), or to NULL if the INI array has no more members – useful for read-only (const ) stringified arrays. More... | |
size_t | ini_array_collapse (char *const ini_string, const char delimiter, const IniFormat format) |
Compresses the distribution of the data of a stringified INI array by removing all the white spaces that surround its delimiters, empty quotes, collapsable spaces, etc. More... | |
char * | ini_array_break (char *const ini_string, const char delimiter, const IniFormat format) |
Replaces the first delimiter found (together with the spaces that surround it) with \0 More... | |
char * | ini_array_release (char **ini_strptr, const char delimiter, const IniFormat format) |
Replaces the first delimiter found (together with the spaces that surround it) with \0 , then shifts the location pointed by ini_strptr to the next member of the INI array, or to NULL if the INI array has no more members. More... | |
int | ini_array_split (char *const ini_string, const char delimiter, const IniFormat format, const IniStrHandler f_foreach, void *const user_data) |
Splits a stringified INI array into NUL-separated members and calls a custom function for each member. More... | |
void | ini_global_set_lowercase_mode (_Bool lowercase) |
Sets the value of the global variable INI_GLOBAL_LOWERCASE_MODE. More... | |
void | ini_global_set_implicit_value (char *const implicit_value, const size_t implicit_v_len) |
Sets the value to be to be assigned to implicit keys. More... | |
IniFormatNum | ini_fton (const IniFormat format) |
Calculates the IniFormatNum of an IniFormat. More... | |
IniFormat | ini_ntof (IniFormatNum format_id) |
Constructs a new IniFormat according to an IniFormatNum. More... | |
int | ini_get_bool (const char *const ini_string, const int return_value) |
Checks whether a string matches one of the booleans listed in the private constant INI_BOOLEANS (case-insensitive) More... | |
Variables | |
int(*const | ini_get_int )(const char *ini_string) |
Link to atoi() More... | |
long int(*const | ini_get_lint )(const char *ini_string) |
Link to atol() More... | |
long long int(*const | ini_get_llint )(const char *ini_string) |
Link to atoll() More... | |
double(*const | ini_get_float )(const char *ini_string) |
Link to atof() More... | |
static const IniFormat | INI_DEFAULT_FORMAT = { INI_EQUALS , 0 , INI_DISABLED_OR_COMMENT , INI_DISABLED_OR_COMMENT , INI_ABSOLUTE_AND_RELATIVE , INI_MULTILINE_EVERYWHERE , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , } |
A model format for standard INI files. More... | |
static const IniFormat | INI_UNIXLIKE_FORMAT = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, } |
A model format for Unix-like .conf files (space characters are delimiters between keys and values) More... | |
_Bool | INI_GLOBAL_LOWERCASE_MODE |
If set to true , key and section names in case-insensitive INI formats will be dispatched lowercase, verbatim otherwise (default value: false ) More... | |
char * | INI_GLOBAL_IMPLICIT_VALUE |
Value to be assigned to implicit keys (default value: NULL ) More... | |
size_t | INI_GLOBAL_IMPLICIT_V_LEN |
Length of the value assigned to implicit keys – this may be any unsigned number, independently of the real length of INI_GLOBAL_IMPLICIT_VALUE (default value: 0 ) More... | |
libconfini header
#define CONFINI_ERROR 252 |
Error mask (flags not present in user-generated interruptions)
#define INIFORMAT_HAS_NO_ESC | ( | FORMAT | ) |
Checks whether a format does not support escape sequences.
#define INIFORMAT_TABLE_AS | ( | _____ | ) |
Calls a user-given macro for each row of the table.
Content of the table:
typedef struct IniDispatch IniDispatch |
Dispatch of a single INI node.
int(* IniDispHandler)(IniDispatch *dispatch, void *user_data) |
Callback function for handling an IniDispatch structure.
dispatch | A pointer to the IniDispatch to handle |
user_data | The custom argument previously passed to the caller function |
24-bit bitfield representing the format of an INI file (INI dialect)
typedef uint32_t IniFormatNum |
The unique ID number of an INI format (24-bit maximum)
typedef struct IniStatistics IniStatistics |
Global statistics about an INI file.
int(* IniStatsHandler)(IniStatistics *statistics, void *user_data) |
Callback function for handling an IniStatistics structure.
statistics | A pointer to the IniStatistics to handle |
user_data | The custom argument previously passed to the caller function |
int(* IniStrHandler)(char *ini_string, size_t string_length, size_t string_num, IniFormat format, void *user_data) |
Callback function for handling an INI string.
ini_string | The INI string to handle |
string_length | The length of the INI string in bytes |
string_num | The unique number that identifies ini_string within a sequence of INI strings; it equals zero if ini_string is the first or the only member of the sequence |
format | The format of the INI file from which ini_string has been extracted |
user_data | The custom argument previously passed to the caller function |
int(* IniSubstrHandler)(const char *ini_string, size_t fragm_offset, size_t fragm_length, size_t fragm_num, IniFormat format, void *user_data) |
Callback function for handling a selected fragment of an INI string.
ini_string | The INI string containing the fragment to handle |
fragm_offset | The offset of the selected fragment in bytes |
fragm_length | The length of the selected fragment in bytes |
fragm_num | The unique number that identifies the selected fragment within a sequence of fragments of ini_string ; it equals zero if the fragment is the first or the only member of the sequence |
format | The format of the INI file from which ini_string has been extracted |
user_data | The custom argument previously passed to the caller function |
enum ConfiniInterruptNo |
Error codes.
enum IniCommentMarker |
Possible values of IniFormat::semicolon_marker and IniFormat::hash_marker (i.e., meaning of /\s+[#;]/
in respect to a format)
enum IniDelimiters |
Most used key-value and array delimiters (but a delimiter may also be any other ASCII character)
enum IniMultiline |
Possible values of IniFormat::multiline_nodes.
enum IniNodeType |
INI node types.
enum IniSectionPaths |
Possible values of IniFormat::section_paths.
char* ini_array_break | ( | char *const | ini_string, |
const char | delimiter, | ||
const IniFormat | format | ||
) |
Replaces the first delimiter found (together with the spaces that surround it) with \0
ini_string | The stringified array – it can be NULL |
delimiter | The delimiter between the array members – if zero (see INI_ANY_SPACE), any space is delimiter (/(?:\\(?:\n\r?|\r\n?)|[\t \v\f])+/ ) |
format | The format of the INI file |
NULL
if the remaining array is emptyUsually ini_string
comes from an IniDispatch (but any other string may be used as well).
Similarly to strtok_r()
this function can be used only once for a given string.
delimiter
matches a metacharacter within the format given ('\\'
, '\''
or '\"'
), its role as metacharacter will have higher priority than its role as delimiter (i.e., the array will have no delimiters and will contain only one member).size_t ini_array_collapse | ( | char *const | ini_string, |
const char | delimiter, | ||
const IniFormat | format | ||
) |
Compresses the distribution of the data of a stringified INI array by removing all the white spaces that surround its delimiters, empty quotes, collapsable spaces, etc.
ini_string | The stringified array |
delimiter | The delimiter between the array members – if zero (INI_ANY_SPACE ) any space is delimiter (/(?:\\(?:\n\r?|\r\n?)|[\t \v\f])+/ ) |
format | The format of the INI file |
Out of quotes similar to ECMAScript ini_string.replace(new RegExp("^\\s+|\\s*(?:(" + delimiter + ")\\s*|($))", "g"), "$1$2")
. If INI_ANY_SPACE (0
) is used as delimiter, one or more different spaces (/[\t \v\f\n\r]+/
) will be always collapsed to one space, independently of what the format says.
Usually ini_string
comes from an IniDispatch (but any other string may be used as well).
This function can be useful before invoking memcpy()
using ini_string
as source, when saving memory is a priority.
The format
argument is used for the following fields:
format.no_single_quotes
format.no_double_quotes
format.do_not_collapse_values
format.preserve_empty_quotes
Examples:
first , second , third , etc.
first,second,third,etc.
INI_ANY_SPACE
as delimiter: first second third etc.
first second third etc.
delimiter
matches a metacharacter within the format given ('\\'
, '\''
or '\"'
), its role as metacharacter will have higher priority than its role as delimiter (i.e., the array will have no delimiters and will contain only one member).int ini_array_foreach | ( | const char *const | ini_string, |
const char | delimiter, | ||
const IniFormat | format, | ||
const IniSubstrHandler | f_foreach, | ||
void *const | user_data | ||
) |
Calls a custom function for each member of a stringified INI array, without modifying the content of the buffer – useful for read-only (const
) stringified arrays.
ini_string | The stringified array (it cannot be NULL ) |
delimiter | The delimiter between the array members – if zero (see INI_ANY_SPACE), any space is delimiter (/(?:\\(?:\n\r?|\r\n?)|[\t \v\f])+/ ) |
format | The format of the INI file |
f_foreach | The function that will be invoked for each array member |
user_data | A custom argument, or NULL |
enum
ConfiniInterruptNo)Usually ini_string
comes from an IniDispatch (but any other string may be used as well).
The function f_foreach
(see IniSubstrHandler data type) will be invoked with six arguments: ini_string
, memb_offset
(the offset of the member in bytes), memb_length
(the length of the member in bytes), memb_num
(the offset of the member in number of members), format
(the format of the INI file), user_data
(the custom argument user_data
previously passed). If f_foreach
returns a non-zero value the function ini_array_foreach() will be interrupted.
delimiter
matches a metacharacter within the format given ('\\'
, '\''
or '\"'
), its role as metacharacter will have higher priority than its role as delimiter (i.e., the array will have no delimiters and will contain only one member)..
size_t ini_array_get_length | ( | const char *const | ini_string, |
const char | delimiter, | ||
const IniFormat | format | ||
) |
Gets the length of a stringified INI array in number of members.
ini_string | The stringified array (it can be NULL ) |
delimiter | The delimiter between the array members – if zero (see INI_ANY_SPACE), any space is delimiter (/(?:\\(?:\n\r?|\r\n?)|[\t \v\f])+/ ) |
format | The format of the INI file |
Usually ini_string
comes from an IniDispatch (but any other string may be used as well).
delimiter
matches a metacharacter within the format given ('\\'
, '\''
or '\"'
), its role as metacharacter will have higher priority than its role as delimiter (i.e., the array will have no delimiters and will contain only one member). _Bool ini_array_match | ( | const char *const | ini_string_a, |
const char *const | ini_string_b, | ||
const char | delimiter, | ||
const IniFormat | format | ||
) |
Compares two INI arrays and checks if they match.
ini_string_a | The first INI array |
ini_string_b | The second INI array |
delimiter | The delimiter between the array members – if zero (see INI_ANY_SPACE), any space is delimiter (/(?:\\(?:\n\r?|\r\n?)|[\t \v\f])+/ ) |
format | The format of the INI file |
true
if the two arrays match, false
otherwiseINI strings are the strings typically dispatched by load_ini_file() and load_ini_path(), which may contain quotes and the three escape sequences \\
, \'
and \"
.
In order to be suitable for both names and values, this function always considers sequences of one or more spaces out of quotes in both strings as collapsed, even when format.do_not_collapse_values
is set to true
.
This function can be used, with '.'
as delimiter, to compare section paths.
This function grants that the result of the comparison between two INI arrays will always match the the literal comparison between the individual members of both arrays after these have been parsed, one by one, by ini_string_parse() (with format.do_not_collapse_values
set to false
).
The format
argument is used for the following fields:
format.case_sensitive
format.no_double_quotes
format.no_single_quotes
format.multiline_nodes
char* ini_array_release | ( | char **const | ini_strptr, |
const char | delimiter, | ||
const IniFormat | format | ||
) |
Replaces the first delimiter found (together with the spaces that surround it) with \0
, then shifts the location pointed by ini_strptr
to the next member of the INI array, or to NULL
if the INI array has no more members.
ini_strptr | The memory location of the stringified array – it cannot be NULL , but it can point to NULL |
delimiter | The delimiter between the array members – if zero (see INI_ANY_SPACE), any space is delimiter (/(?:\\(?:\n\r?|\r\n?)|[\t \v\f])+/ ) |
format | The format of the INI file |
Usually ini_strptr
comes from an IniDispatch (but any other string may be used as well).
Similarly to strtok_r()
this function can be used only once for a given string.
delimiter
matches a metacharacter within the format given ('\\'
, '\''
or '\"'
), its role as metacharacter will have higher priority than its role as delimiter (i.e., the array will have no delimiters and will contain only one member).size_t ini_array_shift | ( | const char **const | ini_strptr, |
const char | delimiter, | ||
const IniFormat | format | ||
) |
Shifts the location pointed by ini_strptr
to the next member of the INI array (without modifying the content of the buffer), or to NULL
if the INI array has no more members – useful for read-only (const
) stringified arrays.
ini_strptr | The memory location of the stringified array – it cannot be NULL , but it can point to NULL |
delimiter | The delimiter between the array members – if zero (see INI_ANY_SPACE), any space is delimiter (/(?:\\(?:\n\r?|\r\n?)|[\t \v\f])+/ ) |
format | The format of the INI file |
Usually ini_strptr
comes from an IniDispatch (but any other string may be used as well).
delimiter
matches a metacharacter within the format given ('\\'
, '\''
or '\"'
), its role as metacharacter will have higher priority than its role as delimiter (i.e., the array will have no delimiters and will contain only one member).int ini_array_split | ( | char *const | ini_string, |
const char | delimiter, | ||
const IniFormat | format, | ||
const IniStrHandler | f_foreach, | ||
void *const | user_data | ||
) |
Splits a stringified INI array into NUL-separated members and calls a custom function for each member.
ini_string | The stringified array (it cannot be NULL ) |
delimiter | The delimiter between the array members – if zero (see INI_ANY_SPACE), any space is delimiter (/(?:\\(?:\n\r?|\r\n?)|[\t \v\f])+/ ) |
format | The format of the INI file |
f_foreach | The function that will be invoked for each array member |
user_data | A custom argument, or NULL |
enum
ConfiniInterruptNo)Usually ini_string
comes from an IniDispatch (but any other string may be used as well).
The function f_foreach
(see IniStrHandler data type) will be invoked with five arguments: member
(the member of the array), memb_length
(the length of the member in bytes), memb_num
(the offset of the member in number of members), format
(the format of the INI file), user_data
(the custom argument user_data
previously passed). If f_foreach
returns a non-zero value the function ini_array_split() will be interrupted.
Similarly to strtok_r()
this function can be used only once for a given string.
delimiter
matches a metacharacter within the format given ('\\'
, '\''
or '\"'
), its role as metacharacter will have higher priority than its role as delimiter (i.e., the array will have no delimiters and will contain only one member)..
IniFormatNum ini_fton | ( | const IniFormat | source | ) |
Calculates the IniFormatNum of an IniFormat.
source | The IniFormat to compute |
int ini_get_bool | ( | const char *const | ini_string, |
const int | return_value | ||
) |
Checks whether a string matches one of the booleans listed in the private constant INI_BOOLEANS (case-insensitive)
ini_string | A string to be checked |
return_value | A value that is returned if no matching boolean has been found |
return_value
if no boolean has been foundUsually ini_string
comes from an IniDispatch (but any other string may be used as well).
void ini_global_set_implicit_value | ( | char *const | implicit_value, |
const size_t | implicit_v_len | ||
) |
Sets the value to be to be assigned to implicit keys.
implicit_value | The string to be used as implicit value (usually "YES" , or "TRUE" ) |
implicit_v_len | The length of implicit_value (usually 0 , independently of its real length) |
void ini_global_set_lowercase_mode | ( | _Bool | lowercase | ) |
Sets the value of the global variable INI_GLOBAL_LOWERCASE_MODE.
lowercase | The new value |
If lowercase
is true
, key and section names in case-insensitive INI formats will be dispatched lowercase, verbatim otherwise (default value: true
).
IniFormat ini_ntof | ( | IniFormatNum | format_num | ) |
Constructs a new IniFormat according to an IniFormatNum.
format_num | The IniFormatNum to parse |
format_num
>
16777215
it will be truncated to 24 bits. _Bool ini_string_match_ii | ( | const char *const | ini_string_a, |
const char *const | ini_string_b, | ||
const IniFormat | format | ||
) |
Compares two INI strings and checks if they match.
ini_string_a | The first INI string unescaped according to format |
ini_string_b | The second INI string unescaped according to format |
format | The format of the INI file |
true
if the two strings match, false
otherwiseINI strings are the strings typically dispatched by load_ini_file() and load_ini_path(), which may contain quotes and the three escape sequences \\
, \'
and \"
.
In order to be suitable for both names and values, this function always considers sequences of one or more spaces out of quotes in both strings as collapsed, even when format.do_not_collapse_values
is set to true
.
This function grants that the result of the comparison between two INI strings
will always match the result of the literal comparison between the same two INI strings after these have been parsed by ini_string_parse() when format.do_not_collapse_values
is set to false
.
The format
argument is used for the following fields:
format.case_sensitive
format.no_double_quotes
format.no_single_quotes
format.multiline_nodes
_Bool ini_string_match_si | ( | const char *const | simple_string, |
const char *const | ini_string, | ||
const IniFormat | format | ||
) |
Compares a simple string and an INI string and and checks if they match.
ini_string | The INI string escaped according to format |
simple_string | The simple string |
format | The format of the INI file |
true
if the two strings match, false
otherwiseINI strings are the strings typically dispatched by load_ini_file() and load_ini_path(), which may contain quotes and the three escape sequences \\
, \'
and \"
. Simple strings are user-given strings or the result of ini_string_parse().
In order to be suitable for both names and values, this function always considers sequences of one or more spaces out of quotes in the INI string as collapsed, even when format.do_not_collapse_values
is set to true
.
This function grants that the result of the comparison between a simple string and an INI string
will always match the result of the literal comparison between the simple string and the INI string after the latter has been parsed by ini_string_parse() when format.do_not_collapse_values
is set to false
.
The format
argument is used for the following fields:
format.case_sensitive
format.no_double_quotes
format.no_single_quotes
format.multiline_nodes
_Bool ini_string_match_ss | ( | const char *const | simple_string_a, |
const char *const | simple_string_b, | ||
const IniFormat | format | ||
) |
Compares two simple strings and checks if they match.
simple_string_a | The first simple string |
simple_string_b | The second simple string |
format | The format of the INI file |
true
if the two strings match, false
otherwiseSimple strings are user-given strings or the result of ini_string_parse(). The format
argument is used for the following fields:
format.case_sensitive
size_t ini_string_parse | ( | char *const | ini_string, |
const IniFormat | format | ||
) |
Unescapes \'
, \"
, and \\
and removes all unescaped quotes (if single/double quotes are considered metacharacters in respect to the format given); if the format allows it, sequences of one or more spaces out of quotes will be collapsed.
ini_string | The string to be unescaped |
format | The format of the INI file |
This function is meant to be used to parse values. In order to parse key and section names please use ini_unquote() instead.
If you only need to compare ini_string
with another string, consider to use ini_string_match_si() and ini_string_match_ii() instead of parsing the former and perform a simple comparison afterwards. These two functions are in fact able to check directly for equality between unparsed INI strings without actually modifying them.
Usually ini_string
comes from an IniDispatch (but any other string may be used as well). If format.do_not_collapse_values
is set to non-zero, spaces surrounding empty quotes will be collapsed together with the latter.
The format
argument is used for the following fields:
format.no_single_quotes
format.no_double_quotes
format.multiline_nodes
format.do_not_collapse_values
format.multiline_nodes
is used only to figure out whether there are escape sequences or not. For all other purposes new line characters will be considered to be equal to any other space character, even if the format is not multi-line – in fact new line characters should never appear in non-multi-line formats .size_t ini_unquote | ( | char *const | ini_string, |
const IniFormat | format | ||
) |
Unescapes \'
, \"
, and \\
and removes all unescaped quotes (if single/double quotes are considered metacharacters in respect to the format given)
ini_string | The string to be unescaped |
format | The format of the INI file |
This function is very similar to ini_string_parse(), except that does not bother collapsing the sequences of more than one space that might result from removing empty quotes. Its purpose is to be used to parse key and section names, since these are always dispatched as already collapsed. In order to parse values, or array parts listed in values, please use ini_string_parse() instead.
If you only need to compare ini_string
with another string, consider to use ini_string_match_si() and ini_string_match_ii() instead of parsing the former and perform a simple comparison afterwards. These two functions are in fact able to check directly for equality between unparsed INI strings without actually modifiyng them.
Usually ini_string
comes from an IniDispatch (but any other string may be used as well). If the string does not contain quotes, or if quotes are considered to be normal characters, no changes will be made.
The format
argument is used for the following fields:
format.no_single_quotes
format.no_double_quotes
format.multiline_nodes
int load_ini_file | ( | FILE *const | ini_file, |
const IniFormat | format, | ||
const IniStatsHandler | f_init, | ||
const IniDispHandler | f_foreach, | ||
void *const | user_data | ||
) |
Parses an INI file and dispatches its content using a FILE
structure as argument.
ini_file | The FILE handle pointing to the INI file to parse |
format | The format of the INI file |
f_init | The function that will be invoked before the first dispatch, or NULL |
f_foreach | The function that will be invoked for each dispatch, or NULL |
user_data | A custom argument, or NULL |
enum
ConfiniInterruptNo)The ini_file
parameter must be a FILE
handle with read privileges. In some platforms, such as Microsoft Windows, it might be needed to add the binary specifier to the mode string ("b"
) in order to prevent discrepancies between the physical size of the file and its computed size:
The parsing algorithms used by libconfini are able to parse any type of file encoded in 8-bit code units, as long as the characters that match the regular expression /[\s\[\]\.\\;#"']/
represent the same code points they represent in ASCII, independently of platform-specific conventions (see, for example, UTF-8 and ISO-8859-1).
NUL
characters, if present in the file, will be removed from the dispatched strings.The function f_init
(see IniStatsHandler data type) will be invoked with two arguments: statistics
(a pointer to an IniStatistics structure containing some properties about the file read) and user_data
(the custom argument user_data
previously passed). If f_init
returns a non-zero value the caller function will be interrupted.
The function f_foreach
(see IniDispHandler data type) will be invoked with two arguments: dispatch
(a pointer to an IniDispatch structure containing the parsed member of the INI file) and user_data
(the custom argument user_data
previously passed). If f_foreach
returns a non-zero value the caller function will be interrupted.
int load_ini_path | ( | const char *const | path, |
const IniFormat | format, | ||
const IniStatsHandler | f_init, | ||
const IniDispHandler | f_foreach, | ||
void *const | user_data | ||
) |
Parses an INI file and dispatches its content using a path as argument.
path | The path of the INI file |
format | The format of the INI file |
f_init | The function that will be invoked before the first dispatch, or NULL |
f_foreach | The function that will be invoked for each dispatch, or NULL |
user_data | A custom argument, or NULL |
enum
ConfiniInterruptNo)The parsing algorithms used by libconfini are able to parse any type of file encoded in 8-bit code units, as long as the characters that match the regular expression /[\s\[\]\.\\;#"']/
represent the same code points they represent in ASCII, independently of platform-specific conventions (see, for example, UTF-8 and ISO-8859-1).
NUL
characters, if present in the file, will be removed from the dispatched strings.For the two parameters f_init
and f_foreach
see function load_ini_file().
|
static |
A model format for standard INI files.
ini_get_float |
Link to atof()
ini_get_int |
Link to atoi()
ini_get_lint |
Link to atol()
ini_get_llint |
Link to atoll()
size_t INI_GLOBAL_IMPLICIT_V_LEN |
Length of the value assigned to implicit keys – this may be any unsigned number, independently of the real length of INI_GLOBAL_IMPLICIT_VALUE (default value: 0
)
char* INI_GLOBAL_IMPLICIT_VALUE |
Value to be assigned to implicit keys (default value: NULL
)
_Bool INI_GLOBAL_LOWERCASE_MODE |
If set to true
, key and section names in case-insensitive INI formats will be dispatched lowercase, verbatim otherwise (default value: false
)
|
static |
A model format for Unix-like .conf files (space characters are delimiters between keys and values)