The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SWMgr Class Reference

#include <swmgr.h>

+ Collaboration diagram for SWMgr:

Public Member Functions

virtual void augmentModules (const char *path, bool multiMod=false)
 
void deleteModule (const char *)
 
virtual char filterText (const char *filterName, SWBuf &text, const SWKey *key=0, const SWModule *module=0)
 
virtual const char * getGlobalOption (const char *option)
 
virtual StringList getGlobalOptions ()
 
virtual const char * getGlobalOptionTip (const char *option)
 
virtual StringList getGlobalOptionValues (const char *option)
 
SWModulegetModule (const char *modName)
 
const SWModulegetModule (const char *modName) const
 
ModMapgetModules ()
 
const ModMapgetModules () const
 
ModMapgetUtilModules ()
 
const ModMapgetUtilModules () const
 
virtual void InstallScan (const char *dir)
 
virtual SWDEPRECATED signed char Load ()
 
virtual signed char load ()
 
virtual signed char setCipherKey (const char *modName, const char *key)
 
virtual void setGlobalOption (const char *option, const char *value)
 
 SWMgr (SWConfig *iconfig=0, SWConfig *isysconfig=0, bool autoload=true, SWFilterMgr *filterMgr=0, bool multiMod=false)
 
 SWMgr (SWFilterMgr *filterMgr, bool multiMod=false)
 
 SWMgr (const char *iConfigPath, bool autoload=true, SWFilterMgr *filterMgr=0, bool multiMod=false, bool augmentHome=true)
 
virtual ~SWMgr ()
 

Static Public Member Functions

static void findConfig (char *configType, char **prefixPath, char **configPath, StringList *augPaths=0, SWConfig **providedSysConf=0)
 
static SWDEPRECATED SWBuf getHomeDir ()
 

Public Attributes

SWConfigconfig
 
char * configPath
 
ModMap Modules
 
char * prefixPath
 
SWConfigsysConfig
 

Static Public Attributes

static const char * globalConfPath = "/etc/sword.conf:/usr/local/etc/sword.conf"
 
static bool isICU = false
 
static const char * MODTYPE_BIBLES = "Biblical Texts"
 
static const char * MODTYPE_COMMENTARIES = "Commentaries"
 
static const char * MODTYPE_DAILYDEVOS = "Daily Devotional"
 
static const char * MODTYPE_GENBOOKS = "Generic Books"
 
static const char * MODTYPE_LEXDICTS = "Lexicons / Dictionaries"
 

Protected Member Functions

virtual SWDEPRECATED void AddEncodingFilters (SWModule *module, ConfigEntMap &section)
 
virtual void addEncodingFilters (SWModule *module, ConfigEntMap &section)
 
virtual void addGlobalOptionFilters (SWModule *module, ConfigEntMap &section)
 
virtual SWDEPRECATED void AddGlobalOptions (SWModule *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end)
 
virtual void addLocalOptionFilters (SWModule *module, ConfigEntMap &section)
 
virtual SWDEPRECATED void AddLocalOptions (SWModule *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end)
 
virtual void addLocalStripFilters (SWModule *module, ConfigEntMap &section)
 
virtual char addModToConfig (FileDesc *conffd, const char *fname)
 
virtual SWDEPRECATED void AddRawFilters (SWModule *module, ConfigEntMap &section)
 
virtual void addRawFilters (SWModule *module, ConfigEntMap &section)
 
virtual SWDEPRECATED void AddRenderFilters (SWModule *module, ConfigEntMap &section)
 
virtual void addRenderFilters (SWModule *module, ConfigEntMap &section)
 
virtual SWDEPRECATED void AddStripFilters (SWModule *module, ConfigEntMap &section)
 
virtual void addStripFilters (SWModule *module, ConfigEntMap &section)
 
virtual SWDEPRECATED void AddStripFilters (SWModule *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end)
 
virtual void createAllModules (bool multiMod=false)
 
SWDEPRECATED void CreateMods (bool multiMod=false)
 
virtual SWModulecreateModule (const char *name, const char *driver, ConfigEntMap &section)
 
virtual void deleteAllModules ()
 
SWDEPRECATED void DeleteMods ()
 
virtual void init ()
 
virtual void loadConfigDir (const char *ipath)
 

Protected Attributes

StringList augPaths
 
FilterMap cipherFilters
 
FilterList cleanupFilters
 
char configType
 
FilterMap extraFilters
 
SWFilterMgrfilterMgr
 
SWFiltergbfplain
 
SWConfighomeConfig
 
SWConfigmyconfig
 
SWConfigmysysconfig
 
OptionFilterMap optionFilters
 
StringList options
 
SWFilterosisplain
 
SWFilterteiplain
 
SWFilterthmlplain
 
SWOptionFiltertransliterator
 

Private Member Functions

void commonInit (SWConfig *iconfig, SWConfig *isysconfig, bool autoload, SWFilterMgr *filterMgr, bool multiMod=false)
 

Private Attributes

bool augmentHome
 
bool mgrModeMultiMod
 
ModMap utilModules
 

Detailed Description

SWMgr exposes an installed module set

SWMgr exposes an installed module set and can be asked to configure the desired markup and options which modules will produce.

Version
Id:
swmgr.h 3820 2020-10-24 20:27:30Z scribe

Definition at line 93 of file swmgr.h.

Constructor & Destructor Documentation

SWMgr::SWMgr ( SWConfig iconfig = 0,
SWConfig isysconfig = 0,
bool  autoload = true,
SWFilterMgr filterMgr = 0,
bool  multiMod = false 
)

Constructs an instance of SWMgr

Parameters
iconfigmanually supply a configuration. If not supplied, SWMgr will look on the system using a complex hierarchical search. See README for detailed specifics.
isysconfigmanually supply a an isysconfig (e.g. /etc/sword.conf)
autoloadwhether 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 completed the contruction and setup of your SWMgr subclass.
filterMgran SWFilterMgr subclass to use to manager filters on modules SWMgr TAKES OWNERSHIP FOR DELETING THIS OBJECT For example, this will create an SWMgr and cause its modules to produce HTMLHREF formatted output when asked for renderable text:

SWMgr *myMgr = new SWMgr(0, 0, true, new MarkupFilterMgr(FMT_HTMLHREF));

Definition at line 368 of file swmgr.cpp.

368  {
369  commonInit(iconfig, isysconfig, autoload, filterMgr, multiMod);
370 }
void commonInit(SWConfig *iconfig, SWConfig *isysconfig, bool autoload, SWFilterMgr *filterMgr, bool multiMod=false)
Definition: swmgr.cpp:335
SWMgr::SWMgr ( SWFilterMgr filterMgr,
bool  multiMod = false 
)

Definition at line 363 of file swmgr.cpp.

363  {
364  commonInit(0, 0, true, filterMgr, multiMod);
365 }
void commonInit(SWConfig *iconfig, SWConfig *isysconfig, bool autoload, SWFilterMgr *filterMgr, bool multiMod=false)
Definition: swmgr.cpp:335
SWMgr::SWMgr ( const char *  iConfigPath,
bool  autoload = true,
SWFilterMgr filterMgr = 0,
bool  multiMod = false,
bool  augmentHome = true 
)
Parameters
iConfigPathprovide a custom path to use for module set location, instead of searching the system for it.

Definition at line 377 of file swmgr.cpp.

377  {
378 
379  init();
380 
381  mgrModeMultiMod = multiMod;
382  SWBuf path;
383 
384  this->filterMgr = filterMgr;
385  if (filterMgr)
386  filterMgr->setParentMgr(this);
387 
388  this->augmentHome = augmentHome;
389 
390  path = iConfigPath;
391  int len = (int)path.length();
392  if ((len < 1) || ((iConfigPath[len-1] != '\\') && (iConfigPath[len-1] != '/')))
393  path += "/";
394  SWLOGTI("Checking at provided path: %s...", path.c_str());
395  if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
396  stdstr(&prefixPath, path.c_str());
397  path += "mods.conf";
398  stdstr(&configPath, path.c_str());
399  }
400  else if (FileMgr::existsDir(path.c_str(), "mods.d")) {
401  SWLOGTI("Found mods.d/");
402  stdstr(&prefixPath, path.c_str());
403  path += "mods.d";
404  stdstr(&configPath, path.c_str());
405  configType = 1;
406  }
407  else {
408  SWLOGTI("Config not found at provided path.");
409  }
410 
411  config = 0;
412  sysConfig = 0;
413 
414  if (autoload && configPath)
415  Load();
416 }
static signed char existsFile(const char *ipath, const char *ifileName=0)
Definition: filemgr.cpp:337
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
static signed char existsDir(const char *ipath, const char *idirName=0)
Definition: filemgr.cpp:357
char configType
Definition: swmgr.h:113
char * prefixPath
Definition: swmgr.h:312
virtual SWDEPRECATED signed char Load()
Definition: swmgr.h:426
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
SWConfig * config
Definition: swmgr.h:302
const char * c_str() const
Definition: swbuf.h:158
bool mgrModeMultiMod
Definition: swmgr.h:96
virtual void init()
Definition: swmgr.cpp:163
SWConfig * sysConfig
Definition: swmgr.h:308
virtual void setParentMgr(SWMgr *parentMgr)
Definition: swfiltermgr.cpp:38
#define SWLOGTI(...)
Definition: defs.h:194
bool augmentHome
Definition: swmgr.h:97
char * configPath
Definition: swmgr.h:316
SWFilterMgr * filterMgr
Definition: swmgr.h:101
SWMgr::~SWMgr ( )
virtual

The destructor of SWMgr. This function cleans up the modules and deletes the created object. Destroying the SWMgr causes all retrieved SWModule object to be invalid, so be sure to destroy only when retrieved objects are no longer needed.

Definition at line 422 of file swmgr.cpp.

422  {
423 
425 
426  for (FilterList::iterator it = cleanupFilters.begin(); it != cleanupFilters.end(); it++)
427  delete (*it);
428 
429  if (homeConfig)
430  delete homeConfig;
431 
432  if (mysysconfig)
433  delete mysysconfig;
434 
435  if (myconfig)
436  delete myconfig;
437 
438  if (prefixPath)
439  delete [] prefixPath;
440 
441  if (configPath)
442  delete [] configPath;
443 
444  if (filterMgr)
445  delete filterMgr;
446 }
virtual void deleteAllModules()
Definition: swmgr.cpp:1519
char * prefixPath
Definition: swmgr.h:312
FilterList cleanupFilters
Definition: swmgr.h:121
SWConfig * myconfig
Definition: swmgr.h:102
SWConfig * mysysconfig
Definition: swmgr.h:103
SWConfig * homeConfig
Definition: swmgr.h:104
char * configPath
Definition: swmgr.h:316
SWFilterMgr * filterMgr
Definition: swmgr.h:101

Member Function Documentation

virtual SWDEPRECATED void SWMgr::AddEncodingFilters ( SWModule module,
ConfigEntMap section 
)
inlineprotectedvirtual
Deprecated:
Use addEncodingFilters instead

Definition at line 196 of file swmgr.h.

196 { addEncodingFilters(module, section); }
virtual void addEncodingFilters(SWModule *module, ConfigEntMap &section)
Definition: swmgr.cpp:1266
void SWMgr::addEncodingFilters ( SWModule module,
ConfigEntMap section 
)
protectedvirtual

Adds appropriate encoding filters to a module. Override to add any special encoding filters. See the module.conf Encoding= entry.

Parameters
modulemodule to which to add encoding filters
sectionconfiguration information for module

