-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConfig.cpp
More file actions
44 lines (37 loc) · 784 Bytes
/
Config.cpp
File metadata and controls
44 lines (37 loc) · 784 Bytes
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
#include "Config.h"
void Config::updateConfig(const char * config_path)
{
FILE* fin = fopen(config_path, "r");
if (!fin)
return;
char buff[1024];
while (fgets(buff, 1024, fin))
{
if (strlen(buff) > 0 && buff[strlen(buff) - 1] == '\n')
buff[strlen(buff) - 1] = '\0';
string s(buff);
if (s.compare(0, 1, "#") == 0)
continue;
size_t pos = s.find('=');
string name = s.substr(0, pos);
string value = s.substr(pos + 1);
config[name] = value;
}
fclose(fin);
}
vector<string> Config::split(string & str, char seq)
{
char * c = &seq;
char *cstr, *p;
vector<string> res;
cstr = new char[str.size() + 1];
strcpy(cstr, str.c_str());
p = strtok(cstr, c);
while (p != NULL)
{
res.push_back(p);
p = strtok(NULL, c);
}
delete[] cstr;
return res;
}