From 87bee54dede4d9d80731a01bd8c4e9384e047e58 Mon Sep 17 00:00:00 2001 From: Alexander Baldeck Date: Sun, 26 Dec 2004 15:54:37 +0000 Subject: - spaces are now stripped when options are being read (relaxed syntax in tmw.ini) - sorry for the "blah" in login.cpp - --- src/configuration.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/configuration.cpp') 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) { -- cgit v1.2.3-70-g09d2