Definition at line 1266 of file swmgr.cpp.

1266  {
1267  if (filterMgr)
1268  filterMgr->addEncodingFilters(module, section);
1269 }
virtual void addEncodingFilters(SWModule *module, ConfigEntMap &section)
Definition: swfiltermgr.cpp:62
SWFilterMgr * filterMgr
Definition: swmgr.h:101
void SWMgr::addGlobalOptionFilters ( SWModule module,
ConfigEntMap section 
)
protectedvirtual

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.

Parameters
modulemodule to which to add encoding filters
sectionconfiguration information for module

Definition at line 1140 of file swmgr.cpp.

1140  {
1141 
1142  ConfigEntMap::iterator start = section.lower_bound("GlobalOptionFilter");
1143  ConfigEntMap::iterator end = section.upper_bound("GlobalOptionFilter");
1144 
1145  for (;start != end; ++start) {
1146  OptionFilterMap::iterator it;
1147  SWBuf filterName = start->second;
1148 
1149 
1150  // special cases for filters with parameters
1151 
1152  if (filterName.startsWith("OSISReferenceLinks")) {
1153  SWBuf params = filterName;
1154  filterName = params.stripPrefix('|', true);
1155  SWBuf optionName = params.stripPrefix('|', true);
1156  SWBuf optionTip = params.stripPrefix('|', true);
1157  SWBuf optionType = params.stripPrefix('|', true);
1158  SWBuf optionSubType = params.stripPrefix('|', true);
1159  SWBuf optionDefaultValue = params.stripPrefix('|', true);
1160  // we'll key off of type and subtype.
1161  filterName = filterName + "." + optionType + "." + optionSubType;
1162 
1163  it = optionFilters.find(filterName);
1164  if (it == optionFilters.end()) {
1165  SWOptionFilter *tmpFilter = new OSISReferenceLinks(optionName, optionTip, optionType, optionSubType, optionDefaultValue);
1166  optionFilters.insert(OptionFilterMap::value_type(filterName, tmpFilter));
1167  cleanupFilters.push_back(tmpFilter);
1168  }
1169  }
1170 
1171 
1172  it = optionFilters.find(filterName);
1173  if (it != optionFilters.end()) {
1174  module->addOptionFilter((*it).second); // add filter to module and option as a valid option
1175  StringList::iterator loop;
1176  for (loop = options.begin(); loop != options.end(); loop++) {
1177  if (!strcmp((*loop).c_str(), (*it).second->getOptionName()))
1178  break;
1179  }
1180  if (loop == options.end()) // if we have not yet included the option
1181  options.push_back((*it).second->getOptionName());
1182  }
1183  }
1184  if (filterMgr)
1185  filterMgr->addGlobalOptions(module, section, start, end);
1186 #ifdef _ICU_
1188 #endif
1189 }
SWOptionFilter * transliterator
Definition: swmgr.h:120
Definition: swbuf.h:47
bool startsWith(const SWBuf &prefix) const
Definition: swbuf.h:486
OptionFilterMap optionFilters
Definition: swmgr.h:114
virtual void addGlobalOptions(SWModule *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end)
Definition: swfiltermgr.cpp:48
virtual SWModule & addOptionFilter(SWOptionFilter *newFilter)
Definition: swmodule.h:727
FilterList cleanupFilters
Definition: swmgr.h:121
const char * stripPrefix(char separator, bool endOfStringAsSeparator=false)
Definition: swbuf.h:457
StringList options
Definition: swmgr.h:123
SWFilterMgr * filterMgr
Definition: swmgr.h:101
virtual SWDEPRECATED void SWMgr::AddGlobalOptions ( SWModule module,
ConfigEntMap section,
ConfigEntMap::iterator  start,
ConfigEntMap::iterator  end 
)
inlineprotectedvirtual
Deprecated:
Use addGlobalOptionFilters instead.

Definition at line 160 of file swmgr.h.

160 { addGlobalOptionFilters(module, section); }
virtual void addGlobalOptionFilters(SWModule *module, ConfigEntMap &section)
Definition: swmgr.cpp:1140
void SWMgr::addLocalOptionFilters ( SWModule module,
ConfigEntMap section 
)
protectedvirtual

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.

Parameters
modulemodule to which to add encoding filters
sectionconfiguration information for module

Definition at line 1215 of file swmgr.cpp.

1215  {
1216 
1217  ConfigEntMap::iterator start = section.lower_bound("LocalOptionFilter");
1218  ConfigEntMap::iterator end = section.upper_bound("LocalOptionFilter");
1219 
1220  for (;start != end; start++) {
1221  OptionFilterMap::iterator it;
1222  it = optionFilters.find((*start).second);
1223  if (it != optionFilters.end()) {
1224  module->addOptionFilter((*it).second); // add filter to module
1225  }
1226  }
1227 
1228  if (filterMgr)
1229  filterMgr->addLocalOptions(module, section, start, end);
1230 }
OptionFilterMap optionFilters
Definition: swmgr.h:114
virtual SWModule & addOptionFilter(SWOptionFilter *newFilter)
Definition: swmodule.h:727
virtual void addLocalOptions(SWModule *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end)
Definition: swfiltermgr.cpp:52
SWFilterMgr * filterMgr
Definition: swmgr.h:101
virtual SWDEPRECATED void SWMgr::AddLocalOptions ( SWModule module,
ConfigEntMap section,
ConfigEntMap::iterator  start,
ConfigEntMap::iterator  end 
)
inlineprotectedvirtual
Deprecated:
Use addLocalOptionFilters instead.

Definition at line 181 of file swmgr.h.

181 { addLocalOptionFilters(module, section); }
virtual void addLocalOptionFilters(SWModule *module, ConfigEntMap &section)
Definition: swmgr.cpp:1215
void SWMgr::addLocalStripFilters ( SWModule module,
ConfigEntMap section 
)
protectedvirtual

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

Parameters
modulemodule to which to add local strip filters
sectionconfiguration information for module

Definition at line 1234 of file swmgr.cpp.

1234  {
1235 
1236  ConfigEntMap::iterator start = section.lower_bound("LocalStripFilter");
1237  ConfigEntMap::iterator end = section.upper_bound("LocalStripFilter");
1238 
1239  for (;start != end; start++) {
1240  OptionFilterMap::iterator it;
1241  it = optionFilters.find((*start).second);
1242  if (it != optionFilters.end()) {
1243  module->addStripFilter((*it).second); // add filter to module
1244  }
1245  }
1246 }
OptionFilterMap optionFilters
Definition: swmgr.h:114
virtual SWModule & addStripFilter(SWFilter *newFilter)
Definition: swmodule.h:681
char SWMgr::addModToConfig ( FileDesc conffd,
const char *  fname 
)
protectedvirtual

Definition at line 1374 of file swmgr.cpp.

1375 {
1376  FileDesc *modfd;
1377  char ch;
1378 
1379  SWLOGTI("Found new module [%s]. Installing...", fname);
1380  modfd = FileMgr::getSystemFileMgr()->open(fname, FileMgr::RDONLY);
1381  ch = '\n';
1382  conffd->write(&ch, 1);
1383  while (modfd->read(&ch, 1) == 1)
1384  conffd->write(&ch, 1);
1385  ch = '\n';
1386  conffd->write(&ch, 1);
1387  FileMgr::getSystemFileMgr()->close(modfd);
1388  return 0;
1389 }
FileDesc * open(const char *path, int mode, bool tryDowngrade)
Definition: filemgr.cpp:175
static unsigned int RDONLY
Definition: filemgr.h:75
long write(const void *buf, long count)
Definition: filemgr.cpp:153
void close(FileDesc *file)
Definition: filemgr.cpp:196
#define SWLOGTI(...)
Definition: defs.h:194
long read(void *buf, long count)
Definition: filemgr.cpp:148
static FileMgr * getSystemFileMgr()
Definition: filemgr.cpp:101
virtual SWDEPRECATED void SWMgr::AddRawFilters ( SWModule module,
ConfigEntMap section 
)
inlineprotectedvirtual
Deprecated:
Use addRawFilters instead.

Definition at line 251 of file swmgr.h.

251 { addRawFilters(module, section); }
virtual void addRawFilters(SWModule *module, ConfigEntMap &section)
Definition: swmgr.cpp:1249
void SWMgr::addRawFilters ( SWModule module,
ConfigEntMap section 
)
protectedvirtual

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.

Parameters
modulemodule to which to add raw filters
sectionconfiguration information for module

Definition at line 1249 of file swmgr.cpp.

1249  {
1250  SWBuf sourceformat, cipherKey;
1251  ConfigEntMap::iterator entry;
1252 
1253  cipherKey = ((entry = section.find("CipherKey")) != section.end()) ? (*entry).second : (SWBuf)"";
1254  if (cipherKey.length()) {
1255  SWFilter *cipherFilter = new CipherFilter(cipherKey.c_str());
1256  cipherFilters.insert(FilterMap::value_type(module->getName(), cipherFilter));
1257  cleanupFilters.push_back(cipherFilter);
1258  module->addRawFilter(cipherFilter);
1259  }
1260 
1261  if (filterMgr)
1262  filterMgr->addRawFilters(module, section);
1263 }
const char * getName() const
Definition: swmodule.cpp:204
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
virtual void addRawFilters(SWModule *module, ConfigEntMap &section)
Definition: swfiltermgr.cpp:92
const char * c_str() const
Definition: swbuf.h:158
FilterMap cipherFilters
Definition: swmgr.h:115
FilterList cleanupFilters
Definition: swmgr.h:121
virtual SWModule & addRawFilter(SWFilter *newFilter)
Definition: swmodule.h:694
SWFilterMgr * filterMgr
Definition: swmgr.h:101
virtual SWDEPRECATED void SWMgr::AddRenderFilters ( SWModule module,
ConfigEntMap section 
)
inlineprotectedvirtual
Deprecated:
Use addRenderFilters instead.

Definition at line 209 of file swmgr.h.

209 { addRenderFilters(module, section); }
virtual void addRenderFilters(SWModule *module, ConfigEntMap &section)
Definition: swmgr.cpp:1272
void SWMgr::addRenderFilters ( SWModule module,
ConfigEntMap section 
)
protectedvirtual

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.

Parameters
modulemodule to which to add render filters
sectionconfiguration information for module

Definition at line 1272 of file swmgr.cpp.

1272  {
1273  SWBuf sourceformat;
1274  ConfigEntMap::iterator entry;
1275 
1276  sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (SWBuf)"";
1277 
1278  // Temporary: To support old module types
1279  // TODO: Remove at 1.6.0 release?
1280  if (!sourceformat.length()) {
1281  sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)"";
1282  if (!stricmp(sourceformat.c_str(), "RawGBF"))
1283  sourceformat = "GBF";
1284  else sourceformat = "";
1285  }
1286 
1287 // process module - eg. follows
1288 // if (!stricmp(sourceformat.c_str(), "GBF")) {
1289 // module->AddRenderFilter(gbftortf);
1290 // }
1291 
1292  if (filterMgr)
1293  filterMgr->addRenderFilters(module, section);
1294 
1295 }
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
int stricmp(const char *s1, const char *s2)
Definition: utilstr.cpp:194
const char * c_str() const
Definition: swbuf.h:158
virtual void addRenderFilters(SWModule *module, ConfigEntMap &section)
Definition: swfiltermgr.cpp:72
SWFilterMgr * filterMgr
Definition: swmgr.h:101
virtual SWDEPRECATED void SWMgr::AddStripFilters ( SWModule module,
ConfigEntMap section 
)
inlineprotectedvirtual
Deprecated:
Use addStripFilters instead.

