diff options
Diffstat (limited to 'src/mgr')
-rw-r--r-- | src/mgr/Makefile | 4 | ||||
-rw-r--r-- | src/mgr/Makefile.am | 22 | ||||
-rw-r--r-- | src/mgr/encfiltmgr.cpp | 152 | ||||
-rw-r--r-- | src/mgr/filemgr.cpp | 357 | ||||
-rw-r--r-- | src/mgr/installmgr.cpp | 629 | ||||
-rw-r--r-- | src/mgr/localemgr.cpp | 190 | ||||
-rw-r--r-- | src/mgr/markupfiltmgr.cpp | 250 | ||||
-rw-r--r-- | src/mgr/swcacher.cpp | 47 | ||||
-rw-r--r-- | src/mgr/swconfig.cpp | 170 | ||||
-rw-r--r-- | src/mgr/swfiltermgr.cpp | 93 | ||||
-rw-r--r-- | src/mgr/swlocale.cpp | 143 | ||||
-rw-r--r-- | src/mgr/swmgr.cpp | 1181 | ||||
-rw-r--r-- | src/mgr/swsearchable.cpp | 42 | ||||
-rw-r--r-- | src/mgr/swsourcemgr.cpp | 91 |
14 files changed, 0 insertions, 3371 deletions
diff --git a/src/mgr/Makefile b/src/mgr/Makefile deleted file mode 100644 index 339f87a..0000000 --- a/src/mgr/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -root := ../.. - -all: - make -C ${root} diff --git a/src/mgr/Makefile.am b/src/mgr/Makefile.am deleted file mode 100644 index 15883b5..0000000 --- a/src/mgr/Makefile.am +++ /dev/null @@ -1,22 +0,0 @@ -mgrdir = $(top_srcdir)/src/mgr - -if CONFDEF -globdef = -DGLOBCONFPATH=\"${globalconfdir}/sword.conf\" -else -globdef = -endif - -INCLUDES += $(globdef) - -libsword_la_SOURCES += $(mgrdir)/swconfig.cpp -libsword_la_SOURCES += $(mgrdir)/swmgr.cpp -libsword_la_SOURCES += $(mgrdir)/swfiltermgr.cpp -libsword_la_SOURCES += $(mgrdir)/encfiltmgr.cpp -libsword_la_SOURCES += $(mgrdir)/markupfiltmgr.cpp -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 deleted file mode 100644 index 35be96a..0000000 --- a/src/mgr/encfiltmgr.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/****************************************************************************** - * swencodingmgr.cpp - implementaion of class EncodingFilterMgr, subclass of - * used to transcode all module text to a requested - * encoding. - * - * 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 <encfiltmgr.h> - -#include <scsuutf8.h> -#include <latin1utf8.h> - -#include <unicodertf.h> -#include <utf8latin1.h> -#include <utf8utf16.h> -#include <utf8html.h> - -#include <swmgr.h> - -SWORD_NAMESPACE_START - -/****************************************************************************** - * EncodingFilterMgr Constructor - initializes instance of EncodingFilterMgr - * - * ENT: - * enc - Encoding format to emit - */ - -EncodingFilterMgr::EncodingFilterMgr (char enc) - : SWFilterMgr() { - - scsuutf8 = new SCSUUTF8(); - latin1utf8 = new Latin1UTF8(); - - encoding = enc; - - switch (encoding) { - case ENC_LATIN1: - targetenc = new UTF8Latin1(); - break; - case ENC_UTF16: - targetenc = new UTF8UTF16(); - break; - case ENC_RTF: - targetenc = new UnicodeRTF(); - break; - case ENC_HTML: - targetenc = new UTF8HTML(); - break; - default: // i.e. case ENC_UTF8 - targetenc = NULL; - } -} - -/****************************************************************************** - * EncodingFilterMgr Destructor - Cleans up instance of EncodingFilterMgr - */ -EncodingFilterMgr::~EncodingFilterMgr() { - if (scsuutf8) - delete scsuutf8; - if (latin1utf8) - delete latin1utf8; - if (targetenc) - delete targetenc; -} - -void EncodingFilterMgr::AddRawFilters(SWModule *module, ConfigEntMap §ion) { - - ConfigEntMap::iterator entry; - - 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")) { - module->AddRawFilter(scsuutf8); - } -} - -void EncodingFilterMgr::AddEncodingFilters(SWModule *module, ConfigEntMap §ion) { - if (targetenc) - module->AddEncodingFilter(targetenc); -} - -/****************************************************************************** - * EncodingFilterMgr::Encoding - sets/gets encoding - * - * ENT: enc - new encoding or 0 to simply get the current encoding - * - * RET: encoding - */ -char EncodingFilterMgr::Encoding(char enc) { - if (enc && enc != encoding) { - encoding = enc; - SWFilter * oldfilter = targetenc; - - switch (encoding) { - case ENC_LATIN1: - targetenc = new UTF8Latin1(); - break; - case ENC_UTF16: - targetenc = new UTF8UTF16(); - break; - case ENC_RTF: - targetenc = new UnicodeRTF(); - break; - case ENC_HTML: - targetenc = new UTF8HTML(); - break; - default: // i.e. case ENC_UTF8 - targetenc = NULL; - } - - ModMap::const_iterator module; - - if (oldfilter != targetenc) { - if (oldfilter) { - if (!targetenc) { - for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++) - module->second->RemoveRenderFilter(oldfilter); - } - else { - for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++) - module->second->ReplaceRenderFilter(oldfilter, targetenc); - } - delete oldfilter; - } - else if (targetenc) { - for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++) - module->second->AddRenderFilter(targetenc); - } - } - - } - return encoding; -} - -SWORD_NAMESPACE_END diff --git a/src/mgr/filemgr.cpp b/src/mgr/filemgr.cpp deleted file mode 100644 index 44bc768..0000000 --- a/src/mgr/filemgr.cpp +++ /dev/null @@ -1,357 +0,0 @@ -/****************************************************************************** - * filemgr.cpp - implementation of class FileMgr used for pooling file - * handles - * - * $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 - * 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 <filemgr.h> -#include <utilstr.h> - -#include <dirent.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <stdio.h> -#include <string.h> -#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, const char *path, int mode, int perms, bool tryDowngrade) { - this->parent = parent; - this->path = 0; - stdstr(&this->path, path); - this->mode = mode; - this->perms = perms; - this->tryDowngrade = tryDowngrade; - offset = 0; - fd = -77; -} - - -FileDesc::~FileDesc() { - if (fd > 0) - close(fd); - - if (path) - delete [] path; -} - - -int FileDesc::getFd() { - if (fd == -77) - fd = parent->sysOpen(this); - return fd; -} - - -FileMgr::FileMgr(int maxFiles) { - this->maxFiles = maxFiles; // must be at least 2 - files = 0; -} - - -FileMgr::~FileMgr() { - FileDesc *tmp; - - while(files) { - tmp = files->next; - delete files; - files = tmp; - } -} - - -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(const char *path, int mode, int perms, bool tryDowngrade) { - FileDesc **tmp, *tmp2; - - for (tmp = &files; *tmp; tmp = &((*tmp)->next)) { - if ((*tmp)->fd < 0) // insert as first non-system_open file - break; - } - - tmp2 = new FileDesc(this, path, mode, perms, tryDowngrade); - tmp2->next = *tmp; - *tmp = tmp2; - - return tmp2; -} - - -void FileMgr::close(FileDesc *file) { - FileDesc **loop; - - for (loop = &files; *loop; loop = &((*loop)->next)) { - if (*loop == file) { - *loop = (*loop)->next; - delete file; - break; - } - } -} - - -// to truncate a file at its current position -// leaving byte at current possition intact -// deleting everything afterward. -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; - - if (writable) { - // get tmpfilename - char *buf = new char [ strlen(file->path) + 10 ]; - int i; - for (i = 0; i < 9999; i++) { - sprintf(buf, "%stmp%.4d", file->path, i); - if (!existsFile(buf)) - break; - } - if (i == 9999) - return -2; - - 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) { - 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|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) - lseek(fd, 0, SEEK_SET); - do { - bytes = read(fd, nibble, 32767); - write(file->getFd(), nibble, bytes); - } while (bytes == 32767); - - ::close(fd); - ::close(file->fd); - 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 - lseek(file->getFd(), -1, SEEK_CUR); - return -1; - } - return 0; -} - - -int FileMgr::sysOpen(FileDesc *file) { - FileDesc **loop; - int openCount = 1; // because we are presently opening 1 file, and we need to be sure to close files to accomodate, if necessary - - for (loop = &files; *loop; loop = &((*loop)->next)) { - - if ((*loop)->fd > 0) { - if (++openCount > maxFiles) { - (*loop)->offset = lseek((*loop)->fd, 0, SEEK_CUR); - ::close((*loop)->fd); - (*loop)->fd = -77; - } - } - - if (*loop == file) { - if (*loop != files) { - *loop = (*loop)->next; - file->next = files; - files = file; - } - if ((!access(file->path, 04)) || ((file->mode & O_CREAT) == O_CREAT)) { // check for at least file exists / read access before we try to open - char tries = (((file->mode & O_RDWR) == O_RDWR) && (file->tryDowngrade)) ? 2 : 1; // try read/write if possible - for (int i = 0; i < tries; i++) { - if (i > 0) { - file->mode = (file->mode & ~O_RDWR); // remove write access - file->mode = (file->mode | O_RDONLY);// add read access - } - file->fd = ::open(file->path, file->mode, file->perms); - - if (file->fd >= 0) - break; - } - - if (file->fd >= 0) - lseek(file->fd, file->offset, SEEK_SET); - } - else file->fd = -1; - if (!*loop) - break; - } - } - return file->fd; -} - - -signed char FileMgr::existsFile(const char *ipath, const char *ifileName) -{ - int len = strlen(ipath) + ((ifileName)?strlen(ifileName):0) + 3; - char *ch; - char *path = new char [ len ]; - strcpy(path, ipath); - - if ((path[strlen(path)-1] == '\\') || (path[strlen(path)-1] == '/')) - path[strlen(path)-1] = 0; - - if (ifileName) { - ch = path + strlen(path); - sprintf(ch, "/%s", ifileName); - } - signed char retVal = !access(path, 04); - delete [] path; - return retVal; -} - - -signed char FileMgr::existsDir(const char *ipath, const char *idirName) -{ - char *ch; - int len = strlen(ipath) + ((idirName)?strlen(idirName):0) + 1; - if (idirName) - len += strlen(idirName); - char *path = new char [ len ]; - strcpy(path, ipath); - - if ((path[strlen(path)-1] == '\\') || (path[strlen(path)-1] == '/')) - path[strlen(path)-1] = 0; - - if (idirName) { - ch = path + strlen(path); - sprintf(ch, "/%s", idirName); - } - signed char retVal = !access(path, 04); - 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 deleted file mode 100644 index 5fbfb05..0000000 --- a/src/mgr/installmgr.cpp +++ /dev/null @@ -1,629 +0,0 @@ -/***************************************************************************** - * 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 deleted file mode 100644 index 6c3da4a..0000000 --- a/src/mgr/localemgr.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/****************************************************************************** - * localemgr.cpp - implementation of class LocaleMgr used to interact with - * registered locales for a sword installation - * - * $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 - * 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 <stdio.h> -#include <stdlib.h> -#include <fcntl.h> - -#ifndef __GNUC__ -#include <io.h> -#else -#include <unistd.h> -#include <unixstr.h> -#endif -#include <sys/stat.h> -#include <dirent.h> - -#include <swmgr.h> -#include <utilfuns.h> - -#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; - SWBuf path; - - defaultLocaleName = 0; - - char *lang = getenv ("LANG"); - if (lang) { - if (strlen(lang) > 0) - setDefaultLocaleName(lang); - else setDefaultLocaleName("en_us"); - } - else setDefaultLocaleName("en_us"); - - if (!iConfigPath) - SWMgr::findConfig(&configType, &prefixPath, &configPath); - else configPath = (char *)iConfigPath; - - if (prefixPath) { - switch (configType) { - case 2: - int i; - for (i = strlen(configPath)-1; ((i) && (configPath[i] != '/') && (configPath[i] != '\\')); i--); - configPath[i] = 0; - path = configPath; - path += "/"; - break; - default: - path = prefixPath; - if ((prefixPath[strlen(prefixPath)-1] != '\\') && (prefixPath[strlen(prefixPath)-1] != '/')) - path += "/"; - - break; - } - if (FileMgr::existsDir(path.c_str(), "locales.d")) { - path += "locales.d"; - loadConfigDir(path.c_str()); - } - } - - if (prefixPath) - delete [] prefixPath; - - if (configPath) - delete [] configPath; -} - - -LocaleMgr::~LocaleMgr() { - if (defaultLocaleName) - delete [] defaultLocaleName; - deleteLocales(); - delete locales; -} - - -void LocaleMgr::loadConfigDir(const char *ipath) { - DIR *dir; - struct dirent *ent; - SWBuf newmodfile; - LocaleMap::iterator it; - - 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; - SWLocale *locale = new SWLocale(newmodfile.c_str()); - if (locale->getName()) { - it = locales->find(locale->getName()); - if (it != locales->end()) { - *((*it).second) += *locale; - delete locale; - } - else locales->insert(LocaleMap::value_type(locale->getName(), locale)); - } - else delete locale; - } - } - closedir(dir); - } -} - - -void LocaleMgr::deleteLocales() { - - LocaleMap::iterator it; - - for (it = locales->begin(); it != locales->end(); it++) - delete (*it).second; - - locales->erase(locales->begin(), locales->end()); -} - - -SWLocale *LocaleMgr::getLocale(const char *name) { - LocaleMap::iterator it; - - it = locales->find(name); - if (it != locales->end()) - return (*it).second; - - return 0; -} - - -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 *text, const char *localeName) { - SWLocale *target; - if (!localeName) { - localeName = getDefaultLocaleName(); - } - target = getLocale(localeName); - if (target) - return target->translate(text); - return text; -} - - -const char *LocaleMgr::getDefaultLocaleName() { - return defaultLocaleName; -} - - -void LocaleMgr::setDefaultLocaleName(const char *name) { - stdstr(&defaultLocaleName, name); -} - -SWORD_NAMESPACE_END diff --git a/src/mgr/markupfiltmgr.cpp b/src/mgr/markupfiltmgr.cpp deleted file mode 100644 index 07a9fb0..0000000 --- a/src/mgr/markupfiltmgr.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/****************************************************************************** - * swmarkupmgr.cpp - implementaion of class MarkupFilterMgr, subclass of - * used to transcode all module text to a requested - * markup. - * - * 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 <thmlplain.h> -#include <gbfplain.h> -#include <thmlgbf.h> -#include <gbfthml.h> -#include <thmlhtml.h> -#include <gbfhtml.h> -#include <plainhtml.h> -#include <thmlhtmlhref.h> -#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 - * - * ENT: - * enc - Encoding format to emit - * mark - Markup format to emit - */ - -MarkupFilterMgr::MarkupFilterMgr (char mark, char enc) - : EncodingFilterMgr(enc) { - - markup = mark; - - CreateFilters(markup); -} - - -/****************************************************************************** - * MarkupFilterMgr Destructor - Cleans up instance of MarkupFilterMgr - */ - -MarkupFilterMgr::~MarkupFilterMgr() { - if (fromthml) - delete (fromthml); - if (fromgbf) - delete (fromgbf); - if (fromplain) - delete (fromplain); - if (fromosis) - delete (fromosis); -} - -/****************************************************************************** - * MarkupFilterMgr::Markup - sets/gets markup - * - * ENT: mark - new encoding or 0 to simply get the current markup - * - * RET: markup - */ -char MarkupFilterMgr::Markup(char mark) { - if (mark && mark != markup) { - markup = mark; - ModMap::const_iterator module; - - SWFilter * oldplain = fromplain; - SWFilter * oldthml = fromthml; - SWFilter * oldgbf = fromgbf; - SWFilter * oldosis = fromosis; - - CreateFilters(markup); - - for (module = getParentMgr()->Modules.begin(); module != getParentMgr()->Modules.end(); module++) - switch (module->second->Markup()) { - case FMT_THML: - if (oldthml != fromthml) { - if (oldthml) { - if (!fromthml) { - module->second->RemoveRenderFilter(oldthml); - } - else { - module->second->ReplaceRenderFilter(oldthml, fromthml); - } - } - else if (fromthml) { - module->second->AddRenderFilter(fromthml); - } - } - break; - case FMT_GBF: - if (oldgbf != fromgbf) { - if (oldgbf) { - if (!fromgbf) { - module->second->RemoveRenderFilter(oldgbf); - } - else { - module->second->ReplaceRenderFilter(oldgbf, fromgbf); - } - } - else if (fromgbf) { - module->second->AddRenderFilter(fromgbf); - } - break; - } - case FMT_PLAIN: - if (oldplain != fromplain) { - if (oldplain) { - if (!fromplain) { - module->second->RemoveRenderFilter(oldplain); - } - else { - module->second->ReplaceRenderFilter(oldplain, fromplain); - } - } - else if (fromplain) { - module->second->AddRenderFilter(fromplain); - } - break; - } - case FMT_OSIS: - if (oldosis != fromosis) { - if (oldosis) { - if (!fromosis) { - module->second->RemoveRenderFilter(oldosis); - } - else { - module->second->ReplaceRenderFilter(oldosis, fromosis); - } - } - else if (fromosis) { - module->second->AddRenderFilter(fromosis); - } - break; - } - } - - if (oldthml) - delete oldthml; - if (oldgbf) - delete oldgbf; - if (oldplain) - delete oldplain; - if (oldosis) - delete oldosis; - } - return markup; -} - -void MarkupFilterMgr::AddRenderFilters(SWModule *module, ConfigEntMap §ion) { - switch (module->Markup()) { - case FMT_THML: - if (fromthml) - module->AddRenderFilter(fromthml); - break; - case FMT_GBF: - if (fromgbf) - module->AddRenderFilter(fromgbf); - break; - case FMT_PLAIN: - if (fromplain) - module->AddRenderFilter(fromplain); - break; - case FMT_OSIS: - if (fromosis) - module->AddRenderFilter(fromosis); - break; - } -} - -void MarkupFilterMgr::CreateFilters(char markup) { - - switch (markup) { - case FMT_PLAIN: - fromplain = NULL; - fromthml = new ThMLPlain(); - fromgbf = new GBFPlain(); - fromosis = NULL; - break; - case FMT_THML: - fromplain = NULL; - fromthml = NULL; - fromgbf = new GBFThML(); - fromosis = NULL; - break; - case FMT_GBF: - fromplain = NULL; - fromthml = new ThMLGBF(); - fromgbf = NULL; - fromosis = NULL; - break; - case FMT_HTML: - fromplain = new PLAINHTML(); - fromthml = new ThMLHTML(); - fromgbf = new GBFHTML(); - fromosis = NULL; - break; - case FMT_HTMLHREF: - fromplain = new PLAINHTML(); - fromthml = new ThMLHTMLHREF(); - fromgbf = new GBFHTMLHREF(); - fromosis = new OSISHTMLHREF(); - break; - case FMT_RTF: - fromplain = NULL; - fromthml = new ThMLRTF(); - fromgbf = new GBFRTF(); - fromosis = new OSISRTF(); - break; - case FMT_OSIS: - fromplain = 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 deleted file mode 100644 index ef04d98..0000000 --- a/src/mgr/swcacher.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************************** - * 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.2 2002/10/01 19:52:40 dglassey 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 <swcacher.h> - -SWORD_NAMESPACE_START - - -SWCacher::SWCacher() { -} - - -SWCacher::~SWCacher() { -} - - -void SWCacher::flush() { -} - -long SWCacher::resourceConsumption() { - return 0; -} - -long SWCacher::lastAccess() { - return 0; -} - -SWORD_NAMESPACE_END diff --git a/src/mgr/swconfig.cpp b/src/mgr/swconfig.cpp deleted file mode 100644 index d9eccc6..0000000 --- a/src/mgr/swconfig.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/****************************************************************************** - * swconfig.cpp - implementation of Class SWConfig used for saving and - * retrieval of configuration information - * - * $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 - * 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 <swconfig.h> -#include <utilfuns.h> - -SWORD_NAMESPACE_START - -SWConfig::SWConfig(const char * ifilename) { - filename = ifilename; - Load(); -} - - -SWConfig::~SWConfig() { -} - - -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 (len>0 && buf[len-1] == '\\') { - buf[(len--)-1] = 0; - line += buf; - continue; - } - line += buf; - - if (len < 253) { - retval = 1; - break; - } - } - return retval; -} - - -void SWConfig::Load() { - FILE *cfile; - char *buf, *data; - SWBuf line; - ConfigEntMap cursect; - SWBuf sectname; - bool first = true; - - Sections.erase(Sections.begin(), Sections.end()); - - if ((cfile = fopen(filename.c_str(), "r"))) { - while (getline(cfile, line)) { - buf = new char [ line.length() + 1 ]; - strcpy(buf, line.c_str()); - if (*strstrip(buf) == '[') { - if (!first) - Sections.insert(SectionMap::value_type(sectname, cursect)); - else first = false; - - cursect.erase(cursect.begin(), cursect.end()); - - strtok(buf, "]"); - sectname = buf+1; - } - else { - strtok(buf, "="); - if ((*buf) && (*buf != '=')) { - if ((data = strtok(NULL, ""))) - cursect.insert(ConfigEntMap::value_type(buf, strstrip(data))); - else cursect.insert(ConfigEntMap::value_type(buf, "")); - } - } - delete [] buf; - } - if (!first) - Sections.insert(SectionMap::value_type(sectname, cursect)); - - fclose(cfile); - } -} - - -void SWConfig::Save() { - FILE *cfile; - SWBuf buf; - SectionMap::iterator sit; - ConfigEntMap::iterator entry; - SWBuf sectname; - - if ((cfile = fopen(filename.c_str(), "w"))) { - - for (sit = Sections.begin(); sit != Sections.end(); sit++) { - buf = "\n["; - buf += (*sit).first.c_str(); - buf += "]\n"; - fputs(buf.c_str(), cfile); - for (entry = (*sit).second.begin(); entry != (*sit).second.end(); entry++) { - buf = (*entry).first.c_str(); - buf += "="; - buf += (*entry).second.c_str(); - buf += "\n"; - fputs(buf.c_str(), cfile); - } - } - fputs("\n", cfile); // so getline will find last line - fclose(cfile); - } -} - - -void SWConfig::augment(SWConfig &addFrom) { - - SectionMap::iterator section; - 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++) { - 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(); - } - } -} - - -ConfigEntMap & SWConfig::operator [] (const char *section) { - return Sections[section]; -} - -SWORD_NAMESPACE_END diff --git a/src/mgr/swfiltermgr.cpp b/src/mgr/swfiltermgr.cpp deleted file mode 100644 index 26ba98a..0000000 --- a/src/mgr/swfiltermgr.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/****************************************************************************** - * swfiltermgr.cpp - definition of class SWFilterMgr used as an interface to - * manage filters on a module - * - * $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 - * 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 <swfiltermgr.h> - -SWORD_NAMESPACE_START - - -SWFilterMgr::SWFilterMgr() { -} - - -SWFilterMgr::~SWFilterMgr() { -} - - -void SWFilterMgr::setParentMgr(SWMgr *parentMgr) { - this->parentMgr = parentMgr; -} - - -SWMgr *SWFilterMgr::getParentMgr() { - return parentMgr; -} - - -void SWFilterMgr::AddGlobalOptions(SWModule * module, ConfigEntMap & section, ConfigEntMap::iterator start, ConfigEntMap::iterator end) { -} - - -void SWFilterMgr::AddLocalOptions(SWModule * module, ConfigEntMap & section, ConfigEntMap::iterator start, ConfigEntMap::iterator end) { -} - - -/** -* Adds the encoding filters which are defined in "section" to the SWModule object "module". -* @param module To this module the encoding filter(s) are added -* @param section We use this section to get a list of filters we should apply to the module -*/ - -void SWFilterMgr::AddEncodingFilters(SWModule * module, ConfigEntMap & section) { -} - - -/** -* Adds the render filters which are defined in "section" to the SWModule object "module". -* @param module To this module the render filter(s) are added -* @param section We use this section to get a list of filters we should apply to the module -*/ - -void SWFilterMgr::AddRenderFilters(SWModule * module, ConfigEntMap & section) { -} - - -/** -* Adds the strip filters which are defined in "section" to the SWModule object "module". -* @param module To this module the strip filter(s) are added -* @param section We use this section to get a list of filters we should apply to the module -*/ - -void SWFilterMgr::AddStripFilters(SWModule * module, ConfigEntMap & section) { -} - - -/** -* Adds the raw filters which are defined in "section" to the SWModule object "module". -* @param module To this module the raw filter(s) are added -* @param section We use this section to get a list of filters we should apply to the module -*/ - -void SWFilterMgr::AddRawFilters(SWModule * module, ConfigEntMap & section) { -} - -SWORD_NAMESPACE_END diff --git a/src/mgr/swlocale.cpp b/src/mgr/swlocale.cpp deleted file mode 100644 index 8cf1e96..0000000 --- a/src/mgr/swlocale.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/****************************************************************************** - * swlocale.cpp - implementation of Class SWLocale used for retrieval - * of locale lookups - * - * $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 - * 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 <swlocale.h> -#include <utilfuns.h> - -SWORD_NAMESPACE_START - -SWLocale::SWLocale(const char * ifilename) { - ConfigEntMap::iterator confEntry; - - name = 0; - description = 0; - bookAbbrevs = 0; - BMAX = 0; - books = 0; - localeSource = new SWConfig(ifilename); - - confEntry = localeSource->Sections["Meta"].find("Name"); - if (confEntry != localeSource->Sections["Meta"].end()) - stdstr(&name, (*confEntry).second.c_str()); - - confEntry = localeSource->Sections["Meta"].find("Description"); - if (confEntry != localeSource->Sections["Meta"].end()) - stdstr(&description, (*confEntry).second.c_str()); -} - - -SWLocale::~SWLocale() { - - delete localeSource; - - if (description) - delete [] description; - - if (name) - delete [] name; - - if (bookAbbrevs) - delete [] bookAbbrevs; - - if (BMAX) { - for (int i = 0; i < 2; i++) - delete [] books[i]; - delete [] BMAX; - delete [] books; - } -} - - -const char *SWLocale::translate(const char *text) { - LookupMap::iterator entry; - - entry = lookupTable.find(text); - - if (entry == lookupTable.end()) { - ConfigEntMap::iterator confEntry; - confEntry = localeSource->Sections["Text"].find(text); - if (confEntry == localeSource->Sections["Text"].end()) - lookupTable.insert(LookupMap::value_type(text, text)); - else lookupTable.insert(LookupMap::value_type(text, (*confEntry).second.c_str())); - entry = lookupTable.find(text); - } - return (*entry).second.c_str(); -} - - -const char *SWLocale::getName() { - return name; -} - - -const char *SWLocale::getDescription() { - return description; -} - - -void SWLocale::augment(SWLocale &addFrom) { - *localeSource += *addFrom.localeSource; -} - - -const struct abbrev *SWLocale::getBookAbbrevs() { - static const char *nullstr = ""; - if (!bookAbbrevs) { - ConfigEntMap::iterator it; - int i; - int size = localeSource->Sections["Book Abbrevs"].size(); - bookAbbrevs = new struct abbrev[size + 1]; - for (i = 0, it = localeSource->Sections["Book Abbrevs"].begin(); it != localeSource->Sections["Book Abbrevs"].end(); it++, i++) { - bookAbbrevs[i].ab = (*it).first.c_str(); - bookAbbrevs[i].book = atoi((*it).second.c_str()); - } - bookAbbrevs[i].ab = nullstr; - bookAbbrevs[i].book = -1; - } - - return bookAbbrevs; -} - - -void SWLocale::getBooks(char **iBMAX, struct sbook ***ibooks) { - if (!BMAX) { - BMAX = new char [2]; - BMAX[0] = VerseKey::builtin_BMAX[0]; - BMAX[1] = VerseKey::builtin_BMAX[1]; - - books = new struct sbook *[2]; - books[0] = new struct sbook[BMAX[0]]; - books[1] = new struct sbook[BMAX[1]]; - - for (int i = 0; i < 2; i++) { - for (int j = 0; j < BMAX[i]; j++) { - books[i][j] = VerseKey::builtin_books[i][j]; - books[i][j].name = translate(VerseKey::builtin_books[i][j].name); - } - } - } - - *iBMAX = BMAX; - *ibooks = books; -} - -SWORD_NAMESPACE_END diff --git a/src/mgr/swmgr.cpp b/src/mgr/swmgr.cpp deleted file mode 100644 index 6207b60..0000000 --- a/src/mgr/swmgr.cpp +++ /dev/null @@ -1,1181 +0,0 @@ -/****************************************************************************** - * swmgr.cpp - implementaion of class SWMgr used to interact with an install - * base of sword modules. - * - * $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 - * 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 <stdio.h> -#include <stdlib.h> -#include <fcntl.h> - -#ifndef __GNUC__ -#include <io.h> -#else -#include <unistd.h> -#include <unixstr.h> -#endif -#include <sys/stat.h> -#ifndef _MSC_VER -#include <iostream> -#endif -#include <dirent.h> - -#include <swmgr.h> -#include <rawtext.h> -#include <rawgenbook.h> -#include <rawcom.h> -#include <hrefcom.h> -#include <rawld.h> -#include <rawld4.h> -#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> -#include <rawfiles.h> -#include <ztext.h> -#include <zld.h> -#include <zcom.h> -#include <lzsscomprs.h> -#include <utf8greekaccents.h> -#include <utf8cantillation.h> -#include <utf8hebrewpoints.h> -#include <greeklexattribs.h> -#include <swfiltermgr.h> -#ifndef EXCLUDEZLIB -#include "zipcomprs.h" -#endif - - -#ifdef _ICU_ -#include <utf8transliterator.h> -#endif - -SWORD_NAMESPACE_START - -#ifdef _ICU_ -bool SWMgr::isICU = true; -#else -bool SWMgr::isICU = false; -#endif - - -bool SWMgr::debug = false; - -#ifdef GLOBCONFPATH -const char *SWMgr::globalConfPath = GLOBCONFPATH; -#else -const char *SWMgr::globalConfPath = "/etc/sword.conf:/usr/local/etc/sword.conf"; -#endif - -void SWMgr::init() { - SWFilter *tmpFilter = 0; - configPath = 0; - prefixPath = 0; - configType = 0; - myconfig = 0; - mysysconfig = 0; - homeConfig = 0; - - - cipherFilters.clear(); - 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); - - tmpFilter = new GBFFootnotes(); - 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); - - tmpFilter = new GBFHeadings(); - 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); - - tmpFilter = new ThMLFootnotes(); - optionFilters.insert(FilterMap::value_type("ThMLFootnotes", tmpFilter)); - cleanupFilters.push_back(tmpFilter); - - tmpFilter = new ThMLMorph(); - optionFilters.insert(FilterMap::value_type("ThMLMorph", tmpFilter)); - cleanupFilters.push_back(tmpFilter); - - tmpFilter = new ThMLHeadings(); - optionFilters.insert(FilterMap::value_type("ThMLHeadings", tmpFilter)); - cleanupFilters.push_back(tmpFilter); - - tmpFilter = new ThMLLemma(); - optionFilters.insert(FilterMap::value_type("ThMLLemma", tmpFilter)); - cleanupFilters.push_back(tmpFilter); - - tmpFilter = new ThMLScripref(); - optionFilters.insert(FilterMap::value_type("ThMLScripref", tmpFilter)); - cleanupFilters.push_back(tmpFilter); - - tmpFilter = new UTF8GreekAccents(); - optionFilters.insert(FilterMap::value_type("UTF8GreekAccents", tmpFilter)); - cleanupFilters.push_back(tmpFilter); - - tmpFilter = new UTF8HebrewPoints(); - optionFilters.insert(FilterMap::value_type("UTF8HebrewPoints", tmpFilter)); - cleanupFilters.push_back(tmpFilter); - - tmpFilter = new UTF8Cantillation(); - optionFilters.insert(FilterMap::value_type("UTF8Cantillation", tmpFilter)); - cleanupFilters.push_back(tmpFilter); - - tmpFilter = new GreekLexAttribs(); - 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_ - 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); -} - - -SWMgr::SWMgr(SWFilterMgr *filterMgr) { - commonInit(0, 0, true, filterMgr); -} - - -SWMgr::SWMgr(SWConfig *iconfig, SWConfig *isysconfig, bool autoload, SWFilterMgr *filterMgr) { - commonInit(iconfig, isysconfig, autoload, filterMgr); -} - - -void SWMgr::commonInit(SWConfig * iconfig, SWConfig * isysconfig, bool autoload, SWFilterMgr *filterMgr) { - this->filterMgr = filterMgr; - if (filterMgr) - filterMgr->setParentMgr(this); - - init(); - - if (iconfig) { - config = iconfig; - myconfig = 0; - } - else config = 0; - if (isysconfig) { - sysconfig = isysconfig; - mysysconfig = 0; - } - else sysconfig = 0; - - if (autoload) - Load(); -} - - -SWMgr::SWMgr(const char *iConfigPath, bool autoload, SWFilterMgr *filterMgr) { - - SWBuf path; - - this->filterMgr = filterMgr; - if (filterMgr) - filterMgr->setParentMgr(this); - - init(); - - path = iConfigPath; - 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()); - 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; - } - } - - config = 0; - sysconfig = 0; - - if (autoload && configPath) - Load(); -} - - -SWMgr::~SWMgr() { - - DeleteMods(); - - for (FilterList::iterator it = cleanupFilters.begin(); it != cleanupFilters.end(); it++) - delete (*it); - - if (homeConfig) - delete homeConfig; - - if (myconfig) - delete myconfig; - - if (prefixPath) - delete [] prefixPath; - - if (configPath) - delete [] configPath; - - if (filterMgr) - delete filterMgr; -} - - -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"); - - *configType = 0; - -#ifndef _MSC_VER - // check working directory -if (debug) - std::cerr << "Checking working directory for mods.conf..."; -#endif - - if (FileMgr::existsFile(".", "mods.conf")) { - -#ifndef _MSC_VER -if (debug) - std::cerr << "found\n"; -#endif - - stdstr(prefixPath, "./"); - stdstr(configPath, "./mods.conf"); - return; - } - -#ifndef _MSC_VER -if (debug) - std::cerr << "\nChecking working directory for mods.d..."; -#endif - - if (FileMgr::existsDir(".", "mods.d")) { - -#ifndef _MSC_VER -if (debug) - std::cerr << "found\n"; -#endif - - stdstr(prefixPath, "./"); - stdstr(configPath, "./mods.d"); - *configType = 1; - return; - } - - - // check environment variable SWORD_PATH -#ifndef _MSC_VER -if (debug) - std::cerr << "\nChecking SWORD_PATH..."; -#endif - - if (envsworddir != NULL) { - -#ifndef _MSC_VER -if (debug) - std::cerr << "found (" << envsworddir << ")\n"; -#endif - - path = envsworddir; - if ((envsworddir[strlen(envsworddir)-1] != '\\') && (envsworddir[strlen(envsworddir)-1] != '/')) - path += "/"; - -#ifndef _MSC_VER -if (debug) - std::cerr << "\nChecking $SWORD_PATH for mods.conf..."; -#endif - - if (FileMgr::existsFile(path.c_str(), "mods.conf")) { - -#ifndef _MSC_VER -if (debug) - std::cerr << "found\n"; -#endif - - stdstr(prefixPath, path.c_str()); - path += "mods.conf"; - stdstr(configPath, path.c_str()); - return; - } - -#ifndef _MSC_VER -if (debug) - std::cerr << "\nChecking $SWORD_PATH for mods.d..."; -#endif - - if (FileMgr::existsDir(path.c_str(), "mods.d")) { - -#ifndef _MSC_VER -if (debug) - std::cerr << "found\n"; -#endif - - stdstr(prefixPath, path.c_str()); - path += "mods.d"; - stdstr(configPath, path.c_str()); - *configType = 1; - return; - } - } - - - // check for systemwide globalConfPath - -#ifndef _MSC_VER -if (debug) - std::cerr << "\nParsing " << globalConfPath << "..."; -#endif - - char *globPaths = 0; - char *gfp; - stdstr(&globPaths, globalConfPath); - for (gfp = strtok(globPaths, ":"); gfp; gfp = strtok(0, ":")) { - -#ifndef _MSC_VER -if (debug) - 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 (sysConfPath.size()) { - -#ifndef _MSC_VER -if (debug) - std::cerr << "found\n"; -#endif - - 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] != '/')) - path += "/"; - -#ifndef _MSC_VER -if (debug) - std::cerr << "DataPath in " << sysConfPath << " is set to: " << path; -#endif - -#ifndef _MSC_VER -if (debug) - std::cerr << "\nChecking for mods.conf in DataPath "; -#endif - if (FileMgr::existsFile(path.c_str(), "mods.conf")) { - -#ifndef _MSC_VER -if (debug) - std::cerr << "found\n"; -#endif - - stdstr(prefixPath, path.c_str()); - path += "mods.conf"; - stdstr(configPath, path.c_str()); - *configType = 1; - } - -#ifndef _MSC_VER -if (debug) - std::cerr << "\nChecking for mods.d in DataPath "; -#endif - - if (FileMgr::existsDir(path.c_str(), "mods.d")) { - -#ifndef _MSC_VER -if (debug) - std::cerr << "found\n"; -#endif - - stdstr(prefixPath, path.c_str()); - path += "mods.d"; - stdstr(configPath, path.c_str()); - *configType = 1; - } - } - 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) - std::cerr << "\nChecking home directory for ~/.sword/mods.conf" << path; -#endif - - if (envhomedir != NULL) { - path = envhomedir; - if ((envhomedir[strlen(envhomedir)-1] != '\\') && (envhomedir[strlen(envhomedir)-1] != '/')) - path += "/"; - path += ".sword/"; - if (FileMgr::existsFile(path.c_str(), "mods.conf")) { - -#ifndef _MSC_VER -if (debug) - std::cerr << " found\n"; -#endif - - stdstr(prefixPath, path.c_str()); - path += "mods.conf"; - stdstr(configPath, path.c_str()); - return; - } - -#ifndef _MSC_VER -if (debug) - std::cerr << "\nChecking home directory for ~/.sword/mods.d" << path; -#endif - - if (FileMgr::existsDir(path.c_str(), "mods.d")) { - -#ifndef _MSC_VER -if (debug) - std::cerr << "found\n"; -#endif - - stdstr(prefixPath, path.c_str()); - path += "mods.d"; - stdstr(configPath, path.c_str()); - *configType = 2; - return; - } - } -} - - -void SWMgr::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()); - } - } -} - - -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 - * - * RET: status - 0 = ok; -1 no config found; 1 = no modules installed - * - */ - -signed char SWMgr::Load() { - signed char ret = 0; - - 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, &augPaths); - if (configPath) { - if (configType) - loadConfigDir(configPath); - else config = myconfig = new SWConfig(configPath); - } - } - - if (config) { - SectionMap::iterator Sectloop, Sectend; - ConfigEntMap::iterator Entryloop, Entryend; - - DeleteMods(); - - for (Sectloop = config->Sections.lower_bound("Globals"), Sectend = config->Sections.upper_bound("Globals"); Sectloop != Sectend; Sectloop++) { // scan thru all 'Globals' sections - for (Entryloop = (*Sectloop).second.lower_bound("AutoInstall"), Entryend = (*Sectloop).second.upper_bound("AutoInstall"); Entryloop != Entryend; Entryloop++) // scan thru all AutoInstall entries - InstallScan((*Entryloop).second.c_str()); // Scan AutoInstall entry directory for new modules and install - } - if (configType) { // force reload on config object because we may have installed new modules - delete myconfig; - config = myconfig = 0; - loadConfigDir(configPath); - } - else config->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 - 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; - - } - else { - SWLog::systemlog->LogError("SWMgr: Can't find 'mods.conf' or 'mods.d'. Try setting:\n\tSWORD_PATH=<directory containing mods.conf>\n\tOr see the README file for a full description of setup options (%s)", (configPath) ? configPath : "<configPath is null>"); - ret = -1; - } - - return ret; -} - -SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap §ion) -{ - SWBuf description, datapath, misc1; - ConfigEntMap::iterator entry; - SWModule *newmod = 0; - SWBuf lang, sourceformat, encoding; - signed char direction, enc, markup; - - 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 : (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_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; - } - - if ((!stricmp(driver, "zText")) || (!stricmp(driver, "zCom"))) { - SWCompress *compress = 0; - int blockType = CHAPTERBLOCKS; - 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")) - blockType = CHAPTERBLOCKS; - else if (!stricmp(misc1.c_str(), "BOOK")) - blockType = BOOKBLOCKS; - - misc1 = ((entry = section.find("CompressType")) != section.end()) ? (*entry).second : (SWBuf)"LZSS"; -#ifndef EXCLUDEZLIB - if (!stricmp(misc1.c_str(), "ZIP")) - compress = new ZipCompress(); - else -#endif - if (!stricmp(misc1.c_str(), "LZSS")) - compress = new LZSSCompress(); - - if (compress) { - 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, "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, "RawGBF")) { - newmod = new RawText(datapath.c_str(), name, 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, "RawFiles")) { - newmod = new RawFiles(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.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()); - } - - 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, "RawLD4")) { - newmod = new RawLD4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str()); - pos = 1; - } - - if (!stricmp(driver, "zLD")) { - SWCompress *compress = 0; - int blockCount; - 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 : (SWBuf)"LZSS"; -#ifndef EXCLUDEZLIB - if (!stricmp(misc1.c_str(), "ZIP")) - compress = new ZipCompress(); - else -#endif - if (!stricmp(misc1.c_str(), "LZSS")) - compress = new LZSSCompress(); - - if (compress) { - newmod = new zLD(datapath.c_str(), name, description.c_str(), blockCount, compress, 0, enc, direction, markup, lang.c_str()); - } - pos = 1; - } - - if (!stricmp(driver, "RawGenBook")) { - newmod = new RawGenBook(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str()); - pos = 1; - } - - 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(§ion); - return newmod; -} - - -void SWMgr::AddGlobalOptions(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end) { - for (;start != end; start++) { - FilterMap::iterator it; - it = optionFilters.find((*start).second); - if (it != optionFilters.end()) { - module->AddOptionFilter((*it).second); // add filter to module and option as a valid option - StringList::iterator loop; - for (loop = options.begin(); loop != options.end(); loop++) { - if (!strcmp((*loop).c_str(), (*it).second->getOptionName())) - break; - } - if (loop == options.end()) // if we have not yet included the option - options.push_back((*it).second->getOptionName()); - } - } - if (filterMgr) - filterMgr->AddGlobalOptions(module, section, start, end); -#ifdef _ICU_ - module->AddOptionFilter(transliterator); -#endif -} - - -void SWMgr::AddLocalOptions(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end) -{ - for (;start != end; start++) { - FilterMap::iterator it; - it = optionFilters.find((*start).second); - if (it != optionFilters.end()) { - module->AddOptionFilter((*it).second); // add filter to module - } - } - - if (filterMgr) - filterMgr->AddLocalOptions(module, section, start, end); -} - - -void SWMgr::AddRawFilters(SWModule *module, ConfigEntMap §ion) { - SWBuf sourceformat, cipherKey; - ConfigEntMap::iterator entry; - - 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); - module->AddRawFilter(cipherFilter); - } - - if (filterMgr) - filterMgr->AddRawFilters(module, section); -} - - -void SWMgr::AddEncodingFilters(SWModule *module, ConfigEntMap §ion) { - if (filterMgr) - filterMgr->AddEncodingFilters(module, section); -} - - -void SWMgr::AddRenderFilters(SWModule *module, ConfigEntMap §ion) { - SWBuf sourceformat; - ConfigEntMap::iterator entry; - - 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.length()) { - sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)""; - if (!stricmp(sourceformat.c_str(), "RawGBF")) - sourceformat = "GBF"; - else sourceformat = ""; - } - -// process module - eg. follows -// if (!stricmp(sourceformat.c_str(), "GBF")) { -// module->AddRenderFilter(gbftortf); -// } - - if (filterMgr) - filterMgr->AddRenderFilters(module, section); - -} - - -void SWMgr::AddStripFilters(SWModule *module, ConfigEntMap §ion) -{ - SWBuf sourceformat; - ConfigEntMap::iterator entry; - - sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (SWBuf)""; - // Temporary: To support old module types - if (!sourceformat.length()) { - sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)""; - if (!stricmp(sourceformat.c_str(), "RawGBF")) - sourceformat = "GBF"; - else sourceformat = ""; - } - - if (!stricmp(sourceformat.c_str(), "GBF")) { - module->AddStripFilter(gbfplain); - } - 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); - -} - - -void SWMgr::CreateMods() { - SectionMap::iterator it; - ConfigEntMap::iterator start; - ConfigEntMap::iterator end; - ConfigEntMap::iterator entry; - SWModule *newmod; - SWBuf driver, misc1; - for (it = config->Sections.begin(); it != config->Sections.end(); it++) { - ConfigEntMap §ion = (*it).second; - newmod = 0; - - 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"); - end = (*it).second.upper_bound("GlobalOptionFilter"); - AddGlobalOptions(newmod, section, start, end); - - start = (*it).second.lower_bound("LocalOptionFilter"); - end = (*it).second.upper_bound("LocalOptionFilter"); - AddLocalOptions(newmod, section, start, end); - - AddRawFilters(newmod, section); - AddStripFilters(newmod, section); - AddRenderFilters(newmod, section); - AddEncodingFilters(newmod, section); - - Modules.insert(ModMap::value_type(newmod->Name(), newmod)); - } - } - } -} - - -void SWMgr::DeleteMods() { - - ModMap::iterator it; - - for (it = Modules.begin(); it != Modules.end(); it++) - delete (*it).second; - - Modules.clear(); -} - - -void SWMgr::InstallScan(const char *dirname) -{ - DIR *dir; - struct dirent *ent; - int conffd = 0; - SWBuf newmodfile; - SWBuf targetName; - - if (!access(dirname, 04)) { - if ((dir = opendir(dirname))) { - rewinddir(dir); - while ((ent = readdir(dir))) { - if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) { - newmodfile = dirname; - if ((dirname[strlen(dirname)-1] != '\\') && (dirname[strlen(dirname)-1] != '/')) - newmodfile += "/"; - newmodfile += ent->d_name; - if (configType) { - if (config > 0) - close(conffd); - targetName = configPath; - if ((configPath[strlen(configPath)-1] != '\\') && (configPath[strlen(configPath)-1] != '/')) - targetName += "/"; - targetName += ent->d_name; - conffd = open(targetName.c_str(), O_WRONLY|O_CREAT, S_IREAD|S_IWRITE); - } - else { - if (conffd < 1) { - conffd = open(config->filename.c_str(), O_WRONLY|O_APPEND); - if (conffd > 0) - lseek(conffd, 0L, SEEK_END); - } - } - AddModToConfig(conffd, newmodfile.c_str()); - unlink(newmodfile.c_str()); - } - } - if (conffd > 0) - close(conffd); - closedir(dir); - } - } -} - - -char SWMgr::AddModToConfig(int conffd, const char *fname) -{ - int modfd; - char ch; - - SWLog::systemlog->LogTimedInformation("Found new module [%s]. Installing...", fname); - modfd = open(fname, O_RDONLY); - ch = '\n'; - write(conffd, &ch, 1); - while (read(modfd, &ch, 1) == 1) - write(conffd, &ch, 1); - ch = '\n'; - write(conffd, &ch, 1); - close(modfd); - return 0; -} - - -void SWMgr::setGlobalOption(const char *option, const char *value) -{ - for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { - if ((*it).second->getOptionName()) { - if (!stricmp(option, (*it).second->getOptionName())) - (*it).second->setOptionValue(value); - } - } -} - - -const char *SWMgr::getGlobalOption(const char *option) -{ - for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { - if ((*it).second->getOptionName()) { - if (!stricmp(option, (*it).second->getOptionName())) - return (*it).second->getOptionValue(); - } - } - return 0; -} - - -const char *SWMgr::getGlobalOptionTip(const char *option) -{ - for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { - if ((*it).second->getOptionName()) { - if (!stricmp(option, (*it).second->getOptionName())) - return (*it).second->getOptionTip(); - } - } - return 0; -} - - -StringList SWMgr::getGlobalOptions() -{ - return options; -} - - -StringList SWMgr::getGlobalOptionValues(const char *option) -{ - StringList options; - for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { - if ((*it).second->getOptionName()) { - if (!stricmp(option, (*it).second->getOptionName())) { - options = (*it).second->getOptionValues(); - break; // just find the first one. All option filters with the same option name should expect the same values - } - } - } - return options; -} - - -signed char SWMgr::setCipherKey(const char *modName, const char *key) { - FilterMap::iterator it; - ModMap::iterator it2; - - // check for filter that already exists - it = cipherFilters.find(modName); - if (it != cipherFilters.end()) { - ((CipherFilter *)(*it).second)->getCipher()->setCipherKey(key); - return 0; - } - // check if module exists - else { - it2 = Modules.find(modName); - if (it2 != Modules.end()) { - SWFilter *cipherFilter = new CipherFilter(key); - cipherFilters.insert(FilterMap::value_type(modName, cipherFilter)); - cleanupFilters.push_back(cipherFilter); - (*it2).second->AddRawFilter(cipherFilter); - return 0; - } - } - return -1; -} - -SWORD_NAMESPACE_END diff --git a/src/mgr/swsearchable.cpp b/src/mgr/swsearchable.cpp deleted file mode 100644 index d81375d..0000000 --- a/src/mgr/swsearchable.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************** - * 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 deleted file mode 100644 index 58df9f0..0000000 --- a/src/mgr/swsourcemgr.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/****************************************************************************** - * 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 |