diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-12-08 14:51:47 +0100 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-12-08 14:51:47 +0100 |
commit | 816f3e001271ed8ab7fdadb6d90aeb2c61362dac (patch) | |
tree | a7e453859a80fb47c7c74cb37791e35ad50f1d97 /src/lib/load_plugin_settings.cpp | |
parent | 3a9554929de070297a0e816eb2839291335a9403 (diff) | |
download | abrt-816f3e001271ed8ab7fdadb6d90aeb2c61362dac.tar.gz abrt-816f3e001271ed8ab7fdadb6d90aeb2c61362dac.tar.xz abrt-816f3e001271ed8ab7fdadb6d90aeb2c61362dac.zip |
removal of C++isms from libabrt, part 1
This patch converts libabrt usage of C++ map<string, string>
to a glib-based container, GHashTable.
It is typedef-ed to map_string_h.
We can't typedef it to map_string_t, since other parts of ABRT
(daemon, cli) still use that name for C++ container.
Also, exceptions are removed everywhere.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src/lib/load_plugin_settings.cpp')
-rw-r--r-- | src/lib/load_plugin_settings.cpp | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/lib/load_plugin_settings.cpp b/src/lib/load_plugin_settings.cpp index 1052f19e..0f389069 100644 --- a/src/lib/load_plugin_settings.cpp +++ b/src/lib/load_plugin_settings.cpp @@ -18,8 +18,10 @@ */ #include "abrtlib.h" -bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings, - bool skipKeysWithoutValue /*= true*/) +/* Returns NULL if open failed. + * Returns empty hash if conf file is empty. + */ +bool load_conf_file(const char *pPath, map_string_h *settings, bool skipKeysWithoutValue) { FILE *fp = stdin; if (strcmp(pPath, "-") != 0) @@ -36,8 +38,13 @@ bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings, bool is_value = false; bool valid = false; bool in_quote = false; - std::string key; - std::string value; + /* We are reusing line buffer to form temporary + * "key\0value\0..." in its beginning + */ + char *key = line; + char *value = line; + char *cur = line; + for (ii = 0; line[ii] != '\0'; ii++) { if (line[ii] == '"') @@ -48,7 +55,7 @@ bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings, { continue; } - if (line[ii] == '#' && !in_quote && key == "") + if (line[ii] == '#' && !in_quote && cur == line) { break; } @@ -56,39 +63,36 @@ bool LoadPluginSettings(const char *pPath, map_plugin_settings_t& pSettings, { is_value = true; valid = true; + *cur++ = '\0'; /* terminate key */ + value = cur; /* remember where value starts */ continue; } - if (!is_value) - { - key += line[ii]; - } - else - { - value += line[ii]; - } + *cur++ = line[ii]; /* store next key or value char */ } + *cur++ = '\0'; /* terminate value */ /* Skip broken or empty lines. */ if (!valid) goto free_line; /* Skip lines with empty key. */ - if (key.length() == 0) + if (key[0] == '\0') goto free_line; - if (skipKeysWithoutValue && value.length() == 0) + if (skipKeysWithoutValue && value[0] == '\0') goto free_line; /* Skip lines with unclosed quotes. */ if (in_quote) goto free_line; - pSettings[key] = value; + g_hash_table_replace(settings, xstrdup(key), xstrdup(value)); free_line: free(line); } if (fp != stdin) fclose(fp); + return true; } |