15 #ifndef _LIBCONFINI_HEADER_ 16 #define _LIBCONFINI_HEADER_ 28 #define _LIBCONFINI_INIFORMAT_DESCR_(NAME, OFFSET, SIZE, DEFVAL) \ 29 unsigned char NAME:SIZE; 30 #define _LIBCONFINI_DEFAULT_FMT_DESCR_(NAME, OFFSET, SIZE, DEFVAL) DEFVAL, 31 #define _LIBCONFINI_UNIXLIKE_FMT_DESCR_(NAME, OFFSET, SIZE, DEFVAL) 0, 32 #define _LIBCONFINI_INIFORMAT_TYPE_ \ 33 struct IniFormat { INIFORMAT_TABLE_AS(_LIBCONFINI_INIFORMAT_DESCR_) } 34 #define _LIBCONFINI_DEFAULT_FORMAT_ \ 35 { INIFORMAT_TABLE_AS(_LIBCONFINI_DEFAULT_FMT_DESCR_) } 36 #define _LIBCONFINI_UNIXLIKE_FORMAT_ \ 37 { INIFORMAT_TABLE_AS(_LIBCONFINI_UNIXLIKE_FMT_DESCR_) } 52 #define INIFORMAT_TABLE_AS(_____) 56 _____( delimiter_symbol, 0, 7, INI_EQUALS ) \ 57 _____( case_sensitive, 7, 1, 0 ) 59 _____( semicolon_marker, 8, 2, INI_DISABLED_OR_COMMENT ) \ 60 _____( hash_marker, 10, 2, INI_DISABLED_OR_COMMENT ) \ 61 _____( section_paths, 12, 2, INI_ABSOLUTE_AND_RELATIVE ) \ 62 _____( multiline_nodes, 14, 2, INI_MULTILINE_EVERYWHERE ) 64 _____( no_single_quotes, 16, 1, 0 ) \ 65 _____( no_double_quotes, 17, 1, 0 ) \ 66 _____( no_spaces_in_names, 18, 1, 0 ) \ 67 _____( implicit_is_not_empty, 19, 1, 0 ) \ 68 _____( do_not_collapse_values, 20, 1, 0 ) \ 69 _____( preserve_empty_quotes, 21, 1, 0 ) \ 70 _____( disabled_after_space, 22, 1, 0 ) \ 71 _____( disabled_can_be_implicit, 23, 1, 0 ) 78 #define INIFORMAT_HAS_NO_ESC(FORMAT) \ 79 (FORMAT.multiline_nodes == INI_NO_MULTILINE && \ 80 FORMAT.no_double_quotes && FORMAT.no_single_quotes) 148 size_t string_length,
159 const char * ini_string,
173 register char *
const ini_buffer,
174 const size_t ini_length,
178 void *
const user_data
183 FILE *
const ini_file,
187 void *
const user_data
192 const char *
const path,
196 void *
const user_data
201 const char *
const simple_string_a,
202 const char *
const simple_string_b,
208 const char *
const simple_string,
209 const char *
const ini_string,
215 const char *
const ini_string_a,
216 const char *
const ini_string_b,
222 const char *
const ini_string_a,
223 const char *
const ini_string_b,
224 const char delimiter,
230 char *
const ini_string,
236 char *
const ini_string,
242 const char *
const ini_string,
243 const char delimiter,
249 const char *
const ini_string,
250 const char delimiter,
253 void *
const user_data
258 const char **
const ini_strptr,
259 const char delimiter,
265 char *
const ini_string,
266 const char delimiter,
272 char *
const ini_string,
273 const char delimiter,
280 const char delimiter,
286 char *
const ini_string,
287 const char delimiter,
290 void *
const user_data
300 char *
const implicit_value,
301 const size_t implicit_v_len
316 const char *
const ini_string,
317 const int return_value
326 const char * ini_string
331 const char * ini_string
336 const char * ini_string
341 const char * ini_string
352 #define CONFINI_ERROR 252 498 #undef _LIBCONFINI_UNIXLIKE_FORMAT_ 499 #undef _LIBCONFINI_DEFAULT_FORMAT_ 500 #undef _LIBCONFINI_INIFORMAT_TYPE_ 501 #undef _LIBCONFINI_UNIXLIKE_FMT_DESCR_ 502 #undef _LIBCONFINI_DEFAULT_FMT_DESCR_ 503 #undef _LIBCONFINI_INIFORMAT_DESCR_ void ini_global_set_lowercase_mode(_Bool lowercase)
Sets the value of the global variable INI_GLOBAL_LOWERCASE_MODE.
Definition: confini.c:4589
Definition: confini.h:447
static const IniFormat INI_UNIXLIKE_FORMAT
A model format for Unix-like .conf files (space characters are delimiters between keys and values)
Definition: confini.h:469
_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.
Definition: confini.c:2794
Definition: confini.h:378
Definition: confini.h:386
Definition: confini.h:367
Definition: confini.h:444
Definition: confini.h:365
Definition: confini.h:361
_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.
Definition: confini.c:3245
Definition: confini.h:453
Definition: confini.h:434
int(* IniDispHandler)(IniDispatch *dispatch, void *user_data)
Callback function for handling an IniDispatch structure.
Definition: confini.h:137
size_t v_len
Definition: confini.h:113
struct IniDispatch IniDispatch
Dispatch of a single INI node.
Definition: confini.h:385
Definition: confini.h:381
Definition: confini.h:428
Global statistics about an INI file.
Definition: confini.h:96
long int(*const ini_get_lint)(const char *ini_string)
Link to atol()
Definition: confini.c:4757
uint8_t type
Definition: confini.h:108
Definition: confini.h:363
IniFormatNum ini_fton(const IniFormat format)
Calculates the IniFormatNum of an IniFormat.
Definition: confini.c:4632
Definition: confini.h:401
Definition: confini.h:366
const size_t bytes
Definition: confini.h:98
static const IniFormat INI_DEFAULT_FORMAT
A model format for standard INI files.
Definition: confini.h:461
IniDelimiters
Most used key-value and array delimiters (but a delimiter may also be any other ASCII character)
Definition: confini.h:394
char * data
Definition: confini.h:109
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 met...
Definition: confini.c:3606
Definition: confini.h:425
IniMultiline
Possible values of IniFormat::multiline_nodes.
Definition: confini.h:443
IniNodeType
INI node types.
Definition: confini.h:376
Definition: confini.h:382
struct IniStatistics IniStatistics
Global statistics about an INI file.
Definition: confini.h:368
Definition: confini.h:384
size_t INI_GLOBAL_IMPLICIT_V_LEN
Length of the value assigned to implicit keys – this may be any unsigned number, independently of the...
Definition: confini.c:4772
Definition: confini.h:395
IniSectionPaths
Possible values of IniFormat::section_paths.
Definition: confini.h:424
int(*const ini_get_int)(const char *ini_string)
Link to atoi()
Definition: confini.c:4755
Definition: confini.h:411
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.
Definition: confini.c:2730
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
Definition: confini.c:4325
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 ...
Definition: confini.c:3910
Definition: confini.h:400
Definition: confini.h:383
int(* IniStatsHandler)(IniStatistics *statistics, void *user_data)
Callback function for handling an IniStatistics structure.
Definition: confini.h:128
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...
Definition: confini.c:4700
Definition: confini.h:359
IniCommentMarker
Possible values of IniFormat::semicolon_marker and IniFormat::hash_marker (i.e., meaning of /\s+[#;]/...
Definition: confini.h:410
char * value
Definition: confini.h:110
Definition: confini.h:416
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 t...
Definition: confini.c:4127
IniFormat ini_ntof(IniFormatNum format_id)
Constructs a new IniFormat according to an IniFormatNum.
Definition: confini.c:4654
size_t d_len
Definition: confini.h:112
_Bool INI_GLOBAL_LOWERCASE_MODE
If set to true, key and section names in case-insensitive INI formats will be dispatched lowercase,...
Definition: confini.c:4768
Definition: confini.h:450
Definition: confini.h:398
uint32_t IniFormatNum
The unique ID number of an INI format (24-bit maximum)
Definition: confini.h:122
ConfiniInterruptNo
Error codes.
Definition: confini.h:358
_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.
Definition: confini.c:3054
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.
Definition: confini.h:158
int strip_ini_cache(register char *const ini_buffer, const size_t ini_length, const IniFormat format, const IniStatsHandler f_init, const IniDispHandler f_foreach, void *const user_data)
Parses and tokenizes a buffer containing an INI file, then dispatches its content to a custom callbac...
Definition: confini.c:2161
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,...
Definition: confini.c:4402
size_t at_len
Definition: confini.h:114
Definition: confini.h:377
Definition: confini.h:399
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...
Definition: confini.c:4470
size_t dispatch_id
Definition: confini.h:115
double(*const ini_get_float)(const char *ini_string)
Link to atof()
Definition: confini.c:4761
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.
Definition: confini.c:4615
const size_t members
Definition: confini.h:99
_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.
Definition: confini.c:2889
Dispatch of a single INI node.
Definition: confini.h:106
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.
Definition: confini.c:2661
const char * append_to
Definition: confini.h:111
Definition: confini.h:414
size_t ini_unquote(char *const ini_string, const IniFormat format)
Unescapes \', \", and \\ and removes all unescaped quotes (if single/double quotes are considered met...
Definition: confini.c:3477
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.
Definition: confini.c:3793
char * INI_GLOBAL_IMPLICIT_VALUE
Value to be assigned to implicit keys (default value: NULL)
Definition: confini.c:4770
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.
Definition: confini.h:146
Definition: confini.h:413
struct IniFormat IniFormat
24-bit bitfield representing the format of an INI file (INI dialect)
const IniFormat format
Definition: confini.h:107
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 ...
Definition: confini.c:4036
Definition: confini.h:431
const IniFormat format
Definition: confini.h:97
long long int(*const ini_get_llint)(const char *ini_string)
Link to atoll()
Definition: confini.c:4759