#include <swmgr.h>

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) |
| const SWModule * | getModule (const char *modName) const |
| SWModule * | getModule (const char *modName) |
| virtual void | InstallScan (const char *dir) |
| virtual signed char | Load () |
| virtual signed char | setCipherKey (const char *modName, const char *key) |
| virtual void | setGlobalOption (const char *option, const char *value) |
| SWMgr (const char *iConfigPath, bool autoload=true, SWFilterMgr *filterMgr=0, bool multiMod=false, bool augmentHome=true) | |
| SWMgr (SWFilterMgr *filterMgr, bool multiMod=false) | |
| SWMgr (SWConfig *iconfig=0, SWConfig *isysconfig=0, bool autoload=true, SWFilterMgr *filterMgr=0, bool multiMod=false) | |
| virtual | ~SWMgr () |
Static Public Member Functions | |
| static void | findConfig (char *configType, char **prefixPath, char **configPath, StringList *augPaths=0, SWConfig **providedSysConf=0) |
| static SWBuf | getHomeDir () |
Public Attributes | |
| SWConfig * | config |
| char * | configPath |
| ModMap | Modules |
| char * | prefixPath |
| SWConfig * | sysConfig |
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 void | AddEncodingFilters (SWModule *module, ConfigEntMap §ion) |
| 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) |
| virtual char | AddModToConfig (FileDesc *conffd, const char *fname) |
| virtual void | AddRawFilters (SWModule *module, ConfigEntMap §ion) |
| virtual void | AddRenderFilters (SWModule *module, ConfigEntMap §ion) |
| virtual void | AddStripFilters (SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end) |
| virtual void | AddStripFilters (SWModule *module, ConfigEntMap §ion) |
| void | CreateMods (bool multiMod=false) |
| virtual SWModule * | createModule (const char *name, const char *driver, ConfigEntMap §ion) |
| void | DeleteMods () |
| virtual void | init () |
| virtual void | loadConfigDir (const char *ipath) |
Protected Attributes | |
| StringList | augPaths |
| FilterMap | cipherFilters |
| FilterList | cleanupFilters |
| char | configType |
| FilterMap | extraFilters |
| SWFilterMgr * | filterMgr |
| SWFilter * | gbfplain |
| SWConfig * | homeConfig |
| SWConfig * | myconfig |
| SWConfig * | mysysconfig |
| OptionFilterMap | optionFilters |
| StringList | options |
| SWFilter * | osisplain |
| SWFilter * | teiplain |
| SWFilter * | thmlplain |
| SWOptionFilter * | transliterator |
Private Member Functions | |
| void | commonInit (SWConfig *iconfig, SWConfig *isysconfig, bool autoload, SWFilterMgr *filterMgr, bool multiMod=false) |
Private Attributes | |
| bool | augmentHome |
| bool | mgrModeMultiMod |
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.
Definition at line 89 of file swmgr.h.
| SWMgr::SWMgr | ( | SWConfig * | iconfig = 0, |
|
| SWConfig * | isysconfig = 0, |
|||
| bool | autoload = true, |
|||
| SWFilterMgr * | filterMgr = 0, |
|||
| bool | multiMod = false | |||
| ) |
Constructs an instance of SWMgr
| iconfig | manually supply a configuration. If not supplied, SWMgr will look on the system using a complex hierarchical search. See README for detailed specifics. | |
| isysconfig | ||
| 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 completed the contruction and setup of your SWMgr subclass. | |
| filterMgr | an 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 318 of file swmgr.cpp.
00318 { 00319 commonInit(iconfig, isysconfig, autoload, filterMgr, multiMod); 00320 }
| SWMgr::SWMgr | ( | SWFilterMgr * | filterMgr, | |
| bool | multiMod = false | |||
| ) |
Definition at line 313 of file swmgr.cpp.
00313 { 00314 commonInit(0, 0, true, filterMgr, multiMod); 00315 }
| SWMgr::SWMgr | ( | const char * | iConfigPath, | |
| bool | autoload = true, |
|||
| SWFilterMgr * | filterMgr = 0, |
|||
| bool | multiMod = false, |
|||
| bool | augmentHome = true | |||
| ) |
| iConfigPath | provide a custom path to use for module set location, instead of searching the system for it. |
Definition at line 323 of file swmgr.cpp.
00323 { 00324 00325 init(); 00326 00327 mgrModeMultiMod = multiMod; 00328 SWBuf path; 00329 00330 this->filterMgr = filterMgr; 00331 if (filterMgr) 00332 filterMgr->setParentMgr(this); 00333 00334 this->augmentHome = augmentHome; 00335 00336 path = iConfigPath; 00337 int len = path.length(); 00338 if ((len < 1) || ((iConfigPath[len-1] != '\\') && (iConfigPath[len-1] != '/'))) 00339 path += "/"; 00340 if (FileMgr::existsFile(path.c_str(), "mods.conf")) { 00341 stdstr(&prefixPath, path.c_str()); 00342 path += "mods.conf"; 00343 stdstr(&configPath, path.c_str()); 00344 } 00345 else { 00346 if (FileMgr::existsDir(path.c_str(), "mods.d")) { 00347 stdstr(&prefixPath, path.c_str()); 00348 path += "mods.d"; 00349 stdstr(&configPath, path.c_str()); 00350 configType = 1; 00351 } 00352 } 00353 00354 config = 0; 00355 sysConfig = 0; 00356 00357 if (autoload && configPath) 00358 Load(); 00359 }
| 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 362 of file swmgr.cpp.
00362 { 00363 00364 DeleteMods(); 00365 00366 for (FilterList::iterator it = cleanupFilters.begin(); it != cleanupFilters.end(); it++) 00367 delete (*it); 00368 00369 if (homeConfig) 00370 delete homeConfig; 00371 00372 if (mysysconfig) 00373 delete mysysconfig; 00374 00375 if (myconfig) 00376 delete myconfig; 00377 00378 if (prefixPath) 00379 delete [] prefixPath; 00380 00381 if (configPath) 00382 delete [] configPath; 00383 00384 if (filterMgr) 00385 delete filterMgr; 00386 }
| void SWMgr::AddEncodingFilters | ( | SWModule * | module, | |
| ConfigEntMap & | section | |||
| ) | [protected, virtual] |
Called to add appropriate Encoding Filters to a module. Override to do special actions, if desired. See the module.conf Encoding= entry.
| module | module to which to add Encoding Filters | |
| section | configuration information from module.conf |
Definition at line 1130 of file swmgr.cpp.
01130 { 01131 if (filterMgr) 01132 filterMgr->AddEncodingFilters(module, section); 01133 }
| void SWMgr::AddGlobalOptions | ( | SWModule * | module, | |
| ConfigEntMap & | section, | |||
| ConfigEntMap::iterator | start, | |||
| ConfigEntMap::iterator | end | |||
| ) | [protected, virtual] |
Definition at line 1038 of file swmgr.cpp.
01038 { 01039 for (;start != end; start++) { 01040 OptionFilterMap::iterator it; 01041 it = optionFilters.find((*start).second); 01042 if (it != optionFilters.end()) { 01043 module->addOptionFilter((*it).second); // add filter to module and option as a valid option 01044 StringList::iterator loop; 01045 for (loop = options.begin(); loop != options.end(); loop++) { 01046 if (!strcmp((*loop).c_str(), (*it).second->getOptionName())) 01047 break; 01048 } 01049 if (loop == options.end()) // if we have not yet included the option 01050 options.push_back((*it).second->getOptionName()); 01051 } 01052 } 01053 if (filterMgr) 01054 filterMgr->AddGlobalOptions(module, section, start, end); 01055 #ifdef _ICU_ 01056 module->addOptionFilter(transliterator); 01057 #endif 01058 }
| void SWMgr::AddLocalOptions | ( | SWModule * | module, | |
| ConfigEntMap & | section, | |||
| ConfigEntMap::iterator | start, | |||
| ConfigEntMap::iterator | end | |||
| ) | [protected, virtual] |
Definition at line 1085 of file swmgr.cpp.
01086 { 01087 for (;start != end; start++) { 01088 OptionFilterMap::iterator it; 01089 it = optionFilters.find((*start).second); 01090 if (it != optionFilters.end()) { 01091 module->addOptionFilter((*it).second); // add filter to module 01092 } 01093 } 01094 01095 if (filterMgr) 01096 filterMgr->AddLocalOptions(module, section, start, end); 01097 }
| char SWMgr::AddModToConfig | ( | FileDesc * | conffd, | |
| const char * | fname | |||
| ) | [protected, virtual] |
Definition at line 1323 of file swmgr.cpp.
01324 { 01325 FileDesc *modfd; 01326 char ch; 01327 01328 SWLog::getSystemLog()->logTimedInformation("Found new module [%s]. Installing...", fname); 01329 modfd = FileMgr::getSystemFileMgr()->open(fname, FileMgr::RDONLY); 01330 ch = '\n'; 01331 conffd->write(&ch, 1); 01332 while (modfd->read(&ch, 1) == 1) 01333 conffd->write(&ch, 1); 01334 ch = '\n'; 01335 conffd->write(&ch, 1); 01336 FileMgr::getSystemFileMgr()->close(modfd); 01337 return 0; 01338 }
| void SWMgr::AddRawFilters | ( | SWModule * | module, | |
| ConfigEntMap & | section | |||
| ) | [protected, virtual] |
Called to add appropriate Raw Filters to a module. Override to do special actions, if desired. See the module.conf CipherKey= entry.
| module | module to which to add Raw Filters | |
| section | configuration information from module.conf |
Definition at line 1113 of file swmgr.cpp.
01113 { 01114 SWBuf sourceformat, cipherKey; 01115 ConfigEntMap::iterator entry; 01116 01117 cipherKey = ((entry = section.find("CipherKey")) != section.end()) ? (*entry).second : (SWBuf)""; 01118 if (cipherKey.length()) { 01119 SWFilter *cipherFilter = new CipherFilter(cipherKey.c_str()); 01120 cipherFilters.insert(FilterMap::value_type(module->getName(), cipherFilter)); 01121 cleanupFilters.push_back(cipherFilter); 01122 module->addRawFilter(cipherFilter); 01123 } 01124 01125 if (filterMgr) 01126 filterMgr->AddRawFilters(module, section); 01127 }
| void SWMgr::AddRenderFilters | ( | SWModule * | module, | |
| ConfigEntMap & | section | |||
| ) | [protected, virtual] |
Called to add appropriate Render Filters to a module. Override to do special actions, if desired. See the module.conf SourceType= entry.
| module | module to which to add Render Filters | |
| section | configuration information from module.conf |
Definition at line 1136 of file swmgr.cpp.
01136 { 01137 SWBuf sourceformat; 01138 ConfigEntMap::iterator entry; 01139 01140 sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (SWBuf)""; 01141 01142 // Temporary: To support old module types 01143 // TODO: Remove at 1.6.0 release? 01144 if (!sourceformat.length()) { 01145 sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)""; 01146 if (!stricmp(sourceformat.c_str(), "RawGBF")) 01147 sourceformat = "GBF"; 01148 else sourceformat = ""; 01149 } 01150 01151 // process module - eg. follows 01152 // if (!stricmp(sourceformat.c_str(), "GBF")) { 01153 // module->AddRenderFilter(gbftortf); 01154 // } 01155 01156 if (filterMgr) 01157 filterMgr->AddRenderFilters(module, section); 01158 01159 }
| void SWMgr::AddStripFilters | ( | SWModule * | module, | |
| ConfigEntMap & | section, | |||
| ConfigEntMap::iterator | start, | |||
| ConfigEntMap::iterator | end | |||
| ) | [protected, virtual] |
Definition at line 1101 of file swmgr.cpp.
01102 { 01103 for (;start != end; start++) { 01104 OptionFilterMap::iterator it; 01105 it = optionFilters.find((*start).second); 01106 if (it != optionFilters.end()) { 01107 module->addStripFilter((*it).second); // add filter to module 01108 } 01109 } 01110 }
| void SWMgr::AddStripFilters | ( | SWModule * | module, | |
| ConfigEntMap & | section | |||
| ) | [protected, virtual] |
Called to add appropriate Strip Filters to a module. Override to do special actions, if desired. See the module.conf SourceType= entry.
| module | module to which to add Strip Filters | |
| section | configuration information from module.conf |
Definition at line 1162 of file swmgr.cpp.
01163 { 01164 SWBuf sourceformat; 01165 ConfigEntMap::iterator entry; 01166 01167 sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (SWBuf)""; 01168 // Temporary: To support old module types 01169 if (!sourceformat.length()) { 01170 sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)""; 01171 if (!stricmp(sourceformat.c_str(), "RawGBF")) 01172 sourceformat = "GBF"; 01173 else sourceformat = ""; 01174 } 01175 01176 if (!stricmp(sourceformat.c_str(), "GBF")) { 01177 module->addStripFilter(gbfplain); 01178 } 01179 else if (!stricmp(sourceformat.c_str(), "ThML")) { 01180 module->addStripFilter(thmlplain); 01181 } 01182 else if (!stricmp(sourceformat.c_str(), "OSIS")) { 01183 module->addStripFilter(osisplain); 01184 } 01185 else if (!stricmp(sourceformat.c_str(), "TEI")) { 01186 module->addStripFilter(teiplain); 01187 } 01188 01189 if (filterMgr) 01190 filterMgr->AddStripFilters(module, section); 01191 01192 }
| void SWMgr::augmentModules | ( | const char * | path, | |
| bool | multiMod = false | |||
| ) | [virtual] |
Adds books from a new path to the library
| path | the path in which to search for books | |
| multiMod | whether 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 711 of file swmgr.cpp.
00711 { 00712 SWBuf path = ipath; 00713 if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/')) 00714 path += "/"; 00715 if (FileMgr::existsDir(path.c_str(), "mods.d")) { 00716 char *savePrefixPath = 0; 00717 char *saveConfigPath = 0; 00718 SWConfig *saveConfig = 0; 00719 stdstr(&savePrefixPath, prefixPath); 00720 stdstr(&prefixPath, path.c_str()); 00721 path += "mods.d"; 00722 stdstr(&saveConfigPath, configPath); 00723 stdstr(&configPath, path.c_str()); 00724 saveConfig = config; 00725 config = myconfig = 0; 00726 loadConfigDir(configPath); 00727 00728 if (multiMod) { 00729 // fix config's Section names to rename modules which are available more than once 00730 // find out which sections are in both config objects 00731 // inserting all configs first is not good because that overwrites old keys and new modules would share the same config 00732 for (SectionMap::iterator it = config->Sections.begin(); it != config->Sections.end();) { 00733 if (saveConfig->Sections.find( (*it).first ) != saveConfig->Sections.end()) { //if the new section is already present rename it 00734 ConfigEntMap entMap((*it).second); 00735 00736 SWBuf name; 00737 int i = 1; 00738 do { //module name already used? 00739 name.setFormatted("%s_%d", (*it).first.c_str(), i); 00740 i++; 00741 } while (config->Sections.find(name) != config->Sections.end()); 00742 00743 config->Sections.insert(SectionMap::value_type(name, entMap) ); 00744 SectionMap::iterator toErase = it++; 00745 config->Sections.erase(toErase); 00746 } 00747 else ++it; 00748 } 00749 } 00750 00751 CreateMods(multiMod); 00752 00753 stdstr(&prefixPath, savePrefixPath); 00754 delete []savePrefixPath; 00755 stdstr(&configPath, saveConfigPath); 00756 delete []saveConfigPath; 00757 00758 (*saveConfig) += *config; 00759 00760 homeConfig = myconfig; 00761 config = myconfig = saveConfig; 00762 } 00763 }
| void SWMgr::commonInit | ( | SWConfig * | iconfig, | |
| SWConfig * | isysconfig, | |||
| bool | autoload, | |||
| SWFilterMgr * | filterMgr, | |||
| bool | multiMod = false | |||
| ) | [private] |
Definition at line 288 of file swmgr.cpp.
00288 { 00289 00290 init(); 00291 00292 mgrModeMultiMod = multiMod; 00293 this->filterMgr = filterMgr; 00294 if (filterMgr) 00295 filterMgr->setParentMgr(this); 00296 00297 if (iconfig) { 00298 config = iconfig; 00299 myconfig = 0; 00300 } 00301 else config = 0; 00302 if (isysconfig) { 00303 sysConfig = isysconfig; 00304 mysysconfig = 0; 00305 } 00306 else sysConfig = 0; 00307 00308 if (autoload) 00309 Load(); 00310 }
| void SWMgr::CreateMods | ( | bool | multiMod = false |
) | [protected] |
Definition at line 1195 of file swmgr.cpp.
01195 { 01196 SectionMap::iterator it; 01197 ConfigEntMap::iterator start; 01198 ConfigEntMap::iterator end; 01199 ConfigEntMap::iterator entry; 01200 SWModule *newmod; 01201 SWBuf driver, misc1; 01202 for (it = config->Sections.begin(); it != config->Sections.end(); it++) { 01203 ConfigEntMap §ion = (*it).second; 01204 newmod = 0; 01205 01206 driver = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)""; 01207 if (driver.length()) { 01208 newmod = createModule((*it).first, driver, section); 01209 if (newmod) { 01210 // Filters to add for this module and globally announce as an option to the user 01211 // e.g. translit, strongs, redletterwords, etc, so users can turn these on and off globally 01212 start = (*it).second.lower_bound("GlobalOptionFilter"); 01213 end = (*it).second.upper_bound("GlobalOptionFilter"); 01214 AddGlobalOptions(newmod, section, start, end); 01215 01216 // Only add the option to the module, don't announce it's availability 01217 // These are useful for like: filters that parse special entryAttribs in a text 01218 // or whatever you might want to happen on entry lookup 01219 start = (*it).second.lower_bound("LocalOptionFilter"); 01220 end = (*it).second.upper_bound("LocalOptionFilter"); 01221 AddLocalOptions(newmod, section, start, end); 01222 01223 //STRIP FILTERS 01224 01225 // add all basic ones for for the modtype 01226 AddStripFilters(newmod, section); 01227 01228 // Any special processing for this module when searching: 01229 // e.g. for papyri, removed all [](). notation 01230 start = (*it).second.lower_bound("LocalStripFilter"); 01231 end = (*it).second.upper_bound("LocalStripFilter"); 01232 AddStripFilters(newmod, section, start, end); 01233 01234 AddRawFilters(newmod, section); 01235 AddRenderFilters(newmod, section); 01236 AddEncodingFilters(newmod, section); 01237 01238 SWModule *oldmod = Modules[newmod->getName()]; 01239 if (oldmod) { 01240 delete oldmod; 01241 } 01242 01243 Modules[newmod->getName()] = newmod; 01244 } 01245 } 01246 } 01247 }
| SWModule * SWMgr::createModule | ( | const char * | name, | |
| const char * | driver, | |||
| ConfigEntMap & | section | |||
| ) | [protected, virtual] |
Definition at line 838 of file swmgr.cpp.
00839 { 00840 SWBuf description, datapath, misc1; 00841 ConfigEntMap::iterator entry; 00842 SWModule *newmod = 0; 00843 SWBuf lang, sourceformat, encoding; 00844 signed char direction, enc, markup; 00845 00846 description = ((entry = section.find("Description")) != section.end()) ? (*entry).second : (SWBuf)""; 00847 lang = ((entry = section.find("Lang")) != section.end()) ? (*entry).second : (SWBuf)"en"; 00848 sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (SWBuf)""; 00849 encoding = ((entry = section.find("Encoding")) != section.end()) ? (*entry).second : (SWBuf)""; 00850 datapath = prefixPath; 00851 if ((prefixPath[strlen(prefixPath)-1] != '\\') && (prefixPath[strlen(prefixPath)-1] != '/')) 00852 datapath += "/"; 00853 00854 SWBuf versification = ((entry = section.find("Versification")) != section.end()) ? (*entry).second : (SWBuf)"KJV"; 00855 00856 // DataPath - relative path to data used by module driver. May be a directory, may be a File. 00857 // Typically not useful by outside world. See AbsoluteDataPath, PrefixPath, and RelativePrefixPath 00858 // below. 00859 misc1 += ((entry = section.find("DataPath")) != section.end()) ? (*entry).second : (SWBuf)""; 00860 char *buf = new char [ strlen(misc1.c_str()) + 1 ]; 00861 char *buf2 = buf; 00862 strcpy(buf, misc1.c_str()); 00863 // for (; ((*buf2) && ((*buf2 == '.') || (*buf2 == '/') || (*buf2 == '\\'))); buf2++); 00864 for (; ((*buf2) && ((*buf2 == '/') || (*buf2 == '\\'))); buf2++); 00865 if (!strncmp(buf2, "./", 2)) { //remove the leading ./ in the module data path to make it look better 00866 buf2 += 2; 00867 } 00868 // PrefixPath - absolute directory path to the repository in which this module was found 00869 section["PrefixPath"] = datapath; 00870 if (*buf2) 00871 datapath += buf2; 00872 delete [] buf; 00873 00874 section["AbsoluteDataPath"] = datapath; 00875 00876 if (!stricmp(sourceformat.c_str(), "GBF")) 00877 markup = FMT_GBF; 00878 else if (!stricmp(sourceformat.c_str(), "ThML")) 00879 markup = FMT_THML; 00880 else if (!stricmp(sourceformat.c_str(), "OSIS")) 00881 markup = FMT_OSIS; 00882 else if (!stricmp(sourceformat.c_str(), "TEI")) 00883 markup = FMT_TEI; 00884 else 00885 markup = FMT_GBF; 00886 00887 if (!stricmp(encoding.c_str(), "UTF-8")) { 00888 enc = ENC_UTF8; 00889 } 00890 else enc = ENC_LATIN1; 00891 00892 if ((entry = section.find("Direction")) == section.end()) { 00893 direction = DIRECTION_LTR; 00894 } 00895 else if (!stricmp((*entry).second.c_str(), "rtol")) { 00896 direction = DIRECTION_RTL; 00897 } 00898 else if (!stricmp((*entry).second.c_str(), "bidi")) { 00899 direction = DIRECTION_BIDI; 00900 } 00901 else { 00902 direction = DIRECTION_LTR; 00903 } 00904 00905 if ((!stricmp(driver, "zText")) || (!stricmp(driver, "zCom"))) { 00906 SWCompress *compress = 0; 00907 int blockType = CHAPTERBLOCKS; 00908 misc1 = ((entry = section.find("BlockType")) != section.end()) ? (*entry).second : (SWBuf)"CHAPTER"; 00909 if (!stricmp(misc1.c_str(), "VERSE")) 00910 blockType = VERSEBLOCKS; 00911 else if (!stricmp(misc1.c_str(), "CHAPTER")) 00912 blockType = CHAPTERBLOCKS; 00913 else if (!stricmp(misc1.c_str(), "BOOK")) 00914 blockType = BOOKBLOCKS; 00915 00916 misc1 = ((entry = section.find("CompressType")) != section.end()) ? (*entry).second : (SWBuf)"LZSS"; 00917 #ifndef EXCLUDEZLIB 00918 if (!stricmp(misc1.c_str(), "ZIP")) 00919 compress = new ZipCompress(); 00920 else 00921 #endif 00922 if (!stricmp(misc1.c_str(), "LZSS")) 00923 compress = new LZSSCompress(); 00924 00925 if (compress) { 00926 if (!stricmp(driver, "zText")) 00927 newmod = new zText(datapath.c_str(), name, description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str(), versification); 00928 else newmod = new zCom(datapath.c_str(), name, description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str(), versification); 00929 } 00930 } 00931 00932 if (!stricmp(driver, "RawText")) { 00933 newmod = new RawText(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), versification); 00934 } 00935 00936 if (!stricmp(driver, "RawText4")) { 00937 newmod = new RawText4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), versification); 00938 } 00939 00940 // backward support old drivers 00941 if (!stricmp(driver, "RawGBF")) { 00942 newmod = new RawText(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str()); 00943 } 00944 00945 if (!stricmp(driver, "RawCom")) { 00946 newmod = new RawCom(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), versification); 00947 } 00948 00949 if (!stricmp(driver, "RawCom4")) { 00950 newmod = new RawCom4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), versification); 00951 } 00952 00953 if (!stricmp(driver, "RawFiles")) { 00954 newmod = new RawFiles(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str()); 00955 } 00956 00957 if (!stricmp(driver, "HREFCom")) { 00958 misc1 = ((entry = section.find("Prefix")) != section.end()) ? (*entry).second : (SWBuf)""; 00959 newmod = new HREFCom(datapath.c_str(), misc1.c_str(), name, description.c_str()); 00960 } 00961 00962 int pos = 0; //used for position of final / in AbsoluteDataPath, but also set to 1 for modules types that need to strip module name 00963 if (!stricmp(driver, "RawLD")) { 00964 bool caseSensitive = ((entry = section.find("CaseSensitiveKeys")) != section.end()) ? (*entry).second == "true": false; 00965 bool strongsPadding = ((entry = section.find("StrongsPadding")) != section.end()) ? (*entry).second == "true": true; 00966 newmod = new RawLD(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), caseSensitive, strongsPadding); 00967 pos = 1; 00968 } 00969 00970 if (!stricmp(driver, "RawLD4")) { 00971 bool caseSensitive = ((entry = section.find("CaseSensitiveKeys")) != section.end()) ? (*entry).second == "true": false; 00972 bool strongsPadding = ((entry = section.find("StrongsPadding")) != section.end()) ? (*entry).second == "true": true; 00973 newmod = new RawLD4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), caseSensitive, strongsPadding); 00974 pos = 1; 00975 } 00976 00977 if (!stricmp(driver, "zLD")) { 00978 SWCompress *compress = 0; 00979 int blockCount; 00980 bool caseSensitive = ((entry = section.find("CaseSensitiveKeys")) != section.end()) ? (*entry).second == "true": false; 00981 bool strongsPadding = ((entry = section.find("StrongsPadding")) != section.end()) ? (*entry).second == "true": true; 00982 misc1 = ((entry = section.find("BlockCount")) != section.end()) ? (*entry).second : (SWBuf)"200"; 00983 blockCount = atoi(misc1.c_str()); 00984 blockCount = (blockCount) ? blockCount : 200; 00985 00986 misc1 = ((entry = section.find("CompressType")) != section.end()) ? (*entry).second : (SWBuf)"LZSS"; 00987 #ifndef EXCLUDEZLIB 00988 if (!stricmp(misc1.c_str(), "ZIP")) 00989 compress = new ZipCompress(); 00990 else 00991 #endif 00992 if (!stricmp(misc1.c_str(), "LZSS")) 00993 compress = new LZSSCompress(); 00994 00995 if (compress) { 00996 newmod = new zLD(datapath.c_str(), name, description.c_str(), blockCount, compress, 0, enc, direction, markup, lang.c_str(), caseSensitive, strongsPadding); 00997 } 00998 pos = 1; 00999 } 01000 01001 if (!stricmp(driver, "RawGenBook")) { 01002 misc1 = ((entry = section.find("KeyType")) != section.end()) ? (*entry).second : (SWBuf)"TreeKey"; 01003 newmod = new RawGenBook(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str(), misc1.c_str()); 01004 pos = 1; 01005 } 01006 01007 if (pos == 1) { 01008 SWBuf &dp = section["AbsoluteDataPath"]; 01009 for (int i = dp.length() - 1; i; i--) { 01010 if (dp[i] == '/') { 01011 dp.setSize(i); 01012 break; 01013 } 01014 } 01015 /* 01016 SWBuf &rdp = section["RelativeDataPath"]; 01017 for (int i = rdp.length() - 1; i; i--) { 01018 if (rdp[i] == '/') { 01019 rdp.setSize(i); 01020 break; 01021 } 01022 } 01023 */ 01024 } 01025 01026 if (newmod) { 01027 // if a specific module type is set in the config, use this 01028 if ((entry = section.find("Type")) != section.end()) 01029 newmod->setType(entry->second.c_str()); 01030 01031 newmod->setConfig(§ion); 01032 } 01033 01034 return newmod; 01035 }
| void SWMgr::DeleteMods | ( | ) | [protected] |
| void SWMgr::deleteModule | ( | const char * | modName | ) |
| char SWMgr::filterText | ( | const char * | filterName, | |
| SWBuf & | text, | |||
| const SWKey * | key = 0, |
|||
| const SWModule * | module = 0 | |||
| ) | [virtual] |
Filters a buffer thru a named filter
| filterName | ||
| text | buffer to filter | |
| key | context key if filter needs this for processing | |
| module | context module if filter needs this for processing |
Definition at line 1061 of file swmgr.cpp.
01062 { 01063 char retVal = -1; 01064 // why didn't we use find here? 01065 for (OptionFilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { 01066 if ((*it).second->getOptionName()) { 01067 if (!stricmp(filterName, (*it).second->getOptionName())) { 01068 retVal = it->second->processText(text, key, module); 01069 break; 01070 } 01071 } 01072 } 01073 01074 if (retVal == -1) { 01075 FilterMap::iterator it = extraFilters.find(filterName); 01076 if (it != extraFilters.end()) { 01077 retVal = it->second->processText(text, key, module); 01078 } 01079 } 01080 01081 return retVal; 01082 }
| void SWMgr::findConfig | ( | char * | configType, | |
| char ** | prefixPath, | |||
| char ** | configPath, | |||
| StringList * | augPaths = 0, |
|||
| SWConfig ** | providedSysConf = 0 | |||
| ) | [static] |
Definition at line 389 of file swmgr.cpp.
00389 { 00390 SWBuf path; 00391 SWBuf sysConfPath; 00392 ConfigEntMap::iterator entry; 00393 ConfigEntMap::iterator lastEntry; 00394 00395 SWConfig *sysConf = 0; 00396 SWBuf sysConfDataPath = ""; 00397 00398 *configType = 0; 00399 00400 SWBuf homeDir = getHomeDir(); 00401 00402 // check for a sysConf passed in to us 00403 SWLog::getSystemLog()->logDebug("Checking for provided SWConfig(\"sword.conf\")..."); 00404 if (providedSysConf && *providedSysConf) { 00405 sysConf = *providedSysConf; 00406 SWLog::getSystemLog()->logDebug("found."); 00407 } 00408 00409 // if we haven't been given our datapath in a sysconf, we need to track it down 00410 if (!sysConf) { 00411 // check working directory 00412 SWLog::getSystemLog()->logDebug("Checking working directory for sword.conf..."); 00413 if (FileMgr::existsFile(".", "sword.conf")) { 00414 SWLog::getSystemLog()->logDebug("Overriding any systemwide or ~/.sword/ sword.conf with one found in current directory."); 00415 sysConfPath = "./sword.conf"; 00416 sysConf = new SWConfig(sysConfPath); 00417 if ((entry = sysConf->Sections["Install"].find("DataPath")) != sysConf->Sections["Install"].end()) { 00418 sysConfDataPath = (*entry).second; 00419 } 00420 if (providedSysConf) { 00421 *providedSysConf = sysConf; 00422 } 00423 else { 00424 delete sysConf; 00425 sysConf = 0; 00426 } 00427 } 00428 if (!sysConfDataPath.size()) { 00429 SWLog::getSystemLog()->logDebug("Checking working directory for mods.conf..."); 00430 if (FileMgr::existsFile(".", "mods.conf")) { 00431 SWLog::getSystemLog()->logDebug("found."); 00432 stdstr(prefixPath, "./"); 00433 stdstr(configPath, "./mods.conf"); 00434 return; 00435 } 00436 00437 SWLog::getSystemLog()->logDebug("Checking working directory for mods.d..."); 00438 if (FileMgr::existsDir(".", "mods.d")) { 00439 SWLog::getSystemLog()->logDebug("found."); 00440 stdstr(prefixPath, "./"); 00441 stdstr(configPath, "./mods.d"); 00442 *configType = 1; 00443 return; 00444 } 00445 00446 // check working directory ../library/ 00447 SWLog::getSystemLog()->logDebug("Checking working directory ../library/ for mods.d..."); 00448 if (FileMgr::existsDir("../library", "mods.d")) { 00449 SWLog::getSystemLog()->logDebug("found."); 00450 stdstr(prefixPath, "../library/"); 00451 stdstr(configPath, "../library/mods.d"); 00452 *configType = 1; 00453 return; 00454 } 00455 00456 // check environment variable SWORD_PATH 00457 SWLog::getSystemLog()->logDebug("Checking $SWORD_PATH..."); 00458 00459 SWBuf envsworddir = getenv("SWORD_PATH"); 00460 if (envsworddir.length()) { 00461 00462 SWLog::getSystemLog()->logDebug("found (%s).", envsworddir.c_str()); 00463 path = envsworddir; 00464 if ((envsworddir[envsworddir.length()-1] != '\\') && (envsworddir[envsworddir.length()-1] != '/')) 00465 path += "/"; 00466 00467 SWLog::getSystemLog()->logDebug("Checking $SWORD_PATH for mods.conf..."); 00468 if (FileMgr::existsFile(path.c_str(), "mods.conf")) { 00469 SWLog::getSystemLog()->logDebug("found."); 00470 stdstr(prefixPath, path.c_str()); 00471 path += "mods.conf"; 00472 stdstr(configPath, path.c_str()); 00473 return; 00474 } 00475 00476 SWLog::getSystemLog()->logDebug("Checking $SWORD_PATH for mods.d..."); 00477 if (FileMgr::existsDir(path.c_str(), "mods.d")) { 00478 SWLog::getSystemLog()->logDebug("found."); 00479 stdstr(prefixPath, path.c_str()); 00480 path += "mods.d"; 00481 stdstr(configPath, path.c_str()); 00482 *configType = 1; 00483 return; 00484 } 00485 } 00486 00487 00488 // check for systemwide globalConfPath 00489 00490 SWLog::getSystemLog()->logDebug("Parsing %s...", globalConfPath); 00491 char *globPaths = 0; 00492 char *gfp; 00493 stdstr(&globPaths, globalConfPath); 00494 for (gfp = strtok(globPaths, ":"); gfp; gfp = strtok(0, ":")) { 00495 SWLog::getSystemLog()->logDebug("Checking for %s...", gfp); 00496 if (FileMgr::existsFile(gfp)) { 00497 SWLog::getSystemLog()->logDebug("found."); 00498 break; 00499 } 00500 } 00501 if (gfp) 00502 sysConfPath = gfp; 00503 delete [] globPaths; 00504 00505 if (homeDir.length()) { 00506 SWBuf tryPath = homeDir; 00507 tryPath += ".sword/sword.conf"; 00508 if (FileMgr::existsFile(tryPath)) { 00509 SWLog::getSystemLog()->logDebug("Overriding any systemwide sword.conf with one found in users home directory (%s)", tryPath.c_str()); 00510 sysConfPath = tryPath; 00511 } 00512 else { 00513 SWBuf tryPath = homeDir; 00514 tryPath += "sword/sword.conf"; 00515 if (FileMgr::existsFile(tryPath)) { 00516 SWLog::getSystemLog()->logDebug("Overriding any systemwide sword.conf with one found in users home directory (%s)", tryPath.c_str()); 00517 sysConfPath = tryPath; 00518 } 00519 } 00520 } 00521 } 00522 } 00523 00524 if (!sysConf && sysConfPath.size()) { 00525 sysConf = new SWConfig(sysConfPath); 00526 } 00527 00528 if (sysConf) { 00529 if ((entry = sysConf->Sections["Install"].find("DataPath")) != sysConf->Sections["Install"].end()) { 00530 sysConfDataPath = (*entry).second; 00531 } 00532 if (sysConfDataPath.size()) { 00533 if ((!sysConfDataPath.endsWith("\\")) && (!sysConfDataPath.endsWith("/"))) 00534 sysConfDataPath += "/"; 00535 00536 path = sysConfDataPath; 00537 SWLog::getSystemLog()->logDebug("DataPath in %s is set to %s.", sysConfPath.c_str(), path.c_str()); 00538 SWLog::getSystemLog()->logDebug("Checking for mods.conf in DataPath..."); 00539 00540 if (FileMgr::existsFile(path.c_str(), "mods.conf")) { 00541 SWLog::getSystemLog()->logDebug("found."); 00542 stdstr(prefixPath, path.c_str()); 00543 path += "mods.conf"; 00544 stdstr(configPath, path.c_str()); 00545 *configType = 1; 00546 } 00547 00548 SWLog::getSystemLog()->logDebug("Checking for mods.d in DataPath..."); 00549 00550 if (FileMgr::existsDir(path.c_str(), "mods.d")) { 00551 SWLog::getSystemLog()->logDebug("found."); 00552 stdstr(prefixPath, path.c_str()); 00553 path += "mods.d"; 00554 stdstr(configPath, path.c_str()); 00555 *configType = 1; 00556 } 00557 } 00558 } 00559 00560 // do some extra processing of sysConf if we have one 00561 if (sysConf) { 00562 if (augPaths) { 00563 augPaths->clear(); 00564 entry = sysConf->Sections["Install"].lower_bound("AugmentPath"); 00565 lastEntry = sysConf->Sections["Install"].upper_bound("AugmentPath"); 00566 for (;entry != lastEntry; entry++) { 00567 path = entry->second; 00568 if ((entry->second.c_str()[strlen(entry->second.c_str())-1] != '\\') && (entry->second.c_str()[strlen(entry->second.c_str())-1] != '/')) 00569 path += "/"; 00570 augPaths->push_back(path); 00571 } 00572 } 00573 if (providedSysConf) { 00574 *providedSysConf = sysConf; 00575 } 00576 else delete sysConf; 00577 } 00578 00579 if (*configType) 00580 return; 00581 00582 // WE STILL HAVEN'T FOUND A CONFIGURATION. LET'S LOOK IN SOME OS SPECIFIC 00583 // LOCATIONS 00584 // 00585 // for various flavors of windoze... 00586 // check %ALLUSERSPROFILE%/Application Data/sword/ 00587 00588 SWLog::getSystemLog()->logDebug("Checking $ALLUSERSPROFILE/Application Data/sword/..."); 00589 00590 SWBuf envallusersdir = getenv("ALLUSERSPROFILE"); 00591 if (envallusersdir.length()) { 00592 SWLog::getSystemLog()->logDebug("found (%s).", envallusersdir.c_str()); 00593 path = envallusersdir; 00594 if ((!path.endsWith("\\")) && (!path.endsWith("/"))) 00595 path += "/"; 00596 00597 path += "Application Data/sword/"; 00598 SWLog::getSystemLog()->logDebug("Checking %s for mods.d...", path.c_str()); 00599 if (FileMgr::existsDir(path.c_str(), "mods.d")) { 00600 SWLog::getSystemLog()->logDebug("found."); 00601 stdstr(prefixPath, path.c_str()); 00602 path += "mods.d"; 00603 stdstr(configPath, path.c_str()); 00604 *configType = 1; 00605 return; 00606 } 00607 } 00608 00609 // for Mac OSX... 00610 // check $HOME/Library/Application Support/Sword/ 00611 00612 SWLog::getSystemLog()->logDebug("Checking $HOME/Library/Application Support/Sword/..."); 00613 00614 SWBuf pathCheck = getHomeDir(); 00615 if (pathCheck.length()) { 00616 SWLog::getSystemLog()->logDebug("found (%s).", pathCheck.c_str()); 00617 path = pathCheck; 00618 if ((!path.endsWith("\\")) && (!path.endsWith("/"))) 00619 path += "/"; 00620 00621 SWLog::getSystemLog()->logDebug("Checking %s for mods.d...", path.c_str()); 00622 if (FileMgr::existsDir(path.c_str(), "mods.d")) { 00623 SWLog::getSystemLog()->logDebug("found."); 00624 stdstr(prefixPath, path.c_str()); 00625 path += "mods.d"; 00626 stdstr(configPath, path.c_str()); 00627 *configType = 1; 00628 return; 00629 } 00630 } 00631 00632 // FINALLY CHECK PERSONAL HOME DIRECTORY LOCATIONS 00633 // check ~/.sword/ 00634 00635 SWLog::getSystemLog()->logDebug("Checking home directory for ~/.sword..."); 00636 00637 if (homeDir.length()) { 00638 path = homeDir; 00639 path += ".sword/"; 00640 SWLog::getSystemLog()->logDebug(" Checking for %smods.conf...", path.c_str()); 00641 if (FileMgr::existsFile(path.c_str(), "mods.conf")) { 00642 SWLog::getSystemLog()->logDebug("found."); 00643 stdstr(prefixPath, path.c_str()); 00644 path += "mods.conf"; 00645 stdstr(configPath, path.c_str()); 00646 return; 00647 } 00648 00649 SWLog::getSystemLog()->logDebug(" Checking for %smods.d...", path.c_str()); 00650 if (FileMgr::existsDir(path.c_str(), "mods.d")) { 00651 SWLog::getSystemLog()->logDebug("found."); 00652 stdstr(prefixPath, path.c_str()); 00653 path += "mods.d"; 00654 stdstr(configPath, path.c_str()); 00655 *configType = 2; 00656 return; 00657 } 00658 00659 path = homeDir; 00660 path += "sword/"; 00661 SWLog::getSystemLog()->logDebug(" Checking for %smods.d...", path.c_str()); 00662 if (FileMgr::existsDir(path.c_str(), "mods.d")) { 00663 SWLog::getSystemLog()->logDebug("found."); 00664 stdstr(prefixPath, path.c_str()); 00665 path += "mods.d"; 00666 stdstr(configPath, path.c_str()); 00667 *configType = 2; 00668 return; 00669 } 00670 } 00671 }
| const char * SWMgr::getGlobalOption | ( | const char * | option | ) | [virtual] |
Get the current value of the given option
| option | the name of the option, who's value is desired |
Definition at line 1352 of file swmgr.cpp.
01353 { 01354 for (OptionFilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { 01355 if ((*it).second->getOptionName()) { 01356 if (!stricmp(option, (*it).second->getOptionName())) 01357 return (*it).second->getOptionValue(); 01358 } 01359 } 01360 return 0; 01361 }
| StringList SWMgr::getGlobalOptions | ( | ) | [virtual] |
| const char * SWMgr::getGlobalOptionTip | ( | const char * | option | ) | [virtual] |
Gets a brief description for the given option
| option | the name of the option, who's tip is desired |
Definition at line 1364 of file swmgr.cpp.
01365 { 01366 for (OptionFilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { 01367 if ((*it).second->getOptionName()) { 01368 if (!stricmp(option, (*it).second->getOptionName())) 01369 return (*it).second->getOptionTip(); 01370 } 01371 } 01372 return 0; 01373 }
| StringList SWMgr::getGlobalOptionValues | ( | const char * | option | ) | [virtual] |
Gets a list of legal values to which a specific option may be set
| option | the name of the option, who's legal values are desired |
Definition at line 1382 of file swmgr.cpp.
01383 { 01384 StringList options; 01385 for (OptionFilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { 01386 if ((*it).second->getOptionName()) { 01387 if (!stricmp(option, (*it).second->getOptionName())) { 01388 options = (*it).second->getOptionValues(); 01389 break; // just find the first one. All option filters with the same option name should expect the same values 01390 } 01391 } 01392 } 01393 return options; 01394 }
| SWBuf SWMgr::getHomeDir | ( | ) | [static] |
Definition at line 270 of file swmgr.cpp.
00270 { 00271 00272 // figure out 'home' directory for app data 00273 SWBuf homeDir = getenv("HOME"); 00274 if (!homeDir.length()) { 00275 // silly windows 00276 homeDir = getenv("APPDATA"); 00277 } 00278 if (homeDir.length()) { 00279 if ((homeDir[homeDir.length()-1] != '\\') && (homeDir[homeDir.length()-1] != '/')) { 00280 homeDir += "/"; 00281 } 00282 } 00283 00284 return homeDir; 00285 }
| const SWModule* SWMgr::getModule | ( | const char * | modName | ) | const [inline] |
| SWModule* SWMgr::getModule | ( | const char * | modName | ) | [inline] |
Gets a specific module by name. e.g. SWModule *kjv = myManager.getModule("KJV");
| modName | the name of the module to retrieve |
| void SWMgr::init | ( | ) | [protected, virtual] |
Definition at line 120 of file swmgr.cpp.
00120 { 00121 SWOptionFilter *tmpFilter = 0; 00122 configPath = 0; 00123 prefixPath = 0; 00124 configType = 0; 00125 myconfig = 0; 00126 mysysconfig = 0; 00127 homeConfig = 0; 00128 augmentHome = true; 00129 00130 cipherFilters.clear(); 00131 optionFilters.clear(); 00132 cleanupFilters.clear(); 00133 extraFilters.clear(); 00134 tmpFilter = new ThMLVariants(); 00135 optionFilters.insert(OptionFilterMap::value_type("ThMLVariants", tmpFilter)); 00136 cleanupFilters.push_back(tmpFilter); 00137 00138 tmpFilter = new GBFStrongs(); 00139 optionFilters.insert(OptionFilterMap::value_type("GBFStrongs", tmpFilter)); 00140 cleanupFilters.push_back(tmpFilter); 00141 00142 tmpFilter = new GBFFootnotes(); 00143 optionFilters.insert(OptionFilterMap::value_type("GBFFootnotes", tmpFilter)); 00144 cleanupFilters.push_back(tmpFilter); 00145 00146 tmpFilter = new GBFRedLetterWords(); 00147 optionFilters.insert(OptionFilterMap::value_type("GBFRedLetterWords", tmpFilter)); 00148 cleanupFilters.push_back(tmpFilter); 00149 00150 tmpFilter = new GBFMorph(); 00151 optionFilters.insert(OptionFilterMap::value_type("GBFMorph", tmpFilter)); 00152 cleanupFilters.push_back(tmpFilter); 00153 00154 tmpFilter = new GBFHeadings(); 00155 optionFilters.insert(OptionFilterMap::value_type("GBFHeadings", tmpFilter)); 00156 cleanupFilters.push_back(tmpFilter); 00157 00158 tmpFilter = new OSISHeadings(); 00159 optionFilters.insert(OptionFilterMap::value_type("OSISHeadings", tmpFilter)); 00160 cleanupFilters.push_back(tmpFilter); 00161 00162 tmpFilter = new OSISStrongs(); 00163 optionFilters.insert(OptionFilterMap::value_type("OSISStrongs", tmpFilter)); 00164 cleanupFilters.push_back(tmpFilter); 00165 00166 tmpFilter = new OSISMorph(); 00167 optionFilters.insert(OptionFilterMap::value_type("OSISMorph", tmpFilter)); 00168 cleanupFilters.push_back(tmpFilter); 00169 00170 tmpFilter = new OSISLemma(); 00171 optionFilters.insert(OptionFilterMap::value_type("OSISLemma", tmpFilter)); 00172 cleanupFilters.push_back(tmpFilter); 00173 00174 tmpFilter = new OSISFootnotes(); 00175 optionFilters.insert(OptionFilterMap::value_type("OSISFootnotes", tmpFilter)); 00176 cleanupFilters.push_back(tmpFilter); 00177 00178 tmpFilter = new OSISScripref(); 00179 optionFilters.insert(OptionFilterMap::value_type("OSISScripref", tmpFilter)); 00180 cleanupFilters.push_back(tmpFilter); 00181 00182 tmpFilter = new OSISRedLetterWords(); 00183 optionFilters.insert(OptionFilterMap::value_type("OSISRedLetterWords", tmpFilter)); 00184 cleanupFilters.push_back(tmpFilter); 00185 00186 tmpFilter = new OSISMorphSegmentation(); 00187 optionFilters.insert(OptionFilterMap::value_type("OSISMorphSegmentation", tmpFilter)); 00188 cleanupFilters.push_back(tmpFilter); 00189 00190 tmpFilter = new OSISRuby(); 00191 optionFilters.insert(OptionFilterMap::value_type("OSISRuby", tmpFilter)); 00192 cleanupFilters.push_back(tmpFilter); 00193 00194 tmpFilter = new ThMLStrongs(); 00195 optionFilters.insert(OptionFilterMap::value_type("ThMLStrongs", tmpFilter)); 00196 cleanupFilters.push_back(tmpFilter); 00197 00198 tmpFilter = new ThMLFootnotes(); 00199 optionFilters.insert(OptionFilterMap::value_type("ThMLFootnotes", tmpFilter)); 00200 cleanupFilters.push_back(tmpFilter); 00201 00202 tmpFilter = new ThMLMorph(); 00203 optionFilters.insert(OptionFilterMap::value_type("ThMLMorph", tmpFilter)); 00204 cleanupFilters.push_back(tmpFilter); 00205 00206 tmpFilter = new ThMLHeadings(); 00207 optionFilters.insert(OptionFilterMap::value_type("ThMLHeadings", tmpFilter)); 00208 cleanupFilters.push_back(tmpFilter); 00209 00210 tmpFilter = new ThMLLemma(); 00211 optionFilters.insert(OptionFilterMap::value_type("ThMLLemma", tmpFilter)); 00212 cleanupFilters.push_back(tmpFilter); 00213 00214 tmpFilter = new ThMLScripref(); 00215 optionFilters.insert(OptionFilterMap::value_type("ThMLScripref", tmpFilter)); 00216 cleanupFilters.push_back(tmpFilter); 00217 00218 tmpFilter = new UTF8GreekAccents(); 00219 optionFilters.insert(OptionFilterMap::value_type("UTF8GreekAccents", tmpFilter)); 00220 cleanupFilters.push_back(tmpFilter); 00221 00222 tmpFilter = new UTF8HebrewPoints(); 00223 optionFilters.insert(OptionFilterMap::value_type("UTF8HebrewPoints", tmpFilter)); 00224 cleanupFilters.push_back(tmpFilter); 00225 00226 tmpFilter = new UTF8ArabicPoints(); 00227 optionFilters.insert(OptionFilterMap::value_type("UTF8ArabicPoints", tmpFilter)); 00228 cleanupFilters.push_back(tmpFilter); 00229 00230 tmpFilter = new UTF8Cantillation(); 00231 optionFilters.insert(OptionFilterMap::value_type("UTF8Cantillation", tmpFilter)); 00232 cleanupFilters.push_back(tmpFilter); 00233 00234 tmpFilter = new GreekLexAttribs(); 00235 optionFilters.insert(OptionFilterMap::value_type("GreekLexAttribs", tmpFilter)); 00236 cleanupFilters.push_back(tmpFilter); 00237 00238 tmpFilter = new PapyriPlain(); 00239 optionFilters.insert(OptionFilterMap::value_type("PapyriPlain", tmpFilter)); 00240 cleanupFilters.push_back(tmpFilter); 00241 00242 // UTF8Transliterator needs to be handled differently because it should always available as an option, for all modules 00243 #ifdef _ICU_ 00244 transliterator = new UTF8Transliterator(); 00245 optionFilters.insert(OptionFilterMap::value_type("UTF8Transliterator", transliterator)); 00246 options.push_back(transliterator->getOptionName()); 00247 cleanupFilters.push_back(transliterator); 00248 #endif 00249 00250 gbfplain = new GBFPlain(); 00251 cleanupFilters.push_back(gbfplain); 00252 00253 thmlplain = new ThMLPlain(); 00254 cleanupFilters.push_back(thmlplain); 00255 00256 osisplain = new OSISPlain(); 00257 cleanupFilters.push_back(osisplain); 00258 00259 teiplain = new TEIPlain(); 00260 cleanupFilters.push_back(teiplain); 00261 00262 // filters which aren't really used anywhere but which we want available for a "FilterName" -> filter mapping (e.g., filterText) 00263 SWFilter *f = new RTFHTML(); 00264 extraFilters.insert(FilterMap::value_type("RTFHTML", f)); 00265 cleanupFilters.push_back(f); 00266 00267 }
| 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
| dir | where to search for new modules |
Definition at line 1270 of file swmgr.cpp.
01271 { 01272 DIR *dir; 01273 struct dirent *ent; 01274 FileDesc *conffd = 0; 01275 SWBuf newmodfile; 01276 SWBuf targetName; 01277 01278 if (FileMgr::existsDir(dirname)) { 01279 if ((dir = opendir(dirname))) { 01280 rewinddir(dir); 01281 while ((ent = readdir(dir))) { 01282 if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) { 01283 newmodfile = dirname; 01284 if ((dirname[strlen(dirname)-1] != '\\') && (dirname[strlen(dirname)-1] != '/')) 01285 newmodfile += "/"; 01286 newmodfile += ent->d_name; 01287 01288 // mods.d 01289 if (configType) { 01290 if (conffd) 01291 FileMgr::getSystemFileMgr()->close(conffd); 01292 targetName = configPath; 01293 if ((configPath[strlen(configPath)-1] != '\\') && (configPath[strlen(configPath)-1] != '/')) 01294 targetName += "/"; 01295 targetName += ent->d_name; 01296 conffd = FileMgr::getSystemFileMgr()->open(targetName.c_str(), FileMgr::WRONLY|FileMgr::CREAT, FileMgr::IREAD|FileMgr::IWRITE); 01297 } 01298 01299 // mods.conf 01300 else { 01301 if (!conffd) { 01302 conffd = FileMgr::getSystemFileMgr()->open(config->filename.c_str(), FileMgr::WRONLY|FileMgr::APPEND); 01303 if (conffd > 0) 01304 conffd->seek(0L, SEEK_END); 01305 else { 01306 FileMgr::getSystemFileMgr()->close(conffd); 01307 conffd = 0; 01308 } 01309 } 01310 } 01311 AddModToConfig(conffd, newmodfile.c_str()); 01312 FileMgr::removeFile(newmodfile.c_str()); 01313 } 01314 } 01315 if (conffd) 01316 FileMgr::getSystemFileMgr()->close(conffd); 01317 closedir(dir); 01318 } 01319 } 01320 }
| signed char SWMgr::Load | ( | ) | [virtual] |
Load all 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.
Definition at line 773 of file swmgr.cpp.
00773 { 00774 signed char ret = 0; 00775 00776 if (!config) { // If we weren't passed a config object at construction, find a config file 00777 if (!configPath) { // If we weren't passed a config path at construction... 00778 SWLog::getSystemLog()->logDebug("LOOKING UP MODULE CONFIGURATION..."); 00779 SWConfig *externalSysConf = sysConfig; // if we have a sysConf before findConfig, then we were provided one from an external source. 00780 findConfig(&configType, &prefixPath, &configPath, &augPaths, &sysConfig); 00781 if (!externalSysConf) mysysconfig = sysConfig; // remind us to delete our own sysConfig in d-tor 00782 SWLog::getSystemLog()->logDebug("LOOKING UP MODULE CONFIGURATION COMPLETE."); 00783 } 00784 if (configPath) { 00785 if (configType) 00786 loadConfigDir(configPath); 00787 else config = myconfig = new SWConfig(configPath); 00788 } 00789 } 00790 00791 if (config) { 00792 SectionMap::iterator Sectloop, Sectend; 00793 ConfigEntMap::iterator Entryloop, Entryend; 00794 00795 DeleteMods(); 00796 00797 for (Sectloop = config->Sections.lower_bound("Globals"), Sectend = config->Sections.upper_bound("Globals"); Sectloop != Sectend; Sectloop++) { // scan thru all 'Globals' sections 00798 for (Entryloop = (*Sectloop).second.lower_bound("AutoInstall"), Entryend = (*Sectloop).second.upper_bound("AutoInstall"); Entryloop != Entryend; Entryloop++) // scan thru all AutoInstall entries 00799 InstallScan((*Entryloop).second.c_str()); // Scan AutoInstall entry directory for new modules and install 00800 } 00801 if (configType) { // force reload on config object because we may have installed new modules 00802 delete myconfig; 00803 config = myconfig = 0; 00804 loadConfigDir(configPath); 00805 } 00806 else config->Load(); 00807 00808 CreateMods(mgrModeMultiMod); 00809 00810 for (std::list<SWBuf>::iterator pathIt = augPaths.begin(); pathIt != augPaths.end(); pathIt++) { 00811 augmentModules(pathIt->c_str(), mgrModeMultiMod); 00812 } 00813 if (augmentHome) { 00814 // augment config with ~/.sword/mods.d if it exists --------------------- 00815 SWBuf homeDir = getHomeDir(); 00816 if (homeDir.length() && configType != 2) { // 2 = user only 00817 SWBuf path = homeDir; 00818 path += ".sword/"; 00819 augmentModules(path.c_str(), mgrModeMultiMod); 00820 path = homeDir; 00821 path += "sword/"; 00822 augmentModules(path.c_str(), mgrModeMultiMod); 00823 } 00824 } 00825 // ------------------------------------------------------------------------- 00826 if (!Modules.size()) // config exists, but no modules 00827 ret = 1; 00828 00829 } 00830 else { 00831 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>"); 00832 ret = -1; 00833 } 00834 00835 return ret; 00836 }
| void SWMgr::loadConfigDir | ( | const char * | ipath | ) | [protected, virtual] |
Definition at line 674 of file swmgr.cpp.
00675 { 00676 DIR *dir; 00677 struct dirent *ent; 00678 SWBuf newmodfile; 00679 00680 if ((dir = opendir(ipath))) { 00681 rewinddir(dir); 00682 while ((ent = readdir(dir))) { 00683 //check whether it ends with .conf, if it doesn't skip it! 00684 if (!ent->d_name || (strlen(ent->d_name) <= 5) || strncmp(".conf", (ent->d_name + strlen(ent->d_name) - 5), 5 )) { 00685 continue; 00686 } 00687 00688 newmodfile = ipath; 00689 if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/')) 00690 newmodfile += "/"; 00691 newmodfile += ent->d_name; 00692 if (config) { 00693 SWConfig tmpConfig(newmodfile.c_str()); 00694 *config += tmpConfig; 00695 } 00696 else config = myconfig = new SWConfig(newmodfile.c_str()); 00697 } 00698 closedir(dir); 00699 00700 if (!config) { // if no .conf file exist yet, create a default 00701 newmodfile = ipath; 00702 if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/')) 00703 newmodfile += "/"; 00704 newmodfile += "globals.conf"; 00705 config = myconfig = new SWConfig(newmodfile.c_str()); 00706 } 00707 } 00708 }
| 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. To write the new unlock key to the config file use code like this:
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; } } } closedir(dir);
| modName | For this module we change the unlockKey | |
| key | This is the new unlck key we use for te module. |
Definition at line 1397 of file swmgr.cpp.
01397 { 01398 FilterMap::iterator it; 01399 ModMap::iterator it2; 01400 01401 // check for filter that already exists 01402 it = cipherFilters.find(modName); 01403 if (it != cipherFilters.end()) { 01404 ((CipherFilter *)(*it).second)->getCipher()->setCipherKey(key); 01405 return 0; 01406 } 01407 // check if module exists 01408 else { 01409 it2 = Modules.find(modName); 01410 if (it2 != Modules.end()) { 01411 SWFilter *cipherFilter = new CipherFilter(key); 01412 cipherFilters.insert(FilterMap::value_type(modName, cipherFilter)); 01413 cleanupFilters.push_back(cipherFilter); 01414 (*it2).second->addRawFilter(cipherFilter); 01415 return 0; 01416 } 01417 } 01418 return -1; 01419 }
| void SWMgr::setGlobalOption | ( | const char * | option, | |
| const char * | value | |||
| ) | [virtual] |
Change the values of global options (e.g. Footnotes, Strong's Number, etc.)
| option | The name of the option, for which you want to change the value. Well known and often used values are "Footnotes" or "Strong's Numbers" | |
| value | new value. Common values are "On" and "Off" |
Definition at line 1341 of file swmgr.cpp.
01342 { 01343 for (OptionFilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { 01344 if ((*it).second->getOptionName()) { 01345 if (!stricmp(option, (*it).second->getOptionName())) 01346 (*it).second->setOptionValue(value); 01347 } 01348 } 01349 }
bool SWMgr::augmentHome [private] |
StringList SWMgr::augPaths [protected] |
FilterMap SWMgr::cipherFilters [protected] |
FilterList SWMgr::cleanupFilters [protected] |
| char* SWMgr::configPath |
char SWMgr::configType [protected] |
FilterMap SWMgr::extraFilters [protected] |
SWFilterMgr* SWMgr::filterMgr [protected] |
SWFilter* SWMgr::gbfplain [protected] |
const char * SWMgr::globalConfPath = "/etc/sword.conf:/usr/local/etc/sword.conf" [static] |
SWConfig* SWMgr::homeConfig [protected] |
SWORD_NAMESPACE_START bool SWMgr::isICU = false [static] |
bool SWMgr::mgrModeMultiMod [private] |
const char * SWMgr::MODTYPE_BIBLES = "Biblical Texts" [static] |
const char * SWMgr::MODTYPE_COMMENTARIES = "Commentaries" [static] |
const char * SWMgr::MODTYPE_DAILYDEVOS = "Daily Devotional" [static] |
const char * SWMgr::MODTYPE_GENBOOKS = "Generic Books" [static] |
const char * SWMgr::MODTYPE_LEXDICTS = "Lexicons / Dictionaries" [static] |
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.
ModMap::iterator it; SWModule *curMod = 0; 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 } }
SWConfig* SWMgr::myconfig [protected] |
SWConfig* SWMgr::mysysconfig [protected] |
OptionFilterMap SWMgr::optionFilters [protected] |
StringList SWMgr::options [protected] |
SWFilter* SWMgr::osisplain [protected] |
| char* SWMgr::prefixPath |
SWFilter* SWMgr::teiplain [protected] |
SWFilter* SWMgr::thmlplain [protected] |
SWOptionFilter* SWMgr::transliterator [protected] |
1.6.1