summaryrefslogtreecommitdiffstats
path: root/ini/ini_parse.c
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2010-11-26 23:11:07 -0500
committerStephen Gallagher <sgallagh@redhat.com>2010-12-21 11:16:09 -0500
commit5dadfb4371b8ba694b8d9431cb6789bf6de485c4 (patch)
tree2b6843eb1b30a5aa4b23a77a74c7d0a797f9d464 /ini/ini_parse.c
parent500eaf3ef5d53a9961443d2f3ea0d7e8b01d4c1f (diff)
downloadding-libs-5dadfb4371b8ba694b8d9431cb6789bf6de485c4.tar.gz
ding-libs-5dadfb4371b8ba694b8d9431cb6789bf6de485c4.tar.xz
ding-libs-5dadfb4371b8ba694b8d9431cb6789bf6de485c4.zip
New copy and folding functionality
* Added method to copy configuration. * Added unit test for it. * Added method to reset boandary for the whole configuration. * Added unit test for it. * Unit test now can read a file save it read again and save. Both saves produce same files! * Reworked the way the parser was dealing with empty lines. It was sutting off the value in the middle if the folded line consisted of just spaces.
Diffstat (limited to 'ini/ini_parse.c')
-rw-r--r--ini/ini_parse.c74
1 files changed, 38 insertions, 36 deletions
diff --git a/ini/ini_parse.c b/ini/ini_parse.c
index 253b78b..c92a163 100644
--- a/ini/ini_parse.c
+++ b/ini/ini_parse.c
@@ -79,6 +79,20 @@ typedef int (*action_fn)(struct parser_obj *);
#define PARSE_DONE 4 /* We are done */
+int is_just_spaces(const char *str, uint32_t len)
+{
+ uint32_t i;
+
+ TRACE_FLOW_ENTRY();
+
+ for (i = 0; i < len; i++) {
+ if (!isspace(str[i])) return 0;
+ }
+
+ TRACE_FLOW_EXIT();
+ return 1;
+}
+
/* Destroy parser object */
void parser_destroy(struct parser_obj *po)
@@ -401,14 +415,24 @@ static int handle_space(struct parser_obj *po, uint32_t *action)
*action = PARSE_READ;
}
else {
- /* We do not have an active value
- * but have a line is starting with a space.
- * For now it is error.
- * We can change it in future if
- * people find it being too restrictive
- */
- *action = PARSE_ERROR;
- po->last_error = ERR_SPACE;
+ /* Check if this is a completely empty line */
+ if (is_just_spaces(po->last_read, po->last_read_len)) {
+ error = handle_comment(po, action);
+ if (error) {
+ TRACE_ERROR_NUMBER("Failed to process comment", error);
+ return error;
+ }
+ }
+ else {
+ /* We do not have an active value
+ * but have a line is starting with a space.
+ * For now it is error.
+ * We can change it in future if
+ * people find it being too restrictive
+ */
+ *action = PARSE_ERROR;
+ po->last_error = ERR_SPACE;
+ }
}
TRACE_FLOW_EXIT();
@@ -425,6 +449,8 @@ static int handle_kvp(struct parser_obj *po, uint32_t *action)
TRACE_FLOW_ENTRY();
+ TRACE_INFO_STRING("Last read:", po->last_read);
+
/* We got a line with KVP */
if (*(po->last_read) == '=') {
po->last_error = ERR_NOKEY;
@@ -681,20 +707,6 @@ static int handle_section(struct parser_obj *po, uint32_t *action)
}
-int is_just_spaces(const char *str, uint32_t len)
-{
- uint32_t i;
-
- TRACE_FLOW_ENTRY();
-
- for (i = 0; i < len; i++) {
- if (!isspace(str[i])) return 0;
- }
-
- TRACE_FLOW_EXIT();
- return 1;
-}
-
/* Inspect the line */
static int parser_inspect(struct parser_obj *po)
{
@@ -716,20 +728,10 @@ static int parser_inspect(struct parser_obj *po)
else if ((*(po->last_read) == ' ') ||
(*(po->last_read) == '\t')) {
- /* Check if this is a completely empty line */
- if (is_just_spaces(po->last_read, po->last_read_len)) {
- error = handle_comment(po, &action);
- if (error) {
- TRACE_ERROR_NUMBER("Failed to process comment", error);
- return error;
- }
- }
- else {
- error = handle_space(po, &action);
- if (error) {
- TRACE_ERROR_NUMBER("Failed to process line wrapping", error);
- return error;
- }
+ error = handle_space(po, &action);
+ if (error) {
+ TRACE_ERROR_NUMBER("Failed to process line wrapping", error);
+ return error;
}
}
else if (*(po->last_read) == '[') {