summaryrefslogtreecommitdiff
path: root/src/conf.cpp
blob: 3dd3c6c0fa0518d468a9e7945a6c86a672bf0e06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*:*
 *: File: ./src/conf.cpp
 *: 
 *: yChat; Homepage: www.yChat.org; Version 0.5.6-BASIC
 *: 
 *: Copyright (C) 2003, 2004 Paul C. Buetow, Volker Richter
 *: 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.
 *:*/

// 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