[sword-svn] r3501 - in trunk: include src/mgr
scribe at crosswire.org
scribe at crosswire.org
Wed Nov 1 03:36:00 MST 2017
Author: scribe
Date: 2017-11-01 03:36:00 -0700 (Wed, 01 Nov 2017)
New Revision: 3501
Modified:
trunk/include/filemgr.h
trunk/include/swmgr.h
trunk/src/mgr/filemgr.cpp
trunk/src/mgr/swmgr.cpp
Log:
Normalized most methods in SWMgr. Moved getHomeDir to a non-static in more appropriate FileMgr
Modified: trunk/include/filemgr.h
===================================================================
--- trunk/include/filemgr.h 2017-11-01 10:35:53 UTC (rev 3500)
+++ trunk/include/filemgr.h 2017-11-01 10:36:00 UTC (rev 3501)
@@ -42,10 +42,21 @@
};
/**
-* This class ist used make file access operations easier.
-* It keeps a list of all open files internally and closes them
-* when the destructor is called.
-*/
+ * This class isolates all file io for SWORD, making OS
+ * level quirks easier to fix. This class is typically
+ * copied and replaced if necessary to get SWORD to run on
+ * a specific platform (e.g., Windows Mobile), but in
+ * the future, statics should be removed to make possible to
+ * instead simply subclass and override necessary methods.
+ *
+ * This class also provides many convenience methods which
+ * make working with data storage easier.
+ *
+ * Conceptually, this factory exposes an interface which
+ * allows SWORD to 'open' every file it wants, without
+ * worrying about OS limits, and takes care of opening and
+ * closing the actual file descriptors when necessary.
+ */
class SWDLLEXPORT FileMgr : public SWCacher {
friend class FileDesc;
@@ -147,6 +158,18 @@
static int removeFile(const char *fName);
static char getLine(FileDesc *fDesc, SWBuf &line);
+ /**
+ * Determines where SWORD looks for the user's home folder. This is
+ * typically used as a place to find any additional personal SWORD
+ * modules which a user might wish to be added to a system-wide
+ * library (e.g., added from ~/.sword/mods.d/ or ~/sword/mods.d/)
+ *
+ * or if a user or UI wishes to override SWORD system configuration
+ * settings (e.g., /etc/sword.conf) with a custom configuration
+ * (e.g., ~/.sword/sword.conf)
+ */
+ SWBuf getHomeDir();
+
};
/**
Modified: trunk/include/swmgr.h
===================================================================
--- trunk/include/swmgr.h 2017-11-01 10:35:53 UTC (rev 3500)
+++ trunk/include/swmgr.h 2017-11-01 10:36:00 UTC (rev 3501)
@@ -101,9 +101,11 @@
SWConfig *myconfig; //made protected because because BibleTime needs it
SWConfig *mysysconfig;
SWConfig *homeConfig;
- void CreateMods(bool multiMod = false);
- virtual SWModule *createModule(const char *name, const char *driver, ConfigEntMap §ion);
- void DeleteMods();
+ /**
+ * Deprecated. Use createAllModules instead
+ */
+ SWDEPRECATED void CreateMods(bool multiMod = false) { createAllModules(multiMod); };
+ SWDEPRECATED void DeleteMods() { deleteAllModules(); }
char configType; // 0 = file; 1 = directory
OptionFilterMap optionFilters;
FilterMap cipherFilters;
@@ -115,49 +117,152 @@
FilterList cleanupFilters;
FilterMap extraFilters;
StringList options;
- virtual void init(); // use to initialize before loading modules
- virtual char AddModToConfig(FileDesc *conffd, const char *fname);
- virtual void loadConfigDir(const char *ipath);
- virtual void AddGlobalOptions(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end);
- virtual void AddLocalOptions(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end);
- StringList augPaths;
+ /**
+ * method to create all modules from configuration.
+ *
+ * Override to add any special processing before or after
+ * calling SWMgr::createAllModules
+ *
+ * e.g., augmenting a localConfig.conf to SWMgr::config
+ * that might store CipheyKey or Font preferences per module
+ * before actual construction of modules
+ *
+ */
+ virtual void createAllModules(bool multiMod = false);
+ /**
+ * called to delete all contructed modules. Undoes createAllModules
+ * override to clean anything up before or after all modules are
+ * deleted
+ */
+ virtual void deleteAllModules();
/**
- * Called to add appropriate Encoding Filters to a module. Override to do special actions,
- * if desired. See the module.conf Encoding= entry.
- * @param module module to which to add Encoding Filters
- * @param section configuration information from module.conf
+ * called to create exactly one module from a config entry
+ * override to do any extra work before or after each module
+ * is created
*/
- virtual void AddEncodingFilters(SWModule *module, ConfigEntMap §ion);
+ virtual SWModule *createModule(const char *name, const char *driver, ConfigEntMap §ion);
/**
- * Called to add appropriate Render Filters to a module. Override to do special actions,
- * if desired. See the module.conf SourceType= entry.
- * @param module module to which to add Render Filters
- * @param section configuration information from module.conf
+ * call by every constructor to initialize SWMgr object
+ * override to include any addition common initialization
*/
- virtual void AddRenderFilters(SWModule *module, ConfigEntMap §ion);
+ virtual void init();
+
/**
- * Called to add appropriate Strip Filters to a module. Override to do special actions,
- * if desired. See the module.conf SourceType= entry.
- * @param module module to which to add Strip Filters
- * @param section configuration information from module.conf
+ * Deprecated. Use addGlobalOptionFilters instead.
*/
- virtual void AddStripFilters(SWModule *module, ConfigEntMap §ion);
+ SWDEPRECATED virtual void AddGlobalOptions(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end) { addGlobalOptionFilters(module, section); }
+ /**
+ * Adds appropriate global option filters to a module. Override to add any special
+ * global option filters. Global option filters typically update SourceType markup
+ * to turn on and off specific features of a text when a user has optionally chosen
+ * to show or hide that feature, e.g. Strongs, Footnotes, Headings, etc.
+ * Global options can also have more than On and Off values, but these are the most
+ * common.
+ * A set of all global options included from an entire library of installed modules
+ * can be obtained from getGlobalOptions and presented to the user. Values to
+ * which each global option may be set can be obtain from getGlobalOptionValues,
+ * and similar. See that family of methods for more information.
+ * See the module.conf GlobalOptionFilter= entries.
+ * @param module module to which to add encoding filters
+ * @param section configuration information for module
+ */
+ virtual void addGlobalOptionFilters(SWModule *module, ConfigEntMap §ion);
- // ones manually specified in .conf file
- virtual void AddStripFilters(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end);
+ /**
+ * Deprecated. Use addLocalOptionFilters instead.
+ */
+ SWDEPRECATED virtual void AddLocalOptions(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end) { addLocalOptionFilters(module, section); }
+ /**
+ * Adds appropriate local option filters to a module. Override to add any special
+ * local option filters. Local options are similar to global options in that
+ * they may be toggled on or off or set to some value from a range of choices
+ * but local option
+ * See the module.conf LocalOptionFilter= entries.
+ * @param module module to which to add encoding filters
+ * @param section configuration information for module
+ */
+ virtual void addLocalOptionFilters(SWModule *module, ConfigEntMap §ion);
/**
- * Called to add appropriate Raw Filters to a module. Override to do special actions,
- * if desired. See the module.conf CipherKey= entry.
- * @param module module to which to add Raw Filters
- * @param section configuration information from module.conf
+ * Deprecated. Use addEncodingFilters instead
*/
- virtual void AddRawFilters(SWModule *module, ConfigEntMap §ion);
+ SWDEPRECATED virtual void AddEncodingFilters(SWModule *module, ConfigEntMap §ion) { addEncodingFilters(module, section); }
+ /**
+ * Adds appropriate encoding filters to a module. Override to add any special
+ * encoding filters.
+ * See the module.conf Encoding= entry.
+ * @param module module to which to add encoding filters
+ * @param section configuration information for module
+ */
+ virtual void addEncodingFilters(SWModule *module, ConfigEntMap §ion);
+ /**
+ * Deprecated. Use addRenderFilters instead.
+ */
+ SWDEPRECATED virtual void AddRenderFilters(SWModule *module, ConfigEntMap §ion) { addRenderFilters(module, section); }
+ /**
+ * Add appropriate render filters to a module. Override to add any special
+ * render filters. Render filters are used for preparing a text for
+ * display and typically convert markup from SourceType
+ * to desired display markup.
+ * See the module.conf SourceType= entry.
+ * @param module module to which to add render filters
+ * @param section configuration information for module
+ */
+ virtual void addRenderFilters(SWModule *module, ConfigEntMap §ion);
+ /**
+ * Deprecated. Use addStripFilters instead.
+ */
+ SWDEPRECATED virtual void AddStripFilters(SWModule *module, ConfigEntMap §ion) { addStripFilters(module, section); }
+ /**
+ * Adds appropriate strip filters to a module. Override to add any special
+ * strip filters. Strip filters are used for preparing text for searching
+ * and typically strip out all markup and leave only searchable words
+ * See the module.conf SourceType= entry.
+ * @param module module to which to add strip filters
+ * @param section configuration information for module
+ */
+ virtual void addStripFilters(SWModule *module, ConfigEntMap §ion);
+
+ /**
+ * Deprecated. Use addLocalStripFilters instead.
+ */
+ SWDEPRECATED virtual void AddStripFilters(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end) { addLocalStripFilters(module, section); }
+ /**
+ * Adds manually specified strip filters specified in module configuration
+ * as LocalStripFilters. These might take care of special cases of preparation
+ * for searching, e.g., removing ()[] and underdot symbols from manuscript modules
+ * @param module module to which to add local strip filters
+ * @param section configuration information for module
+ */
+ virtual void addLocalStripFilters(SWModule *module, ConfigEntMap §ion);
+
+ /**
+ * Deprecated. Use addRawFilters instead.
+ */
+ SWDEPRECATED virtual void AddRawFilters(SWModule *module, ConfigEntMap §ion) { addRawFilters(module, section); }
+ /**
+ * Add appropriate raw filters to a module. Override to add any special
+ * raw filters. Raw filters are used to manipulate a buffer
+ * immediately after it has been read from storage. For example,
+ * any decryption that might need to be done.
+ * See the module.conf CipherKey= entry.
+ * @param module module to which to add raw filters
+ * @param section configuration information for module
+ */
+ virtual void addRawFilters(SWModule *module, ConfigEntMap §ion);
+
+
+ // still to be normalized below ...
+ //
+ StringList augPaths;
+ virtual char AddModToConfig(FileDesc *conffd, const char *fname);
+ virtual void loadConfigDir(const char *ipath);
+
public:
// constants which represent module types used in SWModule::getType
@@ -170,14 +275,32 @@
static bool isICU;
static const char *globalConfPath;
- static SWBuf getHomeDir();
/**
- *
+ * Deprecated. Used FileMgr::getSystemFileMgr()->getHomeDir() instead.
*/
+ SWDEPRECATED static SWBuf getHomeDir();
+
+ /**
+ * Perform all the logic to discover a SWORD configuration and libraries on a system
+ */
static void findConfig(char *configType, char **prefixPath, char **configPath, StringList *augPaths = 0, SWConfig **providedSysConf = 0);
+ /**
+ * The configuration of a loaded library of SWORD modules
+ * e.g., from /usr/share/sword/mods.d/
+ * augmented with ~/.sword/mods.d/
+ *
+ * This represents all discovered modules and their configuration
+ * compiled into a single SWConfig object with each [section]
+ * representing each module. e.g. [KJV]
+ */
SWConfig *config;
+
+ /**
+ * The configuration file for SWORD
+ * e.g., /etc/sword.conf
+ */
SWConfig *sysConfig;
/** The path to main module set and locales
@@ -188,36 +311,43 @@
*/
char *configPath;
+
+ /**
+ * Deprecated. Use getModules instead.
+ */
+ ModMap Modules;
/** The map of available modules.
* This map exposes the installed modules.
- * Here's an example how to iterate over the map and check the module type of each module.
*
- *@code
- * ModMap::iterator it;
- * SWModule *curMod = 0;
+ * Here's an example how to iterate over all
+ * the installed modules and check the module name
+ * and type of each module and do something special
+ * if the module type is a Bible.
*
- * for (it = Modules.begin(); it != Modules.end(); it++) {
- * curMod = (*it).second;
- * if (!strcmp(curMod->Type(), "Biblical Texts")) {
- * // do something with curMod
- * }
- * else if (!strcmp(curMod->Type(), "Commentaries")) {
- * // do something with curMod
- * }
- * else if (!strcmp(curMod->Type(), "Lexicons / Dictionaries")) {
- * // do something with curMod
- * }
+ * @code
+ *
+ * for (ModMap::iterator it = getModules().begin(); it != getModules().end(); ++it) {
+ *
+ * SWBuf modName = it->first;
+ * SWModule *mod = it->second;
+ *
+ * SWBuf modType = mod->getType();
+ *
+ * if (modType == SWMgr::MODTYPE_BIBLES) {
+ * // do something with mod
+ * }
* }
* @endcode
*/
- ModMap Modules;
+ ModMap &getModules();
+ const ModMap &getModules() const { return const_cast<SWMgr *>(this)->getModules(); }
/** Gets a specific module by name. e.g. SWModule *kjv = myManager.getModule("KJV");
* @param modName the name of the module to retrieve
* @return the module, if found, otherwise 0
*/
- SWModule *getModule(const char *modName) { ModMap::iterator it = Modules.find(modName); return ((it != Modules.end()) ? it->second : 0); }
- const SWModule *getModule(const char *modName) const { ModMap::const_iterator it = Modules.find(modName); return ((it != Modules.end()) ? it->second : 0); }
+ SWModule *getModule(const char *modName) { ModMap::iterator it = getModules().find(modName); return ((it != getModules().end()) ? it->second : 0); }
+ const SWModule *getModule(const char *modName) const { ModMap::const_iterator it = getModules().find(modName); return ((it != getModules().end()) ? it->second : 0); }
/** Constructs an instance of SWMgr
@@ -226,7 +356,7 @@
* using a complex hierarchical search. See README for detailed specifics.
* @param isysconfig
* @param autoload whether or not to immediately load modules on construction of this SWMgr.
- * If you reimplemented SWMgr you can set this to false and call SWMgr::Load() after you have
+ * If you reimplemented SWMgr you can set this to false and call SWMgr::load() after you have
* completed the contruction and setup of your SWMgr subclass.
* @param filterMgr an SWFilterMgr subclass to use to manager filters on modules
* SWMgr TAKES OWNERSHIP FOR DELETING THIS OBJECT
@@ -271,12 +401,20 @@
*/
virtual void InstallScan(const char *dir);
- /** Load all modules. Should only be manually called if SWMgr was constructed
+ /**
+ * Deprecated. Use load
+ */
+ SWDEPRECATED virtual signed char Load() { return load(); }
+ /** Loads installed library of SWORD modules.
+ * Should only be manually called if SWMgr was constructed
* without autoload; otherwise, this will be called on SWMgr construction
* Reimplement this function to supply special functionality when modules are
- * initially loaded.
+ * initially loaded. This includes
+ * discovery of config path with SWMgr::fileconfig,
+ * loading of composite SWMgr::config,
+ * and construction of all modules from config using SWMgr::createAllModules
*/
- virtual signed char Load();
+ virtual signed char load();
/** Change the values of global options (e.g. Footnotes, Strong's Number, etc.)
* @param option The name of the option, for which you want to change the
@@ -322,43 +460,53 @@
/**
* Sets the cipher key for the given module. This function updates the key
* at runtime, but it does not write to the config file.
- * To write the new unlock key to the config file use code like this:
+ * This method is NOT the recommended means for applying a CipherKey
+ * to a module.
*
+ * Typically CipherKey entries and other per module user configuration
+ * settings are all saved in a separate localConfig.conf that is updated
+ * by a UI or other client of the library. e.g.,
+ *
+ *
+ * [KJV]
+ * Font=Arial
+ * LocalOptionFilter=SomeSpecialFilterMyUIAppliesToTheKJV
+ *
+ * [ISV]
+ * CipherKey=xyzzy
+ *
+ * [StrongsGreek]
+ * SomeUISetting=false
+ *
+ *
+ * Then these extra config settings in this separate file are applied
+ * just before module creation by overriding SWMgr::createAllModules and
+ * augmenting SWMgr::config with code like this:
+ *
* @code
- * SectionMap::iterator section;
- * ConfigEntMap::iterator entry;
- * DIR *dir = opendir(configPath);
- * struct dirent *ent;
- * char* modFile;
- * if (dir) { // find and update .conf file
- * rewinddir(dir);
- * while ((ent = readdir(dir)))
- * {
- * if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, "..")))
- * {
- * modFile = m_backend->configPath;
- * modFile += "/";
- * modFile += ent->d_name;
- * SWConfig *myConfig = new SWConfig( modFile );
- * section = myConfig->Sections.find( m_module->Name() );
- * if ( section != myConfig->Sections.end() )
- * {
- * entry = section->second.find("CipherKey");
- * if (entry != section->second.end())
- * {
- * entry->second = unlockKey;//set cipher key
- * myConfig->Save();//save config file
- * }
- * }
- * delete myConfig;
- * }
- * }
+ * void createAllModules(bool multiMod) {
+ *
+ * // after SWMgr::config is loaded
+ * // see if we have our own local settings
+ * SWBuf myExtraConf = "~/.myapp/localConf.conf";
+ * bool exists = FileMgr::existsFile(extraConf);
+ * if (exists) {
+ * SWConfig addConfig(extraConf);
+ * this->config->augment(addConfig);
+ * }
+ *
+ * // now that we've augmented SWMgr::config with our own custom
+ * // settings, proceed on with creating modules
+ *
+ * SWMgr::createAllModules(multiMod);
+ *
* }
- * closedir(dir);
* @endcode
*
+ * The above convention is preferred to using this setCipherKey method
+ *
* @param modName For this module we change the unlockKey
- * @param key This is the new unlck key we use for te module.
+ * @param key This is the new unlock key we use for the module.
*/
virtual signed char setCipherKey(const char *modName, const char *key);
};
Modified: trunk/src/mgr/filemgr.cpp
===================================================================
--- trunk/src/mgr/filemgr.cpp 2017-11-01 10:35:53 UTC (rev 3500)
+++ trunk/src/mgr/filemgr.cpp 2017-11-01 10:36:00 UTC (rev 3501)
@@ -24,6 +24,7 @@
#include <filemgr.h>
#include <utilstr.h>
+#include <stdlib.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
@@ -574,4 +575,22 @@
}
+SWBuf FileMgr::getHomeDir() {
+
+ // figure out 'home' directory for app data
+ SWBuf homeDir = getenv("HOME");
+ if (!homeDir.length()) {
+ // silly windows
+ homeDir = getenv("APPDATA");
+ }
+ if (homeDir.length()) {
+ if ((homeDir[homeDir.length()-1] != '\\') && (homeDir[homeDir.length()-1] != '/')) {
+ homeDir += "/";
+ }
+ }
+
+ return homeDir;
+}
+
+
SWORD_NAMESPACE_END
Modified: trunk/src/mgr/swmgr.cpp
===================================================================
--- trunk/src/mgr/swmgr.cpp 2017-11-01 10:35:53 UTC (rev 3500)
+++ trunk/src/mgr/swmgr.cpp 2017-11-01 10:36:00 UTC (rev 3501)
@@ -300,24 +300,11 @@
}
-SWBuf SWMgr::getHomeDir() {
-
- // figure out 'home' directory for app data
- SWBuf homeDir = getenv("HOME");
- if (!homeDir.length()) {
- // silly windows
- homeDir = getenv("APPDATA");
- }
- if (homeDir.length()) {
- if ((homeDir[homeDir.length()-1] != '\\') && (homeDir[homeDir.length()-1] != '/')) {
- homeDir += "/";
- }
- }
-
- return homeDir;
-}
-
-
+// TODO: because we're still calling deprecated virtual Load. Removed in 2.0
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
void SWMgr::commonInit(SWConfig *iconfig, SWConfig *isysconfig, bool autoload, SWFilterMgr *filterMgr, bool multiMod) {
init();
@@ -341,6 +328,9 @@
if (autoload)
Load();
}
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
SWMgr::SWMgr(SWFilterMgr *filterMgr, bool multiMod) {
@@ -353,6 +343,10 @@
}
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
SWMgr::SWMgr(const char *iConfigPath, bool autoload, SWFilterMgr *filterMgr, bool multiMod, bool augmentHome) {
init();
@@ -370,19 +364,20 @@
int len = (int)path.length();
if ((len < 1) || ((iConfigPath[len-1] != '\\') && (iConfigPath[len-1] != '/')))
path += "/";
+ SWLog::getSystemLog()->logDebug("Checking at provided path: %s...", path.c_str());
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;
- }
+ else if (FileMgr::existsDir(path.c_str(), "mods.d")) {
+ SWLog::getSystemLog()->logDebug("Found mods.d/");
+ stdstr(&prefixPath, path.c_str());
+ path += "mods.d";
+ stdstr(&configPath, path.c_str());
+ configType = 1;
}
+ else SWLog::getSystemLog()->logDebug("Config not found at provided path.");
config = 0;
sysConfig = 0;
@@ -390,11 +385,14 @@
if (autoload && configPath)
Load();
}
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
SWMgr::~SWMgr() {
- DeleteMods();
+ deleteAllModules();
for (FilterList::iterator it = cleanupFilters.begin(); it != cleanupFilters.end(); it++)
delete (*it);
@@ -430,7 +428,7 @@
*configType = 0;
- SWBuf homeDir = getHomeDir();
+ SWBuf homeDir = FileMgr::getSystemFileMgr()->getHomeDir();
// check for a sysConf passed in to us
SWLog::getSystemLog()->logDebug("Checking for provided SWConfig(\"sword.conf\")...");
@@ -644,7 +642,7 @@
SWLog::getSystemLog()->logDebug("Checking $HOME/Library/Application Support/Sword/...");
- SWBuf pathCheck = getHomeDir();
+ SWBuf pathCheck = FileMgr::getSystemFileMgr()->getHomeDir();
if (pathCheck.length()) {
SWLog::getSystemLog()->logDebug("found (%s).", pathCheck.c_str());
path = pathCheck;
@@ -781,7 +779,7 @@
}
}
- CreateMods(multiMod);
+ createAllModules(multiMod);
stdstr(&prefixPath, savePrefixPath);
delete []savePrefixPath;
@@ -797,13 +795,13 @@
/***********************************************************************
- * SWMgr::Load - loads actual modules
+ * SWMgr::load - loads actual modules
*
* RET: status - 0 = ok; -1 no config found; 1 = no modules installed
*
*/
-signed char SWMgr::Load() {
+signed char SWMgr::load() {
signed char ret = 0;
if (!config) { // If we weren't passed a config object at construction, find a config file
@@ -825,7 +823,7 @@
SectionMap::iterator Sectloop, Sectend;
ConfigEntMap::iterator Entryloop, Entryend;
- DeleteMods();
+ deleteAllModules();
for (Sectloop = config->getSections().lower_bound("Globals"), Sectend = config->getSections().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
@@ -838,14 +836,14 @@
}
else config->load();
- CreateMods(mgrModeMultiMod);
+ createAllModules(mgrModeMultiMod);
for (std::list<SWBuf>::iterator pathIt = augPaths.begin(); pathIt != augPaths.end(); pathIt++) {
augmentModules(pathIt->c_str(), mgrModeMultiMod);
}
if (augmentHome) {
// augment config with ~/.sword/mods.d if it exists ---------------------
- SWBuf homeDir = getHomeDir();
+ SWBuf homeDir = FileMgr::getSystemFileMgr()->getHomeDir();
if (homeDir.length() && configType != 2) { // 2 = user only
SWBuf path = homeDir;
path += ".sword/";
@@ -856,7 +854,7 @@
}
}
// -------------------------------------------------------------------------
- if (!Modules.size()) // config exists, but no modules
+ if (!getModules().size()) // config exists, but no modules
ret = 1;
}
@@ -1100,8 +1098,11 @@
}
-void SWMgr::AddGlobalOptions(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end) {
+void SWMgr::addGlobalOptionFilters(SWModule *module, ConfigEntMap §ion) {
+ ConfigEntMap::iterator start = section.lower_bound("GlobalOptionFilter");
+ ConfigEntMap::iterator end = section.upper_bound("GlobalOptionFilter");
+
for (;start != end; ++start) {
OptionFilterMap::iterator it;
SWBuf filterName = start->second;
@@ -1149,8 +1150,7 @@
}
-char SWMgr::filterText(const char *filterName, SWBuf &text, const SWKey *key, const SWModule *module)
-{
+char SWMgr::filterText(const char *filterName, SWBuf &text, const SWKey *key, const SWModule *module) {
char retVal = -1;
// why didn't we use find here?
for (OptionFilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
@@ -1173,8 +1173,11 @@
}
-void SWMgr::AddLocalOptions(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end)
-{
+void SWMgr::addLocalOptionFilters(SWModule *module, ConfigEntMap §ion) {
+
+ ConfigEntMap::iterator start = section.lower_bound("LocalOptionFilter");
+ ConfigEntMap::iterator end = section.upper_bound("LocalOptionFilter");
+
for (;start != end; start++) {
OptionFilterMap::iterator it;
it = optionFilters.find((*start).second);
@@ -1189,8 +1192,11 @@
// manually specified StripFilters for special cases, like Papyri marks and such
-void SWMgr::AddStripFilters(SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end)
-{
+void SWMgr::addLocalStripFilters(SWModule *module, ConfigEntMap §ion) {
+
+ ConfigEntMap::iterator start = section.lower_bound("LocalStripFilter");
+ ConfigEntMap::iterator end = section.upper_bound("LocalStripFilter");
+
for (;start != end; start++) {
OptionFilterMap::iterator it;
it = optionFilters.find((*start).second);
@@ -1201,7 +1207,7 @@
}
-void SWMgr::AddRawFilters(SWModule *module, ConfigEntMap §ion) {
+void SWMgr::addRawFilters(SWModule *module, ConfigEntMap §ion) {
SWBuf sourceformat, cipherKey;
ConfigEntMap::iterator entry;
@@ -1218,13 +1224,13 @@
}
-void SWMgr::AddEncodingFilters(SWModule *module, ConfigEntMap §ion) {
+void SWMgr::addEncodingFilters(SWModule *module, ConfigEntMap §ion) {
if (filterMgr)
filterMgr->AddEncodingFilters(module, section);
}
-void SWMgr::AddRenderFilters(SWModule *module, ConfigEntMap §ion) {
+void SWMgr::addRenderFilters(SWModule *module, ConfigEntMap §ion) {
SWBuf sourceformat;
ConfigEntMap::iterator entry;
@@ -1250,7 +1256,7 @@
}
-void SWMgr::AddStripFilters(SWModule *module, ConfigEntMap §ion)
+void SWMgr::addStripFilters(SWModule *module, ConfigEntMap §ion)
{
SWBuf sourceformat;
ConfigEntMap::iterator entry;
@@ -1283,81 +1289,6 @@
}
-void SWMgr::CreateMods(bool multiMod) {
- SectionMap::iterator it;
- ConfigEntMap::iterator start;
- ConfigEntMap::iterator end;
- ConfigEntMap::iterator entry;
- SWModule *newmod;
- SWBuf driver, misc1;
- for (it = config->getSections().begin(); it != config->getSections().end(); it++) {
- ConfigEntMap §ion = (*it).second;
- newmod = 0;
-
- driver = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)"";
- if (driver.length()) {
- newmod = createModule((*it).first, driver, section);
- if (newmod) {
- // Filters to add for this module and globally announce as an option to the user
- // e.g. translit, strongs, redletterwords, etc, so users can turn these on and off globally
- start = section.lower_bound("GlobalOptionFilter");
- end = section.upper_bound("GlobalOptionFilter");
- AddGlobalOptions(newmod, section, start, end);
-
- // Only add the option to the module, don't announce it's availability
- // These are useful for like: filters that parse special entryAttribs in a text
- // or whatever you might want to happen on entry lookup
- start = section.lower_bound("LocalOptionFilter");
- end = section.upper_bound("LocalOptionFilter");
- AddLocalOptions(newmod, section, start, end);
-
- //STRIP FILTERS
-
- // add all basic ones for for the modtype
- AddStripFilters(newmod, section);
-
- // Any special processing for this module when searching:
- // e.g. for papyri, removed all [](). notation
- start = section.lower_bound("LocalStripFilter");
- end = section.upper_bound("LocalStripFilter");
- AddStripFilters(newmod, section, start, end);
-
- AddRawFilters(newmod, section);
- AddRenderFilters(newmod, section);
- AddEncodingFilters(newmod, section);
-
- SWModule *oldmod = Modules[newmod->getName()];
- if (oldmod) {
- delete oldmod;
- }
-
- Modules[newmod->getName()] = newmod;
- }
- }
- }
-}
-
-
-void SWMgr::DeleteMods() {
-
- ModMap::iterator it;
-
- for (it = Modules.begin(); it != Modules.end(); it++)
- delete (*it).second;
-
- Modules.clear();
-}
-
-
-void SWMgr::deleteModule(const char *modName) {
- ModMap::iterator it = Modules.find(modName);
- if (it != Modules.end()) {
- delete (*it).second;
- Modules.erase(it);
- }
-}
-
-
void SWMgr::InstallScan(const char *dirname)
{
DIR *dir;
@@ -1391,7 +1322,7 @@
else {
if (!conffd) {
conffd = FileMgr::getSystemFileMgr()->open(config->getFileName().c_str(), FileMgr::WRONLY|FileMgr::APPEND);
- if (conffd > 0)
+ if (conffd && conffd->getFd() >= 0)
conffd->seek(0L, SEEK_END);
else {
FileMgr::getSystemFileMgr()->close(conffd);
@@ -1484,7 +1415,92 @@
return options;
}
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+// TODO: use deprecated public 'Modules' property for now until we remove deprecation
+// and store in private property
+// also old deprecated virtuals so client overrides still are called
+
+void SWMgr::createAllModules(bool multiMod) {
+ SectionMap::iterator it;
+ ConfigEntMap::iterator entry;
+ SWModule *newmod;
+ SWBuf driver, misc1;
+ for (it = config->getSections().begin(); it != config->getSections().end(); it++) {
+ ConfigEntMap §ion = (*it).second;
+ newmod = 0;
+
+ driver = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)"";
+ if (driver.length()) {
+ newmod = createModule((*it).first, driver, section);
+ if (newmod) {
+ // Filters to add for this module and globally announce as an option to the user
+ // e.g. translit, strongs, redletterwords, etc, so users can turn these on and off globally
+ // TODO: addGlobalOptionFilters(newmod, section);
+ AddGlobalOptions(newmod, section, section.lower_bound("GlobalOptionFilter"), section.upper_bound("GlobalOptionFilter"));
+
+ // Only add the option to the module, don't announce it's availability
+ // These are useful for like: filters that parse special entryAttribs in a text
+ // or whatever you might want to happen on entry lookup
+ // TODO: addLocalOptionFilters(newmod, section);
+ AddLocalOptions(newmod, section, section.lower_bound("LocalOptionFilter"), section.upper_bound("LocalOptionFilter"));
+
+ //STRIP FILTERS
+
+ // add all basic strip filters for for the modtype
+ // TODO: addStripFilters(newmod, section);
+ AddStripFilters(newmod, section);
+
+ // Any module-specific processing specified in module config
+ // as entries LocalStripFilter=
+ // e.g. for papyri, removed all [](). notation
+ // TODO: addLocalStripFilters(newmod, section);
+ AddStripFilters(newmod, section, section.lower_bound("LocalStripFilter"), section.upper_bound("LocalStripFilter"));
+
+ // TODO: addRawFilters(newmod, section);
+ AddRawFilters(newmod, section);
+ // TODO: addRenderFilters(newmod, section);
+ AddRenderFilters(newmod, section);
+ // TODO: addEncodingFilters(newmod, section);
+ AddEncodingFilters(newmod, section);
+
+ // place our module in module container, removing first if one
+ // already exists by our same name
+ SWModule *oldmod = getModule(newmod->getName());
+ if (oldmod) {
+ delete oldmod;
+ }
+
+ Modules[newmod->getName()] = newmod;
+ }
+ }
+ }
+}
+
+
+void SWMgr::deleteAllModules() {
+
+ ModMap::iterator it;
+
+ for (it = getModules().begin(); it != getModules().end(); ++it) {
+ delete (*it).second;
+ }
+
+ Modules.clear();
+}
+
+
+void SWMgr::deleteModule(const char *modName) {
+ ModMap::iterator it = Modules.find(modName);
+ if (it != Modules.end()) {
+ delete (*it).second;
+ Modules.erase(it);
+ }
+}
+
signed char SWMgr::setCipherKey(const char *modName, const char *key) {
FilterMap::iterator it;
ModMap::iterator it2;
@@ -1510,5 +1526,13 @@
}
+ModMap &SWMgr::getModules() { return Modules; }
+
+SWBuf SWMgr::getHomeDir() { return FileMgr::getSystemFileMgr()->getHomeDir(); }
+
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+
SWORD_NAMESPACE_END
More information about the sword-cvs
mailing list