Definition at line 224 of file swmgr.h.

224 { addStripFilters(module, section); }
virtual void addStripFilters(SWModule *module, ConfigEntMap &section)
Definition: swmgr.cpp:1298
void SWMgr::addStripFilters ( SWModule module,
ConfigEntMap section 
)
protectedvirtual

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.

Parameters
modulemodule to which to add strip filters
sectionconfiguration information for module

Definition at line 1298 of file swmgr.cpp.

1299 {
1300  SWBuf sourceformat;
1301  ConfigEntMap::iterator entry;
1302 
1303  sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (SWBuf)"";
1304  // Temporary: To support old module types
1305  if (!sourceformat.length()) {
1306  sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)"";
1307  if (!stricmp(sourceformat.c_str(), "RawGBF"))
1308  sourceformat = "GBF";
1309  else sourceformat = "";
1310  }
1311 
1312  if (!stricmp(sourceformat.c_str(), "GBF")) {
1313  module->addStripFilter(gbfplain);
1314  }
1315  else if (!stricmp(sourceformat.c_str(), "ThML")) {
1316  module->addStripFilter(thmlplain);
1317  }
1318  else if (!stricmp(sourceformat.c_str(), "OSIS")) {
1319  module->addStripFilter(osisplain);
1320  }
1321  else if (!stricmp(sourceformat.c_str(), "TEI")) {
1322  module->addStripFilter(teiplain);
1323  }
1324 
1325  if (filterMgr)
1326  filterMgr->addStripFilters(module, section);
1327 
1328 }
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
SWFilter * gbfplain
Definition: swmgr.h:116
int stricmp(const char *s1, const char *s2)
Definition: utilstr.cpp:194
virtual void addStripFilters(SWModule *module, ConfigEntMap &section)
Definition: swfiltermgr.cpp:82
const char * c_str() const
Definition: swbuf.h:158
virtual SWModule & addStripFilter(SWFilter *newFilter)
Definition: swmodule.h:681
SWFilter * osisplain
Definition: swmgr.h:118
SWFilter * teiplain
Definition: swmgr.h:119
SWFilter * thmlplain
Definition: swmgr.h:117
SWFilterMgr * filterMgr
Definition: swmgr.h:101
virtual SWDEPRECATED void SWMgr::AddStripFilters ( SWModule module,
ConfigEntMap section,
ConfigEntMap::iterator  start,
ConfigEntMap::iterator  end 
)
inlineprotectedvirtual
Deprecated:
Use addLocalStripFilters instead.

Definition at line 238 of file swmgr.h.

238 { addLocalStripFilters(module, section); }
virtual void addLocalStripFilters(SWModule *module, ConfigEntMap &section)
Definition: swmgr.cpp:1234
void SWMgr::augmentModules ( const char *  path,
bool  multiMod = false 
)
virtual

Adds books from a new path to the library

Parameters
paththe path in which to search for books
multiModwhether or not to keep multiple copies of the same book if found in different paths default - false, uses last found version of the book

Definition at line 776 of file swmgr.cpp.

776  {
777  SWBuf path = ipath;
778  if (!path.endsWith("/") && !path.endsWith("\\")) path += "/";
779  if (FileMgr::existsDir(path.c_str(), "mods.d")) {
780  char *savePrefixPath = 0;
781  char *saveConfigPath = 0;
782  SWConfig *saveConfig = 0;
783  stdstr(&savePrefixPath, prefixPath);
784  stdstr(&prefixPath, path.c_str());
785  path += "mods.d";
786  stdstr(&saveConfigPath, configPath);
787  stdstr(&configPath, path.c_str());
788  saveConfig = config;
789  config = myconfig = 0;
791 
792  if (multiMod) {
793  // fix config's Section names to rename modules which are available more than once
794  // find out which sections are in both config objects
795  // inserting all configs first is not good because that overwrites old keys and new modules would share the same config
796  for (SectionMap::iterator it = config->getSections().begin(); it != config->getSections().end();) {
797  if (saveConfig->getSections().find((*it).first) != saveConfig->getSections().end()) { //if the new section is already present rename it
798  ConfigEntMap entMap((*it).second);
799 
800  SWBuf name;
801  int i = 1;
802  do { //module name already used?
803  name.setFormatted("%s_%d", (*it).first.c_str(), i);
804  i++;
805  } while (config->getSections().find(name) != config->getSections().end());
806 
807  config->getSections().insert(SectionMap::value_type(name, entMap) );
808  SectionMap::iterator toErase = it++;
809  config->getSections().erase(toErase);
810  }
811  else ++it;
812  }
813  }
814 
815  createAllModules(multiMod);
816 
817  stdstr(&prefixPath, savePrefixPath);
818  delete []savePrefixPath;
819  stdstr(&configPath, saveConfigPath);
820  delete []saveConfigPath;
821 
822  (*saveConfig) += *config;
823 
825  config = myconfig = saveConfig;
826  }
827 }
Definition: swbuf.h:47
virtual SectionMap & getSections()
Definition: swconfig.cpp:186
static signed char existsDir(const char *ipath, const char *idirName=0)
Definition: filemgr.cpp:357
char * prefixPath
Definition: swmgr.h:312
bool endsWith(const SWBuf &postfix) const
Definition: swbuf.h:501
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
SWConfig * config
Definition: swmgr.h:302
const char * c_str() const
Definition: swbuf.h:158
SWConfig * myconfig
Definition: swmgr.h:102
SWORD_NAMESPACE_START typedef multimapwithdefault< SWBuf, SWBuf, std::less< SWBuf > > ConfigEntMap
Definition: swconfig.h:35
virtual void loadConfigDir(const char *ipath)
Definition: swmgr.cpp:747
virtual void createAllModules(bool multiMod=false)
Definition: swmgr.cpp:1456
SWConfig * homeConfig
Definition: swmgr.h:104
SWBuf & setFormatted(const char *format,...)
Definition: swbuf.cpp:50
char * configPath
Definition: swmgr.h:316
void SWMgr::commonInit ( SWConfig iconfig,
SWConfig isysconfig,
bool  autoload,
SWFilterMgr filterMgr,
bool  multiMod = false 
)
private

Definition at line 335 of file swmgr.cpp.

335  {
336 
337  init();
338 
339  mgrModeMultiMod = multiMod;
340  this->filterMgr = filterMgr;
341  if (filterMgr)
342  filterMgr->setParentMgr(this);
343 
344  if (iconfig) {
345  config = iconfig;
346  myconfig = 0;
347  }
348  else config = 0;
349  if (isysconfig) {
350  sysConfig = isysconfig;
351  mysysconfig = 0;
352  }
353  else sysConfig = 0;
354 
355  if (autoload)
356  Load();
357 }
virtual SWDEPRECATED signed char Load()
Definition: swmgr.h:426
SWConfig * config
Definition: swmgr.h:302
bool mgrModeMultiMod
Definition: swmgr.h:96
virtual void init()
Definition: swmgr.cpp:163
SWConfig * myconfig
Definition: swmgr.h:102
SWConfig * sysConfig
Definition: swmgr.h:308
virtual void setParentMgr(SWMgr *parentMgr)
Definition: swfiltermgr.cpp:38
SWConfig * mysysconfig
Definition: swmgr.h:103
SWFilterMgr * filterMgr
Definition: swmgr.h:101
void SWMgr::createAllModules ( bool  multiMod = false)
protectedvirtual

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

Definition at line 1456 of file swmgr.cpp.

1456  {
1457 SWLOGD("libsword: SWMgr::createAllModules");
1458  SectionMap::iterator it;
1459  ConfigEntMap::iterator entry;
1460  SWModule *newmod;
1461  SWBuf driver, misc1;
1462  for (it = config->getSections().begin(); it != config->getSections().end(); it++) {
1463  ConfigEntMap &section = (*it).second;
1464  newmod = 0;
1465 
1466  driver = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)"";
1467  if (driver.length()) {
1468  newmod = createModule((*it).first, driver, section);
1469  if (newmod) {
1470  // Filters to add for this module and globally announce as an option to the user
1471  // e.g. translit, strongs, redletterwords, etc, so users can turn these on and off globally
1472  // TODO: addGlobalOptionFilters(newmod, section);
1473  AddGlobalOptions(newmod, section, section.lower_bound("GlobalOptionFilter"), section.upper_bound("GlobalOptionFilter"));
1474 
1475  // Only add the option to the module, don't announce it's availability
1476  // These are useful for like: filters that parse special entryAttribs in a text
1477  // or whatever you might want to happen on entry lookup
1478  // TODO: addLocalOptionFilters(newmod, section);
1479  AddLocalOptions(newmod, section, section.lower_bound("LocalOptionFilter"), section.upper_bound("LocalOptionFilter"));
1480 
1481  //STRIP FILTERS
1482 
1483  // add all basic strip filters for for the modtype
1484  // TODO: addStripFilters(newmod, section);
1485  addStripFilters(newmod, section);
1486 
1487  // Any module-specific processing specified in module config
1488  // as entries LocalStripFilter=
1489  // e.g. for papyri, removed all [](). notation
1490  // TODO: addLocalStripFilters(newmod, section);
1491  AddStripFilters(newmod, section, section.lower_bound("LocalStripFilter"), section.upper_bound("LocalStripFilter"));
1492 
1493  // TODO: addRawFilters(newmod, section);
1494  addRawFilters(newmod, section);
1495  // TODO: addRenderFilters(newmod, section);
1496  addRenderFilters(newmod, section);
1497  // TODO: addEncodingFilters(newmod, section);
1498  addEncodingFilters(newmod, section);
1499 
1500  // place our module in module container, removing first if one
1501  // already exists by our same name
1502  SWModule *oldmod = getModule(newmod->getName());
1503  if (oldmod) {
1504  delete oldmod;
1505  }
1506 
1507  // if it's not a utility module save it to Modules
1508  if ( SWBuf("Utility") != newmod->getType() &&
1509  SWBuf("Utility") != newmod->getConfigEntry("Category")) {
1510  Modules[newmod->getName()] = newmod;
1511  }
1512  else utilModules[newmod->getName()] = newmod;
1513  }
1514  }
1515  }
1516 }
const char * getName() const
Definition: swmodule.cpp:204
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
virtual SectionMap & getSections()
Definition: swconfig.cpp:186
const char * getType() const
Definition: swmodule.cpp:232
virtual const char * getConfigEntry(const char *key) const
Definition: swmodule.cpp:1159
virtual SWModule * createModule(const char *name, const char *driver, ConfigEntMap &section)
Definition: swmgr.cpp:909
ModMap Modules
Definition: swmgr.h:322
virtual SWDEPRECATED void AddStripFilters(SWModule *module, ConfigEntMap &section)
Definition: swmgr.h:224
ModMap utilModules
Definition: swmgr.h:95
SWModule * getModule(const char *modName)
Definition: swmgr.h:360
SWConfig * config
Definition: swmgr.h:302
virtual SWDEPRECATED void AddLocalOptions(SWModule *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end)
Definition: swmgr.h:181
virtual void addRenderFilters(SWModule *module, ConfigEntMap &section)
Definition: swmgr.cpp:1272
virtual void addEncodingFilters(SWModule *module, ConfigEntMap &section)
Definition: swmgr.cpp:1266
SWORD_NAMESPACE_START typedef multimapwithdefault< SWBuf, SWBuf, std::less< SWBuf > > ConfigEntMap
Definition: swconfig.h:35
virtual void addRawFilters(SWModule *module, ConfigEntMap &section)
Definition: swmgr.cpp:1249
virtual void addStripFilters(SWModule *module, ConfigEntMap &section)
Definition: swmgr.cpp:1298
#define SWLOGD(...)
Definition: defs.h:187
virtual SWDEPRECATED void AddGlobalOptions(SWModule *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end)
Definition: swmgr.h:160
SWDEPRECATED void SWMgr::CreateMods ( bool  multiMod = false)
inlineprotected
Deprecated:
. Use createAllModules instead

