diff --git a/Config.cc b/Config.cc index a9e82a6..297af8b 100644 --- a/Config.cc +++ b/Config.cc @@ -1,6 +1,7 @@ #include "Config.h" #include +#include #include using namespace std; @@ -16,4 +17,17 @@ Config::Entry::Entry(const string & name) void Config::read(const char * file) { + ifstream ifs(file); + if (ifs.is_open()) + { + string line; + while (!ifs.eof()) + { + getline(ifs, line); + } + } + else + { + cerr << "Warning: Could not open '" << file << "'" << endl; + } } diff --git a/Config.h b/Config.h index f51eb9f..cad4663 100644 --- a/Config.h +++ b/Config.h @@ -23,10 +23,10 @@ class Config protected: }; - void read(const char * file); + std::string port; + std::vector entries; - protected: - std::vector m_entries; + void read(const char * file); }; #endif diff --git a/Makefile b/Makefile index 1e07866..44a2871 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ OBJS += resources.o OBJS += pport.o OBJS += parseCmdLine.o OBJS += Config.o +OBJS += trim.o CXXFLAGS := -O2 -Wall LDFLAGS := -mwindows diff --git a/parseCmdLine.cc b/parseCmdLine.cc index d9ee2f7..fe06584 100644 --- a/parseCmdLine.cc +++ b/parseCmdLine.cc @@ -1,20 +1,9 @@ #include "parseCmdLine.h" +#include "trim.h" #include using namespace std; -static std::string trim(const std::string & orig) -{ - const char ws[] = " \t\r\n\v\f"; - size_t first = orig.find_first_not_of(ws); - size_t last = orig.find_last_not_of(ws); - if (first == string::npos || last == string::npos) - { - return ""; - } - return string(orig, first, last - first + 1); -} - std::vector parseCmdLine(char * cmdline) { enum { WSSKIP, GATHERING, SQUOTE, DQUOTE } state = WSSKIP; diff --git a/trim.cc b/trim.cc new file mode 100644 index 0000000..8220a1c --- /dev/null +++ b/trim.cc @@ -0,0 +1,17 @@ + +#include "trim.h" +#include +using namespace std; + +string trim(const string & orig) +{ + const char ws[] = " \t\r\n\v\f"; + size_t first = orig.find_first_not_of(ws); + size_t last = orig.find_last_not_of(ws); + if (first == string::npos || last == string::npos) + { + return ""; + } + return string(orig, first, last - first + 1); +} + diff --git a/trim.h b/trim.h new file mode 100644 index 0000000..fe38392 --- /dev/null +++ b/trim.h @@ -0,0 +1,9 @@ + +#ifndef TRIM_H +#define TRIM_H + +#include + +std::string trim(const std::string & orig); + +#endif