summaryrefslogtreecommitdiff
path: root/src/mgr/swconfig.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mgr/swconfig.cpp')
-rw-r--r--src/mgr/swconfig.cpp52
1 files changed, 32 insertions, 20 deletions
diff --git a/src/mgr/swconfig.cpp b/src/mgr/swconfig.cpp
index 376c206..309f686 100644
--- a/src/mgr/swconfig.cpp
+++ b/src/mgr/swconfig.cpp
@@ -2,7 +2,7 @@
* swconfig.cpp - implementation of Class SWConfig used for saving and
* retrieval of configuration information
*
- * $Id: swconfig.cpp 1828 2005-06-10 16:24:46Z scribe $
+ * $Id: swconfig.cpp 2218 2008-12-23 09:33:38Z scribe $
*
* Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
@@ -28,6 +28,9 @@
SWORD_NAMESPACE_START
+SWConfig::SWConfig() {
+}
+
SWConfig::SWConfig(const char * ifilename) {
filename = ifilename;
Load();
@@ -38,6 +41,9 @@ SWConfig::~SWConfig() {
}
void SWConfig::Load() {
+
+ if (!filename.size()) return; // assert we have a filename
+
FileDesc *cfile;
char *buf, *data;
SWBuf line;
@@ -60,27 +66,30 @@ void SWConfig::Load() {
}
while (goodLine) {
- buf = new char [ line.length() + 1 ];
- strcpy(buf, line.c_str());
- if (*strstrip(buf) == '[') {
- if (!first)
- Sections.insert(SectionMap::value_type(sectname, cursect));
- else first = false;
-
- cursect.erase(cursect.begin(), cursect.end());
-
- strtok(buf, "]");
- sectname = buf+1;
- }
- else {
- strtok(buf, "=");
- if ((*buf) && (*buf != '=')) {
- if ((data = strtok(NULL, "")))
- cursect.insert(ConfigEntMap::value_type(buf, strstrip(data)));
- else cursect.insert(ConfigEntMap::value_type(buf, ""));
+ // ignore commented lines
+ if (!line.startsWith("#")) {
+ buf = new char [ line.length() + 1 ];
+ strcpy(buf, line.c_str());
+ if (*strstrip(buf) == '[') {
+ if (!first)
+ Sections.insert(SectionMap::value_type(sectname, cursect));
+ else first = false;
+
+ cursect.erase(cursect.begin(), cursect.end());
+
+ strtok(buf, "]");
+ sectname = buf+1;
}
+ else {
+ strtok(buf, "=");
+ if ((*buf) && (*buf != '=')) {
+ if ((data = strtok(NULL, "")))
+ cursect.insert(ConfigEntMap::value_type(buf, strstrip(data)));
+ else cursect.insert(ConfigEntMap::value_type(buf, ""));
+ }
+ }
+ delete [] buf;
}
- delete [] buf;
goodLine = FileMgr::getLine(cfile, line);
}
if (!first)
@@ -92,6 +101,9 @@ void SWConfig::Load() {
void SWConfig::Save() {
+
+ if (!filename.size()) return; // assert we have a filename
+
FileDesc *cfile;
SWBuf buf;
SectionMap::iterator sit;