Definition at line 108 of file swmgr.h.

108 { createAllModules(multiMod); };
virtual void createAllModules(bool multiMod=false)
Definition: swmgr.cpp:1456
SWModule * SWMgr::createModule ( const char *  name,
const char *  driver,
ConfigEntMap section 
)
protectedvirtual

called to create exactly one module from a config entry override to do any extra work before or after each module is created

Definition at line 909 of file swmgr.cpp.

910 {
911  SWBuf description, datapath, misc1;
912  ConfigEntMap::iterator entry;
913  SWModule *newmod = 0;
914  SWBuf lang, sourceformat, encoding;
915  signed char direction, enc, markup;
916 
917  description = ((entry = section.find("Description")) != section.end()) ? (*entry).second : (SWBuf)"";
918  lang = ((entry = section.find("Lang")) != section.end()) ? (*entry).second : (SWBuf)"en";
919  sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (SWBuf)"";
920  encoding = ((entry = section.find("Encoding")) != section.end()) ? (*entry).second : (SWBuf)"";
921  datapath = prefixPath;
922  if ((prefixPath[strlen(prefixPath)-1] != '\\') && (prefixPath[strlen(prefixPath)-1] != '/'))
923  datapath += "/";
924 
925  SWBuf versification = ((entry = section.find("Versification")) != section.end()) ? (*entry).second : (SWBuf)"KJV";
926 
927  // DataPath - relative path to data used by module driver. May be a directory, may be a File.
928  // Typically not useful by outside world. See AbsoluteDataPath, PrefixPath, and RelativePrefixPath
929  // below.
930  misc1 += ((entry = section.find("DataPath")) != section.end()) ? (*entry).second : (SWBuf)"";
931  char *buf = new char [ strlen(misc1.c_str()) + 1 ];
932  char *buf2 = buf;
933  strcpy(buf, misc1.c_str());
934 // for (; ((*buf2) && ((*buf2 == '.') || (*buf2 == '/') || (*buf2 == '\\'))); buf2++);
935  for (; ((*buf2) && ((*buf2 == '/') || (*buf2 == '\\'))); buf2++);
936  if (!strncmp(buf2, "./", 2)) { //remove the leading ./ in the module data path to make it look better
937  buf2 += 2;
938  }
939  // PrefixPath - absolute directory path to the repository in which this module was found
940  section["PrefixPath"] = datapath;
941  if (*buf2)
942  datapath += buf2;
943  delete [] buf;
944 
945  section["AbsoluteDataPath"] = datapath;
946 
947  if (!stricmp(sourceformat.c_str(), "GBF"))
948  markup = FMT_GBF;
949  else if (!stricmp(sourceformat.c_str(), "ThML"))
950  markup = FMT_THML;
951  else if (!stricmp(sourceformat.c_str(), "OSIS"))
952  markup = FMT_OSIS;
953  else if (!stricmp(sourceformat.c_str(), "TEI"))
954  markup = FMT_TEI;
955  else
956  markup = FMT_GBF;
957 
958  if (!stricmp(encoding.c_str(), "UTF-8")) {
959  enc = ENC_UTF8;
960  }
961  else if (!stricmp(encoding.c_str(), "SCSU")) {
962  enc = ENC_SCSU;
963  }
964  else if (!stricmp(encoding.c_str(), "UTF-16")) {
965  enc = ENC_UTF16;
966  }
967  else enc = ENC_LATIN1;
968 
969  if ((entry = section.find("Direction")) == section.end()) {
970  direction = DIRECTION_LTR;
971  }
972  else if (!stricmp((*entry).second.c_str(), "rtol")) {
973  direction = DIRECTION_RTL;
974  }
975  else if (!stricmp((*entry).second.c_str(), "bidi")) {
976  direction = DIRECTION_BIDI;
977  }
978  else {
979  direction = DIRECTION_LTR;
980  }
981 
982  if ((!stricmp(driver, "zText")) || (!stricmp(driver, "zCom")) || (!stricmp(driver, "zText4")) || (!stricmp(driver, "zCom4"))) {
983  SWCompress *compress = 0;
984  int blockType = CHAPTERBLOCKS;
985  misc1 = ((entry = section.find("BlockType")) != section.end()) ? (*entry).second : (SWBuf)"CHAPTER";
986  if (!stricmp(misc1.c_str(), "VERSE"))
987  blockType = VERSEBLOCKS;
988  else if (!stricmp(misc1.c_str(), "CHAPTER"))
989  blockType = CHAPTERBLOCKS;
990  else if (!stricmp(misc1.c_str(), "BOOK"))
991  blockType = BOOKBLOCKS;
992 
993  misc1 = ((entry = section.find("CompressType")) != section.end()) ? (*entry).second : (SWBuf)"LZSS";
994 #ifndef EXCLUDEZLIB
995  if (!stricmp(misc1.c_str(), "ZIP"))
996  compress = new ZipCompress();
997  else
998 #endif
999 #ifndef EXCLUDEBZIP2
1000  if (!stricmp(misc1.c_str(), "BZIP2"))
1001  compress = new Bzip2Compress();
1002  else
1003 #endif
1004 #ifndef EXCLUDEXZ
1005  if (!stricmp(misc1.c_str(), "XZ"))
1006  compress = new XzCompress();
1007  else
1008 #endif
1009  if (!stricmp(misc1.c_str(), "LZSS"))
1010  compress = new LZSSCompress();
1011 
1012  if (compress) {
1013  if (!stricmp(driver, "zText"))
1014  newmod = new zText(datapath.c_str(), name, description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str(), versification);
1015  else if (!stricmp(driver, "zText4"))
1016  newmod = new zText4(datapath.c_str(), name, description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str(), versification);
1017  else if (!stricmp(driver, "zCom4"))
1018  newmod = new zCom4(datapath.c_str(), name, description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str(), versification);
1019  else
1020  newmod = new zCom(datapath.c_str(), name, description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str(), versification);
1021  }
1022  }
1023 
1024  if (!stricmp(driver, "RawText")) {
1025  newmod = new RawText(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), versification);
1026  }
1027 
1028  if (!stricmp(driver, "RawText4")) {
1029  newmod = new RawText4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), versification);
1030  }
1031 
1032  // backward support old drivers
1033  if (!stricmp(driver, "RawGBF")) {
1034  newmod = new RawText(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
1035  }
1036 
1037  if (!stricmp(driver, "RawCom")) {
1038  newmod = new RawCom(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), versification);
1039  }
1040 
1041  if (!stricmp(driver, "RawCom4")) {
1042  newmod = new RawCom4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), versification);
1043  }
1044 
1045  if (!stricmp(driver, "RawFiles")) {
1046  newmod = new RawFiles(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
1047  }
1048 
1049  if (!stricmp(driver, "HREFCom")) {
1050  misc1 = ((entry = section.find("Prefix")) != section.end()) ? (*entry).second : (SWBuf)"";
1051  newmod = new HREFCom(datapath.c_str(), misc1.c_str(), name, description.c_str());
1052  }
1053 
1054  int pos = 0; //used for position of final / in AbsoluteDataPath, but also set to 1 for modules types that need to strip module name
1055  if (!stricmp(driver, "RawLD")) {
1056  bool caseSensitive = ((entry = section.find("CaseSensitiveKeys")) != section.end()) ? (*entry).second == "true": false;
1057  bool strongsPadding = ((entry = section.find("StrongsPadding")) != section.end()) ? (*entry).second == "true": true;
1058  newmod = new RawLD(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), caseSensitive, strongsPadding);
1059  pos = 1;
1060  }
1061 
1062  if (!stricmp(driver, "RawLD4")) {
1063  bool caseSensitive = ((entry = section.find("CaseSensitiveKeys")) != section.end()) ? (*entry).second == "true": false;
1064  bool strongsPadding = ((entry = section.find("StrongsPadding")) != section.end()) ? (*entry).second == "true": true;
1065  newmod = new RawLD4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), caseSensitive, strongsPadding);
1066  pos = 1;
1067  }
1068 
1069  if (!stricmp(driver, "zLD")) {
1070  SWCompress *compress = 0;
1071  int blockCount;
1072  bool caseSensitive = ((entry = section.find("CaseSensitiveKeys")) != section.end()) ? (*entry).second == "true": false;
1073  bool strongsPadding = ((entry = section.find("StrongsPadding")) != section.end()) ? (*entry).second == "true": true;
1074  misc1 = ((entry = section.find("BlockCount")) != section.end()) ? (*entry).second : (SWBuf)"200";
1075  blockCount = atoi(misc1.c_str());
1076  blockCount = (blockCount) ? blockCount : 200;
1077 
1078  misc1 = ((entry = section.find("CompressType")) != section.end()) ? (*entry).second : (SWBuf)"LZSS";
1079 #ifndef EXCLUDEZLIB
1080  if (!stricmp(misc1.c_str(), "ZIP"))
1081  compress = new ZipCompress();
1082  else
1083 #endif
1084 #ifndef EXCLUDEBZIP2
1085  if (!stricmp(misc1.c_str(), "BZIP2"))
1086  compress = new Bzip2Compress();
1087  else
1088 #endif
1089 #ifndef EXCLUDEXZ
1090  if (!stricmp(misc1.c_str(), "XZ"))
1091  compress = new XzCompress();
1092  else
1093 #endif
1094  if (!stricmp(misc1.c_str(), "LZSS"))
1095  compress = new LZSSCompress();
1096 
1097  if (compress) {
1098  newmod = new zLD(datapath.c_str(), name, description.c_str(), blockCount, compress, 0, enc, direction, markup, lang.c_str(), caseSensitive, strongsPadding);
1099  }
1100  pos = 1;
1101  }
1102 
1103  if (!stricmp(driver, "RawGenBook")) {
1104  misc1 = ((entry = section.find("KeyType")) != section.end()) ? (*entry).second : (SWBuf)"TreeKey";
1105  newmod = new RawGenBook(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), misc1.c_str());
1106  pos = 1;
1107  }
1108 
1109  if (pos == 1) {
1110  SWBuf &dp = section["AbsoluteDataPath"];
1111  for (int i = (int)dp.length() - 1; i; i--) {
1112  if (dp[i] == '/') {
1113  dp.setSize(i);
1114  break;
1115  }
1116  }
1117 /*
1118  SWBuf &rdp = section["RelativeDataPath"];
1119  for (int i = rdp.length() - 1; i; i--) {
1120  if (rdp[i] == '/') {
1121  rdp.setSize(i);
1122  break;
1123  }
1124  }
1125 */
1126  }
1127 
1128  if (newmod) {
1129  // if a specific module type is set in the config, use this
1130  if ((entry = section.find("Type")) != section.end())
1131  newmod->setType(entry->second.c_str());
1132 
1133  newmod->setConfig(&section);
1134  }
1135 
1136  return newmod;
1137 }
Definition: zcom4.h:33
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
Definition: rawcom.h:34
Definition: rawld4.h:35
Definition: zld.h:34
int pos
Definition: regex.c:5534
Definition: ztext4.h:39
#define VERSEBLOCKS
Definition: zverse.h:58
char * prefixPath
Definition: swmgr.h:312
SWCompress * compress
Definition: step2vpl.cpp:140
Definition: rawld.h:35
#define CHAPTERBLOCKS
Definition: zverse.h:59
int stricmp(const char *s1, const char *s2)
Definition: utilstr.cpp:194
Definition: zcom.h:33
const char * c_str() const
Definition: swbuf.h:158
virtual void setConfig(ConfigEntMap *config)
Definition: swmodule.cpp:1165
void setType(const char *imodtype)
Definition: swmodule.h:397
#define BOOKBLOCKS
Definition: zverse.h:60
void setSize(unsigned long len)
Definition: swbuf.h:255
Definition: ztext.h:39
void SWMgr::deleteAllModules ( )
protectedvirtual

