summaryrefslogtreecommitdiff
path: root/src/mgr/swmgr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mgr/swmgr.cpp')
-rw-r--r--src/mgr/swmgr.cpp455
1 files changed, 291 insertions, 164 deletions
diff --git a/src/mgr/swmgr.cpp b/src/mgr/swmgr.cpp
index 36aecb0..6207b60 100644
--- a/src/mgr/swmgr.cpp
+++ b/src/mgr/swmgr.cpp
@@ -2,7 +2,7 @@
* swmgr.cpp - implementaion of class SWMgr used to interact with an install
* base of sword modules.
*
- * $Id: swmgr.cpp,v 1.70 2002/03/22 05:26:34 scribe Exp $
+ * $Id: swmgr.cpp,v 1.96 2003/12/05 21:44:33 scribe Exp $
*
* Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
@@ -32,7 +32,7 @@
#endif
#include <sys/stat.h>
#ifndef _MSC_VER
-#include <iostream.h>
+#include <iostream>
#endif
#include <dirent.h>
@@ -46,14 +46,24 @@
#include <utilfuns.h>
#include <gbfplain.h>
#include <thmlplain.h>
+#include <osisplain.h>
#include <gbfstrongs.h>
#include <gbffootnotes.h>
#include <gbfheadings.h>
+#include <gbfredletterwords.h>
#include <gbfmorph.h>
+#include <osisheadings.h>
+#include <osisfootnotes.h>
+#include <osisstrongs.h>
+#include <osismorph.h>
+#include <osislemma.h>
+#include <osisredletterwords.h>
+#include <osisscripref.h>
#include <thmlstrongs.h>
#include <thmlfootnotes.h>
#include <thmlheadings.h>
#include <thmlmorph.h>
+#include <thmlvariants.h>
#include <thmllemma.h>
#include <thmlscripref.h>
#include <cipherfil.h>
@@ -67,17 +77,24 @@
#include <utf8hebrewpoints.h>
#include <greeklexattribs.h>
#include <swfiltermgr.h>
+#ifndef EXCLUDEZLIB
+#include "zipcomprs.h"
+#endif
-
-#ifdef ICU
+#ifdef _ICU_
#include <utf8transliterator.h>
#endif
-#ifndef EXCLUDEZLIB
-#include <zipcomprs.h>
+SWORD_NAMESPACE_START
+
+#ifdef _ICU_
+bool SWMgr::isICU = true;
+#else
+bool SWMgr::isICU = false;
#endif
+
bool SWMgr::debug = false;
#ifdef GLOBCONFPATH
@@ -100,6 +117,10 @@ void SWMgr::init() {
optionFilters.clear();
cleanupFilters.clear();
+ tmpFilter = new ThMLVariants();
+ optionFilters.insert(FilterMap::value_type("ThMLVariants", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
tmpFilter = new GBFStrongs();
optionFilters.insert(FilterMap::value_type("GBFStrongs", tmpFilter));
cleanupFilters.push_back(tmpFilter);
@@ -108,6 +129,10 @@ void SWMgr::init() {
optionFilters.insert(FilterMap::value_type("GBFFootnotes", tmpFilter));
cleanupFilters.push_back(tmpFilter);
+ tmpFilter = new GBFRedLetterWords();
+ optionFilters.insert(FilterMap::value_type("GBFRedLetterWords", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
tmpFilter = new GBFMorph();
optionFilters.insert(FilterMap::value_type("GBFMorph", tmpFilter));
cleanupFilters.push_back(tmpFilter);
@@ -116,6 +141,34 @@ void SWMgr::init() {
optionFilters.insert(FilterMap::value_type("GBFHeadings", tmpFilter));
cleanupFilters.push_back(tmpFilter);
+ tmpFilter = new OSISHeadings();
+ optionFilters.insert(FilterMap::value_type("OSISHeadings", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
+ tmpFilter = new OSISStrongs();
+ optionFilters.insert(FilterMap::value_type("OSISStrongs", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
+ tmpFilter = new OSISMorph();
+ optionFilters.insert(FilterMap::value_type("OSISMorph", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
+ tmpFilter = new OSISLemma();
+ optionFilters.insert(FilterMap::value_type("OSISLemma", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
+ tmpFilter = new OSISFootnotes();
+ optionFilters.insert(FilterMap::value_type("OSISFootnotes", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
+ tmpFilter = new OSISScripref();
+ optionFilters.insert(FilterMap::value_type("OSISScripref", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
+ tmpFilter = new OSISRedLetterWords();
+ optionFilters.insert(FilterMap::value_type("OSISRedLetterWords", tmpFilter));
+ cleanupFilters.push_back(tmpFilter);
+
tmpFilter = new ThMLStrongs();
optionFilters.insert(FilterMap::value_type("ThMLStrongs", tmpFilter));
cleanupFilters.push_back(tmpFilter);
@@ -156,18 +209,22 @@ void SWMgr::init() {
optionFilters.insert(FilterMap::value_type("GreekLexAttribs", tmpFilter));
cleanupFilters.push_back(tmpFilter);
-/* UTF8Transliterator needs to be handled differently because it should always available as an option, for all modules
-#ifdef ICU
- tmpFilter = new UTF8Transliterator();
- optionFilters.insert(FilterMap::value_type("UTF8Transliterator", tmpFilter));
- cleanupFilters.push_back(tmpFilter);
+// UTF8Transliterator needs to be handled differently because it should always available as an option, for all modules
+#ifdef _ICU_
+ transliterator = new UTF8Transliterator();
+ optionFilters.insert(FilterMap::value_type("UTF8Transliterator", transliterator));
+ options.push_back(transliterator->getOptionName());
+ cleanupFilters.push_back(transliterator);
#endif
-*/
+
gbfplain = new GBFPlain();
cleanupFilters.push_back(gbfplain);
thmlplain = new ThMLPlain();
cleanupFilters.push_back(thmlplain);
+
+ osisplain = new OSISPlain();
+ cleanupFilters.push_back(osisplain);
}
@@ -206,7 +263,7 @@ void SWMgr::commonInit(SWConfig * iconfig, SWConfig * isysconfig, bool autoload,
SWMgr::SWMgr(const char *iConfigPath, bool autoload, SWFilterMgr *filterMgr) {
- string path;
+ SWBuf path;
this->filterMgr = filterMgr;
if (filterMgr)
@@ -215,7 +272,8 @@ SWMgr::SWMgr(const char *iConfigPath, bool autoload, SWFilterMgr *filterMgr) {
init();
path = iConfigPath;
- if ((iConfigPath[strlen(iConfigPath)-1] != '\\') && (iConfigPath[strlen(iConfigPath)-1] != '/'))
+ int len = path.length();
+ if ((len < 1) || (iConfigPath[len-1] != '\\') && (iConfigPath[len-1] != '/'))
path += "/";
if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
stdstr(&prefixPath, path.c_str());
@@ -263,9 +321,10 @@ SWMgr::~SWMgr() {
}
-void SWMgr::findConfig(char *configType, char **prefixPath, char **configPath) {
- string path;
+void SWMgr::findConfig(char *configType, char **prefixPath, char **configPath, std::list<SWBuf> *augPaths) {
+ SWBuf path;
ConfigEntMap::iterator entry;
+ ConfigEntMap::iterator lastEntry;
char *envsworddir = getenv ("SWORD_PATH");
char *envhomedir = getenv ("HOME");
@@ -275,14 +334,14 @@ void SWMgr::findConfig(char *configType, char **prefixPath, char **configPath) {
#ifndef _MSC_VER
// check working directory
if (debug)
- cerr << "Checking working directory for mods.conf...";
+ std::cerr << "Checking working directory for mods.conf...";
#endif
if (FileMgr::existsFile(".", "mods.conf")) {
#ifndef _MSC_VER
if (debug)
- cerr << "found\n";
+ std::cerr << "found\n";
#endif
stdstr(prefixPath, "./");
@@ -292,14 +351,14 @@ if (debug)
#ifndef _MSC_VER
if (debug)
- cerr << "\nChecking working directory for mods.d...";
+ std::cerr << "\nChecking working directory for mods.d...";
#endif
if (FileMgr::existsDir(".", "mods.d")) {
#ifndef _MSC_VER
if (debug)
- cerr << "found\n";
+ std::cerr << "found\n";
#endif
stdstr(prefixPath, "./");
@@ -312,14 +371,14 @@ if (debug)
// check environment variable SWORD_PATH
#ifndef _MSC_VER
if (debug)
- cerr << "\nChecking SWORD_PATH...";
+ std::cerr << "\nChecking SWORD_PATH...";
#endif
if (envsworddir != NULL) {
#ifndef _MSC_VER
if (debug)
- cerr << "found (" << envsworddir << ")\n";
+ std::cerr << "found (" << envsworddir << ")\n";
#endif
path = envsworddir;
@@ -328,14 +387,14 @@ if (debug)
#ifndef _MSC_VER
if (debug)
- cerr << "\nChecking $SWORD_PATH for mods.conf...";
+ std::cerr << "\nChecking $SWORD_PATH for mods.conf...";
#endif
if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
#ifndef _MSC_VER
if (debug)
- cerr << "found\n";
+ std::cerr << "found\n";
#endif
stdstr(prefixPath, path.c_str());
@@ -346,14 +405,14 @@ if (debug)
#ifndef _MSC_VER
if (debug)
- cerr << "\nChecking $SWORD_PATH for mods.d...";
+ std::cerr << "\nChecking $SWORD_PATH for mods.d...";
#endif
if (FileMgr::existsDir(path.c_str(), "mods.d")) {
#ifndef _MSC_VER
if (debug)
- cerr << "found\n";
+ std::cerr << "found\n";
#endif
stdstr(prefixPath, path.c_str());
@@ -369,7 +428,7 @@ if (debug)
#ifndef _MSC_VER
if (debug)
- cerr << "\nParsing " << globalConfPath << "...";
+ std::cerr << "\nParsing " << globalConfPath << "...";
#endif
char *globPaths = 0;
@@ -377,23 +436,41 @@ if (debug)
stdstr(&globPaths, globalConfPath);
for (gfp = strtok(globPaths, ":"); gfp; gfp = strtok(0, ":")) {
- #ifndef _MSC_VER
+#ifndef _MSC_VER
if (debug)
- cerr << "\nChecking for " << gfp << "...";
+ std::cerr << "\nChecking for " << gfp << "...";
#endif
if (FileMgr::existsFile(gfp))
break;
}
+ SWBuf sysConfPath;
+ if (gfp)
+ sysConfPath = gfp;
+
+ SWBuf homeDir = getenv ("HOME");
+ if (homeDir.size() > 0) {
+ if ((homeDir[homeDir.size()-1] != '\\') && (homeDir[homeDir.size()-1] != '/'))
+ homeDir += "/";
+ homeDir += ".sword/sword.conf";
+ if (FileMgr::existsFile(homeDir)) {
+#ifndef _MSC_VER
+if (debug)
+ std::cerr << "\nOverriding any systemwide sword.conf with one found in users home directory." << gfp << "...";
+#endif
+ sysConfPath = homeDir;
+ }
+ }
+
- if (gfp) {
+ if (sysConfPath.size()) {
#ifndef _MSC_VER
if (debug)
- cerr << "found\n";
+ std::cerr << "found\n";
#endif
- SWConfig etcconf(gfp);
+ SWConfig etcconf(sysConfPath);
if ((entry = etcconf.Sections["Install"].find("DataPath")) != etcconf.Sections["Install"].end()) {
path = (*entry).second;
if (((*entry).second.c_str()[strlen((*entry).second.c_str())-1] != '\\') && ((*entry).second.c_str()[strlen((*entry).second.c_str())-1] != '/'))
@@ -401,56 +478,66 @@ if (debug)
#ifndef _MSC_VER
if (debug)
- cerr << "DataPath in " << gfp << " is set to: " << path;
+ std::cerr << "DataPath in " << sysConfPath << " is set to: " << path;
#endif
#ifndef _MSC_VER
if (debug)
- cerr << "\nChecking for mods.conf in DataPath ";
+ std::cerr << "\nChecking for mods.conf in DataPath ";
#endif
if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
#ifndef _MSC_VER
if (debug)
- cerr << "found\n";
+ std::cerr << "found\n";
#endif
stdstr(prefixPath, path.c_str());
path += "mods.conf";
stdstr(configPath, path.c_str());
- delete [] globPaths;
- return;
+ *configType = 1;
}
#ifndef _MSC_VER
if (debug)
- cerr << "\nChecking for mods.d in DataPath ";
+ std::cerr << "\nChecking for mods.d in DataPath ";
#endif
if (FileMgr::existsDir(path.c_str(), "mods.d")) {
#ifndef _MSC_VER
if (debug)
- cerr << "found\n";
+ std::cerr << "found\n";
#endif
stdstr(prefixPath, path.c_str());
path += "mods.d";
stdstr(configPath, path.c_str());
*configType = 1;
- delete [] globPaths;
- return;
+ }
+ }
+ if (augPaths) {
+ augPaths->clear();
+ entry = etcconf.Sections["Install"].lower_bound("AugmentPath");
+ lastEntry = etcconf.Sections["Install"].upper_bound("AugmentPath");
+ for (;entry != lastEntry; entry++) {
+ path = entry->second;
+ if ((entry->second.c_str()[strlen(entry->second.c_str())-1] != '\\') && (entry->second.c_str()[strlen(entry->second.c_str())-1] != '/'))
+ path += "/";
+ augPaths->push_back(path);
}
}
}
delete [] globPaths;
+ if (*configType)
+ return;
// check ~/.sword/
#ifndef _MSC_VER
if (debug)
- cerr << "\nChecking home directory for ~/.sword/mods.conf" << path;
+ std::cerr << "\nChecking home directory for ~/.sword/mods.conf" << path;
#endif
if (envhomedir != NULL) {
@@ -462,7 +549,7 @@ if (debug)
#ifndef _MSC_VER
if (debug)
- cerr << " found\n";
+ std::cerr << " found\n";
#endif
stdstr(prefixPath, path.c_str());
@@ -473,14 +560,14 @@ if (debug)
#ifndef _MSC_VER
if (debug)
- cerr << "\nChecking home directory for ~/.sword/mods.d" << path;
+ std::cerr << "\nChecking home directory for ~/.sword/mods.d" << path;
#endif
if (FileMgr::existsDir(path.c_str(), "mods.d")) {
#ifndef _MSC_VER
if (debug)
- cerr << "found\n";
+ std::cerr << "found\n";
#endif
stdstr(prefixPath, path.c_str());
@@ -497,7 +584,7 @@ void SWMgr::loadConfigDir(const char *ipath)
{
DIR *dir;
struct dirent *ent;
- string newmodfile;
+ SWBuf newmodfile;
if ((dir = opendir(ipath))) {
rewinddir(dir);
@@ -526,6 +613,36 @@ void SWMgr::loadConfigDir(const char *ipath)
}
+void SWMgr::augmentModules(const char *ipath) {
+ SWBuf path = ipath;
+ if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/'))
+ path += "/";
+ if (FileMgr::existsDir(path.c_str(), "mods.d")) {
+ char *savePrefixPath = 0;
+ char *saveConfigPath = 0;
+ SWConfig *saveConfig = 0;
+ stdstr(&savePrefixPath, prefixPath);
+ stdstr(&prefixPath, path.c_str());
+ path += "mods.d";
+ stdstr(&saveConfigPath, configPath);
+ stdstr(&configPath, path.c_str());
+ saveConfig = config;
+ config = myconfig = 0;
+ loadConfigDir(configPath);
+
+ CreateMods();
+
+ stdstr(&prefixPath, savePrefixPath);
+ delete []savePrefixPath;
+ stdstr(&configPath, saveConfigPath);
+ delete []saveConfigPath;
+ (*saveConfig) += *config;
+ homeConfig = myconfig;
+ config = myconfig = saveConfig;
+ }
+}
+
+
/***********************************************************************
* SWMgr::Load - loads actual modules
*
@@ -538,7 +655,7 @@ signed char SWMgr::Load() {
if (!config) { // If we weren't passed a config object at construction, find a config file
if (!configPath) // If we weren't passed a config path at construction...
- findConfig(&configType, &prefixPath, &configPath);
+ findConfig(&configType, &prefixPath, &configPath, &augPaths);
if (configPath) {
if (configType)
loadConfigDir(configPath);
@@ -565,37 +682,18 @@ signed char SWMgr::Load() {
CreateMods();
+ for (std::list<SWBuf>::iterator pathIt = augPaths.begin(); pathIt != augPaths.end(); pathIt++) {
+ augmentModules(pathIt->c_str());
+ }
// augment config with ~/.sword/mods.d if it exists ---------------------
- char *envhomedir = getenv ("HOME");
- if (envhomedir != NULL && configType != 2) { // 2 = user only
- string path = envhomedir;
- if ((envhomedir[strlen(envhomedir)-1] != '\\') && (envhomedir[strlen(envhomedir)-1] != '/'))
- path += "/";
- path += ".sword/";
- if (FileMgr::existsDir(path.c_str(), "mods.d")) {
- char *savePrefixPath = 0;
- char *saveConfigPath = 0;
- SWConfig *saveConfig = 0;
- stdstr(&savePrefixPath, prefixPath);
- stdstr(&prefixPath, path.c_str());
- path += "mods.d";
- stdstr(&saveConfigPath, configPath);
- stdstr(&configPath, path.c_str());
- saveConfig = config;
- config = myconfig = 0;
- loadConfigDir(configPath);
-
- CreateMods();
-
- stdstr(&prefixPath, savePrefixPath);
- delete []savePrefixPath;
- stdstr(&configPath, saveConfigPath);
- delete []saveConfigPath;
- (*saveConfig) += *config;
- homeConfig = myconfig;
- config = myconfig = saveConfig;
- }
- }
+ char *envhomedir = getenv ("HOME");
+ if (envhomedir != NULL && configType != 2) { // 2 = user only
+ SWBuf path = envhomedir;
+ if ((envhomedir[strlen(envhomedir)-1] != '\\') && (envhomedir[strlen(envhomedir)-1] != '/'))
+ path += "/";
+ path += ".sword/";
+ augmentModules(path.c_str());
+ }
// -------------------------------------------------------------------------
if ( !Modules.size() ) // config exists, but no modules
ret = 1;
@@ -609,65 +707,69 @@ signed char SWMgr::Load() {
return ret;
}
-SWModule *SWMgr::CreateMod(string name, string driver, ConfigEntMap &section)
+SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &section)
{
- string description, datapath, misc1;
+ SWBuf description, datapath, misc1;
ConfigEntMap::iterator entry;
SWModule *newmod = 0;
- string lang, sourceformat, encoding;
- signed char direction, enc, markup;
+ SWBuf lang, sourceformat, encoding;
+ signed char direction, enc, markup;
- description = ((entry = section.find("Description")) != section.end()) ? (*entry).second : (string)"";
- lang = ((entry = section.find("Lang")) != section.end()) ? (*entry).second : (string)"en";
- sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (string)"";
- encoding = ((entry = section.find("Encoding")) != section.end()) ? (*entry).second : (string)"";
+ description = ((entry = section.find("Description")) != section.end()) ? (*entry).second : (SWBuf)"";
+ lang = ((entry = section.find("Lang")) != section.end()) ? (*entry).second : (SWBuf)"en";
+ sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (SWBuf)"";
+ encoding = ((entry = section.find("Encoding")) != section.end()) ? (*entry).second : (SWBuf)"";
datapath = prefixPath;
if ((prefixPath[strlen(prefixPath)-1] != '\\') && (prefixPath[strlen(prefixPath)-1] != '/'))
datapath += "/";
- misc1 += ((entry = section.find("DataPath")) != section.end()) ? (*entry).second : (string)"";
+ misc1 += ((entry = section.find("DataPath")) != section.end()) ? (*entry).second : (SWBuf)"";
char *buf = new char [ strlen(misc1.c_str()) + 1 ];
char *buf2 = buf;
strcpy(buf, misc1.c_str());
// for (; ((*buf2) && ((*buf2 == '.') || (*buf2 == '/') || (*buf2 == '\\'))); buf2++);
for (; ((*buf2) && ((*buf2 == '/') || (*buf2 == '\\'))); buf2++);
+ if (!strncmp(buf2, "./", 2)) { //remove the leading ./ in the module data path to make it look better
+ buf2 += 2;
+ }
if (*buf2)
datapath += buf2;
delete [] buf;
section["AbsoluteDataPath"] = datapath;
- if (!stricmp(sourceformat.c_str(), "GBF"))
- markup = FMT_GBF;
- else if (!stricmp(sourceformat.c_str(), "ThML"))
- markup = FMT_THML;
- else if (!stricmp(sourceformat.c_str(), "OSIS"))
- markup = FMT_OSIS;
- else
- markup = FMT_PLAIN;
-
- if (!stricmp(encoding.c_str(), "SCSU"))
- enc = ENC_SCSU;
- else if (!stricmp(encoding.c_str(), "UTF-8"))
- enc = ENC_UTF8;
- else enc = ENC_LATIN1;
+ if (!stricmp(sourceformat.c_str(), "GBF"))
+ markup = FMT_GBF;
+ else if (!stricmp(sourceformat.c_str(), "ThML"))
+ markup = FMT_THML;
+ else if (!stricmp(sourceformat.c_str(), "OSIS"))
+ markup = FMT_OSIS;
+ else
+ markup = FMT_GBF;
+
+ if (!stricmp(encoding.c_str(), "SCSU"))
+ enc = ENC_SCSU;
+ else if (!stricmp(encoding.c_str(), "UTF-8")) {
+ enc = ENC_UTF8;
+ }
+ else enc = ENC_LATIN1;
if ((entry = section.find("Direction")) == section.end()) {
- direction = DIRECTION_LTR;
- }
- else if (!stricmp((*entry).second.c_str(), "rtol")) {
- direction = DIRECTION_RTL;
- }
- else if (!stricmp((*entry).second.c_str(), "bidi")) {
- direction = DIRECTION_BIDI;
- }
- else {
- direction = DIRECTION_LTR;
- }
+ direction = DIRECTION_LTR;
+ }
+ else if (!stricmp((*entry).second.c_str(), "rtol")) {
+ direction = DIRECTION_RTL;
+ }
+ else if (!stricmp((*entry).second.c_str(), "bidi")) {
+ direction = DIRECTION_BIDI;
+ }
+ else {
+ direction = DIRECTION_LTR;
+ }
- if ((!stricmp(driver.c_str(), "zText")) || (!stricmp(driver.c_str(), "zCom"))) {
+ if ((!stricmp(driver, "zText")) || (!stricmp(driver, "zCom"))) {
SWCompress *compress = 0;
int blockType = CHAPTERBLOCKS;
- misc1 = ((entry = section.find("BlockType")) != section.end()) ? (*entry).second : (string)"CHAPTER";
+ misc1 = ((entry = section.find("BlockType")) != section.end()) ? (*entry).second : (SWBuf)"CHAPTER";
if (!stricmp(misc1.c_str(), "VERSE"))
blockType = VERSEBLOCKS;
else if (!stricmp(misc1.c_str(), "CHAPTER"))
@@ -675,7 +777,7 @@ SWModule *SWMgr::CreateMod(string name, string driver, ConfigEntMap &section)
else if (!stricmp(misc1.c_str(), "BOOK"))
blockType = BOOKBLOCKS;
- misc1 = ((entry = section.find("CompressType")) != section.end()) ? (*entry).second : (string)"LZSS";
+ misc1 = ((entry = section.find("CompressType")) != section.end()) ? (*entry).second : (SWBuf)"LZSS";
#ifndef EXCLUDEZLIB
if (!stricmp(misc1.c_str(), "ZIP"))
compress = new ZipCompress();
@@ -685,48 +787,53 @@ SWModule *SWMgr::CreateMod(string name, string driver, ConfigEntMap &section)
compress = new LZSSCompress();
if (compress) {
- if (!stricmp(driver.c_str(), "zText"))
- newmod = new zText(datapath.c_str(), name.c_str(), description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str());
- else newmod = new zCom(datapath.c_str(), name.c_str(), description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str());
+ if (!stricmp(driver, "zText"))
+ newmod = new zText(datapath.c_str(), name, description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str());
+ else newmod = new zCom(datapath.c_str(), name, description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str());
}
}
- if (!stricmp(driver.c_str(), "RawText")) {
- newmod = new RawText(datapath.c_str(), name.c_str(), description.c_str(), 0, enc, direction, markup, lang.c_str());
+ if (!stricmp(driver, "RawText")) {
+ newmod = new RawText(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
}
// backward support old drivers
- if (!stricmp(driver.c_str(), "RawGBF")) {
- newmod = new RawText(datapath.c_str(), name.c_str(), description.c_str(), 0, enc, direction, markup, lang.c_str());
+ if (!stricmp(driver, "RawGBF")) {
+ newmod = new RawText(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
}
- if (!stricmp(driver.c_str(), "RawCom")) {
- newmod = new RawCom(datapath.c_str(), name.c_str(), description.c_str(), 0, enc, direction, markup, lang.c_str());
+ if (!stricmp(driver, "RawCom")) {
+ newmod = new RawCom(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
}
- if (!stricmp(driver.c_str(), "RawFiles")) {
- newmod = new RawFiles(datapath.c_str(), name.c_str(), description.c_str(), 0, enc, direction, markup, lang.c_str());
+ if (!stricmp(driver, "RawFiles")) {
+ newmod = new RawFiles(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
}
- if (!stricmp(driver.c_str(), "HREFCom")) {
- misc1 = ((entry = section.find("Prefix")) != section.end()) ? (*entry).second : (string)"";
- newmod = new HREFCom(datapath.c_str(), misc1.c_str(), name.c_str(), description.c_str());
+ if (!stricmp(driver, "HREFCom")) {
+ misc1 = ((entry = section.find("Prefix")) != section.end()) ? (*entry).second : (SWBuf)"";
+ newmod = new HREFCom(datapath.c_str(), misc1.c_str(), name, description.c_str());
}
- if (!stricmp(driver.c_str(), "RawLD"))
- newmod = new RawLD(datapath.c_str(), name.c_str(), description.c_str(), 0, enc, direction, markup, lang.c_str());
+ int pos; //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());
+ pos = 1;
+ }
- if (!stricmp(driver.c_str(), "RawLD4"))
- newmod = new RawLD4(datapath.c_str(), name.c_str(), description.c_str(), 0, enc, direction, markup, lang.c_str());
+ if (!stricmp(driver, "RawLD4")) {
+ newmod = new RawLD4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
+ pos = 1;
+ }
- if (!stricmp(driver.c_str(), "zLD")) {
+ if (!stricmp(driver, "zLD")) {
SWCompress *compress = 0;
int blockCount;
- misc1 = ((entry = section.find("BlockCount")) != section.end()) ? (*entry).second : (string)"200";
+ misc1 = ((entry = section.find("BlockCount")) != section.end()) ? (*entry).second : (SWBuf)"200";
blockCount = atoi(misc1.c_str());
blockCount = (blockCount) ? blockCount : 200;
- misc1 = ((entry = section.find("CompressType")) != section.end()) ? (*entry).second : (string)"LZSS";
+ misc1 = ((entry = section.find("CompressType")) != section.end()) ? (*entry).second : (SWBuf)"LZSS";
#ifndef EXCLUDEZLIB
if (!stricmp(misc1.c_str(), "ZIP"))
compress = new ZipCompress();
@@ -736,18 +843,31 @@ SWModule *SWMgr::CreateMod(string name, string driver, ConfigEntMap &section)
compress = new LZSSCompress();
if (compress) {
- newmod = new zLD(datapath.c_str(), name.c_str(), 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());
}
+ pos = 1;
}
- if (!stricmp(driver.c_str(), "RawGenBook")) {
- newmod = new RawGenBook(datapath.c_str(), name.c_str(), description.c_str(), 0, enc, direction, markup, lang.c_str());
+ if (!stricmp(driver, "RawGenBook")) {
+ newmod = new RawGenBook(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
+ pos = 1;
}
- // 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->setConfig(&section);
+ if (pos == 1) {
+ SWBuf &dp = section["AbsoluteDataPath"];
+ for (int i = dp.length() - 1; i; i--) {
+ if (dp[i] == '/') {
+ dp.setSize(i);
+ break;
+ }
+ }
+ }
+
+ // 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->setConfig(&section);
return newmod;
}
@@ -758,7 +878,7 @@ void SWMgr::AddGlobalOptions(SWModule *module, ConfigEntMap &section, ConfigEntM
it = optionFilters.find((*start).second);
if (it != optionFilters.end()) {
module->AddOptionFilter((*it).second); // add filter to module and option as a valid option
- OptionsList::iterator loop;
+ StringList::iterator loop;
for (loop = options.begin(); loop != options.end(); loop++) {
if (!strcmp((*loop).c_str(), (*it).second->getOptionName()))
break;
@@ -769,6 +889,9 @@ void SWMgr::AddGlobalOptions(SWModule *module, ConfigEntMap &section, ConfigEntM
}
if (filterMgr)
filterMgr->AddGlobalOptions(module, section, start, end);
+#ifdef _ICU_
+ module->AddOptionFilter(transliterator);
+#endif
}
@@ -788,11 +911,11 @@ void SWMgr::AddLocalOptions(SWModule *module, ConfigEntMap &section, ConfigEntMa
void SWMgr::AddRawFilters(SWModule *module, ConfigEntMap &section) {
- string sourceformat, cipherKey;
+ SWBuf sourceformat, cipherKey;
ConfigEntMap::iterator entry;
- cipherKey = ((entry = section.find("CipherKey")) != section.end()) ? (*entry).second : (string)"";
- if (!cipherKey.empty()) {
+ 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));
cleanupFilters.push_back(cipherFilter);
@@ -805,22 +928,21 @@ void SWMgr::AddRawFilters(SWModule *module, ConfigEntMap &section) {
void SWMgr::AddEncodingFilters(SWModule *module, ConfigEntMap &section) {
-
if (filterMgr)
filterMgr->AddEncodingFilters(module, section);
}
void SWMgr::AddRenderFilters(SWModule *module, ConfigEntMap &section) {
- string sourceformat;
+ SWBuf sourceformat;
ConfigEntMap::iterator entry;
- sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (string)"";
+ sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (SWBuf)"";
// Temporary: To support old module types
- // TODO: Remove at 1.6.0 release?
- if (sourceformat.empty()) {
- sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (string)"";
+ // TODO: Remove at 1.6.0 release?
+ if (!sourceformat.length()) {
+ sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)"";
if (!stricmp(sourceformat.c_str(), "RawGBF"))
sourceformat = "GBF";
else sourceformat = "";
@@ -839,13 +961,13 @@ void SWMgr::AddRenderFilters(SWModule *module, ConfigEntMap &section) {
void SWMgr::AddStripFilters(SWModule *module, ConfigEntMap &section)
{
- string sourceformat;
+ SWBuf sourceformat;
ConfigEntMap::iterator entry;
- sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (string)"";
+ sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (SWBuf)"";
// Temporary: To support old module types
- if (sourceformat.empty()) {
- sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (string)"";
+ if (!sourceformat.length()) {
+ sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)"";
if (!stricmp(sourceformat.c_str(), "RawGBF"))
sourceformat = "GBF";
else sourceformat = "";
@@ -857,6 +979,9 @@ void SWMgr::AddStripFilters(SWModule *module, ConfigEntMap &section)
else if (!stricmp(sourceformat.c_str(), "ThML")) {
module->AddStripFilter(thmlplain);
}
+ else if (!stricmp(sourceformat.c_str(), "OSIS")) {
+ module->AddStripFilter(osisplain);
+ }
if (filterMgr)
filterMgr->AddStripFilters(module, section);
@@ -870,13 +995,13 @@ void SWMgr::CreateMods() {
ConfigEntMap::iterator end;
ConfigEntMap::iterator entry;
SWModule *newmod;
- string driver, misc1;
+ SWBuf driver, misc1;
for (it = config->Sections.begin(); it != config->Sections.end(); it++) {
ConfigEntMap &section = (*it).second;
newmod = 0;
- driver = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (string)"";
- if (!driver.empty()) {
+ driver = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)"";
+ if (driver.length()) {
newmod = CreateMod((*it).first, driver, section);
if (newmod) {
start = (*it).second.lower_bound("GlobalOptionFilter");
@@ -915,8 +1040,8 @@ void SWMgr::InstallScan(const char *dirname)
DIR *dir;
struct dirent *ent;
int conffd = 0;
- string newmodfile;
- string targetName;
+ SWBuf newmodfile;
+ SWBuf targetName;
if (!access(dirname, 04)) {
if ((dir = opendir(dirname))) {
@@ -1008,15 +1133,15 @@ const char *SWMgr::getGlobalOptionTip(const char *option)
}
-OptionsList SWMgr::getGlobalOptions()
+StringList SWMgr::getGlobalOptions()
{
return options;
}
-OptionsList SWMgr::getGlobalOptionValues(const char *option)
+StringList SWMgr::getGlobalOptionValues(const char *option)
{
- OptionsList options;
+ StringList options;
for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
if ((*it).second->getOptionName()) {
if (!stricmp(option, (*it).second->getOptionName())) {
@@ -1052,3 +1177,5 @@ signed char SWMgr::setCipherKey(const char *modName, const char *key) {
}
return -1;
}
+
+SWORD_NAMESPACE_END