diff options
Diffstat (limited to 'src/conf')
| -rwxr-xr-x | src/conf/conf.cpp | 18 | ||||
| -rwxr-xr-x | src/conf/conf.h | 10 | ||||
| -rwxr-xr-x | src/conf/lang.cpp | 67 | ||||
| -rwxr-xr-x | src/conf/lang.h | 23 |
4 files changed, 100 insertions, 18 deletions
diff --git a/src/conf/conf.cpp b/src/conf/conf.cpp index e54cbd4..6670f66 100755 --- a/src/conf/conf.cpp +++ b/src/conf/conf.cpp @@ -1,3 +1,5 @@ +// class conf implementation. + #ifndef CONF_CPP #define CONF_CPP @@ -17,7 +19,7 @@ conf::conf( string s_conf, map<string,string>* p_start_params ) : nmap<string,st 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() ); @@ -77,14 +79,14 @@ conf::parse_xml(TiXmlNode* p_node, vector<string>* p_vec) { //cout << p_vec->size() << ": (Value:" << p_child->Value() << ") (Type:" << p_child->Type() << ")" << endl; - if ( strcmp(p_child->Value(),"category") == 0 ) + 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 ) + else if ( strcmp(p_child->Value(),"option") == 0) { string s_option_name = ""; @@ -150,14 +152,4 @@ conf::exit_if_xml_error() const } } -//<<* -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"; -} -//*>> - #endif diff --git a/src/conf/conf.h b/src/conf/conf.h index 3a7d0c6..7508872 100755 --- a/src/conf/conf.h +++ b/src/conf/conf.h @@ -1,7 +1,9 @@ +// class conf declaration. this class parses the server config file. + #ifndef CONF_H #define CONF_H -class conf; // Predefine for nmap.tmpl +class conf; #include "../incl.h" #include "../maps/nmap.h" @@ -16,12 +18,10 @@ private: TiXmlDocument* p_xml; void exit_if_xml_error() const; void parse_xml( TiXmlNode* p_node, vector<string>* p_vec); - public: - conf(string s_conf, map<string,string>* p_start_params); + //conf ( string s_conf ); + conf ( string s_conf, map<string,string>* p_start_params ); ~conf(); - - string colored_error_msg( string s_key ); //<< }; #endif diff --git a/src/conf/lang.cpp b/src/conf/lang.cpp new file mode 100755 index 0000000..04dd13b --- /dev/null +++ b/src/conf/lang.cpp @@ -0,0 +1,67 @@ +#ifndef LANG_CPP +#define LANG_CPP + +#include <fstream> +#include "lang.h" + +using namespace std; + +lang::lang( string s_lang = "en" ) : nmap<string,string>::nmap(HMAPOCC), name::name( s_lang ) +{ + parse( ); // parse the config file. +} + +lang::~lang() +{} + +void +lang::parse() +{ + // wrap::system_message( CFILEOK + get_name() ); + + string filename(wrap::CONF->get_elem("LANGUAGE_DIR")); + filename.append(get_name()+".txt"); + + ifstream fs_conf( filename.c_str() ); + + if ( ! fs_conf ) + { + // wrap::system_message( CFILEOFF + get_name() ); + return; + } + + char c_buf[READBUF]; + + while( fs_conf.getline( c_buf, READBUF ) ) + { + string s_token( c_buf ); + unsigned int ui_pos = s_token.find( "#", 0 ); + + // if line is commented out: + if ( ui_pos == 0 ) + continue; + + ui_pos = s_token.find( ";", 0 ); + + // if token has not been found. + if ( ui_pos == string::npos ) + continue; + + s_token = s_token.substr( 0 , --ui_pos ); + ui_pos = s_token.find ( "\"", 0 ); + + if ( ui_pos == string::npos ) + continue; + + string s_val = s_token.substr( ui_pos+1, s_token.length() ); + string s_key = s_token.substr( 0 , --ui_pos ); + + // fill the map. + nmap<string,string>::add_elem(s_val, s_key ); + } + + fs_conf.close(); + fs_conf.~ifstream(); +} + +#endif diff --git a/src/conf/lang.h b/src/conf/lang.h new file mode 100755 index 0000000..6230e2f --- /dev/null +++ b/src/conf/lang.h @@ -0,0 +1,23 @@ +#include "../incl.h" + +#ifndef LANG_H +#define LANG_H + +#include "../name.h" +#include "../maps/nmap.h" + +using namespace std; + +class lang : public nmap<string,string>, name +{ +private: + +public: + // public methods: + lang ( string s_lang ); // standard constructor. + ~lang(); // standard destructor. + + virtual void parse( ); // parses the config file. +}; + +#endif |