called to delete all contructed modules. Undoes createAllModules override to clean anything up before or after all modules are deleted

Definition at line 1519 of file swmgr.cpp.

1519  {
1520 
1521  ModMap::iterator it;
1522 
1523  for (it = getModules().begin(); it != getModules().end(); ++it) {
1524  delete (*it).second;
1525  }
1526  for (it = getUtilModules().begin(); it != getUtilModules().end(); ++it) {
1527  delete (*it).second;
1528  }
1529 
1530  Modules.clear();
1531  utilModules.clear();
1532 }
ModMap Modules
Definition: swmgr.h:322
ModMap & getModules()
Definition: swmgr.cpp:1574
ModMap & getUtilModules()
Definition: swmgr.cpp:1575
ModMap utilModules
Definition: swmgr.h:95
SWDEPRECATED void SWMgr::DeleteMods ( )
inlineprotected
Deprecated:
. Use deleteAllModules instead

Definition at line 112 of file swmgr.h.

112 { deleteAllModules(); }
virtual void deleteAllModules()
Definition: swmgr.cpp:1519
void SWMgr::deleteModule ( const char *  modName)

Definition at line 1535 of file swmgr.cpp.

1535  {
1536  ModMap::iterator it = Modules.find(modName);
1537  if (it != Modules.end()) {
1538  delete (*it).second;
1539  Modules.erase(it);
1540  }
1541  else {
1542  it = utilModules.find(modName);
1543  if (it != utilModules.end()) {
1544  delete (*it).second;
1545  utilModules.erase(it);
1546  }
1547  }
1548 }
ModMap Modules
Definition: swmgr.h:322
ModMap utilModules
Definition: swmgr.h:95
char SWMgr::filterText ( const char *  filterName,
SWBuf text,
const SWKey key = 0,
const SWModule module = 0 
)
virtual

Filters a buffer thru a named filter

Parameters
filterNamename of filter which the buffer should be filtered through
textbuffer to filter
keycontext key if filter needs this for processing
modulecontext module if filter needs this for processing
Returns
error status

Definition at line 1192 of file swmgr.cpp.

1192  {
1193  signed char retVal = -1;
1194  // why didn't we use find here?
1195  for (OptionFilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
1196  if ((*it).second->getOptionName()) {
1197  if (!stricmp(filterName, (*it).second->getOptionName())) {
1198  retVal = it->second->processText(text, key, module);
1199  break;
1200  }
1201  }
1202  }
1203 
1204  if (retVal == -1) {
1205  FilterMap::iterator it = extraFilters.find(filterName);
1206  if (it != extraFilters.end()) {
1207  retVal = it->second->processText(text, key, module);
1208  }
1209  }
1210 
1211  return retVal;
1212 }
FilterMap extraFilters
Definition: swmgr.h:122
int stricmp(const char *s1, const char *s2)
Definition: utilstr.cpp:194
OptionFilterMap optionFilters
Definition: swmgr.h:114
void SWMgr::findConfig ( char *  configType,
char **  prefixPath,
char **  configPath,
StringList augPaths = 0,
SWConfig **  providedSysConf = 0 
)
static

Perform all the logic to discover a SWORD configuration and libraries on a system

Definition at line 449 of file swmgr.cpp.

449  {
450  static bool setLogLevel = false;
451  SWBuf path;
452  SWBuf sysConfPath;
453  ConfigEntMap::iterator entry;
454  ConfigEntMap::iterator lastEntry;
455 
456  if (!setLogLevel) {
457  SWBuf envLogLevel = FileMgr::getEnvValue("SWORD_LOGLEVEL");
458  if (envLogLevel.length()) {
459  setSystemLogLevel(0, envLogLevel);
460  setLogLevel = true;
461  }
462  }
463 
464  SWConfig *sysConf = 0;
465  SWBuf sysConfDataPath = "";
466 
467  *configType = 0;
468 
470 
471  // check for a sysConf passed in to us
472  SWLOGTI("Checking for provided SWConfig(\"sword.conf\")...");
473  if (providedSysConf && *providedSysConf) {
474  sysConf = *providedSysConf;
475  SWLOGTI("found.");
476  if (!setLogLevel) { setSystemLogLevel(sysConf); setLogLevel = true; }
477  }
478 
479  // if we haven't been given our datapath in a sysconf, we need to track it down
480  if (!sysConf) {
481  // check working directory
482  SWLOGTI("Checking working directory for sword.conf...");
483  if (FileMgr::existsFile(".", "sword.conf")) {
484  SWLOGTI("Overriding any systemwide or ~/.sword/ sword.conf with one found in current directory.");
485  sysConfPath = "./sword.conf";
486  sysConf = new SWConfig(sysConfPath);
487  if ((entry = sysConf->getSection("Install").find("DataPath")) != sysConf->getSection("Install").end()) {
488  sysConfDataPath = (*entry).second;
489  }
490  if (!setLogLevel) { setSystemLogLevel(sysConf); setLogLevel = true; }
491  if (providedSysConf) {
492  *providedSysConf = sysConf;
493  }
494  else {
495  delete sysConf;
496  sysConf = 0;
497  }
498  }
499  if (!sysConfDataPath.size()) {
500  SWLOGTI("Checking working directory for mods.conf...");
501  if (FileMgr::existsFile(".", "mods.conf")) {
502  SWLOGTI("found.");
503  stdstr(prefixPath, "./");
504  stdstr(configPath, "./mods.conf");
505  return;
506  }
507 
508  SWLOGTI("Checking working directory for mods.d...");
509  if (FileMgr::existsDir(".", "mods.d")) {
510  SWLOGTI("found.");
511  stdstr(prefixPath, "./");
512  stdstr(configPath, "./mods.d");
513  *configType = 1;
514  return;
515  }
516 
517  // check working directory ../library/
518  SWLOGTI("Checking working directory ../library/ for mods.d...");
519  if (FileMgr::existsDir("../library", "mods.d")) {
520  SWLOGTI("found.");
521  stdstr(prefixPath, "../library/");
522  stdstr(configPath, "../library/mods.d");
523  *configType = 1;
524  return;
525  }
526 
527  // check environment variable SWORD_PATH
528  SWLOGTI("Checking $SWORD_PATH...");
529 
530  SWBuf envsworddir = FileMgr::getEnvValue("SWORD_PATH");
531  if (envsworddir.length()) {
532 
533  SWLOGTI("found (%s).", envsworddir.c_str());
534  path = envsworddir;
535  if ((envsworddir[envsworddir.length()-1] != '\\') && (envsworddir[envsworddir.length()-1] != '/'))
536  path += "/";
537 
538  SWLOGTI("Checking $SWORD_PATH for mods.conf...");
539  if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
540  SWLOGTI("found.");
541  stdstr(prefixPath, path.c_str());
542  path += "mods.conf";
543  stdstr(configPath, path.c_str());
544  return;
545  }
546 
547  SWLOGTI("Checking $SWORD_PATH for mods.d...");
548  if (FileMgr::existsDir(path.c_str(), "mods.d")) {
549  SWLOGTI("found.");
550  stdstr(prefixPath, path.c_str());
551  path += "mods.d";
552  stdstr(configPath, path.c_str());
553  *configType = 1;
554  return;
555  }
556  }
557 
558 
559  // check for systemwide globalConfPath
560 
561  SWLOGTI("Parsing %s...", globalConfPath);
562  char *globPaths = 0;
563  char *gfp;
564  stdstr(&globPaths, globalConfPath);
565  for (gfp = strtok(globPaths, ":"); gfp; gfp = strtok(0, ":")) {
566  SWLOGTI("Checking for %s...", gfp);
567  if (FileMgr::existsFile(gfp)) {
568  SWLOGTI("found.");
569  break;
570  }
571  }
572  if (gfp)
573  sysConfPath = gfp;
574  delete [] globPaths;
575 
576  if (homeDir.length()) {
577  SWBuf tryPath = homeDir;
578  tryPath += ".sword/sword.conf";
579  if (FileMgr::existsFile(tryPath)) {
580  SWLOGTI("Overriding any systemwide sword.conf with one found in users home directory (%s)", tryPath.c_str());
581  sysConfPath = tryPath;
582  }
583  else {
584  SWBuf tryPath = homeDir;
585  tryPath += "sword/sword.conf";
586  if (FileMgr::existsFile(tryPath)) {
587  SWLOGTI("Overriding any systemwide sword.conf with one found in users home directory (%s)", tryPath.c_str());
588  sysConfPath = tryPath;
589  }
590  }
591  }
592  }
593  }
594 
595  if (!sysConf && sysConfPath.size()) {
596  sysConf = new SWConfig(sysConfPath);
597  }
598 
599  if (sysConf) {
600  if (!setLogLevel) { setSystemLogLevel(sysConf); setLogLevel = true; }
601  if ((entry = sysConf->getSection("Install").find("DataPath")) != sysConf->getSection("Install").end()) {
602  sysConfDataPath = (*entry).second;
603  }
604  if (sysConfDataPath.size()) {
605  if ((!sysConfDataPath.endsWith("\\")) && (!sysConfDataPath.endsWith("/")))
606  sysConfDataPath += "/";
607 
608  path = sysConfDataPath;
609  SWLOGTI("DataPath in %s is set to %s.", sysConfPath.c_str(), path.c_str());
610  SWLOGTI("Checking for mods.conf in DataPath...");
611 
612  if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
613  SWLOGTI("found.");
614  stdstr(prefixPath, path.c_str());
615  path += "mods.conf";
616  stdstr(configPath, path.c_str());
617  *configType = 1;
618  }
619 
620  SWLOGTI("Checking for mods.d in DataPath...");
621 
622  if (FileMgr::existsDir(path.c_str(), "mods.d")) {
623  SWLOGTI("found.");
624  stdstr(prefixPath, path.c_str());
625  path += "mods.d";
626  stdstr(configPath, path.c_str());
627  *configType = 1;
628  }
629  }
630  }
631 
632  // do some extra processing of sysConf if we have one
633  if (sysConf) {
634  if (!setLogLevel) { setSystemLogLevel(sysConf); setLogLevel = true; }
635  if (augPaths) {
636  augPaths->clear();
637  entry = sysConf->getSection("Install").lower_bound("AugmentPath");
638  lastEntry = sysConf->getSection("Install").upper_bound("AugmentPath");
639  for (;entry != lastEntry; entry++) {
640  path = entry->second;
641  if ((entry->second.c_str()[strlen(entry->second.c_str())-1] != '\\') && (entry->second.c_str()[strlen(entry->second.c_str())-1] != '/'))
642  path += "/";
643  augPaths->push_back(path);
644  }
645  }
646  if (providedSysConf) {
647  *providedSysConf = sysConf;
648  }
649  else delete sysConf;
650  }
651 
652  if (*configType)
653  return;
654 
655  // WE STILL HAVEN'T FOUND A CONFIGURATION. LET'S LOOK IN SOME OS SPECIFIC
656  // LOCATIONS
657  //
658  // for various flavors of windoze...
659  // check %ALLUSERSPROFILE%/Application Data/sword/
660 
661  SWLOGTI("Checking $ALLUSERSPROFILE/Application Data/sword/...");
662 
663  SWBuf envallusersdir = FileMgr::getEnvValue("ALLUSERSPROFILE");
664  if (envallusersdir.length()) {
665  SWLOGTI("found (%s).", envallusersdir.c_str());
666  path = envallusersdir;
667  if ((!path.endsWith("\\")) && (!path.endsWith("/")))
668  path += "/";
669 
670  path += "Application Data/sword/";
671  SWLOGTI("Checking %s for mods.d...", path.c_str());
672  if (FileMgr::existsDir(path.c_str(), "mods.d")) {
673  SWLOGTI("found.");
674  stdstr(prefixPath, path.c_str());
675  path += "mods.d";
676  stdstr(configPath, path.c_str());
677  *configType = 1;
678  return;
679  }
680  }
681 
682  // for Mac OSX...
683  // check $HOME/Library/Application Support/Sword/
684 
685  SWLOGTI("Checking $HOME/Library/Application Support/Sword/...");
686 
687  SWBuf pathCheck = FileMgr::getSystemFileMgr()->getHomeDir();
688  if (pathCheck.length()) {
689  SWLOGTI("found (%s).", pathCheck.c_str());
690  path = pathCheck;
691  if ((!path.endsWith("\\")) && (!path.endsWith("/")))
692  path += "/";
693 
694  SWLOGTI("Checking %s for mods.d...", path.c_str());
695  if (FileMgr::existsDir(path.c_str(), "mods.d")) {
696  SWLOGTI("found.");
697  stdstr(prefixPath, path.c_str());
698  path += "mods.d";
699  stdstr(configPath, path.c_str());
700  *configType = 1;
701  return;
702  }
703  }
704 
705  // FINALLY CHECK PERSONAL HOME DIRECTORY LOCATIONS
706  // check ~/.sword/
707 
708  SWLOGTI("Checking home directory for ~/.sword...");
709 
710  if (homeDir.length()) {
711  path = homeDir;
712  path += ".sword/";
713  SWLOGTI(" Checking for %smods.conf...", path.c_str());
714  if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
715  SWLOGTI("found.");
716  stdstr(prefixPath, path.c_str());
717  path += "mods.conf";
718  stdstr(configPath, path.c_str());
719  return;
720  }
721 
722  SWLOGTI(" Checking for %smods.d...", path.c_str());
723  if (FileMgr::existsDir(path.c_str(), "mods.d")) {
724  SWLOGTI("found.");
725  stdstr(prefixPath, path.c_str());
726  path += "mods.d";
727  stdstr(configPath, path.c_str());
728  *configType = 2;
729  return;
730  }
731 
732  path = homeDir;
733  path += "sword/";
734  SWLOGTI(" Checking for %smods.d...", path.c_str());
735  if (FileMgr::existsDir(path.c_str(), "mods.d")) {
736  SWLOGTI("found.");
737  stdstr(prefixPath, path.c_str());
738  path += "mods.d";
739  stdstr(configPath, path.c_str());
740  *configType = 2;
741  return;
742  }
743  }
744 }
static signed char existsFile(const char *ipath, const char *ifileName=0)
Definition: filemgr.cpp:337
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
static signed char existsDir(const char *ipath, const char *idirName=0)
Definition: filemgr.cpp:357
static SWBuf getEnvValue(const char *variableName)
Definition: filemgr.cpp:316
char configType
Definition: swmgr.h:113
char * prefixPath
Definition: swmgr.h:312
bool endsWith(const SWBuf &postfix) const
Definition: swbuf.h:501
SWORD_NAMESPACE_START char * stdstr(char **ipstr, const char *istr, unsigned int memPadFactor=1)
Definition: utilstr.h:44
ConfigEntMap & getSection(const char *section)
Definition: swconfig.h:76
const char * c_str() const
Definition: swbuf.h:158
StringList augPaths
Definition: swmgr.h:266
unsigned long size() const
Definition: swbuf.h:185
#define SWLOGTI(...)
Definition: defs.h:194
SWBuf getHomeDir()
Definition: filemgr.cpp:681
static const char * globalConfPath
Definition: swmgr.h:281
char * configPath
Definition: swmgr.h:316
static FileMgr * getSystemFileMgr()
Definition: filemgr.cpp:101
const char * SWMgr::getGlobalOption ( const char *  option)
virtual

