summaryrefslogtreecommitdiff
path: root/src/mgr/swmgr.cpp
diff options
context:
space:
mode:
authorRoberto C. Sanchez <roberto@connexer.com>2014-05-12 08:21:30 -0400
committerRoberto C. Sanchez <roberto@connexer.com>2014-05-12 08:21:30 -0400
commit7a00574163029c0c2b649878c95d5acbd083564a (patch)
treec13cc5736025834df2874ed87ee8598070025ea6 /src/mgr/swmgr.cpp
parentb745315323de9f27538edac9453205ca70e6186e (diff)
Imported Upstream version 1.7.2+dfsg
Diffstat (limited to 'src/mgr/swmgr.cpp')
-rw-r--r--src/mgr/swmgr.cpp179
1 files changed, 136 insertions, 43 deletions
diff --git a/src/mgr/swmgr.cpp b/src/mgr/swmgr.cpp
index 3ee253f..0a2d583 100644
--- a/src/mgr/swmgr.cpp
+++ b/src/mgr/swmgr.cpp
@@ -1,10 +1,10 @@
/******************************************************************************
- * swmgr.cpp - implementaion of class SWMgr used to interact with an install
- * base of sword modules.
*
- * $Id: swmgr.cpp 2374 2009-05-04 03:48:01Z scribe $
+ * swmgr.cpp - used to interact with an install base of sword modules
*
- * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ * $Id: swmgr.cpp 2985 2013-10-04 14:38:14Z scribe $
+ *
+ * Copyright 1998-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -51,6 +51,8 @@
#include <gbfheadings.h>
#include <gbfredletterwords.h>
#include <gbfmorph.h>
+#include <osisenum.h>
+#include <osisglosses.h>
#include <osisheadings.h>
#include <osisfootnotes.h>
#include <osisstrongs.h>
@@ -58,8 +60,10 @@
#include <osislemma.h>
#include <osisredletterwords.h>
#include <osismorphsegmentation.h>
-#include <osisruby.h>
#include <osisscripref.h>
+#include <osisvariants.h>
+#include <osisxlit.h>
+#include <osisreferencelinks.h>
#include <thmlstrongs.h>
#include <thmlfootnotes.h>
#include <thmlheadings.h>
@@ -81,6 +85,7 @@
#include <swfiltermgr.h>
#include <swcipher.h>
#include <swoptfilter.h>
+#include <rtfhtml.h>
#include <swlog.h>
@@ -88,6 +93,8 @@
#ifndef EXCLUDEZLIB
#include "zipcomprs.h"
+#include "bz2comprs.h"
+#include "xzcomprs.h"
#endif
@@ -95,8 +102,10 @@
#include <utf8transliterator.h>
#endif
+
SWORD_NAMESPACE_START
+
#ifdef _ICU_
bool SWMgr::isICU = true;
#else
@@ -110,6 +119,14 @@ const char *SWMgr::globalConfPath = GLOBCONFPATH;
const char *SWMgr::globalConfPath = "/etc/sword.conf:/usr/local/etc/sword.conf";
#endif
+
+const char *SWMgr::MODTYPE_BIBLES = "Biblical Texts";
+const char *SWMgr::MODTYPE_COMMENTARIES = "Commentaries";
+const char *SWMgr::MODTYPE_LEXDICTS = "Lexicons / Dictionaries";
+const char *SWMgr::MODTYPE_GENBOOKS = "Generic Books";
+const char *SWMgr::MODTYPE_DAILYDEVOS = "Daily Devotional";
+
+
void SWMgr::init() {
SWOptionFilter *tmpFilter = 0;
configPath = 0;
@@ -123,6 +140,7 @@ void SWMgr::init() {
cipherFilters.clear();
optionFilters.clear();
cleanupFilters.clear();
+ extraFilters.clear();
tmpFilter = new ThMLVariants();
optionFilters.insert(OptionFilterMap::value_type("ThMLVariants", tmpFilter));
cleanupFilters.push_back(tmpFilter);
@@ -179,10 +197,23 @@ void SWMgr::init() {
optionFilters.insert(OptionFilterMap::value_type("OSISMorphSegmentation", tmpFilter));
cleanupFilters.push_back(tmpFilter);
- tmpFilter = new OSISRuby();
+ tmpFilter = new OSISGlosses();
+ optionFilters.insert(OptionFilterMap::value_type("OSISGlosses", tmpFilter));
optionFilters.insert(OptionFilterMap::value_type("OSISRuby", tmpFilter));
cleanupFilters.push_back(tmpFilter);
+ tmpFilter = new OSISXlit();
+ optionFilters.insert(OptionFilterMap::value_type("OSISXlit", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
+ tmpFilter = new OSISEnum();
+ optionFilters.insert(OptionFilterMap::value_type("OSISEnum", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
+ tmpFilter = new OSISVariants();
+ optionFilters.insert(OptionFilterMap::value_type("OSISVariants", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
tmpFilter = new ThMLStrongs();
optionFilters.insert(OptionFilterMap::value_type("ThMLStrongs", tmpFilter));
cleanupFilters.push_back(tmpFilter);
@@ -241,15 +272,25 @@ void SWMgr::init() {
gbfplain = new GBFPlain();
cleanupFilters.push_back(gbfplain);
+ extraFilters.insert(FilterMap::value_type("GBFPlain", gbfplain));
thmlplain = new ThMLPlain();
cleanupFilters.push_back(thmlplain);
+ extraFilters.insert(FilterMap::value_type("ThMLPlain", thmlplain));
osisplain = new OSISPlain();
cleanupFilters.push_back(osisplain);
+ extraFilters.insert(FilterMap::value_type("OSISPlain", osisplain));
teiplain = new TEIPlain();
cleanupFilters.push_back(teiplain);
+ extraFilters.insert(FilterMap::value_type("TEIPlain", teiplain));
+
+ // filters which aren't really used anywhere but which we want available for a "FilterName" -> filter mapping (e.g., filterText)
+ SWFilter *f = new RTFHTML();
+ extraFilters.insert(FilterMap::value_type("RTFHTML", f));
+ cleanupFilters.push_back(f);
+
}
@@ -715,7 +756,7 @@ void SWMgr::augmentModules(const char *ipath, bool multiMod) {
// fix config's Section names to rename modules which are available more than once
// find out which sections are in both config objects
// inserting all configs first is not good because that overwrites old keys and new modules would share the same config
- for (SectionMap::iterator it = config->Sections.begin(); it != config->Sections.end(); ++it) {
+ for (SectionMap::iterator it = config->Sections.begin(); it != config->Sections.end();) {
if (saveConfig->Sections.find( (*it).first ) != saveConfig->Sections.end()) { //if the new section is already present rename it
ConfigEntMap entMap((*it).second);
@@ -727,8 +768,10 @@ void SWMgr::augmentModules(const char *ipath, bool multiMod) {
} while (config->Sections.find(name) != config->Sections.end());
config->Sections.insert(SectionMap::value_type(name, entMap) );
- config->Sections.erase(it);
+ SectionMap::iterator toErase = it++;
+ config->Sections.erase(toErase);
}
+ else ++it;
}
}
@@ -819,7 +862,8 @@ signed char SWMgr::Load() {
return ret;
}
-SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &section)
+
+SWModule *SWMgr::createModule(const char *name, const char *driver, ConfigEntMap &section)
{
SWBuf description, datapath, misc1;
ConfigEntMap::iterator entry;
@@ -868,7 +912,9 @@ SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &s
else
markup = FMT_GBF;
- if (!stricmp(encoding.c_str(), "UTF-8")) {
+ if (!stricmp(encoding.c_str(), "SCSU"))
+ enc = ENC_SCSU;
+ else if (!stricmp(encoding.c_str(), "UTF-8")) {
enc = ENC_UTF8;
}
else enc = ENC_LATIN1;
@@ -889,7 +935,6 @@ SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &s
if ((!stricmp(driver, "zText")) || (!stricmp(driver, "zCom"))) {
SWCompress *compress = 0;
int blockType = CHAPTERBLOCKS;
- int blockNum = 1;
misc1 = ((entry = section.find("BlockType")) != section.end()) ? (*entry).second : (SWBuf)"CHAPTER";
if (!stricmp(misc1.c_str(), "VERSE"))
blockType = VERSEBLOCKS;
@@ -898,14 +943,17 @@ SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &s
else if (!stricmp(misc1.c_str(), "BOOK"))
blockType = BOOKBLOCKS;
- misc1 = ((entry = section.find("BlockNumber")) != section.end()) ? (*entry).second : (SWBuf)"1";
- blockNum = atoi(misc1.c_str());
-
misc1 = ((entry = section.find("CompressType")) != section.end()) ? (*entry).second : (SWBuf)"LZSS";
#ifndef EXCLUDEZLIB
if (!stricmp(misc1.c_str(), "ZIP"))
compress = new ZipCompress();
else
+ if (!stricmp(misc1.c_str(), "BZIP2_UNSUPPORTED"))
+ compress = new Bzip2Compress();
+ else
+ if (!stricmp(misc1.c_str(), "XZ_UNSUPPORTED"))
+ compress = new XzCompress();
+ else
#endif
if (!stricmp(misc1.c_str(), "LZSS"))
compress = new LZSSCompress();
@@ -949,18 +997,24 @@ SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &s
int pos = 0; //used for position of final / in AbsoluteDataPath, but also set to 1 for modules types that need to strip module name
if (!stricmp(driver, "RawLD")) {
- newmod = new RawLD(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
+ bool caseSensitive = ((entry = section.find("CaseSensitiveKeys")) != section.end()) ? (*entry).second == "true": false;
+ bool strongsPadding = ((entry = section.find("StrongsPadding")) != section.end()) ? (*entry).second == "true": true;
+ newmod = new RawLD(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), caseSensitive, strongsPadding);
pos = 1;
}
if (!stricmp(driver, "RawLD4")) {
- newmod = new RawLD4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
+ bool caseSensitive = ((entry = section.find("CaseSensitiveKeys")) != section.end()) ? (*entry).second == "true": false;
+ bool strongsPadding = ((entry = section.find("StrongsPadding")) != section.end()) ? (*entry).second == "true": true;
+ newmod = new RawLD4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), caseSensitive, strongsPadding);
pos = 1;
}
if (!stricmp(driver, "zLD")) {
SWCompress *compress = 0;
int blockCount;
+ bool caseSensitive = ((entry = section.find("CaseSensitiveKeys")) != section.end()) ? (*entry).second == "true": false;
+ bool strongsPadding = ((entry = section.find("StrongsPadding")) != section.end()) ? (*entry).second == "true": true;
misc1 = ((entry = section.find("BlockCount")) != section.end()) ? (*entry).second : (SWBuf)"200";
blockCount = atoi(misc1.c_str());
blockCount = (blockCount) ? blockCount : 200;
@@ -975,7 +1029,7 @@ SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &s
compress = new LZSSCompress();
if (compress) {
- newmod = new zLD(datapath.c_str(), name, description.c_str(), blockCount, compress, 0, enc, direction, markup, lang.c_str());
+ newmod = new zLD(datapath.c_str(), name, description.c_str(), blockCount, compress, 0, enc, direction, markup, lang.c_str(), caseSensitive, strongsPadding);
}
pos = 1;
}
@@ -1008,7 +1062,7 @@ SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &s
if (newmod) {
// if a specific module type is set in the config, use this
if ((entry = section.find("Type")) != section.end())
- newmod->Type(entry->second.c_str());
+ newmod->setType(entry->second.c_str());
newmod->setConfig(&section);
}
@@ -1018,11 +1072,37 @@ SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &s
void SWMgr::AddGlobalOptions(SWModule *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end) {
- for (;start != end; start++) {
+
+ for (;start != end; ++start) {
OptionFilterMap::iterator it;
- it = optionFilters.find((*start).second);
+ SWBuf filterName = start->second;
+
+
+ // special cases for filters with parameters
+
+ if (filterName.startsWith("OSISReferenceLinks")) {
+ SWBuf params = filterName;
+ filterName = params.stripPrefix('|', true);
+ SWBuf optionName = params.stripPrefix('|', true);
+ SWBuf optionTip = params.stripPrefix('|', true);
+ SWBuf optionType = params.stripPrefix('|', true);
+ SWBuf optionSubType = params.stripPrefix('|', true);
+ SWBuf optionDefaultValue = params.stripPrefix('|', true);
+ // we'll key off of type and subtype.
+ filterName = filterName + "." + optionType + "." + optionSubType;
+
+ it = optionFilters.find(filterName);
+ if (it == optionFilters.end()) {
+ SWOptionFilter *tmpFilter = new OSISReferenceLinks(optionName, optionTip, optionType, optionSubType, optionDefaultValue);
+ optionFilters.insert(OptionFilterMap::value_type(filterName, tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+ }
+ }
+
+
+ it = optionFilters.find(filterName);
if (it != optionFilters.end()) {
- module->AddOptionFilter((*it).second); // add filter to module and option as a valid option
+ module->addOptionFilter((*it).second); // add filter to module and option as a valid option
StringList::iterator loop;
for (loop = options.begin(); loop != options.end(); loop++) {
if (!strcmp((*loop).c_str(), (*it).second->getOptionName()))
@@ -1035,20 +1115,31 @@ void SWMgr::AddGlobalOptions(SWModule *module, ConfigEntMap &section, ConfigEntM
if (filterMgr)
filterMgr->AddGlobalOptions(module, section, start, end);
#ifdef _ICU_
- module->AddOptionFilter(transliterator);
+ module->addOptionFilter(transliterator);
#endif
}
char SWMgr::filterText(const char *filterName, SWBuf &text, const SWKey *key, const SWModule *module)
- {
+{
char retVal = -1;
+ // why didn't we use find here?
for (OptionFilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
if ((*it).second->getOptionName()) {
- if (!stricmp(filterName, (*it).second->getOptionName()))
- retVal = it->second->processText(text, key, module); // add filter to module
+ if (!stricmp(filterName, (*it).second->getOptionName())) {
+ retVal = it->second->processText(text, key, module);
+ break;
+ }
+ }
+ }
+
+ if (retVal == -1) {
+ FilterMap::iterator it = extraFilters.find(filterName);
+ if (it != extraFilters.end()) {
+ retVal = it->second->processText(text, key, module);
}
}
+
return retVal;
}
@@ -1059,7 +1150,7 @@ void SWMgr::AddLocalOptions(SWModule *module, ConfigEntMap &section, ConfigEntMa
OptionFilterMap::iterator it;
it = optionFilters.find((*start).second);
if (it != optionFilters.end()) {
- module->AddOptionFilter((*it).second); // add filter to module
+ module->addOptionFilter((*it).second); // add filter to module
}
}
@@ -1075,7 +1166,7 @@ void SWMgr::AddStripFilters(SWModule *module, ConfigEntMap &section, ConfigEntMa
OptionFilterMap::iterator it;
it = optionFilters.find((*start).second);
if (it != optionFilters.end()) {
- module->AddStripFilter((*it).second); // add filter to module
+ module->addStripFilter((*it).second); // add filter to module
}
}
}
@@ -1088,9 +1179,9 @@ void SWMgr::AddRawFilters(SWModule *module, ConfigEntMap &section) {
cipherKey = ((entry = section.find("CipherKey")) != section.end()) ? (*entry).second : (SWBuf)"";
if (cipherKey.length()) {
SWFilter *cipherFilter = new CipherFilter(cipherKey.c_str());
- cipherFilters.insert(FilterMap::value_type(module->Name(), cipherFilter));
+ cipherFilters.insert(FilterMap::value_type(module->getName(), cipherFilter));
cleanupFilters.push_back(cipherFilter);
- module->AddRawFilter(cipherFilter);
+ module->addRawFilter(cipherFilter);
}
if (filterMgr)
@@ -1145,16 +1236,16 @@ void SWMgr::AddStripFilters(SWModule *module, ConfigEntMap &section)
}
if (!stricmp(sourceformat.c_str(), "GBF")) {
- module->AddStripFilter(gbfplain);
+ module->addStripFilter(gbfplain);
}
else if (!stricmp(sourceformat.c_str(), "ThML")) {
- module->AddStripFilter(thmlplain);
+ module->addStripFilter(thmlplain);
}
else if (!stricmp(sourceformat.c_str(), "OSIS")) {
- module->AddStripFilter(osisplain);
+ module->addStripFilter(osisplain);
}
else if (!stricmp(sourceformat.c_str(), "TEI")) {
- module->AddStripFilter(teiplain);
+ module->addStripFilter(teiplain);
}
if (filterMgr)
@@ -1176,19 +1267,19 @@ void SWMgr::CreateMods(bool multiMod) {
driver = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)"";
if (driver.length()) {
- newmod = CreateMod((*it).first, driver, section);
+ newmod = createModule((*it).first, driver, section);
if (newmod) {
// Filters to add for this module and globally announce as an option to the user
// e.g. translit, strongs, redletterwords, etc, so users can turn these on and off globally
- start = (*it).second.lower_bound("GlobalOptionFilter");
- end = (*it).second.upper_bound("GlobalOptionFilter");
+ start = section.lower_bound("GlobalOptionFilter");
+ end = section.upper_bound("GlobalOptionFilter");
AddGlobalOptions(newmod, section, start, end);
// Only add the option to the module, don't announce it's availability
// These are useful for like: filters that parse special entryAttribs in a text
// or whatever you might want to happen on entry lookup
- start = (*it).second.lower_bound("LocalOptionFilter");
- end = (*it).second.upper_bound("LocalOptionFilter");
+ start = section.lower_bound("LocalOptionFilter");
+ end = section.upper_bound("LocalOptionFilter");
AddLocalOptions(newmod, section, start, end);
//STRIP FILTERS
@@ -1198,20 +1289,20 @@ void SWMgr::CreateMods(bool multiMod) {
// Any special processing for this module when searching:
// e.g. for papyri, removed all [](). notation
- start = (*it).second.lower_bound("LocalStripFilter");
- end = (*it).second.upper_bound("LocalStripFilter");
+ start = section.lower_bound("LocalStripFilter");
+ end = section.upper_bound("LocalStripFilter");
AddStripFilters(newmod, section, start, end);
AddRawFilters(newmod, section);
AddRenderFilters(newmod, section);
AddEncodingFilters(newmod, section);
- SWModule *oldmod = Modules[newmod->Name()];
+ SWModule *oldmod = Modules[newmod->getName()];
if (oldmod) {
delete oldmod;
}
- Modules[newmod->Name()] = newmod;
+ Modules[newmod->getName()] = newmod;
}
}
}
@@ -1382,11 +1473,13 @@ signed char SWMgr::setCipherKey(const char *modName, const char *key) {
SWFilter *cipherFilter = new CipherFilter(key);
cipherFilters.insert(FilterMap::value_type(modName, cipherFilter));
cleanupFilters.push_back(cipherFilter);
- (*it2).second->AddRawFilter(cipherFilter);
+ (*it2).second->addRawFilter(cipherFilter);
return 0;
}
}
return -1;
}
+
SWORD_NAMESPACE_END
+