diff --git a/ini/ini_configobj.h b/ini/ini_configobj.h index 6f2d692..12920db 100644 --- a/ini/ini_configobj.h +++ b/ini/ini_configobj.h @@ -363,6 +363,8 @@ enum ERR_PARSE { #define INI_PARSE_NOTAB 0x0004 /** @brief Do not allow C-style comments */ #define INI_PARSE_NO_C_COMMENTS 0x0008 +/** @brief Skip lines that are not KVPs */ +#define INI_PARSE_IGNORE_NON_KVP 0x0010 /** * @} diff --git a/ini/ini_parse.c b/ini/ini_parse.c index 0de4e35..e5baeca 100644 --- a/ini/ini_parse.c +++ b/ini/ini_parse.c @@ -966,8 +966,18 @@ static int handle_kvp(struct parser_obj *po, uint32_t *action) /* Check if we have the key */ if (*(str) == '=') { TRACE_ERROR_STRING("No key", str); - po->last_error = ERR_NOKEY; - *action = PARSE_ERROR; + + if (po->parse_flags & INI_PARSE_IGNORE_NON_KVP) { + /* Clean everything as if nothing happened */ + free(po->last_read); + po->last_read = NULL; + po->last_read_len = 0; + *action = PARSE_READ; + } else { + po->last_error = ERR_NOKEY; + *action = PARSE_ERROR; + } + TRACE_FLOW_EXIT(); return EOK; } @@ -975,9 +985,18 @@ static int handle_kvp(struct parser_obj *po, uint32_t *action) /* Find "=" */ eq = strchr(str, '='); if (eq == NULL) { - TRACE_ERROR_STRING("No equal sign", str); - po->last_error = ERR_NOEQUAL; - *action = PARSE_ERROR; + if (po->parse_flags & INI_PARSE_IGNORE_NON_KVP) { + /* Clean everything as if nothing happened */ + free(po->last_read); + po->last_read = NULL; + po->last_read_len = 0; + *action = PARSE_READ; + } else { + TRACE_ERROR_STRING("No equal sign", str); + po->last_error = ERR_NOEQUAL; + *action = PARSE_ERROR; + } + TRACE_FLOW_EXIT(); return EOK; }