Get the current value of the given option

Parameters
optionthe name of the option, who's value is desired
Returns
the value of the given option

Definition at line 1403 of file swmgr.cpp.

1404 {
1405  for (OptionFilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
1406  if ((*it).second->getOptionName()) {
1407  if (!stricmp(option, (*it).second->getOptionName()))
1408  return (*it).second->getOptionValue();
1409  }
1410  }
1411  return 0;
1412 }
int stricmp(const char *s1, const char *s2)
Definition: utilstr.cpp:194
OptionFilterMap optionFilters
Definition: swmgr.h:114
StringList SWMgr::getGlobalOptions ( )
virtual

Gets a list of all available option names

Returns
list of option names

Definition at line 1427 of file swmgr.cpp.

1428 {
1429  return options;
1430 }
StringList options
Definition: swmgr.h:123
const char * SWMgr::getGlobalOptionTip ( const char *  option)
virtual

Gets a brief description for the given option

Parameters
optionthe name of the option, who's tip is desired
Returns
description text
See Also
setGlobalOption, getGlobalOption, getGlobalOptions

Definition at line 1415 of file swmgr.cpp.

1416 {
1417  for (OptionFilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
1418  if ((*it).second->getOptionName()) {
1419  if (!stricmp(option, (*it).second->getOptionName()))
1420  return (*it).second->getOptionTip();
1421  }
1422  }
1423  return 0;
1424 }
int stricmp(const char *s1, const char *s2)
Definition: utilstr.cpp:194
OptionFilterMap optionFilters
Definition: swmgr.h:114
StringList SWMgr::getGlobalOptionValues ( const char *  option)
virtual

Gets a list of legal values to which a specific option may be set

Parameters
optionthe name of the option, who's legal values are desired
Returns
a list of legal values for the given option

Definition at line 1433 of file swmgr.cpp.

1434 {
1436  for (OptionFilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
1437  if ((*it).second->getOptionName()) {
1438  if (!stricmp(option, (*it).second->getOptionName())) {
1439  options = (*it).second->getOptionValues();
1440  break; // just find the first one. All option filters with the same option name should expect the same values
1441  }
1442  }
1443  }
1444  return options;
1445 }
int stricmp(const char *s1, const char *s2)
Definition: utilstr.cpp:194
OptionFilterMap optionFilters
Definition: swmgr.h:114
std::list< SWBuf > StringList
Definition: swmodule.cpp:91
StringList options
Definition: swmgr.h:123
SWBuf SWMgr::getHomeDir ( )
static
Deprecated:
Used FileMgr::getSystemFileMgr()->getHomeDir() instead.

Definition at line 1577 of file swmgr.cpp.

1577 { return FileMgr::getSystemFileMgr()->getHomeDir(); }
SWBuf getHomeDir()
Definition: filemgr.cpp:681
static FileMgr * getSystemFileMgr()
Definition: filemgr.cpp:101
SWModule* SWMgr::getModule ( const char *  modName)
inline

Gets a specific module by name. e.g. SWModule *kjv = myManager.getModule("KJV");

Parameters
modNamethe name of the module to retrieve
Returns
the module, if found, otherwise 0

Definition at line 360 of file swmgr.h.

360  {
361  ModMap::iterator it = getModules().find(modName);
362  if (it == getModules().end()) it = getUtilModules().find(modName);
363  return ((it != getUtilModules().end()) ? it->second : 0);
364  }
ModMap & getModules()
Definition: swmgr.cpp:1574
ModMap & getUtilModules()
Definition: swmgr.cpp:1575
const SWModule* SWMgr::getModule ( const char *  modName) const
inline

Definition at line 365 of file swmgr.h.

365  {
366  ModMap::const_iterator it = getModules().find(modName);
367  if (it == getModules().end()) it = getUtilModules().find(modName);
368  return ((it != getUtilModules().end()) ? it->second : 0);
369  }
ModMap & getModules()
Definition: swmgr.cpp:1574
ModMap & getUtilModules()
Definition: swmgr.cpp:1575
ModMap & SWMgr::getModules ( )

The map of available modules. This map exposes the installed modules.

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 (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
}
}

Definition at line 1574 of file swmgr.cpp.

1574 { return Modules; }
ModMap Modules
Definition: swmgr.h:322
const ModMap& SWMgr::getModules ( ) const
inline

Definition at line 348 of file swmgr.h.

348 { return const_cast<SWMgr *>(this)->getModules(); }
Definition: swmgr.h:93
ModMap & getModules()
Definition: swmgr.cpp:1574
ModMap & SWMgr::getUtilModules ( )

Utility modules are not meant for user to see as general addins, but instead are modules which provide utility tools for frontends which may wish to use them.

Definition at line 1575 of file swmgr.cpp.

1575 { return utilModules; }
ModMap utilModules
Definition: swmgr.h:95
const ModMap& SWMgr::getUtilModules ( ) const
inline

Definition at line 354 of file swmgr.h.

354 { return const_cast<SWMgr *>(this)->getUtilModules(); }
Definition: swmgr.h:93
ModMap & getUtilModules()
Definition: swmgr.cpp:1575
void SWMgr::init ( )
protectedvirtual

call by every constructor to initialize SWMgr object override to include any addition common initialization

Definition at line 163 of file swmgr.cpp.

