diff options
author | Alexander Baldeck <alexander@archlinux.org> | 2004-12-26 15:54:37 +0000 |
---|---|---|
committer | Alexander Baldeck <alexander@archlinux.org> | 2004-12-26 15:54:37 +0000 |
commit | 87bee54dede4d9d80731a01bd8c4e9384e047e58 (patch) | |
tree | d64820c88cc9530736839d833a1838820bfbecd6 /src/configuration.cpp | |
parent | 0ad7cabf1feaa6af32f127254453f6b37d9fecc6 (diff) | |
download | mana-87bee54dede4d9d80731a01bd8c4e9384e047e58.tar.gz mana-87bee54dede4d9d80731a01bd8c4e9384e047e58.tar.bz2 mana-87bee54dede4d9d80731a01bd8c4e9384e047e58.tar.xz mana-87bee54dede4d9d80731a01bd8c4e9384e047e58.zip |
- spaces are now stripped when options are being read (relaxed syntax in tmw.ini)
- sorry for the "blah" in login.cpp
-
Diffstat (limited to 'src/configuration.cpp')
-rw-r--r-- | src/configuration.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/configuration.cpp b/src/configuration.cpp index 06296bf1..599cc3f5 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -25,20 +25,34 @@ /** \brief read INI file and parse all options into memory \param filename full path to INI file (~/.manaworld/tmw.ini) + + NOTE: + first a line is checked wether it is a comment or not by + looking for INI_COMMENTER. after this another check is + done for INI_DELIMITER if the previous check failed. + if this line is a valid option all spaces in it get + stripped away (including the value) and it is added to + the list iniOptions. */ void Configuration::init(std::string filename) { std::ifstream inFile(filename.c_str(), std::ifstream::in); std::string inBuffer; - int position; + unsigned int position; INI_OPTION optionTmp; + iniOptions.clear(); + while (inFile.good()) { getline(inFile, inBuffer, '\n'); if(inBuffer.substr(0,1) != INI_COMMENTER) { position = inBuffer.find(INI_DELIMITER, 0); - if(position > 0 && position >= -1) { + if(position != std::string::npos) { + // replace spaces with void :) + while(inBuffer.find(" ", 0) != std::string::npos) { + inBuffer.replace(inBuffer.find(" ", 0), 1, ""); + } optionTmp.key = inBuffer.substr(0, position); optionTmp.stringValue = inBuffer.substr(position+1, inBuffer.length()); inBuffer = inBuffer.substr(position+1, inBuffer.length()); @@ -59,6 +73,10 @@ void Configuration::init(std::string filename) { #endif } +/** + \brief write the current settings back to an ini-file + \param filename full path to INI file (~/.manaworld/tmw.ini) +*/ bool Configuration::write(std::string filename) { std::ofstream out(filename.c_str(), std::ofstream::out | std::ofstream::trunc); char tmp[20]; @@ -84,6 +102,11 @@ bool Configuration::write(std::string filename) { return true; } +/** + \brief set an option using a string value + \param key option identifier + \param value value +*/ void Configuration::setValue(std::string key, std::string value) { INI_OPTION optionTmp; if(getValue(key, "") == "") { @@ -108,6 +131,11 @@ void Configuration::setValue(std::string key, std::string value) { } } +/** + \brief set an option using a numeric value + \param key option identifier + \param value value +*/ void Configuration::setValue(std::string key, float value) { INI_OPTION optionTmp; if(getValue(key, 0) == 0) { |