diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2007-04-23 00:48:37 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2007-04-23 00:48:37 +0000 |
commit | b3376bfe4e26591e1dc1066d8f2270baf4f9f759 (patch) | |
tree | 6cba270a59320bf7c77266fe736cfb68bc2521a0 /src/configuration.cpp | |
parent | 6d09c8f4667f75fece4a5549de237e17490398cf (diff) | |
download | mana-b3376bfe4e26591e1dc1066d8f2270baf4f9f759.tar.gz mana-b3376bfe4e26591e1dc1066d8f2270baf4f9f759.tar.bz2 mana-b3376bfe4e26591e1dc1066d8f2270baf4f9f759.tar.xz mana-b3376bfe4e26591e1dc1066d8f2270baf4f9f759.zip |
Merged Björn Steinbrinks improvements at the xml parsing from trunk version.
Diffstat (limited to 'src/configuration.cpp')
-rw-r--r-- | src/configuration.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/configuration.cpp b/src/configuration.cpp index 53f6785e..d33df386 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -30,6 +30,7 @@ #include "log.h" #include "utils/tostring.h" +#include "utils/xml.h" void Configuration::init(const std::string &filename) { @@ -48,14 +49,14 @@ void Configuration::init(const std::string &filename) if (!doc) return; - xmlNodePtr node = xmlDocGetRootElement(doc); + xmlNodePtr rootNode = xmlDocGetRootElement(doc); - if (!node || !xmlStrEqual(node->name, BAD_CAST "configuration")) { + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "configuration")) { logger->log("Warning: No configuration file (%s)", filename.c_str()); return; } - for (node = node->xmlChildrenNode; node != NULL; node = node->next) + for_each_xml_child_node(node, rootNode) { if (!xmlStrEqual(node->name, BAD_CAST "option")) continue; @@ -79,6 +80,8 @@ void Configuration::write() // Do not attempt to write to file that cannot be opened for writing FILE *testFile = fopen(mConfigPath.c_str(), "w"); if (!testFile) { + logger->log("Configuration::write() couldn't open %s for writing", + mConfigPath.c_str()); return; } else { @@ -87,8 +90,12 @@ void Configuration::write() xmlTextWriterPtr writer = xmlNewTextWriterFilename(mConfigPath.c_str(), 0); - if (!writer) + if (!writer) { + logger->log("Configuration::write() error while creating writer"); return; + } + + logger->log("Configuration::write() writing configuration..."); xmlTextWriterSetIndent(writer, 1); xmlTextWriterStartDocument(writer, NULL, NULL, NULL); @@ -96,9 +103,6 @@ void Configuration::write() for (OptionIterator i = mOptions.begin(); i != mOptions.end(); i++) { - logger->log("Configuration::write(%s, \"%s\")", - i->first.c_str(), i->second.c_str()); - xmlTextWriterStartElement(writer, BAD_CAST "option"); xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST i->first.c_str()); |