diff options
| author | admin (centauri.fritz.box) <puppet@mx.buetow.org> | 2014-06-30 23:29:34 +0200 |
|---|---|---|
| committer | admin (centauri.fritz.box) <puppet@mx.buetow.org> | 2014-06-30 23:29:34 +0200 |
| commit | 813ee1984130c44f737f27426cc8414d19cf3bd9 (patch) | |
| tree | 737daaeefa0ee1f2d66821821de489b70522db37 /conf.cpp | |
| parent | 332d7b2107833018b3ef67b64ffe121bff1ef4fb (diff) | |
| parent | 7ead5b7a9ea99a3e0f1459187b3262f7054f0126 (diff) | |
Merge remote-tracking branch 'remotes/github/0.5' into 0.50.5
Diffstat (limited to 'conf.cpp')
| -rw-r--r-- | conf.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/conf.cpp b/conf.cpp new file mode 100644 index 0000000..3ff71b8 --- /dev/null +++ b/conf.cpp @@ -0,0 +1,75 @@ +// class conf implementation. + +#ifndef s_conf_CXX +#define s_conf_CXX + +#include <fstream> +#include "conf.h" + +using namespace std; + +conf::conf( string s_conf = CONFILE ) : name( s_conf ) +{ + parse( ); // parse the config file. +} + +conf::~conf() +{ +} + +void +conf::parse() +{ +#ifdef VERBOSE + cout << CFILEOK << get_name() << endl; +#endif + + ifstream fs_conf( get_name().c_str() ); + + if ( ! fs_conf ) + { +#ifdef VERBOSE + cout << CFILENO << get_name() << endl; +#endif + 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 ); + +#ifdef VERBOSE2 + cout << s_key << "=" << s_val << endl; +#endif + + // fill the map. + map_vals[s_key] = s_val; + } + + fs_conf.close(); + fs_conf.~ifstream(); +} + +#endif |
