summaryrefslogtreecommitdiff
path: root/src/mgr
diff options
context:
space:
mode:
Diffstat (limited to 'src/mgr')
-rw-r--r--src/mgr/Makefile.am5
-rw-r--r--src/mgr/encfiltmgr.cpp8
-rw-r--r--src/mgr/filemgr.cpp117
-rw-r--r--src/mgr/installmgr.cpp629
-rw-r--r--src/mgr/localemgr.cpp39
-rw-r--r--src/mgr/markupfiltmgr.cpp26
-rw-r--r--src/mgr/swcacher.cpp6
-rw-r--r--src/mgr/swconfig.cpp48
-rw-r--r--src/mgr/swfiltermgr.cpp5
-rw-r--r--src/mgr/swlocale.cpp8
-rw-r--r--src/mgr/swmgr.cpp455
-rw-r--r--src/mgr/swsearchable.cpp42
-rw-r--r--src/mgr/swsourcemgr.cpp91
13 files changed, 1261 insertions, 218 deletions
diff --git a/src/mgr/Makefile.am b/src/mgr/Makefile.am
index e312702..15883b5 100644
--- a/src/mgr/Makefile.am
+++ b/src/mgr/Makefile.am
@@ -6,7 +6,7 @@ else
globdef =
endif
-DEFS += $(globdef)
+INCLUDES += $(globdef)
libsword_la_SOURCES += $(mgrdir)/swconfig.cpp
libsword_la_SOURCES += $(mgrdir)/swmgr.cpp
@@ -17,3 +17,6 @@ libsword_la_SOURCES += $(mgrdir)/filemgr.cpp
libsword_la_SOURCES += $(mgrdir)/swlocale.cpp
libsword_la_SOURCES += $(mgrdir)/localemgr.cpp
libsword_la_SOURCES += $(mgrdir)/swcacher.cpp
+libsword_la_SOURCES += $(mgrdir)/swsearchable.cpp
+libsword_la_SOURCES += $(mgrdir)/installmgr.cpp
+
diff --git a/src/mgr/encfiltmgr.cpp b/src/mgr/encfiltmgr.cpp
index ab55de9..35be96a 100644
--- a/src/mgr/encfiltmgr.cpp
+++ b/src/mgr/encfiltmgr.cpp
@@ -31,6 +31,8 @@
#include <swmgr.h>
+SWORD_NAMESPACE_START
+
/******************************************************************************
* EncodingFilterMgr Constructor - initializes instance of EncodingFilterMgr
*
@@ -80,8 +82,8 @@ void EncodingFilterMgr::AddRawFilters(SWModule *module, ConfigEntMap &section) {
ConfigEntMap::iterator entry;
- string encoding = ((entry = section.find("Encoding")) != section.end()) ? (*entry).second : (string)"";
- if (encoding.empty() || !stricmp(encoding.c_str(), "Latin-1")) {
+ SWBuf encoding = ((entry = section.find("Encoding")) != section.end()) ? (*entry).second : (SWBuf)"";
+ if (!encoding.length() || !stricmp(encoding.c_str(), "Latin-1")) {
module->AddRawFilter(latin1utf8);
}
else if (!stricmp(encoding.c_str(), "SCSU")) {
@@ -146,3 +148,5 @@ char EncodingFilterMgr::Encoding(char enc) {
}
return encoding;
}
+
+SWORD_NAMESPACE_END
diff --git a/src/mgr/filemgr.cpp b/src/mgr/filemgr.cpp
index e380514..44bc768 100644
--- a/src/mgr/filemgr.cpp
+++ b/src/mgr/filemgr.cpp
@@ -2,7 +2,7 @@
* filemgr.cpp - implementation of class FileMgr used for pooling file
* handles
*
- * $Id: filemgr.cpp,v 1.21 2002/03/16 17:34:41 scribe Exp $
+ * $Id: filemgr.cpp,v 1.33 2003/12/23 01:36:12 chrislit Exp $
*
* Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
@@ -29,19 +29,34 @@
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
-#ifndef __GNUC__
+#if !defined(__GNUC__) && !defined(_WIN32_WCE)
#include <io.h>
+#include <direct.h>
#else
#include <unistd.h>
#endif
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+#ifndef S_IRGRP
+#define S_IRGRP 0
+#endif
+
+#ifndef S_IROTH
+#define S_IROTH 0
+#endif
+
+SWORD_NAMESPACE_START
+
// ---------------- statics -----------------
FileMgr FileMgr::systemFileMgr;
// --------------- end statics --------------
-FileDesc::FileDesc(FileMgr *parent, char *path, int mode, int perms, bool tryDowngrade) {
+FileDesc::FileDesc(FileMgr *parent, const char *path, int mode, int perms, bool tryDowngrade) {
this->parent = parent;
this->path = 0;
stdstr(&this->path, path);
@@ -86,11 +101,11 @@ FileMgr::~FileMgr() {
}
-FileDesc *FileMgr::open(char *path, int mode, bool tryDowngrade) {
- return open(path, mode, S_IREAD | S_IWRITE, tryDowngrade);
+FileDesc *FileMgr::open(const char *path, int mode, bool tryDowngrade) {
+ return open(path, mode, S_IREAD | S_IWRITE|S_IRGRP|S_IROTH, tryDowngrade);
}
-FileDesc *FileMgr::open(char *path, int mode, int perms, bool tryDowngrade) {
+FileDesc *FileMgr::open(const char *path, int mode, int perms, bool tryDowngrade) {
FileDesc **tmp, *tmp2;
for (tmp = &files; *tmp; tmp = &((*tmp)->next)) {
@@ -126,6 +141,8 @@ signed char FileMgr::trunc(FileDesc *file) {
static const char *writeTest = "x";
long size = lseek(file->getFd(), 1, SEEK_CUR);
+ if (size == 1) // was empty
+ size = 0;
char nibble [ 32767 ];
bool writable = write(file->getFd(), writeTest, 1);
int bytes = 0;
@@ -142,19 +159,19 @@ signed char FileMgr::trunc(FileDesc *file) {
if (i == 9999)
return -2;
- int fd = ::open(buf, O_CREAT|O_RDWR, S_IREAD|S_IWRITE);
+ int fd = ::open(buf, O_CREAT|O_RDWR, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
if (fd < 0)
return -3;
lseek(file->getFd(), 0, SEEK_SET);
- while (size > 0) {
+ while (size > 0) {
bytes = read(file->getFd(), nibble, 32767);
write(fd, nibble, (bytes < size)?bytes:size);
size -= bytes;
}
// zero out the file
::close(file->fd);
- file->fd = ::open(file->path, O_TRUNC, S_IREAD|S_IWRITE);
+ file->fd = ::open(file->path, O_TRUNC, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
::close(file->fd);
file->fd = -77; // force file open by filemgr
// copy tmp file back (dumb, but must preserve file permissions)
@@ -166,7 +183,7 @@ signed char FileMgr::trunc(FileDesc *file) {
::close(fd);
::close(file->fd);
- unlink(buf); // remove our tmp file
+ removeFile(buf); // remove our tmp file
file->fd = -77; // causes file to be swapped out forcing open on next call to getFd()
}
else { // put offset back and return failure
@@ -259,6 +276,82 @@ signed char FileMgr::existsDir(const char *ipath, const char *idirName)
sprintf(ch, "/%s", idirName);
}
signed char retVal = !access(path, 04);
- delete [] path;
- return retVal;
+ delete [] path;
+ return retVal;
+}
+
+
+int FileMgr::createParent(const char *pName) {
+ char *buf = new char [ strlen(pName) + 1 ];
+ int retCode = 0;
+
+ strcpy(buf, pName);
+ int end = strlen(buf) - 1;
+ while (end) {
+ if ((buf[end] == '/') || (buf[end] == '\\'))
+ break;
+ end--;
+ }
+ buf[end] = 0;
+ if (strlen(buf)>0) {
+ if (access(buf, 02)) { // not exists with write access?
+ if ((retCode = mkdir(buf
+#ifndef WIN32
+ , 0755
+#endif
+ ))) {
+ createParent(buf);
+ retCode = mkdir(buf
+#ifndef WIN32
+ , 0755
+#endif
+ );
+ }
+ }
+ }
+ else retCode = -1;
+ delete [] buf;
+ return retCode;
+}
+
+
+int FileMgr::createPathAndFile(const char *fName) {
+ int fd;
+
+ fd = ::open(fName, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+ if (fd < 1) {
+ createParent(fName);
+ fd = ::open(fName, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
+ }
+ return fd;
}
+
+
+int FileMgr::copyFile(const char *sourceFile, const char *targetFile) {
+ int sfd, dfd, len;
+ char buf[4096];
+
+ if ((sfd = ::open(sourceFile, O_RDONLY|O_BINARY)) < 1)
+ return -1;
+ if ((dfd = createPathAndFile(targetFile)) < 1)
+ return -1;
+
+ do {
+ len = read(sfd, buf, 4096);
+ write(dfd, buf, len);
+ }
+ while(len == 4096);
+ ::close(dfd);
+ ::close(sfd);
+
+ return 0;
+}
+
+
+int FileMgr::removeFile(const char *fName) {
+ return ::remove(fName);
+}
+
+
+
+SWORD_NAMESPACE_END
diff --git a/src/mgr/installmgr.cpp b/src/mgr/installmgr.cpp
new file mode 100644
index 0000000..5fbfb05
--- /dev/null
+++ b/src/mgr/installmgr.cpp
@@ -0,0 +1,629 @@
+/*****************************************************************************
+ * InstallMgr functions to be made into something usefully exposed by
+ * master Glassey
+ *
+ */
+
+
+#ifndef EXCLUDEZLIB
+extern "C" {
+#include <untgz.h>
+}
+#endif
+
+
+#include <installmgr.h>
+#include <filemgr.h>
+
+#include <fcntl.h>
+#ifndef __GNUC__
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+#ifdef CURLAVAILABLE
+#include <curl/curl.h>
+#include <curl/types.h>
+#include <curl/easy.h>
+#endif
+
+#include <defs.h>
+#include <vector>
+#include <swmgr.h>
+#include <dirent.h>
+
+using namespace std;
+
+SWORD_NAMESPACE_START
+
+int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream);
+int my_fprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
+
+static InstallMgr_init _InstallMgr_init;
+
+InstallMgr_init::InstallMgr_init() {
+#ifdef CURLAVAILABLE
+ curl_global_init(CURL_GLOBAL_DEFAULT);
+#else
+// fprintf(stderr, "libCURL is needed for remote installation functions\n");
+#endif
+}
+
+InstallMgr_init::~InstallMgr_init() {
+#ifdef CURLAVAILABLE
+ curl_global_cleanup();
+#else
+// fprintf(stderr, "libCURL is needed for remote installation functions\n");
+#endif
+}
+
+
+int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
+ struct FtpFile *out=(struct FtpFile *)stream;
+ if (out && !out->stream) {
+ /* open file for writing */
+ out->stream=fopen(out->filename, "wb");
+ if (!out->stream)
+ return -1; /* failure, can't open file to write */
+ }
+ return fwrite(buffer, size, nmemb, out->stream);
+}
+
+
+int my_fprogress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) {
+ if (clientp) {
+ ((InstallMgr *)clientp)->statusUpdate(dltotal, dlnow);
+ }
+ return 0;
+}
+
+
+InstallMgr::InstallMgr(const char *privatePath) {
+ this->privatePath = 0;
+ stdstr(&(this->privatePath), privatePath);
+ SWBuf confPath = (SWBuf)privatePath + "/InstallMgr.conf";
+ FileMgr::createParent(confPath.c_str());
+
+ installConf = new SWConfig(confPath.c_str());
+
+ SectionMap::iterator sourcesSection;
+ ConfigEntMap::iterator sourceBegin;
+ ConfigEntMap::iterator sourceEnd;
+
+ sources.clear();
+
+ sourcesSection = installConf->Sections.find("Sources");
+ passive = (!stricmp((*installConf)["General"]["PassiveFTP"].c_str(), "true"));
+
+ if (sourcesSection != installConf->Sections.end()) {
+ sourceBegin = sourcesSection->second.lower_bound("FTPSource");
+ sourceEnd = sourcesSection->second.upper_bound("FTPSource");
+
+ while (sourceBegin != sourceEnd) {
+ InstallSource *is = new InstallSource("FTP", sourceBegin->second.c_str());
+ sources[is->caption] = is;
+ SWBuf parent = (SWBuf)privatePath + "/" + is->source + "/file";
+ FileMgr::createParent(parent.c_str());
+ is->localShadow = (SWBuf)privatePath + "/" + is->source;
+ sourceBegin++;
+ }
+ }
+}
+
+
+InstallMgr::~InstallMgr() {
+ delete [] privatePath;
+ delete installConf;
+}
+
+
+void InstallMgr::statusUpdate(double dltotal, double dlnow) {
+}
+
+void InstallMgr::preDownloadStatus(long totalBytes, long completedBytes, const char *message) {
+}
+
+char InstallMgr::FTPURLGetFile(void *session, const char *dest, const char *sourceurl) {
+ char retVal = 0;
+#ifdef CURLAVAILABLE
+ struct FtpFile ftpfile = {dest, NULL};
+
+ CURL *curl = (CURL *)session;
+ CURLcode res;
+
+ if (curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, sourceurl);
+
+ curl_easy_setopt(curl, CURLOPT_USERPWD, "ftp:installmgr@user.com");
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
+ if (!passive)
+ curl_easy_setopt(curl, CURLOPT_FTPPORT, "-");
+ curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
+ curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, this);
+ curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_fprogress);
+ /* Set a pointer to our struct to pass to the callback */
+ curl_easy_setopt(curl, CURLOPT_FILE, &ftpfile);
+
+ /* Switch on full protocol/debug output */
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE);
+
+ res = curl_easy_perform(curl);
+
+ if(CURLE_OK != res) {
+ retVal = -1;
+ }
+ }
+
+ if (ftpfile.stream)
+ fclose(ftpfile.stream); /* close the local file */
+#else
+ fprintf(stderr, "libCURL is needed for remote installation functions\n");
+#endif
+ return retVal;
+}
+
+
+
+vector<struct ftpparse> InstallMgr::FTPURLGetDir(void *session, const char *dirurl) {
+
+ vector<struct ftpparse> dirList;
+
+ if (!FTPURLGetFile(session, "dirlist", dirurl)) {
+ int fd = open("dirlist", O_RDONLY|O_BINARY);
+ long size = lseek(fd, 0, SEEK_END);
+ lseek(fd, 0, SEEK_SET);
+ char *buf = new char [ size + 1 ];
+ read(fd, buf, size);
+ close(fd);
+ char *start = buf;
+ char *end = start;
+ while (start < (buf+size)) {
+ struct ftpparse item;
+ bool looking = true;
+ for (end = start; *end; end++) {
+ if (looking) {
+ if ((*end == 10) || (*end == 13)) {
+ *end = 0;
+ looking = false;
+ }
+ }
+ else if ((*end != 10) && (*end != 13))
+ break;
+ }
+ int status = ftpparse(&item, start, end - start);
+ if (status)
+ dirList.push_back(item);
+ start = end;
+ }
+ }
+ return dirList;
+}
+
+
+void *InstallMgr::FTPOpenSession() {
+ void *retVal = 0;
+#ifdef CURLAVAILABLE
+ CURL *curl;
+
+ retVal = curl_easy_init();
+#else
+ fprintf(stderr, "libCURL is needed for remote installation functions\n");
+#endif
+ return retVal;
+}
+
+
+void InstallMgr::FTPCloseSession(void *session) {
+#ifdef CURLAVAILABLE
+ CURL *curl = (CURL *)session;
+ curl_easy_cleanup(curl);
+#else
+ fprintf(stderr, "libCURL is needed for remote installation functions\n");
+#endif
+}
+
+
+int InstallMgr::removeModule(SWMgr *manager, const char *modName) {
+ SectionMap::iterator module;
+ ConfigEntMap::iterator fileBegin;
+ ConfigEntMap::iterator fileEnd, entry;
+
+ module = manager->config->Sections.find(modName);
+
+ if (module != manager->config->Sections.end()) {
+
+ fileBegin = module->second.lower_bound("File");
+ fileEnd = module->second.upper_bound("File");
+
+ SWBuf modFile;
+ SWBuf modDir;
+ entry = module->second.find("AbsoluteDataPath");
+ modDir = entry->second.c_str();
+ if (fileBegin != fileEnd) { // remove each file
+ while (fileBegin != fileEnd) {
+ modFile = modDir;
+ modFile += "/";
+ modFile += fileBegin->second.c_str();
+ //remove file
+ remove(modFile.c_str());
+ fileBegin++;
+ }
+ }
+ else { //remove all files in DataPath directory
+
+ DIR *dir;
+ struct dirent *ent;
+ ConfigEntMap::iterator entry;
+
+
+ if (dir = opendir(modDir.c_str())) {
+ rewinddir(dir);
+ while ((ent = readdir(dir))) {
+ if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
+ modFile = modDir;
+ modFile += "/";
+ modFile += ent->d_name;
+ remove(modFile.c_str());
+ }
+ }
+ closedir(dir);
+ }
+ if (dir = opendir(manager->configPath)) { // find and remove .conf file
+ rewinddir(dir);
+ while ((ent = readdir(dir))) {
+ if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
+ modFile = manager->configPath;
+ modFile += "/";
+ modFile += ent->d_name;
+ SWConfig *config = new SWConfig(modFile.c_str());
+ if (config->Sections.find(modName) != config->Sections.end()) {
+ delete config;
+ remove(modFile.c_str());
+ }
+ else delete config;
+ }
+ }
+ closedir(dir);
+ }
+ }
+ return 0;
+ }
+ return 1;
+}
+
+
+
+InstallSource::InstallSource(const char *type, const char *confEnt) {
+ this->type = type;
+ mgr = 0;
+ userData = 0;
+ if (confEnt) {
+ char *buf = 0;
+ stdstr(&buf, confEnt);
+
+ caption = strtok(buf, "|");
+ source = strtok(0, "|");
+ directory = strtok(0, "|");
+ delete [] buf;
+ }
+}
+
+
+InstallSource::~InstallSource() {
+ if (mgr)
+ delete mgr;
+}
+
+
+void InstallSource::flush() {
+ if (mgr) {
+ delete mgr;
+ mgr = 0;
+ }
+}
+
+
+SWMgr *InstallSource::getMgr() {
+ if (!mgr)
+ mgr = new SWMgr(localShadow.c_str());
+ return mgr;
+}
+
+
+int InstallMgr::FTPCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer, const char *suffix) {
+ terminate = false;
+ long i;
+ void *session = FTPOpenSession();
+ SWBuf url = (SWBuf)"ftp://" + is->source + is->directory.c_str() + "/"; //dont forget the final slash
+ if (FTPURLGetFile(session, "dirlist", url.c_str())) {
+ return -1;
+ }
+ if (dirTransfer) {
+ SWBuf url = (SWBuf)"ftp://" + is->source + is->directory.c_str() + "/" + src + "/"; //dont forget the final slash
+ vector<struct ftpparse> dirList = FTPURLGetDir(session, url.c_str());
+
+ if (!dirList.size()) {
+ return -1;
+ }
+
+ long totalBytes = 0;
+ for (i = 0; i < dirList.size(); i++)
+ totalBytes += dirList[i].size;
+ long completedBytes = 0;
+ for (i = 0; i < dirList.size(); i++) {
+ if (dirList[i].flagtrycwd != 1) {
+ SWBuf buffer = (SWBuf)dest + "/" + (dirList[i].name);
+ if (!strcmp(&buffer.c_str()[buffer.length()-strlen(suffix)], suffix)) {
+ SWBuf buffer2 = "Downloading (";
+ buffer2.appendFormatted("%d", i+1);
+ buffer2 += " of ";
+ buffer2.appendFormatted("%d", dirList.size());
+ buffer2 += "): ";
+ buffer2 += (dirList[i].name);
+ preDownloadStatus(totalBytes, completedBytes, buffer2.c_str());
+ FileMgr::createParent(buffer.c_str()); // make sure parent directory exists
+ try {
+ SWBuf url = (SWBuf)"ftp://" + is->source + is->directory.c_str() + "/" + src + "/" + dirList[i].name; //dont forget the final slash
+ if (FTPURLGetFile(session, buffer.c_str(), url.c_str())) {
+ return -2;
+ }
+ completedBytes += dirList[i].size;
+ }
+ catch (...) {}
+ if (terminate)
+ break;
+ }
+ }
+ }
+ }
+ else {
+// Synchronize((TThreadMethod)&PreDownload2);
+ try {
+ SWBuf url = (SWBuf)"ftp://" + is->source + is->directory.c_str() + "/" + src; //dont forget the final slash
+ if (FTPURLGetFile(session, dest, url.c_str())) {
+ return -1;
+ }
+ }
+ catch(...) {
+ terminate = true;
+ }
+ }
+ try {
+ FTPCloseSession(session);
+ }
+ catch(...){}
+ return 0;
+}
+
+
+int InstallMgr::installModule(SWMgr *destMgr, const char *fromLocation, const char *modName, InstallSource *is) {
+ SectionMap::iterator module, section;
+ ConfigEntMap::iterator fileBegin;
+ ConfigEntMap::iterator fileEnd;
+ ConfigEntMap::iterator entry;
+ SWBuf sourceDir;
+ SWBuf buffer;
+ bool aborted = false;
+ bool cipher = false;
+ DIR *dir;
+ struct dirent *ent;
+ SWBuf modFile;
+
+
+ if (is)
+ sourceDir = (SWBuf)privatePath + "/" + is->source;
+ else sourceDir = fromLocation;
+
+ if (sourceDir[sourceDir.length()-1] != '/')
+ sourceDir += '/';
+
+ SWMgr mgr(sourceDir.c_str());
+
+ module = mgr.config->Sections.find(modName);
+
+ if (module != mgr.config->Sections.end()) {
+
+ entry = module->second.find("CipherKey");
+ if (entry != module->second.end())
+ cipher = true;
+
+ fileEnd = module->second.upper_bound("File");
+ fileBegin = module->second.lower_bound("File");
+
+ if (fileBegin != fileEnd) { // copy each file
+ if (is) {
+ while (fileBegin != fileEnd) { // ftp each file first
+ buffer = sourceDir + "/" + fileBegin->second.c_str();
+ if (FTPCopy(is, fileBegin->second.c_str(), buffer.c_str())) {
+ aborted = true;
+ break; // user aborted
+ }
+ fileBegin++;
+ }
+ fileBegin = module->second.lower_bound("File");
+ }
+
+ if (!aborted) {
+ // DO THE INSTALL
+ while (fileBegin != fileEnd) {
+ copyFileToSWORDInstall(destMgr, sourceDir.c_str(), fileBegin->second.c_str());
+ fileBegin++;
+ }
+ }
+ //---------------
+
+ if (is) {
+ fileBegin = module->second.lower_bound("File");
+ while (fileBegin != fileEnd) { // delete each tmp ftp file
+ buffer = sourceDir + "/" + fileBegin->second.c_str();
+ remove(buffer.c_str());
+ fileBegin++;
+ }
+ }
+ }
+ else { //copy all files in DataPath directory
+ ConfigEntMap::iterator entry;
+ SWBuf sourceOrig = sourceDir;
+
+ entry = module->second.find("DataPath");
+ if (entry != module->second.end()) {
+ SWBuf modDir = entry->second.c_str();
+ entry = module->second.find("ModDrv");
+ if (entry != module->second.end()) {
+ if (!strcmp(entry->second.c_str(), "RawLD") || !strcmp(entry->second.c_str(), "RawLD4") || !strcmp(entry->second.c_str(), "zLD") || !strcmp(entry->second.c_str(), "RawGenBook") || !strcmp(entry->second.c_str(), "zGenBook")) {
+ int end = modDir.length() - 1;
+ while (end >= 0) { //while(end) wouldn't work for length() == 0
+ if (modDir[end] == '/')
+ break;
+
+ modDir--; //remove last char
+ end--;
+ }
+ }
+
+ //make sure there's no trailing slash in modDir, required for Bibles and Commentaries
+ if ( modDir.length() && (modDir[modDir.length()-1] == '/')) //last char is a slash
+ modDir--; //remove the slash
+ }
+
+ if (is) {
+ buffer = sourceDir + "/" + modDir;
+ if (FTPCopy(is, modDir.c_str(), buffer.c_str(), true)) {
+ aborted = true; // user aborted
+ }
+ }
+ sourceDir += "/";
+ sourceDir += modDir;
+ if (!aborted) {
+ if (dir = opendir(sourceDir.c_str())) {
+ rewinddir(dir);
+ while ((ent = readdir(dir))) {
+ if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
+ modFile = modDir;
+ modFile += "/";
+ modFile += ent->d_name;
+ copyFileToSWORDInstall(destMgr, sourceOrig.c_str(), modFile.c_str());
+ }
+ }
+ closedir(dir);
+ }
+ }
+ if (is) { // delete tmp ftp files
+ if (dir = opendir(sourceDir.c_str())) {
+ rewinddir(dir);
+ while ((ent = readdir(dir))) {
+ if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
+ modFile = sourceOrig + "/" + modDir;
+ modFile += "/";
+ modFile += ent->d_name;
+ remove(modFile.c_str());
+ }
+ }
+ closedir(dir);
+ }
+ }
+ sourceDir = sourceOrig;
+ sourceDir += "/mods.d/";
+ }
+ }
+ if (!aborted) {
+ if (dir = opendir(sourceDir.c_str())) { // find and copy .conf file
+ rewinddir(dir);
+ while ((ent = readdir(dir))) {
+ if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
+ modFile = sourceDir;
+ modFile += ent->d_name;
+ SWConfig *config = new SWConfig(modFile.c_str());
+ if (config->Sections.find(modName) != config->Sections.end()) {
+ SWBuf targetFile = destMgr->configPath; //"./mods.d/";
+ targetFile += "/";
+ targetFile += ent->d_name;
+ FileMgr::copyFile(modFile.c_str(), targetFile.c_str());
+ if (cipher) {
+ if (getCipherCode(modName, config)) {
+ SWMgr newDest(destMgr->prefixPath);
+ removeModule(&newDest, modName);
+ aborted = true;
+ }
+ else {
+ config->Save();
+ FileMgr::copyFile(modFile.c_str(), targetFile.c_str());
+ }
+ }
+ }
+ delete config;
+ }
+ }
+ closedir(dir);
+ }
+ }
+ return (aborted) ? -1 : 0;
+ }
+ return 1;
+}
+
+
+// return aborted
+bool InstallMgr::getCipherCode(const char *modName, SWConfig *config) {
+ return false;
+}
+
+int InstallMgr::copyFileToSWORDInstall(SWMgr *manager, const char *sourceDir, const char *fName) {
+ SWBuf sourcePath = sourceDir;
+ sourcePath += fName;
+
+ SWBuf dest;
+ dest = manager->prefixPath;
+ if ((manager->prefixPath[strlen(manager->prefixPath)-1] != '\\') && ( manager->prefixPath[strlen(manager->prefixPath)-1] != '/'))
+ dest += "/";
+ dest += fName;
+
+ return FileMgr::copyFile(sourcePath.c_str(), dest.c_str());
+}
+
+
+void InstallMgr::refreshRemoteSource(InstallSource *is) {
+ DIR *dir;
+ struct dirent *ent;
+ ConfigEntMap::iterator entry;
+ SWBuf modDir;
+ SWBuf modFile;
+ SWBuf root = privatePath;
+ root += (SWBuf)"/" + is->source.c_str();
+ SWBuf target = root + "/mods.d";
+
+ if (dir = opendir(target.c_str())) {
+ rewinddir(dir);
+ while ((ent = readdir(dir))) {
+ if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
+ modFile = target;
+ modFile += "/";
+ modFile += ent->d_name;
+ remove(modFile.c_str());
+ }
+ }
+ closedir(dir);
+ }
+
+
+
+#ifndef EXCLUDEZLIB
+ SWBuf archive = root + "/mods.d.tar.gz";
+ if (!FTPCopy(is, "mods.d.tar.gz", archive.c_str(), false)) {
+ int fd = open(archive.c_str(), O_RDONLY|O_BINARY);
+ untargz(fd, root.c_str());
+ close(fd);
+ }
+ else
+#endif
+ FTPCopy(is, "mods.d", target.c_str(), true, ".conf");
+ is->flush();
+}
+
+SWORD_NAMESPACE_END
+
diff --git a/src/mgr/localemgr.cpp b/src/mgr/localemgr.cpp
index a21896d..6c3da4a 100644
--- a/src/mgr/localemgr.cpp
+++ b/src/mgr/localemgr.cpp
@@ -2,7 +2,7 @@
* localemgr.cpp - implementation of class LocaleMgr used to interact with
* registered locales for a sword installation
*
- * $Id: localemgr.cpp,v 1.11 2002/03/15 07:47:35 scribe Exp $
+ * $Id: localemgr.cpp,v 1.16 2003/07/05 04:58:42 scribe Exp $
*
* Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
@@ -39,15 +39,18 @@
#include <localemgr.h>
#include <filemgr.h>
+SWORD_NAMESPACE_START
+
LocaleMgr LocaleMgr::systemLocaleMgr;
LocaleMgr::LocaleMgr(const char *iConfigPath) {
+ locales = new LocaleMap();
char *prefixPath = 0;
char *configPath = 0;
char configType = 0;
- string path;
+ SWBuf path;
defaultLocaleName = 0;
@@ -97,13 +100,14 @@ LocaleMgr::~LocaleMgr() {
if (defaultLocaleName)
delete [] defaultLocaleName;
deleteLocales();
+ delete locales;
}
void LocaleMgr::loadConfigDir(const char *ipath) {
DIR *dir;
struct dirent *ent;
- string newmodfile;
+ SWBuf newmodfile;
LocaleMap::iterator it;
if ((dir = opendir(ipath))) {
@@ -116,12 +120,12 @@ void LocaleMgr::loadConfigDir(const char *ipath) {
newmodfile += ent->d_name;
SWLocale *locale = new SWLocale(newmodfile.c_str());
if (locale->getName()) {
- it = locales.find(locale->getName());
- if (it != locales.end()) {
+ it = locales->find(locale->getName());
+ if (it != locales->end()) {
*((*it).second) += *locale;
delete locale;
}
- else locales.insert(LocaleMap::value_type(locale->getName(), locale));
+ else locales->insert(LocaleMap::value_type(locale->getName(), locale));
}
else delete locale;
}
@@ -135,36 +139,39 @@ void LocaleMgr::deleteLocales() {
LocaleMap::iterator it;
- for (it = locales.begin(); it != locales.end(); it++)
+ for (it = locales->begin(); it != locales->end(); it++)
delete (*it).second;
- locales.erase(locales.begin(), locales.end());
+ locales->erase(locales->begin(), locales->end());
}
SWLocale *LocaleMgr::getLocale(const char *name) {
LocaleMap::iterator it;
- it = locales.find(name);
- if (it != locales.end())
+ it = locales->find(name);
+ if (it != locales->end())
return (*it).second;
return 0;
}
-list <string> LocaleMgr::getAvailableLocales() {
- list <string> retVal;
- for (LocaleMap::iterator it = locales.begin(); it != locales.end(); it++)
+std::list <SWBuf> LocaleMgr::getAvailableLocales() {
+ std::list <SWBuf> retVal;
+ for (LocaleMap::iterator it = locales->begin(); it != locales->end(); it++)
retVal.push_back((*it).second->getName());
return retVal;
}
-const char *LocaleMgr::translate(const char *name, const char *text) {
+const char *LocaleMgr::translate(const char *text, const char *localeName) {
SWLocale *target;
- target = getLocale(name);
+ if (!localeName) {
+ localeName = getDefaultLocaleName();
+ }
+ target = getLocale(localeName);
if (target)
return target->translate(text);
return text;
@@ -179,3 +186,5 @@ const char *LocaleMgr::getDefaultLocaleName() {
void LocaleMgr::setDefaultLocaleName(const char *name) {
stdstr(&defaultLocaleName, name);
}
+
+SWORD_NAMESPACE_END
diff --git a/src/mgr/markupfiltmgr.cpp b/src/mgr/markupfiltmgr.cpp
index 22a34c5..07a9fb0 100644
--- a/src/mgr/markupfiltmgr.cpp
+++ b/src/mgr/markupfiltmgr.cpp
@@ -30,11 +30,19 @@
#include <gbfhtmlhref.h>
#include <thmlrtf.h>
#include <gbfrtf.h>
+#include <gbfosis.h>
+#include <thmlosis.h>
+#include <osisrtf.h>
+#include <osishtmlhref.h>
+#include <gbfwebif.h>
+#include <thmlwebif.h>
+#include <osiswebif.h>
#include <markupfiltmgr.h>
#include <swmgr.h>
+SWORD_NAMESPACE_START
/******************************************************************************
* MarkupFilterMgr Constructor - initializes instance of MarkupFilterMgr
@@ -212,23 +220,31 @@ void MarkupFilterMgr::CreateFilters(char markup) {
fromosis = NULL;
break;
case FMT_HTMLHREF:
- fromplain = NULL;
+ fromplain = new PLAINHTML();
fromthml = new ThMLHTMLHREF();
fromgbf = new GBFHTMLHREF();
- fromosis = NULL;
+ fromosis = new OSISHTMLHREF();
break;
case FMT_RTF:
fromplain = NULL;
fromthml = new ThMLRTF();
fromgbf = new GBFRTF();
- fromosis = NULL;
+ fromosis = new OSISRTF();
break;
case FMT_OSIS:
fromplain = NULL;
- fromthml = NULL;
- fromgbf = NULL;
+ fromthml = new ThMLOSIS();
+ fromgbf = new GBFOSIS();
fromosis = NULL;
break;
+ case FMT_WEBIF:
+ fromplain = NULL;
+ fromthml = new ThMLWEBIF();
+ fromgbf = new GBFWEBIF();
+ fromosis = new OSISWEBIF();
+ break;
}
}
+
+SWORD_NAMESPACE_END
diff --git a/src/mgr/swcacher.cpp b/src/mgr/swcacher.cpp
index 8128a70..ef04d98 100644
--- a/src/mgr/swcacher.cpp
+++ b/src/mgr/swcacher.cpp
@@ -2,7 +2,7 @@
* swcacher.h - definition of class SWCacher used to provide an interface for
* objects that cache and want a standard interface for cleaning up.
*
- * $Id: swcacher.cpp,v 1.1 2002/03/16 01:12:37 scribe Exp $
+ * $Id: swcacher.cpp,v 1.2 2002/10/01 19:52:40 dglassey Exp $
*
* Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
@@ -22,6 +22,8 @@
#include <swcacher.h>
+SWORD_NAMESPACE_START
+
SWCacher::SWCacher() {
}
@@ -41,3 +43,5 @@ long SWCacher::resourceConsumption() {
long SWCacher::lastAccess() {
return 0;
}
+
+SWORD_NAMESPACE_END
diff --git a/src/mgr/swconfig.cpp b/src/mgr/swconfig.cpp
index ad97d00..d9eccc6 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,v 1.5 2001/03/11 22:34:58 scribe Exp $
+ * $Id: swconfig.cpp,v 1.13 2003/06/27 01:41:07 scribe Exp $
*
* Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
@@ -23,6 +23,7 @@
#include <swconfig.h>
#include <utilfuns.h>
+SWORD_NAMESPACE_START
SWConfig::SWConfig(const char * ifilename) {
filename = ifilename;
@@ -34,25 +35,29 @@ SWConfig::~SWConfig() {
}
-char SWConfig::getline(FILE *fp, string &line)
+char SWConfig::getline(FILE *fp, SWBuf &line)
{
char retval = 0;
char buf[255];
+ int len;
line = "";
while (fgets(buf, 254, fp)) {
while (buf[strlen(buf)-1] == '\n' || buf[strlen(buf)-1] == '\r')
buf[strlen(buf)-1] = 0;
+ len = strlen(buf);
+ while (len>0 && buf[len-1] == '\n' || buf[len-1] == '\r')
+ buf[(len--)-1] = 0;
- if (buf[strlen(buf)-1] == '\\') {
- buf[strlen(buf)-1] = 0;
+ if (len>0 && buf[len-1] == '\\') {
+ buf[(len--)-1] = 0;
line += buf;
continue;
}
line += buf;
- if (strlen(buf) < 253) {
+ if (len < 253) {
retval = 1;
break;
}
@@ -64,9 +69,9 @@ char SWConfig::getline(FILE *fp, string &line)
void SWConfig::Load() {
FILE *cfile;
char *buf, *data;
- string line;
+ SWBuf line;
ConfigEntMap cursect;
- string sectname;
+ SWBuf sectname;
bool first = true;
Sections.erase(Sections.begin(), Sections.end());
@@ -105,10 +110,10 @@ void SWConfig::Load() {
void SWConfig::Save() {
FILE *cfile;
- string buf;
+ SWBuf buf;
SectionMap::iterator sit;
ConfigEntMap::iterator entry;
- string sectname;
+ SWBuf sectname;
if ((cfile = fopen(filename.c_str(), "w"))) {
@@ -131,20 +136,35 @@ void SWConfig::Save() {
}
-SWConfig &SWConfig::operator +=(SWConfig &addFrom)
-{
+void SWConfig::augment(SWConfig &addFrom) {
SectionMap::iterator section;
- ConfigEntMap::iterator entry;
+ ConfigEntMap::iterator entry, start, end;
for (section = addFrom.Sections.begin(); section != addFrom.Sections.end(); section++) {
for (entry = (*section).second.begin(); entry != (*section).second.end(); entry++) {
- Sections[(*section).first].insert(ConfigEntMap::value_type((*entry).first, (*entry).second));
+ start = Sections[section->first].lower_bound(entry->first);
+ end = Sections[section->first].upper_bound(entry->first);
+ if (start != end) {
+ if (((++start) != end)
+ || ((++(addFrom.Sections[section->first].lower_bound(entry->first))) != addFrom.Sections[section->first].upper_bound(entry->first))) {
+ for (--start; start != end; start++) {
+ if (!strcmp(start->second.c_str(), entry->second.c_str()))
+ break;
+ }
+ if (start == end)
+ Sections[(*section).first].insert(ConfigEntMap::value_type((*entry).first, (*entry).second));
+ }
+ else Sections[section->first][entry->first.c_str()] = entry->second.c_str();
+ }
+ else Sections[section->first][entry->first.c_str()] = entry->second.c_str();
}
}
- return *this;
}
+
ConfigEntMap & SWConfig::operator [] (const char *section) {
return Sections[section];
}
+
+SWORD_NAMESPACE_END
diff --git a/src/mgr/swfiltermgr.cpp b/src/mgr/swfiltermgr.cpp
index 264b5a6..26ba98a 100644
--- a/src/mgr/swfiltermgr.cpp
+++ b/src/mgr/swfiltermgr.cpp
@@ -2,7 +2,7 @@
* swfiltermgr.cpp - definition of class SWFilterMgr used as an interface to
* manage filters on a module
*
- * $Id: swfiltermgr.cpp,v 1.2 2001/11/30 12:04:34 scribe Exp $
+ * $Id: swfiltermgr.cpp,v 1.3 2002/10/01 19:52:40 dglassey Exp $
*
* Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
@@ -22,6 +22,8 @@
#include <swfiltermgr.h>
+SWORD_NAMESPACE_START
+
SWFilterMgr::SWFilterMgr() {
}
@@ -88,3 +90,4 @@ void SWFilterMgr::AddStripFilters(SWModule * module, ConfigEntMap & section) {
void SWFilterMgr::AddRawFilters(SWModule * module, ConfigEntMap & section) {
}
+SWORD_NAMESPACE_END
diff --git a/src/mgr/swlocale.cpp b/src/mgr/swlocale.cpp
index b630383..8cf1e96 100644
--- a/src/mgr/swlocale.cpp
+++ b/src/mgr/swlocale.cpp
@@ -2,7 +2,7 @@
* swlocale.cpp - implementation of Class SWLocale used for retrieval
* of locale lookups
*
- * $Id: swlocale.cpp,v 1.3 2000/03/13 09:36:03 scribe Exp $
+ * $Id: swlocale.cpp,v 1.5 2002/10/01 19:52:40 dglassey Exp $
*
* Copyright 2000 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
@@ -23,6 +23,7 @@
#include <swlocale.h>
#include <utilfuns.h>
+SWORD_NAMESPACE_START
SWLocale::SWLocale(const char * ifilename) {
ConfigEntMap::iterator confEntry;
@@ -93,9 +94,8 @@ const char *SWLocale::getDescription() {
}
-SWLocale &SWLocale::operator +=(SWLocale &addFrom) {
+void SWLocale::augment(SWLocale &addFrom) {
*localeSource += *addFrom.localeSource;
- return *this;
}
@@ -139,3 +139,5 @@ void SWLocale::getBooks(char **iBMAX, struct sbook ***ibooks) {
*iBMAX = BMAX;
*ibooks = books;
}
+
+SWORD_NAMESPACE_END
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
diff --git a/src/mgr/swsearchable.cpp b/src/mgr/swsearchable.cpp
new file mode 100644
index 0000000..d81375d
--- /dev/null
+++ b/src/mgr/swsearchable.cpp
@@ -0,0 +1,42 @@
+/******************************************************************************
+ * swsearchable.h - definition of class SWSearchable used to provide an
+ * interface for objects that be searched.
+ *
+ * $Id: swsearchable.cpp,v 1.1 2003/08/29 06:00:16 scribe Exp $
+ *
+ * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ * CrossWire Bible Society
+ * P. O. Box 2528
+ * Tempe, AZ 85280-2528
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ */
+
+#include <swsearchable.h>
+
+SWORD_NAMESPACE_START
+
+void SWSearchable::nullPercent(char percent, void *percentUserData) {}
+
+SWSearchable::SWSearchable() {
+}
+
+
+SWSearchable::~SWSearchable() {
+}
+
+ // special search framework
+signed char SWSearchable::createSearchFramework() {
+ return 0;
+}
+
+
+SWORD_NAMESPACE_END
diff --git a/src/mgr/swsourcemgr.cpp b/src/mgr/swsourcemgr.cpp
new file mode 100644
index 0000000..58df9f0
--- /dev/null
+++ b/src/mgr/swsourcemgr.cpp
@@ -0,0 +1,91 @@
+/******************************************************************************
+ * swsourcemgr.cpp - implementaion of class SWMgr used to interact with an install
+ * base of sword modules.
+ *
+ * $Id: swsourcemgr.cpp,v 1.2 2003/06/27 01:41:07 scribe Exp $
+ *
+ * Copyright 2002 CrossWire Bible Society (http://www.crosswire.org)
+ * CrossWire Bible Society
+ * P. O. Box 2528
+ * Tempe, AZ 85280-2528
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ */
+
+ #include "swsourcemgr.h"
+ #include "filemgr.h"
+ #include "utilstr.h"
+ #include "swconfig.h"
+ #include <dirent.h>
+
+ SWORD_NAMESPACE_START
+
+ SWSourceMgr::SWSourceMgr(const char *iConfigPath) {
+ SWBuf path;
+
+ //init();
+
+ path = iConfigPath;
+ if ((iConfigPath[strlen(iConfigPath)-1] != '\\') && (iConfigPath[strlen(iConfigPath)-1] != '/'))
+ path += "/";
+ if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
+ stdstr(&prefixPath, path.c_str());
+ path += "mods.conf";
+ stdstr(&configPath, path.c_str());
+ }
+ else {
+ if (FileMgr::existsDir(path.c_str(), "mods.d")) {
+ stdstr(&prefixPath, path.c_str());
+ path += "mods.d";
+ stdstr(&configPath, path.c_str());
+ configType = 1;
+ }
+ }
+
+ if (configPath)
+ loadConfigDir(configPath);
+}
+
+void SWSourceMgr::loadConfigDir(const char *ipath)
+{
+ DIR *dir;
+ struct dirent *ent;
+ SWBuf newmodfile;
+
+ if ((dir = opendir(ipath))) {
+ rewinddir(dir);
+ while ((ent = readdir(dir))) {
+ if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
+ newmodfile = ipath;
+ if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/'))
+ newmodfile += "/";
+ newmodfile += ent->d_name;
+ if (config) {
+ SWConfig tmpConfig(newmodfile.c_str());
+ *config += tmpConfig;
+ }
+ else config = myconfig = new SWConfig(newmodfile.c_str());
+ }
+ }
+ closedir(dir);
+ if (!config) { // if no .conf file exist yet, create a default
+ newmodfile = ipath;
+ if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/'))
+ newmodfile += "/";
+ newmodfile += "globals.conf";
+ config = myconfig = new SWConfig(newmodfile.c_str());
+ }
+ }
+}
+
+
+
+ SWORD_NAMESPACE_END