diff options
| author | Paul Buetow <paul@buetow.org> | 2013-04-06 13:14:47 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2013-04-06 13:14:47 +0200 |
| commit | 2860b03f00e48264ed15c132ad90b240ebe6070b (patch) | |
| tree | 09ed88e28d4a83eb2b1cb17c2d424ba6467292f7 /src/conf/conf.cpp | |
| parent | eab0b1c2d649fa16707b24cd2a91f195078167b0 (diff) | |
tagging ychat-0.7.9.5ychat-0.7.9.5
Diffstat (limited to 'src/conf/conf.cpp')
| -rw-r--r--[-rwxr-xr-x] | src/conf/conf.cpp | 225 |
1 files changed, 133 insertions, 92 deletions
diff --git a/src/conf/conf.cpp b/src/conf/conf.cpp index 67849ef..a8b8410 100755..100644 --- a/src/conf/conf.cpp +++ b/src/conf/conf.cpp @@ -1,4 +1,26 @@ -// class conf implementation. +/*:* + *: File: ./src/conf/conf.cpp + *: + *: yChat; Homepage: www.yChat.org; Version 0.7.9.5-RELEASE + *: + *: Copyright (C) 2003 Paul C. Buetow, Volker Richter + *: Copyright (C) 2004 Paul C. Buetow + *: Copyright (C) 2005 EXA Digital Solutions GbR + *: + *: This program is free software; you can redistribute it and/or + *: modify it under the terms of the GNU General Public License + *: as published by the Free Software Foundation; either version 2 + *: of the License, or (at your option) any later version. + *: + *: This program is distributed in the hope that it will be useful, + *: but WITHOUT ANY WARRANTY; without even the implied warranty of + *: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *: GNU General Public License for more details. + *: + *: You should have received a copy of the GNU General Public License + *: along with this program; if not, write to the Free Software + *: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *:*/ #ifndef CONF_CPP #define CONF_CPP @@ -8,136 +30,147 @@ using namespace std; -conf::conf( string s_conf, map<string,string>* p_start_params ) : nmap<string,string>::nmap(HMAPOCC), name::name( s_conf ) +conf::conf( string s_conf, map<string,string>* p_start_params ) : name::name( s_conf ) { - string s_check[] = { - get_name(), - string(getenv("HOME"))+string("/.ychat/") + get_name(), - string("./etc/") + get_name(), - string("/etc/") + get_name(), - string(PREFIX+string("etc/")+get_name()) }; + string s_check[] = { + get_name(), + string(getenv("HOME"))+string("/.ychat/") + get_name(), + string("./etc/") + get_name(), + string("/etc/") + get_name(), + string(PREFIX+string("etc/")+get_name()) }; - string s_config; + string s_config; - for ( int i = 0; i<4; i++ ) + for ( int i = 0; i < 4; ++i ) + { + cout << "Checking for " << s_check[i]; + ifstream if_check( s_check[i].c_str() ); + if( if_check ) { - cout << "Checking for " << s_check[i]; - ifstream if_check( s_check[i].c_str() ); - if( if_check ) - { - s_config = s_check[i]; - if_check.close(); - cout << "... ok!" << endl; - break; - } - cout << "... not ok!" << endl; + s_config = s_check[i]; + if_check.close(); + cout << "... ok!" << endl; + break; } + cout << "... not ok!" << endl; + } - if ( s_config.empty() ) - { - cout << CFILEFA << endl; - exit(1); - } + if ( s_config.empty() ) + { + cout << CFILEFA << endl; + exit(1); + } - else - { - cout << CFILEOK << "..." << endl; - } + else + { + cout << CFILEOK << "..." << endl; + } - p_xml = new TiXmlDocument(s_config.c_str()); - TiXmlBase::SetCondenseWhiteSpace( false ); - - if ( !p_xml->LoadFile() ) - { - cout << XMLER1 << endl; - exit(1); - } + p_xml = new TiXmlDocument(s_config.c_str()); + TiXmlBase::SetCondenseWhiteSpace( false ); + + if ( !p_xml->LoadFile() ) + { + cout << XMLER1 << endl; + exit(1); + } - vector<string> vec_string; - parse_xml(p_xml, &vec_string); + vector<string> vec_string; + parse_xml(p_xml, &vec_string); - nmap<string,string>::add_elem_insecure(tool::ychat_version(), "ychat.version"); - - // Overrides ychat.conf values with command line options (ychat -o key1 value1 -o key2 value2 ...) - map<string,string>::iterator iter; - for ( iter = p_start_params->begin(); iter != p_start_params->end(); iter++ ) - { - nmap<string,string>::del_elem_insecure(iter->first); - nmap<string,string>::add_elem_insecure(iter->second, iter->first); - } + shashmap<string>::add_elem_insecure(tool::ychat_version(), "ychat.version"); + + // Overrides ychat.conf values with command line options (ychat -o key1 value1 -o key2 value2 ...) + map<string,string>::iterator iter; + for ( iter = p_start_params->begin(); iter != p_start_params->end(); iter++ ) + { + shashmap<string>::del_elem_insecure(iter->first); + shashmap<string>::add_elem_insecure(iter->second, iter->first); + } - delete p_xml; + delete p_xml; } void conf::parse_xml(TiXmlNode* p_node, vector<string>* p_vec) { if ( p_node->NoChildren() ) - return; + return; for ( TiXmlNode* p_child = p_node->FirstChild(); p_child; p_child = p_child->NextSibling() ) { - //cout << p_vec->size() << ": (Value:" << p_child->Value() << ") (Type:" << p_child->Type() << ")" << endl; + //cout << p_vec->size() << ": (Value:" << p_child->Value() << ") (Type:" << p_child->Type() << ")" << endl; - if ( strcmp(p_child->Value(),"category") == 0) - { - p_vec->push_back(p_child->ToElement()->Attribute("name")); - parse_xml(p_child, p_vec); - p_vec->pop_back(); - } + if ( strcmp(p_child->Value(),"config") == 0 ) + { + parse_xml(p_child, p_vec); + } - else if ( strcmp(p_child->Value(),"option") == 0) - { - string s_option_name = ""; + else if ( strcmp(p_child->Value(),"category") == 0 ) + { + p_vec->push_back(p_child->ToElement()->Attribute("name")); + parse_xml(p_child, p_vec); + p_vec->pop_back(); + } + + else if ( strcmp(p_child->Value(),"option") == 0 ) + { + string s_option_name = ""; - for ( vector<string>::iterator iter = p_vec->begin(); iter != p_vec->end(); ++iter ) - s_option_name.append(*iter + "."); + for ( vector<string>::iterator iter = p_vec-> + begin(); + iter != p_vec->end(); + ++iter ) + s_option_name.append(*iter + "."); - TiXmlElement* p_element = p_child->ToElement(); - exit_if_xml_error(); + TiXmlElement* p_element = p_child->ToElement(); + exit_if_xml_error(); - s_option_name.append(p_element->Attribute("name")); + s_option_name.append(p_element->Attribute("name")); #ifdef VERBOSE - cout << XMLREAD << s_option_name; + cout << XMLREAD << s_option_name; #endif - TiXmlNode *p_node_value = p_element->FirstChild("value"); - TiXmlNode *p_node_descr = p_element->FirstChild("descr"); + TiXmlNode *p_node_value = p_element->FirstChild("value"); + TiXmlNode *p_node_descr = p_element->FirstChild("descr"); - TiXmlText* p_text_value = NULL; - TiXmlText* p_text_descr = NULL; + TiXmlText* p_text_value = NULL; + TiXmlText* p_text_descr = NULL; - if ( p_node_value && p_node_value->FirstChild() ) - p_text_value = p_node_value->FirstChild()->ToText(); + if ( p_node_value && p_node_value->FirstChild() + ) + p_text_value = p_node_value->FirstChild()->ToText(); - if ( p_node_descr && p_node_descr->FirstChild() ) - p_text_descr = p_node_descr->FirstChild()->ToText(); + if ( p_node_descr && p_node_descr->FirstChild() + ) + p_text_descr = p_node_descr->FirstChild()->ToText(); - if ( !p_text_value ) - continue; + if ( !p_text_value ) + continue; #ifdef VERBOSE - cout << " := " << p_text_value->Value() << endl; + cout << " := " << p_text_value->Value() << endl; #endif - nmap<string,string>::add_elem_insecure(p_text_value->Value(), s_option_name); + shashmap<string>::add_elem_insecure(p_text_value->Value(), s_option_name); - if ( !p_text_descr ) - continue; + if ( !p_text_descr ) + continue; - s_option_name.append(".descr"); + s_option_name.append(".descr"); #ifdef VERBOSE - cout << XMLREAD << s_option_name << endl; + cout << XMLREAD << s_option_name << endl; #endif - nmap<string,string>::add_elem_insecure(p_text_descr->Value(), s_option_name); - } + shashmap<string>::add_elem_insecure(p_text_descr->Value(), s_option_name); + } } - exit_if_xml_error(); + exit_if_xml_error() + ; } -conf::~conf() +conf::~conf() { delete p_xml; } @@ -145,19 +178,27 @@ conf::~conf() void conf::exit_if_xml_error() const { - if ( p_xml->Error() ) - { - cout << XMLERR << p_xml->ErrorDesc() << endl; - exit(1); - } + if ( p_xml->Error() ) + { + cout << XMLERR << p_xml->ErrorDesc() << endl; + exit(1); + } } //<<* string conf::colored_error_msg(string s_key) { - return "<font color=\"#" + nmap<string,string>::get_elem("chat.html.errorcolor") + "\">" + nmap<string,string>::get_elem(s_key) + "</font><br>\n"; + return "<font color=\"#" + + shashmap<string>::get_elem("chat.html.errorcolor") + + "\">" + shashmap<string>::get_elem(s_key) + "</font><br>\n"; } //*>> +int +conf::get_int(string s_key) +{ + return tool::string2int(get_elem(s_key)); +} + #endif |
