summaryrefslogtreecommitdiff
path: root/conf.cpp
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2013-04-06 13:14:44 +0200
committerPaul Buetow <paul@buetow.org>2013-04-06 13:14:44 +0200
commitca28c0e618890330d429c0dc12429255b20f0c90 (patch)
treeecc02da0184cf4e8bdba94dcdd831abdd1e51b3c /conf.cpp
parentb3a99e6e15af3be25394e66d1138bb2682f565c3 (diff)
tagging ychat-0.5.0ychat-0.5.0
Diffstat (limited to 'conf.cpp')
-rwxr-xr-xconf.cpp82
1 files changed, 35 insertions, 47 deletions
diff --git a/conf.cpp b/conf.cpp
index e4fcc0b..3ff71b8 100755
--- a/conf.cpp
+++ b/conf.cpp
@@ -4,84 +4,72 @@
#define s_conf_CXX
#include <fstream>
-#include "s_ncur.h"
#include "conf.h"
using namespace std;
conf::conf( string s_conf = CONFILE ) : name( s_conf )
{
- parse( ); // parse the config file.
+ parse( ); // parse the config file.
}
conf::~conf()
-{}
+{
+}
void
conf::parse()
{
#ifdef VERBOSE
- cout << CFILEOK << get_name() << endl;
+ cout << CFILEOK << get_name() << endl;
#endif
- string s_configfile=get_name();
-
- string homeconfig=string(getenv("HOME"))+string("/.ychat/")+get_name();
- ifstream homecheck( homeconfig.c_str() );
- if( homecheck )
- {
- homecheck.close();
- s_configfile=homeconfig;
- }
-
- ifstream fs_conf( s_configfile.c_str() );
+ ifstream fs_conf( get_name().c_str() );
- if ( ! fs_conf )
- {
+ if ( ! fs_conf )
+ {
#ifdef VERBOSE
- cout << CFILENO << get_name() << endl;
+ cout << CFILENO << get_name() << endl;
#endif
+ return;
+ }
- return;
- }
+ char c_buf[READBUF];
- 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;
- while( fs_conf.getline( c_buf, READBUF ) )
- {
- string s_token( c_buf );
- unsigned int ui_pos = s_token.find( "#", 0 );
+ ui_pos = s_token.find( ";", 0 );
- // if line is commented out:
- if ( ui_pos == 0 )
- continue;
+ // if token has not been found.
+ if ( ui_pos == string::npos )
+ continue;
- ui_pos = s_token.find( ";", 0 );
+ s_token = s_token.substr( 0 , --ui_pos );
+ ui_pos = s_token.find ( "\"", 0 );
- // if token has not been found.
- if ( ui_pos == string::npos )
- continue;
+ 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 );
+ 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;
+ cout << s_key << "=" << s_val << endl;
#endif
- // fill the map.
- map_vals[s_key] = s_val;
- }
+ // fill the map.
+ map_vals[s_key] = s_val;
+ }
- fs_conf.close();
- fs_conf.~ifstream();
+ fs_conf.close();
+ fs_conf.~ifstream();
}
#endif