163  {
164  SWOptionFilter *tmpFilter = 0;
165  configPath = 0;
166  prefixPath = 0;
167  configType = 0;
168  myconfig = 0;
169  mysysconfig = 0;
170  homeConfig = 0;
171  augmentHome = true;
172 
173  cipherFilters.clear();
174  optionFilters.clear();
175  cleanupFilters.clear();
176  extraFilters.clear();
177  tmpFilter = new ThMLVariants();
178  optionFilters.insert(OptionFilterMap::value_type("ThMLVariants", tmpFilter));
179  cleanupFilters.push_back(tmpFilter);
180 
181  tmpFilter = new GBFStrongs();
182  optionFilters.insert(OptionFilterMap::value_type("GBFStrongs", tmpFilter));
183  cleanupFilters.push_back(tmpFilter);
184 
185  tmpFilter = new GBFFootnotes();
186  optionFilters.insert(OptionFilterMap::value_type("GBFFootnotes", tmpFilter));
187  cleanupFilters.push_back(tmpFilter);
188 
189  tmpFilter = new GBFRedLetterWords();
190  optionFilters.insert(OptionFilterMap::value_type("GBFRedLetterWords", tmpFilter));
191  cleanupFilters.push_back(tmpFilter);
192 
193  tmpFilter = new GBFMorph();
194  optionFilters.insert(OptionFilterMap::value_type("GBFMorph", tmpFilter));
195  cleanupFilters.push_back(tmpFilter);
196 
197  tmpFilter = new GBFHeadings();
198  optionFilters.insert(OptionFilterMap::value_type("GBFHeadings", tmpFilter));
199  cleanupFilters.push_back(tmpFilter);
200 
201  tmpFilter = new OSISHeadings();
202  optionFilters.insert(OptionFilterMap::value_type("OSISHeadings", tmpFilter));
203  cleanupFilters.push_back(tmpFilter);
204 
205  tmpFilter = new OSISStrongs();
206  optionFilters.insert(OptionFilterMap::value_type("OSISStrongs", tmpFilter));
207  cleanupFilters.push_back(tmpFilter);
208 
209  tmpFilter = new OSISMorph();
210  optionFilters.insert(OptionFilterMap::value_type("OSISMorph", tmpFilter));
211  cleanupFilters.push_back(tmpFilter);
212 
213  tmpFilter = new OSISLemma();
214  optionFilters.insert(OptionFilterMap::value_type("OSISLemma", tmpFilter));
215  cleanupFilters.push_back(tmpFilter);
216 
217  tmpFilter = new OSISFootnotes();
218  optionFilters.insert(OptionFilterMap::value_type("OSISFootnotes", tmpFilter));
219  cleanupFilters.push_back(tmpFilter);
220 
221  tmpFilter = new OSISScripref();
222  optionFilters.insert(OptionFilterMap::value_type("OSISScripref", tmpFilter));
223  cleanupFilters.push_back(tmpFilter);
224 
225  tmpFilter = new OSISRedLetterWords();
226  optionFilters.insert(OptionFilterMap::value_type("OSISRedLetterWords", tmpFilter));
227  cleanupFilters.push_back(tmpFilter);
228 
229  tmpFilter = new OSISMorphSegmentation();
230  optionFilters.insert(OptionFilterMap::value_type("OSISMorphSegmentation", tmpFilter));
231  cleanupFilters.push_back(tmpFilter);
232 
233  tmpFilter = new OSISGlosses();
234  optionFilters.insert(OptionFilterMap::value_type("OSISGlosses", tmpFilter));
235  optionFilters.insert(OptionFilterMap::value_type("OSISRuby", tmpFilter));
236  cleanupFilters.push_back(tmpFilter);
237 
238  tmpFilter = new OSISXlit();
239  optionFilters.insert(OptionFilterMap::value_type("OSISXlit", tmpFilter));
240  cleanupFilters.push_back(tmpFilter);
241 
242  tmpFilter = new OSISEnum();
243  optionFilters.insert(OptionFilterMap::value_type("OSISEnum", tmpFilter));
244  cleanupFilters.push_back(tmpFilter);
245 
246  tmpFilter = new OSISVariants();
247  optionFilters.insert(OptionFilterMap::value_type("OSISVariants", tmpFilter));
248  cleanupFilters.push_back(tmpFilter);
249 
250  tmpFilter = new ThMLStrongs();
251  optionFilters.insert(OptionFilterMap::value_type("ThMLStrongs", tmpFilter));
252  cleanupFilters.push_back(tmpFilter);
253 
254  tmpFilter = new ThMLFootnotes();
255  optionFilters.insert(OptionFilterMap::value_type("ThMLFootnotes", tmpFilter));
256  cleanupFilters.push_back(tmpFilter);
257 
258  tmpFilter = new ThMLMorph();
259  optionFilters.insert(OptionFilterMap::value_type("ThMLMorph", tmpFilter));
260  cleanupFilters.push_back(tmpFilter);
261 
262  tmpFilter = new ThMLHeadings();
263  optionFilters.insert(OptionFilterMap::value_type("ThMLHeadings", tmpFilter));
264  cleanupFilters.push_back(tmpFilter);
265 
266  tmpFilter = new ThMLLemma();
267  optionFilters.insert(OptionFilterMap::value_type("ThMLLemma", tmpFilter));
268  cleanupFilters.push_back(tmpFilter);
269 
270  tmpFilter = new ThMLScripref();
271  optionFilters.insert(OptionFilterMap::value_type("ThMLScripref", tmpFilter));
272  cleanupFilters.push_back(tmpFilter);
273 
274  tmpFilter = new UTF8GreekAccents();
275  optionFilters.insert(OptionFilterMap::value_type("UTF8GreekAccents", tmpFilter));
276  cleanupFilters.push_back(tmpFilter);
277 
278  tmpFilter = new UTF8HebrewPoints();
279  optionFilters.insert(OptionFilterMap::value_type("UTF8HebrewPoints", tmpFilter));
280  cleanupFilters.push_back(tmpFilter);
281 
282  tmpFilter = new UTF8ArabicPoints();
283  optionFilters.insert(OptionFilterMap::value_type("UTF8ArabicPoints", tmpFilter));
284  cleanupFilters.push_back(tmpFilter);
285 
286  tmpFilter = new UTF8Cantillation();
287  optionFilters.insert(OptionFilterMap::value_type("UTF8Cantillation", tmpFilter));
288  cleanupFilters.push_back(tmpFilter);
289 
290  tmpFilter = new GreekLexAttribs();
291  optionFilters.insert(OptionFilterMap::value_type("GreekLexAttribs", tmpFilter));
292  cleanupFilters.push_back(tmpFilter);
293 
294  tmpFilter = new PapyriPlain();
295  optionFilters.insert(OptionFilterMap::value_type("PapyriPlain", tmpFilter));
296  cleanupFilters.push_back(tmpFilter);
297 
298 // UTF8Transliterator needs to be handled differently because it should always available as an option, for all modules
299 #ifdef _ICU_
301  optionFilters.insert(OptionFilterMap::value_type("UTF8Transliterator", transliterator));
302  options.push_back(transliterator->getOptionName());
303  cleanupFilters.push_back(transliterator);
304 #endif
305 
306  gbfplain = new GBFPlain();
307  cleanupFilters.push_back(gbfplain);
308  extraFilters.insert(FilterMap::value_type("GBFPlain", gbfplain));
309 
310  thmlplain = new ThMLPlain();
311  cleanupFilters.push_back(thmlplain);
312  extraFilters.insert(FilterMap::value_type("ThMLPlain", thmlplain));
313 
314  osisplain = new OSISPlain();
315  cleanupFilters.push_back(osisplain);
316  extraFilters.insert(FilterMap::value_type("OSISPlain", osisplain));
317 
318  teiplain = new TEIPlain();
319  cleanupFilters.push_back(teiplain);
320  extraFilters.insert(FilterMap::value_type("TEIPlain", teiplain));
321 
322  // filters which aren't really used anywhere but which we want available for a "FilterName" -> filter mapping (e.g., filterText)
323  SWFilter *f = new RTFHTML();
324  extraFilters.insert(FilterMap::value_type("RTFHTML", f));
325  cleanupFilters.push_back(f);
326 
327 }
SWOptionFilter * transliterator
Definition: swmgr.h:120
virtual const char * getOptionName()
Definition: swoptfilter.h:72
char configType
Definition: swmgr.h:113
char * prefixPath
Definition: swmgr.h:312
SWFilter * gbfplain
Definition: swmgr.h:116
FilterMap extraFilters
Definition: swmgr.h:122
OptionFilterMap optionFilters
Definition: swmgr.h:114
FilterMap cipherFilters
Definition: swmgr.h:115
FilterList cleanupFilters
Definition: swmgr.h:121
SWConfig * myconfig
Definition: swmgr.h:102
StringList options
Definition: swmgr.h:123
SWFilter * osisplain
Definition: swmgr.h:118
SWFilter * teiplain
Definition: swmgr.h:119
SWConfig * mysysconfig
Definition: swmgr.h:103
bool augmentHome
Definition: swmgr.h:97
SWConfig * homeConfig
Definition: swmgr.h:104
SWFilter * thmlplain
Definition: swmgr.h:117
char * configPath
Definition: swmgr.h:316
void SWMgr::InstallScan ( const char *  dir)
virtual

Looks for any newly installed module.conf file in the path provided, displays the copyright information to the user, and then copies the module.conf to the main module set's mods.d directory

Parameters
dirwhere to search for new modules

Definition at line 1331 of file swmgr.cpp.

1332 {
1333  FileDesc *conffd = 0;
1334  SWBuf newModFile;
1335  SWBuf targetName;
1336  SWBuf basePath = dirname;
1337  if (!basePath.endsWith("/") && !basePath.endsWith("\\")) basePath += "/";
1338 
1339  std::vector<DirEntry> dirList = FileMgr::getDirList(dirname);
1340  for (unsigned int i = 0; i < dirList.size(); ++i) {
1341  newModFile = basePath + dirList[i].name;
1342 
1343  // mods.d
1344  if (configType) {
1345  if (conffd)
1346  FileMgr::getSystemFileMgr()->close(conffd);
1347  targetName = configPath;
1348  if ((configPath[strlen(configPath)-1] != '\\') && (configPath[strlen(configPath)-1] != '/'))
1349  targetName += "/";
1350  targetName += dirList[i].name;
1352  }
1353 
1354  // mods.conf
1355  else {
1356  if (!conffd) {
1358  if (conffd && conffd->getFd() >= 0)
1359  conffd->seek(0L, SEEK_END);
1360  else {
1361  FileMgr::getSystemFileMgr()->close(conffd);
1362  conffd = 0;
1363  }
1364  }
1365  }
1366  addModToConfig(conffd, newModFile.c_str());
1367  FileMgr::removeFile(newModFile.c_str());
1368  }
1369  if (conffd)
1370  FileMgr::getSystemFileMgr()->close(conffd);
1371 }
long seek(long offset, int whence)
Definition: filemgr.cpp:143
FileDesc * open(const char *path, int mode, bool tryDowngrade)
Definition: filemgr.cpp:175
Definition: swbuf.h:47
char configType
Definition: swmgr.h:113
#define SEEK_END
Definition: zconf.h:246
SWBuf getFileName() const
Definition: swconfig.cpp:191
int getFd()
Definition: filemgr.h:231
bool endsWith(const SWBuf &postfix) const
Definition: swbuf.h:501
SWConfig * config
Definition: swmgr.h:302
void close(FileDesc *file)
Definition: filemgr.cpp:196
const char * c_str() const
Definition: swbuf.h:158
static int removeFile(const char *fName)
Definition: filemgr.cpp:517
static unsigned int APPEND
Definition: filemgr.h:73
static std::vector< struct DirEntry > getDirList(const char *dirPath, bool includeSize=false, bool includeIsDirectory=true)
Definition: filemgr.cpp:379
static unsigned int CREAT
Definition: filemgr.h:72
static unsigned int IWRITE
Definition: filemgr.h:79
static unsigned int WRONLY
Definition: filemgr.h:77
static unsigned int IREAD
Definition: filemgr.h:78
virtual char addModToConfig(FileDesc *conffd, const char *fname)
Definition: swmgr.cpp:1374
char * configPath
Definition: swmgr.h:316
static FileMgr * getSystemFileMgr()
Definition: filemgr.cpp:101
virtual SWDEPRECATED signed char SWMgr::Load ( )
inlinevirtual
Deprecated:
Use load

Definition at line 426 of file swmgr.h.

426 { return load(); }
virtual signed char load()
Definition: swmgr.cpp:837
signed char SWMgr::load ( )
virtual

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. This includes discovery of config path with SWMgr::fileconfig, loading of composite SWMgr::config, and construction of all modules from config using SWMgr::createAllModules

Definition at line 837 of file swmgr.cpp.

