From d81433c272dc189ff50ecde109cd0040f21fa8b0 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 23 Jun 2004 19:36:18 +0300 Subject: [PATCH] Allow empty section name. --HG-- branch : HEAD --- src/lib-settings/settings.c | 63 ++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/src/lib-settings/settings.c b/src/lib-settings/settings.c index ecdbcea573..16e03d5d53 100644 --- a/src/lib-settings/settings.c +++ b/src/lib-settings/settings.c @@ -124,7 +124,7 @@ int settings_read(const char *path, const char *section, line[len] = '\0'; /* a) key = value - b) section_type section_name { + b) section_type [section_name] { c) } */ key = line; while (!IS_WHITE(*line) && *line != '\0' && *line != '=') @@ -134,25 +134,8 @@ int settings_read(const char *path, const char *section, while (IS_WHITE(*line)) line++; } - if (strcmp(key, "}") == 0 && *line == '\0') { - if (sections == 0) - errormsg = "Unexpected '}'"; - else { - if (skip > 0) - skip--; - else { - sect_callback(NULL, NULL, context, - &errormsg); - if (root_section == sections && - errormsg == NULL) { - /* we found the section, - now quit */ - break; - } - } - sections--; - } - } else if (*line == '=') { + if (*line == '=') { + /* a) */ *line++ = '\0'; while (IS_WHITE(*line)) line++; @@ -166,17 +149,22 @@ int settings_read(const char *path, const char *section, errormsg = skip ? NULL : callback(key, line, context); - } else { + } else if (strcmp(key, "}") != 0 || *line != '\0') { + /* b) + errors */ line[-1] = '\0'; - name = line; - while (!IS_WHITE(*line) && *line != '\0') - line++; - - if (*line != '\0') { - *line++ = '\0'; - while (IS_WHITE(*line)) + if (*line == '{') + name = ""; + else { + name = line; + while (!IS_WHITE(*line) && *line != '\0') line++; + + if (*line != '\0') { + *line++ = '\0'; + while (IS_WHITE(*line)) + line++; + } } if (*line != '{') @@ -207,6 +195,25 @@ int settings_read(const char *path, const char *section, &errormsg); } } + } else { + /* c) */ + if (sections == 0) + errormsg = "Unexpected '}'"; + else { + if (skip > 0) + skip--; + else { + sect_callback(NULL, NULL, context, + &errormsg); + if (root_section == sections && + errormsg == NULL) { + /* we found the section, + now quit */ + break; + } + } + sections--; + } } if (errormsg != NULL) { -- 2.47.3