bugfixes in config parser, works now

This commit is contained in:
Phitherek 2012-09-07 14:02:32 +02:00
parent e89ecd7c1f
commit e8805247a3

33
3m.cpp
View File

@ -47,16 +47,17 @@ string line = "";
conf >> line; conf >> line;
if(conf) { if(conf) {
if(action == "parse") { if(action == "parse") {
if(line[0] = "[") { if(line[0] == '[') {
string sa = "";
int i = 1; int i = 1;
while(line[i] != "]") { string sa = "";
if(i >= line.length()-1 && line[i] != "]") { while(line[i] != ']') {
if(i >= line.length()-1 && line[i] != ']') {
cerr << "Config parse error: Found " << line[i] << " although ] was expected." << endl; cerr << "Config parse error: Found " << line[i] << " although ] was expected." << endl;
conf.close(); conf.close();
return 1; return 1;
} }
sa += line[i]; sa += line[i];
i++;
} }
if(sa == "localpath") { if(sa == "localpath") {
action = "localpath"; action = "localpath";
@ -64,38 +65,44 @@ action = "localpath";
action = "modlist"; action = "modlist";
} else if(sa == "repoinfo") { } else if(sa == "repoinfo") {
action = "repoinfo"; action = "repoinfo";
} else if(sa == "end") {
action = "end";
} else { } else {
cerr << "Config parse error: Found " << sa << " although localpath, modlist or repoinfo was expected." << endl; cerr << "Config parse error: Found " << sa << " although localpath, modlist or repoinfo was expected." << endl;
conf.close(); conf.close();
return 1; return 1;
} }
} else { } else {
cerr << "Config parse error: Found " << line[i] << " although [ was expected." << endl; cerr << "Config parse error: Found " << line[0] << " although [ was expected." << endl;
conf.close(); conf.close();
return 1; return 1;
} }
} else if(action == "localpath") { } else if(action == "localpath") {
if(line[0] == "[") { if(line[0] == '[') {
cerr << "Config parse error: Found [ although string and not option was expected." << endl; cerr << "Config parse error: Found [ although string and not option was expected." << endl;
conf.close(); conf.close();
return 1; return 1;
} }
localpath = line; *localpath = line;
action = "parse";
} else if(action == "modlist") { } else if(action == "modlist") {
if(line[0] == "[") { if(line[0] == '[') {
cerr << "Config parse error: Found [ although string and not option was expected." << endl; cerr << "Config parse error: Found [ although string and not option was expected." << endl;
conf.close(); conf.close();
return 1; return 1;
} }
modlist = line; *modlist = line;
action = "parse";
} else if(action == "repoinfo") { } else if(action == "repoinfo") {
if(line[0] == "[") { if(line[0] == '[') {
cerr << "Config parse error: Found [ although string and not option was expected." << endl; cerr << "Config parse error: Found [ although string and not option was expected." << endl;
conf.close(); conf.close();
return 1; return 1;
} }
repoinfo = line; *repoinfo = line;
} action = "parse";
} else if(action == "end") {
return 0;
} }
} }
} }
@ -105,7 +112,7 @@ return 0;
int main(int argc, char **argv) { int main(int argc, char **argv) {
homedir = getenv("HOME"); homedir = getenv("HOME");
string config; string config;
sstream sconfig; stringstream sconfig;
sconfig << homedir << "/.3m/config"; sconfig << homedir << "/.3m/config";
config = sconfig.str(); config = sconfig.str();
int ps; int ps;