837  {
838  signed char ret = 0;
839 
840  if (!config) { // If we weren't passed a config object at construction, find a config file
841  if (!configPath) { // If we weren't passed a config path at construction...
842  SWLOGTI("LOOKING UP MODULE CONFIGURATION...");
843  SWConfig *externalSysConf = sysConfig; // if we have a sysConf before findConfig, then we were provided one from an external source.
845  if (!externalSysConf) mysysconfig = sysConfig; // remind us to delete our own sysConfig in d-tor
846  SWLOGTI("LOOKING UP MODULE CONFIGURATION COMPLETE.");
847  }
848  if (configPath) {
849  SWLOGTI("LOADING MODULE CONFIGURATIONS...");
850  if (configType)
852  else config = myconfig = new SWConfig(configPath);
853  SWLOGTI("LOADING MODULE CONFIGURATIONS COMPLETE.");
854  }
855  }
856 
857  if (config) {
858 
859  SWLOGTI("LOADING MODULE LIBRARY...");
860 
861  SectionMap::iterator Sectloop, Sectend;
862  ConfigEntMap::iterator Entryloop, Entryend;
863 
865 
866  for (Sectloop = config->getSections().lower_bound("Globals"), Sectend = config->getSections().upper_bound("Globals"); Sectloop != Sectend; Sectloop++) { // scan thru all 'Globals' sections
867  for (Entryloop = (*Sectloop).second.lower_bound("AutoInstall"), Entryend = (*Sectloop).second.upper_bound("AutoInstall"); Entryloop != Entryend; Entryloop++) // scan thru all AutoInstall entries
868  InstallScan((*Entryloop).second.c_str()); // Scan AutoInstall entry directory for new modules and install
869  }
870  if (configType) { // force reload on config object because we may have installed new modules
871  delete myconfig;
872  config = myconfig = 0;
874  }
875  else config->load();
876 
878 
879  for (std::list<SWBuf>::iterator pathIt = augPaths.begin(); pathIt != augPaths.end(); pathIt++) {
880  augmentModules(pathIt->c_str(), mgrModeMultiMod);
881  }
882  if (augmentHome) {
883  // augment config with ~/.sword/mods.d if it exists ---------------------
885  if (homeDir.length() && configType != 2) { // 2 = user only
886  SWBuf path = homeDir;
887  path += ".sword/";
889  path = homeDir;
890  path += "sword/";
891  augmentModules(path.c_str(), mgrModeMultiMod);
892  }
893  }
894 // -------------------------------------------------------------------------
895  if (!getModules().size()) // config exists, but no modules
896  ret = 1;
897 
898  SWLOGTI("LOADING MODULE LIBRARY COMPLETE.");
899  }
900  else {
901  SWLog::getSystemLog()->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>");
902  ret = -1;
903  }
904 
905  return ret;
906 }
virtual void deleteAllModules()
Definition: swmgr.cpp:1519
virtual void InstallScan(const char *dir)
Definition: swmgr.cpp:1331
virtual void load()
Definition: swconfig.cpp:55
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
virtual SectionMap & getSections()
Definition: swconfig.cpp:186
char configType
Definition: swmgr.h:113
static SWLog * getSystemLog()
Definition: swlog.cpp:53
char * prefixPath
Definition: swmgr.h:312
ModMap & getModules()
Definition: swmgr.cpp:1574
virtual void augmentModules(const char *path, bool multiMod=false)
Definition: swmgr.cpp:776
SWConfig * config
Definition: swmgr.h:302
const char * c_str() const
Definition: swbuf.h:158
bool mgrModeMultiMod
Definition: swmgr.h:96
StringList augPaths
Definition: swmgr.h:266
SWConfig * myconfig
Definition: swmgr.h:102
SWConfig * sysConfig
Definition: swmgr.h:308
static void findConfig(char *configType, char **prefixPath, char **configPath, StringList *augPaths=0, SWConfig **providedSysConf=0)
Definition: swmgr.cpp:449
void logError(const char *fmt,...) const
Definition: swlog.cpp:87
#define SWLOGTI(...)
Definition: defs.h:194
reg_syntax_t ret
Definition: regex.c:1351
virtual void loadConfigDir(const char *ipath)
Definition: swmgr.cpp:747
SWConfig * mysysconfig
Definition: swmgr.h:103
virtual void createAllModules(bool multiMod=false)
Definition: swmgr.cpp:1456
bool augmentHome
Definition: swmgr.h:97
SWBuf getHomeDir()
Definition: filemgr.cpp:681
char * configPath
Definition: swmgr.h:316
static FileMgr * getSystemFileMgr()
Definition: filemgr.cpp:101
void SWMgr::loadConfigDir ( const char *  ipath)
protectedvirtual

Definition at line 747 of file swmgr.cpp.

748 {
749  SWBuf basePath = ipath;
750  if (!basePath.endsWith("/") && !basePath.endsWith("\\")) basePath += "/";
751 
752  SWBuf newModFile;
753 
754  std::vector<DirEntry> dirList = FileMgr::getDirList(ipath);
755  for (unsigned int i = 0; i < dirList.size(); ++i) {
756  //check whether it ends with .conf, if it doesn't skip it!
757  if (!dirList[i].name.endsWith(".conf")) {
758  continue;
759  }
760 
761  newModFile = basePath + dirList[i].name;
762  if (config) {
763  SWConfig tmpConfig(newModFile);
764  config->augment(tmpConfig);
765  }
766  else config = myconfig = new SWConfig(newModFile);
767  }
768 
769  if (!config) { // if no .conf file exist yet, create a default
770  newModFile = basePath + "globals.conf";
771  config = myconfig = new SWConfig(newModFile);
772  }
773 }
Definition: swbuf.h:47
bool endsWith(const SWBuf &postfix) const
Definition: swbuf.h:501
SWConfig * config
Definition: swmgr.h:302
virtual void augment(const SWConfig &addFrom)
Definition: swconfig.cpp:148
SWConfig * myconfig
Definition: swmgr.h:102
static std::vector< struct DirEntry > getDirList(const char *dirPath, bool includeSize=false, bool includeIsDirectory=true)
Definition: filemgr.cpp:379
signed char SWMgr::setCipherKey ( const char *  modName,
const char *  key 
)
virtual

Sets the cipher key for the given module. This function updates the key at runtime, but it does not write to the config file. 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:

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
}

The above convention is preferred to using this setCipherKey method

Parameters
modNameFor this module we change the unlockKey
keyThis is the new unlock key we use for the module.

Definition at line 1550 of file swmgr.cpp.

1550  {
1551  FilterMap::iterator it;
1552 
1553  // check for filter that already exists
1554  it = cipherFilters.find(modName);
1555  if (it != cipherFilters.end()) {
1556  ((CipherFilter *)(*it).second)->getCipher()->setCipherKey(key);
1557  return 0;
1558  }
1559  // check if module exists
1560  else {
1561  SWModule *mod = getModule(modName);
1562  if (mod) {
1563  SWFilter *cipherFilter = new CipherFilter(key);
1564  cipherFilters.insert(FilterMap::value_type(modName, cipherFilter));
1565  cleanupFilters.push_back(cipherFilter);
1566  mod->addRawFilter(cipherFilter);
1567  return 0;
1568  }
1569  }
1570  return -1;
1571 }
SWModule * getModule(const char *modName)
Definition: swmgr.h:360
FilterMap cipherFilters
Definition: swmgr.h:115
FilterList cleanupFilters
Definition: swmgr.h:121
virtual SWModule & addRawFilter(SWFilter *newFilter)
Definition: swmodule.h:694
void SWMgr::setGlobalOption ( const char *  option,
const char *  value 
)
virtual

Change the values of global options (e.g. Footnotes, Strong's Number, etc.)

Parameters
optionThe name of the option, for which you want to change the value. Well known and often used values are "Footnotes" or "Strong's Numbers"
valuenew value. Common values are "On" and "Off"

Definition at line 1392 of file swmgr.cpp.

1393 {
1394  for (OptionFilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
1395  if ((*it).second->getOptionName()) {
1396  if (!stricmp(option, (*it).second->getOptionName()))
1397  (*it).second->setOptionValue(value);
1398  }
1399  }
1400 }
int stricmp(const char *s1, const char *s2)
Definition: utilstr.cpp:194
OptionFilterMap optionFilters
Definition: swmgr.h:114

Member Data Documentation

bool SWMgr::augmentHome
private

Definition at line 97 of file swmgr.h.

StringList SWMgr::augPaths
protected

Definition at line 266 of file swmgr.h.

FilterMap SWMgr::cipherFilters
protected

Definition at line 115 of file swmgr.h.

FilterList SWMgr::cleanupFilters
protected

Definition at line 121 of file swmgr.h.

SWConfig* SWMgr::config

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]

Definition at line 302 of file swmgr.h.

char* SWMgr::configPath

path to main module set configuration

Definition at line 316 of file swmgr.h.

char SWMgr::configType
protected

Definition at line 113 of file swmgr.h.

FilterMap SWMgr::extraFilters
protected

Definition at line 122 of file swmgr.h.

SWFilterMgr* SWMgr::filterMgr
protected

Definition at line 101 of file swmgr.h.

SWFilter* SWMgr::gbfplain
protected

Definition at line 116 of file swmgr.h.

const char * SWMgr::globalConfPath = "/etc/sword.conf:/usr/local/etc/sword.conf"
static

Definition at line 281 of file swmgr.h.

SWConfig* SWMgr::homeConfig
protected

Definition at line 104 of file swmgr.h.

SWORD_NAMESPACE_START bool SWMgr::isICU = false
static

Definition at line 280 of file swmgr.h.

bool SWMgr::mgrModeMultiMod
private

Definition at line 96 of file swmgr.h.

const char * SWMgr::MODTYPE_BIBLES = "Biblical Texts"
static

Definition at line 273 of file swmgr.h.

const char * SWMgr::MODTYPE_COMMENTARIES = "Commentaries"
static

Definition at line 274 of file swmgr.h.

const char * SWMgr::MODTYPE_DAILYDEVOS = "Daily Devotional"
static

Definition at line 277 of file swmgr.h.

const char * SWMgr::MODTYPE_GENBOOKS = "Generic Books"
static

Definition at line 276 of file swmgr.h.

const char * SWMgr::MODTYPE_LEXDICTS = "Lexicons / Dictionaries"
static

Definition at line 275 of file swmgr.h.

ModMap SWMgr::Modules

Deprecated. Use getModules instead.

Definition at line 322 of file swmgr.h.

SWConfig* SWMgr::myconfig
protected

Definition at line 102 of file swmgr.h.

SWConfig* SWMgr::mysysconfig
protected

Definition at line 103 of file swmgr.h.

OptionFilterMap SWMgr::optionFilters
protected

Definition at line 114 of file swmgr.h.

StringList SWMgr::options
protected

Definition at line 123 of file swmgr.h.

SWFilter* SWMgr::osisplain
protected

Definition at line 118 of file swmgr.h.

char* SWMgr::prefixPath

The path to main module set and locales

Definition at line 312 of file swmgr.h.

SWConfig* SWMgr::sysConfig

The configuration file for SWORD e.g., /etc/sword.conf

Definition at line 308 of file swmgr.h.

SWFilter* SWMgr::teiplain
protected

Definition at line 119 of file swmgr.h.

SWFilter* SWMgr::thmlplain
protected

Definition at line 117 of file swmgr.h.

SWOptionFilter* SWMgr::transliterator
protected

Definition at line 120 of file swmgr.h.

ModMap SWMgr::utilModules
private

Definition at line 95 of file swmgr.h.


The documentation for this class was generated from the following files: