ready to start using Config

git-svn-id: http://apu.dw.local/svnusers/JoshHoltrop/pppc/trunk@54 8131a0b2-b21c-1c47-bd6a-f003126495bd
This commit is contained in:
joshholtrop 2009-08-19 17:49:12 +00:00
parent 3c22f00c7d
commit 90f46c2917
2 changed files with 12 additions and 3 deletions

View File

@ -26,7 +26,7 @@ void Config::read(const char * file)
ifstream ifs(file); ifstream ifs(file);
if (ifs.is_open()) if (ifs.is_open())
{ {
int entry_num = -1; int entry_num = -1; /* start in "global" section (-1) */
string line; string line;
while (!ifs.eof()) while (!ifs.eof())
{ {
@ -36,7 +36,7 @@ void Config::read(const char * file)
if (line == "") /* skip blank lines */ if (line == "") /* skip blank lines */
continue; continue;
if (line[0] == ';' || line[0] == '#') /* skip comments */ if (line[0] == ';') /* skip comments */
continue; continue;
/* Look for the beginning of a new entry section */ /* Look for the beginning of a new entry section */
@ -54,7 +54,9 @@ void Config::read(const char * file)
if (parts.first == "port") if (parts.first == "port")
{ {
if (parts.second != "") if (parts.second != "")
{
port = parts.second; port = parts.second;
}
} }
else else
{ {
@ -110,13 +112,19 @@ Config::Action Config::parseAction(const string & str)
{ {
string s = str; string s = str;
Action res = NONE; Action res = NONE;
/* lowercase the string */
for (int sz = s.size(), i = 0; i < sz; i++) for (int sz = s.size(), i = 0; i < sz; i++)
{
s[i] = tolower(s[i]); s[i] = tolower(s[i]);
if (s == "on") }
if (s == "on")
res = ON; res = ON;
else if (s == "off") else if (s == "off")
res = OFF; res = OFF;
else if (s == "previous") else if (s == "previous")
res = PREVIOUS; res = PREVIOUS;
return res; return res;
} }

View File

@ -1,4 +1,5 @@
; Global options
port = LPT1 port = LPT1
[Light] [Light]