<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>swmgr.cpp Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.2.15 --> <center> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> </center> <hr><h1>swmgr.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font> 00002 <font class="comment"> * swmgr.cpp - implementaion of class SWMgr used to interact with an install</font> 00003 <font class="comment"> * base of sword modules.</font> 00004 <font class="comment"> *</font> 00005 <font class="comment"> * $Id: swmgr_8cpp-source.html,v 1.3 2002/06/20 20:23:10 mgruner Exp $</font> 00006 <font class="comment"> *</font> 00007 <font class="comment"> * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)</font> 00008 <font class="comment"> * CrossWire Bible Society</font> 00009 <font class="comment"> * P. O. Box 2528</font> 00010 <font class="comment"> * Tempe, AZ 85280-2528</font> 00011 <font class="comment"> *</font> 00012 <font class="comment"> * This program is free software; you can redistribute it and/or modify it</font> 00013 <font class="comment"> * under the terms of the GNU General Public License as published by the</font> 00014 <font class="comment"> * Free Software Foundation version 2.</font> 00015 <font class="comment"> *</font> 00016 <font class="comment"> * This program is distributed in the hope that it will be useful, but</font> 00017 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font> 00018 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font> 00019 <font class="comment"> * General Public License for more details.</font> 00020 <font class="comment"> *</font> 00021 <font class="comment"> */</font> 00022 00023 <font class="preprocessor">#include <stdio.h></font> 00024 <font class="preprocessor">#include <stdlib.h></font> 00025 <font class="preprocessor">#include <fcntl.h></font> 00026 00027 <font class="preprocessor">#ifndef __GNUC__</font> 00028 <font class="preprocessor"></font><font class="preprocessor">#include <io.h></font> 00029 <font class="preprocessor">#else</font> 00030 <font class="preprocessor"></font><font class="preprocessor">#include <unistd.h></font> 00031 <font class="preprocessor">#include <unixstr.h></font> 00032 <font class="preprocessor">#endif</font> 00033 <font class="preprocessor"></font><font class="preprocessor">#include <sys/stat.h></font> 00034 <font class="preprocessor">#ifndef _MSC_VER</font> 00035 <font class="preprocessor"></font><font class="preprocessor">#include <iostream.h></font> 00036 <font class="preprocessor">#endif</font> 00037 <font class="preprocessor"></font><font class="preprocessor">#include <dirent.h></font> 00038 00039 <font class="preprocessor">#include <swmgr.h></font> 00040 <font class="preprocessor">#include <rawtext.h></font> 00041 <font class="preprocessor">#include <rawgenbook.h></font> 00042 <font class="preprocessor">#include <rawcom.h></font> 00043 <font class="preprocessor">#include <hrefcom.h></font> 00044 <font class="preprocessor">#include <rawld.h></font> 00045 <font class="preprocessor">#include <rawld4.h></font> 00046 <font class="preprocessor">#include <utilfuns.h></font> 00047 <font class="preprocessor">#include <gbfplain.h></font> 00048 <font class="preprocessor">#include <thmlplain.h></font> 00049 <font class="preprocessor">#include <gbfstrongs.h></font> 00050 <font class="preprocessor">#include <gbffootnotes.h></font> 00051 <font class="preprocessor">#include <gbfheadings.h></font> 00052 <font class="preprocessor">#include <gbfmorph.h></font> 00053 <font class="preprocessor">#include <thmlstrongs.h></font> 00054 <font class="preprocessor">#include <thmlfootnotes.h></font> 00055 <font class="preprocessor">#include <thmlheadings.h></font> 00056 <font class="preprocessor">#include <thmlmorph.h></font> 00057 <font class="preprocessor">#include <thmllemma.h></font> 00058 <font class="preprocessor">#include <thmlscripref.h></font> 00059 <font class="preprocessor">#include <cipherfil.h></font> 00060 <font class="preprocessor">#include <rawfiles.h></font> 00061 <font class="preprocessor">#include <ztext.h></font> 00062 <font class="preprocessor">#include <zld.h></font> 00063 <font class="preprocessor">#include <zcom.h></font> 00064 <font class="preprocessor">#include <lzsscomprs.h></font> 00065 <font class="preprocessor">#include <utf8greekaccents.h></font> 00066 <font class="preprocessor">#include <utf8cantillation.h></font> 00067 <font class="preprocessor">#include <utf8hebrewpoints.h></font> 00068 <font class="preprocessor">#include <greeklexattribs.h></font> 00069 <font class="preprocessor">#include <swfiltermgr.h></font> 00070 00071 00072 00073 <font class="preprocessor">#ifdef ICU</font> 00074 <font class="preprocessor"></font><font class="preprocessor">#include <utf8transliterator.h></font> 00075 <font class="preprocessor">#endif</font> 00076 <font class="preprocessor"></font> 00077 <font class="preprocessor">#ifndef EXCLUDEZLIB</font> 00078 <font class="preprocessor"></font><font class="preprocessor">#include <zipcomprs.h></font> 00079 <font class="preprocessor">#endif</font> 00080 <font class="preprocessor"></font> <a name="l00081"></a><a class="code" href="class_s_w_mgr.html#p0">00081</a> <font class="keywordtype">bool</font> <a class="code" href="class_s_w_mgr.html#p0">SWMgr::debug</a> = <font class="keyword">false</font>; 00082 00083 <font class="preprocessor">#ifdef GLOBCONFPATH</font> 00084 <font class="preprocessor"></font><font class="keyword">const</font> <font class="keywordtype">char</font> *SWMgr::globalConfPath = GLOBCONFPATH; 00085 <font class="preprocessor">#else</font> 00086 <font class="preprocessor"></font><font class="keyword">const</font> <font class="keywordtype">char</font> *SWMgr::globalConfPath = <font class="stringliteral">"/etc/sword.conf:/usr/local/etc/sword.conf"</font>; 00087 <font class="preprocessor">#endif</font> 00088 <font class="preprocessor"></font> 00089 <font class="keywordtype">void</font> SWMgr::init() { 00090 SWFilter *tmpFilter = 0; 00091 configPath = 0; 00092 <a class="code" href="class_s_w_mgr.html#m3">prefixPath</a> = 0; 00093 configType = 0; 00094 myconfig = 0; 00095 mysysconfig = 0; 00096 homeConfig = 0; 00097 00098 00099 cipherFilters.clear(); 00100 optionFilters.clear(); 00101 cleanupFilters.clear(); 00102 00103 tmpFilter = <font class="keyword">new</font> <a class="code" href="class_g_b_f_strongs.html">GBFStrongs</a>(); 00104 optionFilters.insert(FilterMap::value_type(<font class="stringliteral">"GBFStrongs"</font>, tmpFilter)); 00105 cleanupFilters.push_back(tmpFilter); 00106 00107 tmpFilter = <font class="keyword">new</font> <a class="code" href="class_g_b_f_footnotes.html">GBFFootnotes</a>(); 00108 optionFilters.insert(FilterMap::value_type(<font class="stringliteral">"GBFFootnotes"</font>, tmpFilter)); 00109 cleanupFilters.push_back(tmpFilter); 00110 00111 tmpFilter = <font class="keyword">new</font> <a class="code" href="class_g_b_f_morph.html">GBFMorph</a>(); 00112 optionFilters.insert(FilterMap::value_type(<font class="stringliteral">"GBFMorph"</font>, tmpFilter)); 00113 cleanupFilters.push_back(tmpFilter); 00114 00115 tmpFilter = <font class="keyword">new</font> <a class="code" href="class_g_b_f_headings.html">GBFHeadings</a>(); 00116 optionFilters.insert(FilterMap::value_type(<font class="stringliteral">"GBFHeadings"</font>, tmpFilter)); 00117 cleanupFilters.push_back(tmpFilter); 00118 00119 tmpFilter = <font class="keyword">new</font> <a class="code" href="class_th_m_l_strongs.html">ThMLStrongs</a>(); 00120 optionFilters.insert(FilterMap::value_type(<font class="stringliteral">"ThMLStrongs"</font>, tmpFilter)); 00121 cleanupFilters.push_back(tmpFilter); 00122 00123 tmpFilter = <font class="keyword">new</font> <a class="code" href="class_th_m_l_footnotes.html">ThMLFootnotes</a>(); 00124 optionFilters.insert(FilterMap::value_type(<font class="stringliteral">"ThMLFootnotes"</font>, tmpFilter)); 00125 cleanupFilters.push_back(tmpFilter); 00126 00127 tmpFilter = <font class="keyword">new</font> <a class="code" href="class_th_m_l_morph.html">ThMLMorph</a>(); 00128 optionFilters.insert(FilterMap::value_type(<font class="stringliteral">"ThMLMorph"</font>, tmpFilter)); 00129 cleanupFilters.push_back(tmpFilter); 00130 00131 tmpFilter = <font class="keyword">new</font> <a class="code" href="class_th_m_l_headings.html">ThMLHeadings</a>(); 00132 optionFilters.insert(FilterMap::value_type(<font class="stringliteral">"ThMLHeadings"</font>, tmpFilter)); 00133 cleanupFilters.push_back(tmpFilter); 00134 00135 tmpFilter = <font class="keyword">new</font> <a class="code" href="class_th_m_l_lemma.html">ThMLLemma</a>(); 00136 optionFilters.insert(FilterMap::value_type(<font class="stringliteral">"ThMLLemma"</font>, tmpFilter)); 00137 cleanupFilters.push_back(tmpFilter); 00138 00139 tmpFilter = <font class="keyword">new</font> <a class="code" href="class_th_m_l_scripref.html">ThMLScripref</a>(); 00140 optionFilters.insert(FilterMap::value_type(<font class="stringliteral">"ThMLScripref"</font>, tmpFilter)); 00141 cleanupFilters.push_back(tmpFilter); 00142 00143 tmpFilter = <font class="keyword">new</font> <a class="code" href="class_u_t_f8_greek_accents.html">UTF8GreekAccents</a>(); 00144 optionFilters.insert(FilterMap::value_type(<font class="stringliteral">"UTF8GreekAccents"</font>, tmpFilter)); 00145 cleanupFilters.push_back(tmpFilter); 00146 00147 tmpFilter = <font class="keyword">new</font> <a class="code" href="class_u_t_f8_hebrew_points.html">UTF8HebrewPoints</a>(); 00148 optionFilters.insert(FilterMap::value_type(<font class="stringliteral">"UTF8HebrewPoints"</font>, tmpFilter)); 00149 cleanupFilters.push_back(tmpFilter); 00150 00151 tmpFilter = <font class="keyword">new</font> <a class="code" href="class_u_t_f8_cantillation.html">UTF8Cantillation</a>(); 00152 optionFilters.insert(FilterMap::value_type(<font class="stringliteral">"UTF8Cantillation"</font>, tmpFilter)); 00153 cleanupFilters.push_back(tmpFilter); 00154 00155 tmpFilter = <font class="keyword">new</font> <a class="code" href="class_greek_lex_attribs.html">GreekLexAttribs</a>(); 00156 optionFilters.insert(FilterMap::value_type(<font class="stringliteral">"GreekLexAttribs"</font>, tmpFilter)); 00157 cleanupFilters.push_back(tmpFilter); 00158 00159 <font class="comment">/* UTF8Transliterator needs to be handled differently because it should always available as an option, for all modules</font> 00160 <font class="comment">#ifdef ICU</font> 00161 <font class="comment"> tmpFilter = new UTF8Transliterator();</font> 00162 <font class="comment"> optionFilters.insert(FilterMap::value_type("UTF8Transliterator", tmpFilter));</font> 00163 <font class="comment"> cleanupFilters.push_back(tmpFilter);</font> 00164 <font class="comment">#endif</font> 00165 <font class="comment">*/</font> 00166 gbfplain = <font class="keyword">new</font> <a class="code" href="class_g_b_f_plain.html">GBFPlain</a>(); 00167 cleanupFilters.push_back(gbfplain); 00168 00169 thmlplain = <font class="keyword">new</font> <a class="code" href="class_th_m_l_plain.html">ThMLPlain</a>(); 00170 cleanupFilters.push_back(thmlplain); 00171 } 00172 00173 <a name="l00174"></a><a class="code" href="class_s_w_mgr.html#a1">00174</a> <a class="code" href="class_s_w_mgr.html#a0">SWMgr::SWMgr</a>(SWFilterMgr *filterMgr) { 00175 commonInit(0, 0, <font class="keyword">true</font>, filterMgr); 00176 } 00177 00178 <a name="l00179"></a><a class="code" href="class_s_w_mgr.html#a0">00179</a> <a class="code" href="class_s_w_mgr.html#a0">SWMgr::SWMgr</a>(<a class="code" href="class_s_w_config.html">SWConfig</a> *iconfig, <a class="code" href="class_s_w_config.html">SWConfig</a> *isysconfig, <font class="keywordtype">bool</font> autoload, SWFilterMgr *filterMgr) { 00180 commonInit(iconfig, isysconfig, autoload, filterMgr); 00181 } 00182 00183 00184 <font class="keywordtype">void</font> SWMgr::commonInit(<a class="code" href="class_s_w_config.html">SWConfig</a> * iconfig, <a class="code" href="class_s_w_config.html">SWConfig</a> * isysconfig, <font class="keywordtype">bool</font> autoload, SWFilterMgr *filterMgr) { 00185 this->filterMgr = filterMgr; 00186 <font class="keywordflow">if</font> (filterMgr) 00187 filterMgr->setParentMgr(<font class="keyword">this</font>); 00188 00189 init(); 00190 00191 <font class="keywordflow">if</font> (iconfig) { 00192 <a class="code" href="class_s_w_mgr.html#m0">config</a> = iconfig; 00193 myconfig = 0; 00194 } 00195 <font class="keywordflow">else</font> <a class="code" href="class_s_w_mgr.html#m0">config</a> = 0; 00196 <font class="keywordflow">if</font> (isysconfig) { 00197 sysconfig = isysconfig; 00198 mysysconfig = 0; 00199 } 00200 <font class="keywordflow">else</font> sysconfig = 0; 00201 00202 <font class="keywordflow">if</font> (autoload) 00203 <a class="code" href="class_s_w_mgr.html#a5">Load</a>(); 00204 } 00205 00206 <a name="l00207"></a><a class="code" href="class_s_w_mgr.html#a2">00207</a> <a class="code" href="class_s_w_mgr.html#a0">SWMgr::SWMgr</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *iConfigPath, <font class="keywordtype">bool</font> autoload, SWFilterMgr *filterMgr) { 00208 00209 string path; 00210 00211 this->filterMgr = filterMgr; 00212 <font class="keywordflow">if</font> (filterMgr) 00213 filterMgr->setParentMgr(<font class="keyword">this</font>); 00214 00215 init(); 00216 00217 path = iConfigPath; 00218 <font class="keywordflow">if</font> ((iConfigPath[strlen(iConfigPath)-1] != <font class="charliteral">'\\'</font>) && (iConfigPath[strlen(iConfigPath)-1] != <font class="charliteral">'/'</font>)) 00219 path += <font class="stringliteral">"/"</font>; 00220 <font class="keywordflow">if</font> (FileMgr::existsFile(path.c_str(), <font class="stringliteral">"mods.conf"</font>)) { 00221 stdstr(&<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>, path.c_str()); 00222 path += <font class="stringliteral">"mods.conf"</font>; 00223 stdstr(&configPath, path.c_str()); 00224 } 00225 <font class="keywordflow">else</font> { 00226 <font class="keywordflow">if</font> (FileMgr::existsDir(path.c_str(), <font class="stringliteral">"mods.d"</font>)) { 00227 stdstr(&<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>, path.c_str()); 00228 path += <font class="stringliteral">"mods.d"</font>; 00229 stdstr(&configPath, path.c_str()); 00230 configType = 1; 00231 } 00232 } 00233 00234 <a class="code" href="class_s_w_mgr.html#m0">config</a> = 0; 00235 sysconfig = 0; 00236 00237 <font class="keywordflow">if</font> (autoload && configPath) 00238 <a class="code" href="class_s_w_mgr.html#a5">Load</a>(); 00239 } 00240 00241 <a name="l00242"></a><a class="code" href="class_s_w_mgr.html#a3">00242</a> <a class="code" href="class_s_w_mgr.html#a3">SWMgr::~SWMgr</a>() { 00243 00244 DeleteMods(); 00245 00246 <font class="keywordflow">for</font> (FilterList::iterator it = cleanupFilters.begin(); it != cleanupFilters.end(); it++) 00247 <font class="keyword">delete</font> (*it); 00248 00249 <font class="keywordflow">if</font> (homeConfig) 00250 <font class="keyword">delete</font> homeConfig; 00251 00252 <font class="keywordflow">if</font> (myconfig) 00253 <font class="keyword">delete</font> myconfig; 00254 00255 <font class="keywordflow">if</font> (prefixPath) 00256 <font class="keyword">delete</font> [] <a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>; 00257 00258 <font class="keywordflow">if</font> (configPath) 00259 <font class="keyword">delete</font> [] configPath; 00260 00261 <font class="keywordflow">if</font> (filterMgr) 00262 <font class="keyword">delete</font> filterMgr; 00263 } 00264 00265 00266 <font class="keywordtype">void</font> SWMgr::findConfig(<font class="keywordtype">char</font> *configType, <font class="keywordtype">char</font> **prefixPath, <font class="keywordtype">char</font> **configPath) { 00267 string path; 00268 ConfigEntMap::iterator entry; 00269 00270 <font class="keywordtype">char</font> *envsworddir = getenv (<font class="stringliteral">"SWORD_PATH"</font>); 00271 <font class="keywordtype">char</font> *envhomedir = getenv (<font class="stringliteral">"HOME"</font>); 00272 00273 *configType = 0; 00274 00275 <font class="preprocessor">#ifndef _MSC_VER</font> 00276 <font class="preprocessor"></font> <font class="comment">// check working directory</font> 00277 <font class="keywordflow">if</font> (debug) 00278 cerr << <font class="stringliteral">"Checking working directory for mods.conf..."</font>; 00279 <font class="preprocessor">#endif</font> 00280 <font class="preprocessor"></font> 00281 <font class="keywordflow">if</font> (FileMgr::existsFile(<font class="stringliteral">"."</font>, <font class="stringliteral">"mods.conf"</font>)) { 00282 00283 <font class="preprocessor">#ifndef _MSC_VER</font> 00284 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00285 cerr << <font class="stringliteral">"found\n"</font>; 00286 <font class="preprocessor">#endif</font> 00287 <font class="preprocessor"></font> 00288 stdstr(<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>, <font class="stringliteral">"./"</font>); 00289 stdstr(configPath, <font class="stringliteral">"./mods.conf"</font>); 00290 <font class="keywordflow">return</font>; 00291 } 00292 00293 <font class="preprocessor">#ifndef _MSC_VER</font> 00294 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00295 cerr << <font class="stringliteral">"\nChecking working directory for mods.d..."</font>; 00296 <font class="preprocessor">#endif</font> 00297 <font class="preprocessor"></font> 00298 <font class="keywordflow">if</font> (FileMgr::existsDir(<font class="stringliteral">"."</font>, <font class="stringliteral">"mods.d"</font>)) { 00299 00300 <font class="preprocessor">#ifndef _MSC_VER</font> 00301 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00302 cerr << <font class="stringliteral">"found\n"</font>; 00303 <font class="preprocessor">#endif</font> 00304 <font class="preprocessor"></font> 00305 stdstr(<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>, <font class="stringliteral">"./"</font>); 00306 stdstr(configPath, <font class="stringliteral">"./mods.d"</font>); 00307 *configType = 1; 00308 <font class="keywordflow">return</font>; 00309 } 00310 00311 00312 <font class="comment">// check environment variable SWORD_PATH</font> 00313 <font class="preprocessor">#ifndef _MSC_VER</font> 00314 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00315 cerr << <font class="stringliteral">"\nChecking SWORD_PATH..."</font>; 00316 <font class="preprocessor">#endif</font> 00317 <font class="preprocessor"></font> 00318 <font class="keywordflow">if</font> (envsworddir != NULL) { 00319 00320 <font class="preprocessor">#ifndef _MSC_VER</font> 00321 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00322 cerr << <font class="stringliteral">"found ("</font> << envsworddir << <font class="stringliteral">")\n"</font>; 00323 <font class="preprocessor">#endif</font> 00324 <font class="preprocessor"></font> 00325 path = envsworddir; 00326 <font class="keywordflow">if</font> ((envsworddir[strlen(envsworddir)-1] != <font class="charliteral">'\\'</font>) && (envsworddir[strlen(envsworddir)-1] != <font class="charliteral">'/'</font>)) 00327 path += <font class="stringliteral">"/"</font>; 00328 00329 <font class="preprocessor">#ifndef _MSC_VER</font> 00330 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00331 cerr << <font class="stringliteral">"\nChecking $SWORD_PATH for mods.conf..."</font>; 00332 <font class="preprocessor">#endif</font> 00333 <font class="preprocessor"></font> 00334 <font class="keywordflow">if</font> (FileMgr::existsFile(path.c_str(), <font class="stringliteral">"mods.conf"</font>)) { 00335 00336 <font class="preprocessor">#ifndef _MSC_VER</font> 00337 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00338 cerr << <font class="stringliteral">"found\n"</font>; 00339 <font class="preprocessor">#endif</font> 00340 <font class="preprocessor"></font> 00341 stdstr(<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>, path.c_str()); 00342 path += <font class="stringliteral">"mods.conf"</font>; 00343 stdstr(configPath, path.c_str()); 00344 <font class="keywordflow">return</font>; 00345 } 00346 00347 <font class="preprocessor">#ifndef _MSC_VER</font> 00348 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00349 cerr << <font class="stringliteral">"\nChecking $SWORD_PATH for mods.d..."</font>; 00350 <font class="preprocessor">#endif</font> 00351 <font class="preprocessor"></font> 00352 <font class="keywordflow">if</font> (FileMgr::existsDir(path.c_str(), <font class="stringliteral">"mods.d"</font>)) { 00353 00354 <font class="preprocessor">#ifndef _MSC_VER</font> 00355 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00356 cerr << <font class="stringliteral">"found\n"</font>; 00357 <font class="preprocessor">#endif</font> 00358 <font class="preprocessor"></font> 00359 stdstr(<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>, path.c_str()); 00360 path += <font class="stringliteral">"mods.d"</font>; 00361 stdstr(configPath, path.c_str()); 00362 *configType = 1; 00363 <font class="keywordflow">return</font>; 00364 } 00365 } 00366 00367 00368 <font class="comment">// check for systemwide globalConfPath</font> 00369 00370 <font class="preprocessor">#ifndef _MSC_VER</font> 00371 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00372 cerr << <font class="stringliteral">"\nParsing "</font> << globalConfPath << <font class="stringliteral">"..."</font>; 00373 <font class="preprocessor">#endif</font> 00374 <font class="preprocessor"></font> 00375 <font class="keywordtype">char</font> *globPaths = 0; 00376 <font class="keywordtype">char</font> *gfp; 00377 stdstr(&globPaths, globalConfPath); 00378 <font class="keywordflow">for</font> (gfp = strtok(globPaths, <font class="stringliteral">":"</font>); gfp; gfp = strtok(0, <font class="stringliteral">":"</font>)) { 00379 00380 <font class="preprocessor"> #ifndef _MSC_VER</font> 00381 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00382 cerr << <font class="stringliteral">"\nChecking for "</font> << gfp << <font class="stringliteral">"..."</font>; 00383 <font class="preprocessor">#endif</font> 00384 <font class="preprocessor"></font> 00385 <font class="keywordflow">if</font> (FileMgr::existsFile(gfp)) 00386 <font class="keywordflow">break</font>; 00387 } 00388 00389 <font class="keywordflow">if</font> (gfp) { 00390 00391 <font class="preprocessor">#ifndef _MSC_VER</font> 00392 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00393 cerr << <font class="stringliteral">"found\n"</font>; 00394 <font class="preprocessor">#endif</font> 00395 <font class="preprocessor"></font> 00396 <a class="code" href="class_s_w_config.html">SWConfig</a> etcconf(gfp); 00397 <font class="keywordflow">if</font> ((entry = etcconf.<a class="code" href="class_s_w_config.html#m1">Sections</a>[<font class="stringliteral">"Install"</font>].find(<font class="stringliteral">"DataPath"</font>)) != etcconf.<a class="code" href="class_s_w_config.html#m1">Sections</a>[<font class="stringliteral">"Install"</font>].end()) { 00398 path = (*entry).second; 00399 <font class="keywordflow">if</font> (((*entry).second.c_str()[strlen((*entry).second.c_str())-1] != <font class="charliteral">'\\'</font>) && ((*entry).second.c_str()[strlen((*entry).second.c_str())-1] != <font class="charliteral">'/'</font>)) 00400 path += <font class="stringliteral">"/"</font>; 00401 00402 <font class="preprocessor">#ifndef _MSC_VER</font> 00403 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00404 cerr << <font class="stringliteral">"DataPath in "</font> << gfp << <font class="stringliteral">" is set to: "</font> << path; 00405 <font class="preprocessor">#endif</font> 00406 <font class="preprocessor"></font> 00407 <font class="preprocessor">#ifndef _MSC_VER</font> 00408 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00409 cerr << <font class="stringliteral">"\nChecking for mods.conf in DataPath "</font>; 00410 <font class="preprocessor">#endif</font> 00411 <font class="preprocessor"></font> <font class="keywordflow">if</font> (FileMgr::existsFile(path.c_str(), <font class="stringliteral">"mods.conf"</font>)) { 00412 00413 <font class="preprocessor">#ifndef _MSC_VER</font> 00414 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00415 cerr << <font class="stringliteral">"found\n"</font>; 00416 <font class="preprocessor">#endif</font> 00417 <font class="preprocessor"></font> 00418 stdstr(<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>, path.c_str()); 00419 path += <font class="stringliteral">"mods.conf"</font>; 00420 stdstr(configPath, path.c_str()); 00421 <font class="keyword">delete</font> [] globPaths; 00422 <font class="keywordflow">return</font>; 00423 } 00424 00425 <font class="preprocessor">#ifndef _MSC_VER</font> 00426 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00427 cerr << <font class="stringliteral">"\nChecking for mods.d in DataPath "</font>; 00428 <font class="preprocessor">#endif</font> 00429 <font class="preprocessor"></font> 00430 <font class="keywordflow">if</font> (FileMgr::existsDir(path.c_str(), <font class="stringliteral">"mods.d"</font>)) { 00431 00432 <font class="preprocessor">#ifndef _MSC_VER</font> 00433 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00434 cerr << <font class="stringliteral">"found\n"</font>; 00435 <font class="preprocessor">#endif</font> 00436 <font class="preprocessor"></font> 00437 stdstr(<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>, path.c_str()); 00438 path += <font class="stringliteral">"mods.d"</font>; 00439 stdstr(configPath, path.c_str()); 00440 *configType = 1; 00441 <font class="keyword">delete</font> [] globPaths; 00442 <font class="keywordflow">return</font>; 00443 } 00444 } 00445 } 00446 00447 <font class="keyword">delete</font> [] globPaths; 00448 00449 <font class="comment">// check ~/.sword/</font> 00450 00451 <font class="preprocessor">#ifndef _MSC_VER</font> 00452 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00453 cerr << <font class="stringliteral">"\nChecking home directory for ~/.sword/mods.conf"</font> << path; 00454 <font class="preprocessor">#endif</font> 00455 <font class="preprocessor"></font> 00456 <font class="keywordflow">if</font> (envhomedir != NULL) { 00457 path = envhomedir; 00458 <font class="keywordflow">if</font> ((envhomedir[strlen(envhomedir)-1] != <font class="charliteral">'\\'</font>) && (envhomedir[strlen(envhomedir)-1] != <font class="charliteral">'/'</font>)) 00459 path += <font class="stringliteral">"/"</font>; 00460 path += <font class="stringliteral">".sword/"</font>; 00461 <font class="keywordflow">if</font> (FileMgr::existsFile(path.c_str(), <font class="stringliteral">"mods.conf"</font>)) { 00462 00463 <font class="preprocessor">#ifndef _MSC_VER</font> 00464 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00465 cerr << <font class="stringliteral">" found\n"</font>; 00466 <font class="preprocessor">#endif</font> 00467 <font class="preprocessor"></font> 00468 stdstr(<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>, path.c_str()); 00469 path += <font class="stringliteral">"mods.conf"</font>; 00470 stdstr(configPath, path.c_str()); 00471 <font class="keywordflow">return</font>; 00472 } 00473 00474 <font class="preprocessor">#ifndef _MSC_VER</font> 00475 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00476 cerr << <font class="stringliteral">"\nChecking home directory for ~/.sword/mods.d"</font> << path; 00477 <font class="preprocessor">#endif</font> 00478 <font class="preprocessor"></font> 00479 <font class="keywordflow">if</font> (FileMgr::existsDir(path.c_str(), <font class="stringliteral">"mods.d"</font>)) { 00480 00481 <font class="preprocessor">#ifndef _MSC_VER</font> 00482 <font class="preprocessor"></font><font class="keywordflow">if</font> (debug) 00483 cerr << <font class="stringliteral">"found\n"</font>; 00484 <font class="preprocessor">#endif</font> 00485 <font class="preprocessor"></font> 00486 stdstr(<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>, path.c_str()); 00487 path += <font class="stringliteral">"mods.d"</font>; 00488 stdstr(configPath, path.c_str()); 00489 *configType = 2; 00490 <font class="keywordflow">return</font>; 00491 } 00492 } 00493 } 00494 00495 00496 <font class="keywordtype">void</font> SWMgr::loadConfigDir(<font class="keyword">const</font> <font class="keywordtype">char</font> *ipath) 00497 { 00498 DIR *dir; 00499 <font class="keyword">struct </font>dirent *ent; 00500 string newmodfile; 00501 00502 <font class="keywordflow">if</font> ((dir = opendir(ipath))) { 00503 rewinddir(dir); 00504 <font class="keywordflow">while</font> ((ent = readdir(dir))) { 00505 <font class="keywordflow">if</font> ((strcmp(ent->d_name, <font class="stringliteral">"."</font>)) && (strcmp(ent->d_name, <font class="stringliteral">".."</font>))) { 00506 newmodfile = ipath; 00507 <font class="keywordflow">if</font> ((ipath[strlen(ipath)-1] != <font class="charliteral">'\\'</font>) && (ipath[strlen(ipath)-1] != <font class="charliteral">'/'</font>)) 00508 newmodfile += <font class="stringliteral">"/"</font>; 00509 newmodfile += ent->d_name; 00510 <font class="keywordflow">if</font> (config) { 00511 <a class="code" href="class_s_w_config.html">SWConfig</a> tmpConfig(newmodfile.c_str()); 00512 *<a class="code" href="class_s_w_mgr.html#m0">config</a> += tmpConfig; 00513 } 00514 <font class="keywordflow">else</font> <a class="code" href="class_s_w_mgr.html#m0">config</a> = myconfig = <font class="keyword">new</font> <a class="code" href="class_s_w_config.html">SWConfig</a>(newmodfile.c_str()); 00515 } 00516 } 00517 closedir(dir); 00518 <font class="keywordflow">if</font> (!<a class="code" href="class_s_w_mgr.html#m0">config</a>) { <font class="comment">// if no .conf file exist yet, create a default</font> 00519 newmodfile = ipath; 00520 <font class="keywordflow">if</font> ((ipath[strlen(ipath)-1] != <font class="charliteral">'\\'</font>) && (ipath[strlen(ipath)-1] != <font class="charliteral">'/'</font>)) 00521 newmodfile += <font class="stringliteral">"/"</font>; 00522 newmodfile += <font class="stringliteral">"globals.conf"</font>; 00523 <a class="code" href="class_s_w_mgr.html#m0">config</a> = myconfig = <font class="keyword">new</font> <a class="code" href="class_s_w_config.html">SWConfig</a>(newmodfile.c_str()); 00524 } 00525 } 00526 } 00527 00528 00529 <font class="comment">/***********************************************************************</font> 00530 <font class="comment"> * SWMgr::Load - loads actual modules</font> 00531 <font class="comment"> *</font> 00532 <font class="comment"> * RET: status - 0 = ok; -1 no config found; 1 = no modules installed</font> 00533 <font class="comment"> *</font> 00534 <font class="comment"> */</font> 00535 <a name="l00536"></a><a class="code" href="class_s_w_mgr.html#a5">00536</a> <font class="keywordtype">signed</font> <font class="keywordtype">char</font> <a class="code" href="class_s_w_mgr.html#a5">SWMgr::Load</a>() { 00537 <font class="keywordtype">signed</font> <font class="keywordtype">char</font> ret = 0; 00538 00539 <font class="keywordflow">if</font> (!<a class="code" href="class_s_w_mgr.html#m0">config</a>) { <font class="comment">// If we weren't passed a config object at construction, find a config file</font> 00540 <font class="keywordflow">if</font> (!configPath) <font class="comment">// If we weren't passed a config path at construction...</font> 00541 findConfig(&configType, &<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>, &configPath); 00542 <font class="keywordflow">if</font> (configPath) { 00543 <font class="keywordflow">if</font> (configType) 00544 loadConfigDir(configPath); 00545 <font class="keywordflow">else</font> <a class="code" href="class_s_w_mgr.html#m0">config</a> = myconfig = <font class="keyword">new</font> <a class="code" href="class_s_w_config.html">SWConfig</a>(configPath); 00546 } 00547 } 00548 00549 <font class="keywordflow">if</font> (config) { 00550 SectionMap::iterator Sectloop, Sectend; 00551 ConfigEntMap::iterator Entryloop, Entryend; 00552 00553 DeleteMods(); 00554 00555 <font class="keywordflow">for</font> (Sectloop = <a class="code" href="class_s_w_mgr.html#m0">config</a>-><a class="code" href="class_s_w_config.html#m1">Sections</a>.lower_bound(<font class="stringliteral">"Globals"</font>), Sectend = <a class="code" href="class_s_w_mgr.html#m0">config</a>-><a class="code" href="class_s_w_config.html#m1">Sections</a>.upper_bound(<font class="stringliteral">"Globals"</font>); Sectloop != Sectend; Sectloop++) { <font class="comment">// scan thru all 'Globals' sections</font> 00556 <font class="keywordflow">for</font> (Entryloop = (*Sectloop).second.lower_bound(<font class="stringliteral">"AutoInstall"</font>), Entryend = (*Sectloop).second.upper_bound(<font class="stringliteral">"AutoInstall"</font>); Entryloop != Entryend; Entryloop++) <font class="comment">// scan thru all AutoInstall entries</font> 00557 <a class="code" href="class_s_w_mgr.html#a4">InstallScan</a>((*Entryloop).second.c_str()); <font class="comment">// Scan AutoInstall entry directory for new modules and install</font> 00558 } 00559 <font class="keywordflow">if</font> (configType) { <font class="comment">// force reload on config object because we may have installed new modules</font> 00560 <font class="keyword">delete</font> myconfig; 00561 <a class="code" href="class_s_w_mgr.html#m0">config</a> = myconfig = 0; 00562 loadConfigDir(configPath); 00563 } 00564 <font class="keywordflow">else</font> <a class="code" href="class_s_w_mgr.html#m0">config</a>-><a class="code" href="class_s_w_config.html#a2">Load</a>(); 00565 00566 CreateMods(); 00567 00568 <font class="comment">// augment config with ~/.sword/mods.d if it exists ---------------------</font> 00569 <font class="keywordtype">char</font> *envhomedir = getenv (<font class="stringliteral">"HOME"</font>); 00570 <font class="keywordflow">if</font> (envhomedir != NULL && configType != 2) { <font class="comment">// 2 = user only</font> 00571 string path = envhomedir; 00572 <font class="keywordflow">if</font> ((envhomedir[strlen(envhomedir)-1] != <font class="charliteral">'\\'</font>) && (envhomedir[strlen(envhomedir)-1] != <font class="charliteral">'/'</font>)) 00573 path += <font class="stringliteral">"/"</font>; 00574 path += <font class="stringliteral">".sword/"</font>; 00575 <font class="keywordflow">if</font> (FileMgr::existsDir(path.c_str(), <font class="stringliteral">"mods.d"</font>)) { 00576 <font class="keywordtype">char</font> *savePrefixPath = 0; 00577 <font class="keywordtype">char</font> *saveConfigPath = 0; 00578 <a class="code" href="class_s_w_config.html">SWConfig</a> *saveConfig = 0; 00579 stdstr(&savePrefixPath, <a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>); 00580 stdstr(&<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>, path.c_str()); 00581 path += <font class="stringliteral">"mods.d"</font>; 00582 stdstr(&saveConfigPath, configPath); 00583 stdstr(&configPath, path.c_str()); 00584 saveConfig = <a class="code" href="class_s_w_mgr.html#m0">config</a>; 00585 <a class="code" href="class_s_w_mgr.html#m0">config</a> = myconfig = 0; 00586 loadConfigDir(configPath); 00587 00588 CreateMods(); 00589 00590 stdstr(&<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>, savePrefixPath); 00591 <font class="keyword">delete</font> []savePrefixPath; 00592 stdstr(&configPath, saveConfigPath); 00593 <font class="keyword">delete</font> []saveConfigPath; 00594 (*saveConfig) += *<a class="code" href="class_s_w_mgr.html#m0">config</a>; 00595 homeConfig = myconfig; 00596 <a class="code" href="class_s_w_mgr.html#m0">config</a> = myconfig = saveConfig; 00597 } 00598 } 00599 <font class="comment">// -------------------------------------------------------------------------</font> 00600 <font class="keywordflow">if</font> ( !<a class="code" href="class_s_w_mgr.html#m2">Modules</a>.size() ) <font class="comment">// config exists, but no modules</font> 00601 ret = 1; 00602 00603 } 00604 <font class="keywordflow">else</font> { 00605 SWLog::systemlog->LogError(<font class="stringliteral">"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)"</font>, (configPath) ? configPath : <font class="stringliteral">"<configPath is null>"</font>); 00606 ret = -1; 00607 } 00608 00609 <font class="keywordflow">return</font> ret; 00610 } 00611 00612 <a class="code" href="class_s_w_module.html">SWModule</a> *SWMgr::CreateMod(string name, string driver, ConfigEntMap &section) 00613 { 00614 string description, datapath, misc1; 00615 ConfigEntMap::iterator entry; 00616 <a class="code" href="class_s_w_module.html">SWModule</a> *newmod = 0; 00617 string lang, sourceformat, encoding; 00618 <font class="keywordtype">signed</font> <font class="keywordtype">char</font> direction, enc, markup; 00619 00620 description = ((entry = section.find(<font class="stringliteral">"Description"</font>)) != section.end()) ? (*entry).second : (string)<font class="stringliteral">""</font>; 00621 lang = ((entry = section.find(<font class="stringliteral">"Lang"</font>)) != section.end()) ? (*entry).second : (string)<font class="stringliteral">"en"</font>; 00622 sourceformat = ((entry = section.find(<font class="stringliteral">"SourceType"</font>)) != section.end()) ? (*entry).second : (string)<font class="stringliteral">""</font>; 00623 encoding = ((entry = section.find(<font class="stringliteral">"Encoding"</font>)) != section.end()) ? (*entry).second : (string)<font class="stringliteral">""</font>; 00624 datapath = <a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>; 00625 <font class="keywordflow">if</font> ((<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>[strlen(<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>)-1] != <font class="charliteral">'\\'</font>) && (<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>[strlen(<a class="code" href="class_s_w_mgr.html#m3">prefixPath</a>)-1] != <font class="charliteral">'/'</font>)) 00626 datapath += <font class="stringliteral">"/"</font>; 00627 misc1 += ((entry = section.find(<font class="stringliteral">"DataPath"</font>)) != section.end()) ? (*entry).second : (string)<font class="stringliteral">""</font>; 00628 <font class="keywordtype">char</font> *buf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ strlen(misc1.c_str()) + 1 ]; 00629 <font class="keywordtype">char</font> *buf2 = buf; 00630 strcpy(buf, misc1.c_str()); 00631 <font class="comment">// for (; ((*buf2) && ((*buf2 == '.') || (*buf2 == '/') || (*buf2 == '\\'))); buf2++);</font> 00632 <font class="keywordflow">for</font> (; ((*buf2) && ((*buf2 == <font class="charliteral">'/'</font>) || (*buf2 == <font class="charliteral">'\\'</font>))); buf2++); 00633 <font class="keywordflow">if</font> (*buf2) 00634 datapath += buf2; 00635 <font class="keyword">delete</font> [] buf; 00636 00637 section[<font class="stringliteral">"AbsoluteDataPath"</font>] = datapath; 00638 00639 <font class="keywordflow">if</font> (!stricmp(sourceformat.c_str(), <font class="stringliteral">"GBF"</font>)) 00640 markup = FMT_GBF; 00641 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!stricmp(sourceformat.c_str(), <font class="stringliteral">"ThML"</font>)) 00642 markup = FMT_THML; 00643 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!stricmp(sourceformat.c_str(), <font class="stringliteral">"OSIS"</font>)) 00644 markup = FMT_OSIS; 00645 <font class="keywordflow">else</font> 00646 markup = FMT_PLAIN; 00647 00648 <font class="keywordflow">if</font> (!stricmp(encoding.c_str(), <font class="stringliteral">"SCSU"</font>)) 00649 enc = ENC_SCSU; 00650 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!stricmp(encoding.c_str(), <font class="stringliteral">"UTF-8"</font>)) { 00651 enc = ENC_UTF8; 00652 } 00653 <font class="keywordflow">else</font> enc = ENC_LATIN1; 00654 00655 <font class="keywordflow">if</font> ((entry = section.find(<font class="stringliteral">"Direction"</font>)) == section.end()) { 00656 direction = DIRECTION_LTR; 00657 } 00658 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!stricmp((*entry).second.c_str(), <font class="stringliteral">"rtol"</font>)) { 00659 direction = DIRECTION_RTL; 00660 } 00661 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!stricmp((*entry).second.c_str(), <font class="stringliteral">"bidi"</font>)) { 00662 direction = DIRECTION_BIDI; 00663 } 00664 <font class="keywordflow">else</font> { 00665 direction = DIRECTION_LTR; 00666 } 00667 00668 <font class="keywordflow">if</font> ((!stricmp(driver.c_str(), <font class="stringliteral">"zText"</font>)) || (!stricmp(driver.c_str(), <font class="stringliteral">"zCom"</font>))) { 00669 SWCompress *compress = 0; 00670 <font class="keywordtype">int</font> blockType = CHAPTERBLOCKS; 00671 misc1 = ((entry = section.find(<font class="stringliteral">"BlockType"</font>)) != section.end()) ? (*entry).second : (string)<font class="stringliteral">"CHAPTER"</font>; 00672 <font class="keywordflow">if</font> (!stricmp(misc1.c_str(), <font class="stringliteral">"VERSE"</font>)) 00673 blockType = VERSEBLOCKS; 00674 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!stricmp(misc1.c_str(), <font class="stringliteral">"CHAPTER"</font>)) 00675 blockType = CHAPTERBLOCKS; 00676 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!stricmp(misc1.c_str(), <font class="stringliteral">"BOOK"</font>)) 00677 blockType = BOOKBLOCKS; 00678 00679 misc1 = ((entry = section.find(<font class="stringliteral">"CompressType"</font>)) != section.end()) ? (*entry).second : (string)<font class="stringliteral">"LZSS"</font>; 00680 <font class="preprocessor">#ifndef EXCLUDEZLIB</font> 00681 <font class="preprocessor"></font> <font class="keywordflow">if</font> (!stricmp(misc1.c_str(), <font class="stringliteral">"ZIP"</font>)) 00682 compress = <font class="keyword">new</font> ZipCompress(); 00683 <font class="keywordflow">else</font> 00684 <font class="preprocessor">#endif</font> 00685 <font class="preprocessor"></font> <font class="keywordflow">if</font> (!stricmp(misc1.c_str(), <font class="stringliteral">"LZSS"</font>)) 00686 compress = <font class="keyword">new</font> LZSSCompress(); 00687 00688 <font class="keywordflow">if</font> (compress) { 00689 <font class="keywordflow">if</font> (!stricmp(driver.c_str(), <font class="stringliteral">"zText"</font>)) 00690 newmod = <font class="keyword">new</font> zText(datapath.c_str(), name.c_str(), description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str()); 00691 <font class="keywordflow">else</font> newmod = <font class="keyword">new</font> zCom(datapath.c_str(), name.c_str(), description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str()); 00692 } 00693 } 00694 00695 <font class="keywordflow">if</font> (!stricmp(driver.c_str(), <font class="stringliteral">"RawText"</font>)) { 00696 newmod = <font class="keyword">new</font> RawText(datapath.c_str(), name.c_str(), description.c_str(), 0, enc, direction, markup, lang.c_str()); 00697 } 00698 00699 <font class="comment">// backward support old drivers</font> 00700 <font class="keywordflow">if</font> (!stricmp(driver.c_str(), <font class="stringliteral">"RawGBF"</font>)) { 00701 newmod = <font class="keyword">new</font> RawText(datapath.c_str(), name.c_str(), description.c_str(), 0, enc, direction, markup, lang.c_str()); 00702 } 00703 00704 <font class="keywordflow">if</font> (!stricmp(driver.c_str(), <font class="stringliteral">"RawCom"</font>)) { 00705 newmod = <font class="keyword">new</font> RawCom(datapath.c_str(), name.c_str(), description.c_str(), 0, enc, direction, markup, lang.c_str()); 00706 } 00707 00708 <font class="keywordflow">if</font> (!stricmp(driver.c_str(), <font class="stringliteral">"RawFiles"</font>)) { 00709 newmod = <font class="keyword">new</font> RawFiles(datapath.c_str(), name.c_str(), description.c_str(), 0, enc, direction, markup, lang.c_str()); 00710 } 00711 00712 <font class="keywordflow">if</font> (!stricmp(driver.c_str(), <font class="stringliteral">"HREFCom"</font>)) { 00713 misc1 = ((entry = section.find(<font class="stringliteral">"Prefix"</font>)) != section.end()) ? (*entry).second : (string)<font class="stringliteral">""</font>; 00714 newmod = <font class="keyword">new</font> HREFCom(datapath.c_str(), misc1.c_str(), name.c_str(), description.c_str()); 00715 } 00716 00717 <font class="keywordflow">if</font> (!stricmp(driver.c_str(), <font class="stringliteral">"RawLD"</font>)) 00718 newmod = <font class="keyword">new</font> RawLD(datapath.c_str(), name.c_str(), description.c_str(), 0, enc, direction, markup, lang.c_str()); 00719 00720 <font class="keywordflow">if</font> (!stricmp(driver.c_str(), <font class="stringliteral">"RawLD4"</font>)) 00721 newmod = <font class="keyword">new</font> RawLD4(datapath.c_str(), name.c_str(), description.c_str(), 0, enc, direction, markup, lang.c_str()); 00722 00723 <font class="keywordflow">if</font> (!stricmp(driver.c_str(), <font class="stringliteral">"zLD"</font>)) { 00724 SWCompress *compress = 0; 00725 <font class="keywordtype">int</font> blockCount; 00726 misc1 = ((entry = section.find(<font class="stringliteral">"BlockCount"</font>)) != section.end()) ? (*entry).second : (string)<font class="stringliteral">"200"</font>; 00727 blockCount = atoi(misc1.c_str()); 00728 blockCount = (blockCount) ? blockCount : 200; 00729 00730 misc1 = ((entry = section.find(<font class="stringliteral">"CompressType"</font>)) != section.end()) ? (*entry).second : (string)<font class="stringliteral">"LZSS"</font>; 00731 <font class="preprocessor">#ifndef EXCLUDEZLIB</font> 00732 <font class="preprocessor"></font> <font class="keywordflow">if</font> (!stricmp(misc1.c_str(), <font class="stringliteral">"ZIP"</font>)) 00733 compress = <font class="keyword">new</font> ZipCompress(); 00734 <font class="keywordflow">else</font> 00735 <font class="preprocessor">#endif</font> 00736 <font class="preprocessor"></font> <font class="keywordflow">if</font> (!stricmp(misc1.c_str(), <font class="stringliteral">"LZSS"</font>)) 00737 compress = <font class="keyword">new</font> LZSSCompress(); 00738 00739 <font class="keywordflow">if</font> (compress) { 00740 newmod = <font class="keyword">new</font> zLD(datapath.c_str(), name.c_str(), description.c_str(), blockCount, compress, 0, enc, direction, markup, lang.c_str()); 00741 } 00742 } 00743 00744 <font class="keywordflow">if</font> (!stricmp(driver.c_str(), <font class="stringliteral">"RawGenBook"</font>)) { 00745 newmod = <font class="keyword">new</font> RawGenBook(datapath.c_str(), name.c_str(), description.c_str(), 0, enc, direction, markup, lang.c_str()); 00746 } 00747 <font class="comment">// if a specific module type is set in the config, use this</font> 00748 <font class="keywordflow">if</font> ((entry = section.find(<font class="stringliteral">"Type"</font>)) != section.end()) 00749 newmod-><a class="code" href="class_s_w_module.html#a17">Type</a>(entry->second.c_str()); 00750 00751 newmod-><a class="code" href="class_s_w_module.html#a5">setConfig</a>(&section); 00752 <font class="keywordflow">return</font> newmod; 00753 } 00754 00755 00756 <font class="keywordtype">void</font> SWMgr::AddGlobalOptions(<a class="code" href="class_s_w_module.html">SWModule</a> *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end) { 00757 <font class="keywordflow">for</font> (;start != end; start++) { 00758 FilterMap::iterator it; 00759 it = optionFilters.find((*start).second); 00760 <font class="keywordflow">if</font> (it != optionFilters.end()) { 00761 module-><a class="code" href="class_s_w_module.html#a54">AddOptionFilter</a>((*it).second); <font class="comment">// add filter to module and option as a valid option</font> 00762 OptionsList::iterator loop; 00763 <font class="keywordflow">for</font> (loop = options.begin(); loop != options.end(); loop++) { 00764 <font class="keywordflow">if</font> (!strcmp((*loop).c_str(), (*it).second->getOptionName())) 00765 <font class="keywordflow">break</font>; 00766 } 00767 <font class="keywordflow">if</font> (loop == options.end()) <font class="comment">// if we have not yet included the option</font> 00768 options.push_back((*it).second->getOptionName()); 00769 } 00770 } 00771 <font class="keywordflow">if</font> (filterMgr) 00772 filterMgr->AddGlobalOptions(module, section, start, end); 00773 } 00774 00775 00776 <font class="keywordtype">void</font> SWMgr::AddLocalOptions(<a class="code" href="class_s_w_module.html">SWModule</a> *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end) 00777 { 00778 <font class="keywordflow">for</font> (;start != end; start++) { 00779 FilterMap::iterator it; 00780 it = optionFilters.find((*start).second); 00781 <font class="keywordflow">if</font> (it != optionFilters.end()) { 00782 module-><a class="code" href="class_s_w_module.html#a54">AddOptionFilter</a>((*it).second); <font class="comment">// add filter to module</font> 00783 } 00784 } 00785 00786 <font class="keywordflow">if</font> (filterMgr) 00787 filterMgr->AddLocalOptions(module, section, start, end); 00788 } 00789 00790 <a name="l00791"></a><a class="code" href="class_s_w_mgr.html#b11">00791</a> <font class="keywordtype">void</font> <a class="code" href="class_s_w_mgr.html#b11">SWMgr::AddRawFilters</a>(<a class="code" href="class_s_w_module.html">SWModule</a> *module, ConfigEntMap &section) { 00792 string sourceformat, cipherKey; 00793 ConfigEntMap::iterator entry; 00794 00795 cipherKey = ((entry = section.find(<font class="stringliteral">"CipherKey"</font>)) != section.end()) ? (*entry).second : (string)<font class="stringliteral">""</font>; 00796 <font class="keywordflow">if</font> (!cipherKey.empty()) { 00797 SWFilter *cipherFilter = <font class="keyword">new</font> CipherFilter(cipherKey.c_str()); 00798 cipherFilters.insert(FilterMap::value_type(module-><a class="code" href="class_s_w_module.html#a15">Name</a>(), cipherFilter)); 00799 cleanupFilters.push_back(cipherFilter); 00800 module-><a class="code" href="class_s_w_module.html#a51">AddRawFilter</a>(cipherFilter); 00801 } 00802 00803 <font class="keywordflow">if</font> (filterMgr) 00804 filterMgr->AddRawFilters(module, section); 00805 } 00806 00807 <a name="l00808"></a><a class="code" href="class_s_w_mgr.html#b8">00808</a> <font class="keywordtype">void</font> <a class="code" href="class_s_w_mgr.html#b8">SWMgr::AddEncodingFilters</a>(<a class="code" href="class_s_w_module.html">SWModule</a> *module, ConfigEntMap &section) { 00809 00810 <font class="keywordflow">if</font> (filterMgr) 00811 filterMgr->AddEncodingFilters(module, section); 00812 } 00813 00814 <a name="l00815"></a><a class="code" href="class_s_w_mgr.html#b9">00815</a> <font class="keywordtype">void</font> <a class="code" href="class_s_w_mgr.html#b9">SWMgr::AddRenderFilters</a>(<a class="code" href="class_s_w_module.html">SWModule</a> *module, ConfigEntMap &section) { 00816 string sourceformat; 00817 ConfigEntMap::iterator entry; 00818 00819 sourceformat = ((entry = section.find(<font class="stringliteral">"SourceType"</font>)) != section.end()) ? (*entry).second : (string)<font class="stringliteral">""</font>; 00820 00821 <font class="comment">// Temporary: To support old module types</font> 00822 <font class="comment">// TODO: Remove at 1.6.0 release?</font> 00823 <font class="keywordflow">if</font> (sourceformat.empty()) { 00824 sourceformat = ((entry = section.find(<font class="stringliteral">"ModDrv"</font>)) != section.end()) ? (*entry).second : (string)<font class="stringliteral">""</font>; 00825 <font class="keywordflow">if</font> (!stricmp(sourceformat.c_str(), <font class="stringliteral">"RawGBF"</font>)) 00826 sourceformat = <font class="stringliteral">"GBF"</font>; 00827 <font class="keywordflow">else</font> sourceformat = <font class="stringliteral">""</font>; 00828 } 00829 00830 <font class="comment">// process module - eg. follows</font> 00831 <font class="comment">// if (!stricmp(sourceformat.c_str(), "GBF")) {</font> 00832 <font class="comment">// module->AddRenderFilter(gbftortf);</font> 00833 <font class="comment">// }</font> 00834 00835 <font class="keywordflow">if</font> (filterMgr) 00836 filterMgr->AddRenderFilters(module, section); 00837 00838 } 00839 00840 <a name="l00841"></a><a class="code" href="class_s_w_mgr.html#b10">00841</a> <font class="keywordtype">void</font> <a class="code" href="class_s_w_mgr.html#b10">SWMgr::AddStripFilters</a>(<a class="code" href="class_s_w_module.html">SWModule</a> *module, ConfigEntMap &section) 00842 { 00843 string sourceformat; 00844 ConfigEntMap::iterator entry; 00845 00846 sourceformat = ((entry = section.find(<font class="stringliteral">"SourceType"</font>)) != section.end()) ? (*entry).second : (string)<font class="stringliteral">""</font>; 00847 <font class="comment">// Temporary: To support old module types</font> 00848 <font class="keywordflow">if</font> (sourceformat.empty()) { 00849 sourceformat = ((entry = section.find(<font class="stringliteral">"ModDrv"</font>)) != section.end()) ? (*entry).second : (string)<font class="stringliteral">""</font>; 00850 <font class="keywordflow">if</font> (!stricmp(sourceformat.c_str(), <font class="stringliteral">"RawGBF"</font>)) 00851 sourceformat = <font class="stringliteral">"GBF"</font>; 00852 <font class="keywordflow">else</font> sourceformat = <font class="stringliteral">""</font>; 00853 } 00854 00855 <font class="keywordflow">if</font> (!stricmp(sourceformat.c_str(), <font class="stringliteral">"GBF"</font>)) { 00856 module-><a class="code" href="class_s_w_module.html#a49">AddStripFilter</a>(gbfplain); 00857 } 00858 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!stricmp(sourceformat.c_str(), <font class="stringliteral">"ThML"</font>)) { 00859 module-><a class="code" href="class_s_w_module.html#a49">AddStripFilter</a>(thmlplain); 00860 } 00861 00862 <font class="keywordflow">if</font> (filterMgr) 00863 filterMgr->AddStripFilters(module, section); 00864 00865 } 00866 00867 00868 <font class="keywordtype">void</font> SWMgr::CreateMods() { 00869 SectionMap::iterator it; 00870 ConfigEntMap::iterator start; 00871 ConfigEntMap::iterator end; 00872 ConfigEntMap::iterator entry; 00873 <a class="code" href="class_s_w_module.html">SWModule</a> *newmod; 00874 string driver, misc1; 00875 <font class="keywordflow">for</font> (it = <a class="code" href="class_s_w_mgr.html#m0">config</a>-><a class="code" href="class_s_w_config.html#m1">Sections</a>.begin(); it != <a class="code" href="class_s_w_mgr.html#m0">config</a>-><a class="code" href="class_s_w_config.html#m1">Sections</a>.end(); it++) { 00876 ConfigEntMap &section = (*it).second; 00877 newmod = 0; 00878 00879 driver = ((entry = section.find(<font class="stringliteral">"ModDrv"</font>)) != section.end()) ? (*entry).second : (string)<font class="stringliteral">""</font>; 00880 <font class="keywordflow">if</font> (!driver.empty()) { 00881 newmod = CreateMod((*it).first, driver, section); 00882 <font class="keywordflow">if</font> (newmod) { 00883 start = (*it).second.lower_bound(<font class="stringliteral">"GlobalOptionFilter"</font>); 00884 end = (*it).second.upper_bound(<font class="stringliteral">"GlobalOptionFilter"</font>); 00885 AddGlobalOptions(newmod, section, start, end); 00886 00887 start = (*it).second.lower_bound(<font class="stringliteral">"LocalOptionFilter"</font>); 00888 end = (*it).second.upper_bound(<font class="stringliteral">"LocalOptionFilter"</font>); 00889 AddLocalOptions(newmod, section, start, end); 00890 00891 <a class="code" href="class_s_w_mgr.html#b11">AddRawFilters</a>(newmod, section); 00892 <a class="code" href="class_s_w_mgr.html#b10">AddStripFilters</a>(newmod, section); 00893 <a class="code" href="class_s_w_mgr.html#b9">AddRenderFilters</a>(newmod, section); 00894 <a class="code" href="class_s_w_mgr.html#b8">AddEncodingFilters</a>(newmod, section); 00895 00896 <a class="code" href="class_s_w_mgr.html#m2">Modules</a>.insert(ModMap::value_type(newmod-><a class="code" href="class_s_w_module.html#a15">Name</a>(), newmod)); 00897 } 00898 } 00899 } 00900 } 00901 00902 00903 <font class="keywordtype">void</font> SWMgr::DeleteMods() { 00904 00905 ModMap::iterator it; 00906 00907 <font class="keywordflow">for</font> (it = <a class="code" href="class_s_w_mgr.html#m2">Modules</a>.begin(); it != <a class="code" href="class_s_w_mgr.html#m2">Modules</a>.end(); it++) 00908 <font class="keyword">delete</font> (*it).second; 00909 00910 <a class="code" href="class_s_w_mgr.html#m2">Modules</a>.clear(); 00911 } 00912 00913 <a name="l00914"></a><a class="code" href="class_s_w_mgr.html#a4">00914</a> <font class="keywordtype">void</font> <a class="code" href="class_s_w_mgr.html#a4">SWMgr::InstallScan</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *dirname) 00915 { 00916 DIR *dir; 00917 <font class="keyword">struct </font>dirent *ent; 00918 <font class="keywordtype">int</font> conffd = 0; 00919 string newmodfile; 00920 string targetName; 00921 00922 <font class="keywordflow">if</font> (!access(dirname, 04)) { 00923 <font class="keywordflow">if</font> ((dir = opendir(dirname))) { 00924 rewinddir(dir); 00925 <font class="keywordflow">while</font> ((ent = readdir(dir))) { 00926 <font class="keywordflow">if</font> ((strcmp(ent->d_name, <font class="stringliteral">"."</font>)) && (strcmp(ent->d_name, <font class="stringliteral">".."</font>))) { 00927 newmodfile = dirname; 00928 <font class="keywordflow">if</font> ((dirname[strlen(dirname)-1] != <font class="charliteral">'\\'</font>) && (dirname[strlen(dirname)-1] != <font class="charliteral">'/'</font>)) 00929 newmodfile += <font class="stringliteral">"/"</font>; 00930 newmodfile += ent->d_name; 00931 <font class="keywordflow">if</font> (configType) { 00932 <font class="keywordflow">if</font> (<a class="code" href="class_s_w_mgr.html#m0">config</a> > 0) 00933 close(conffd); 00934 targetName = configPath; 00935 <font class="keywordflow">if</font> ((configPath[strlen(configPath)-1] != <font class="charliteral">'\\'</font>) && (configPath[strlen(configPath)-1] != <font class="charliteral">'/'</font>)) 00936 targetName += <font class="stringliteral">"/"</font>; 00937 targetName += ent->d_name; 00938 conffd = open(targetName.c_str(), O_WRONLY|O_CREAT, S_IREAD|S_IWRITE); 00939 } 00940 <font class="keywordflow">else</font> { 00941 <font class="keywordflow">if</font> (conffd < 1) { 00942 conffd = open(<a class="code" href="class_s_w_mgr.html#m0">config</a>-><a class="code" href="class_s_w_config.html#m0">filename</a>.c_str(), O_WRONLY|O_APPEND); 00943 <font class="keywordflow">if</font> (conffd > 0) 00944 lseek(conffd, 0L, SEEK_END); 00945 } 00946 } 00947 AddModToConfig(conffd, newmodfile.c_str()); 00948 unlink(newmodfile.c_str()); 00949 } 00950 } 00951 <font class="keywordflow">if</font> (conffd > 0) 00952 close(conffd); 00953 closedir(dir); 00954 } 00955 } 00956 } 00957 00958 00959 <font class="keywordtype">char</font> SWMgr::AddModToConfig(<font class="keywordtype">int</font> conffd, <font class="keyword">const</font> <font class="keywordtype">char</font> *fname) 00960 { 00961 <font class="keywordtype">int</font> modfd; 00962 <font class="keywordtype">char</font> ch; 00963 00964 SWLog::systemlog->LogTimedInformation(<font class="stringliteral">"Found new module [%s]. Installing..."</font>, fname); 00965 modfd = open(fname, O_RDONLY); 00966 ch = <font class="charliteral">'\n'</font>; 00967 write(conffd, &ch, 1); 00968 <font class="keywordflow">while</font> (read(modfd, &ch, 1) == 1) 00969 write(conffd, &ch, 1); 00970 ch = <font class="charliteral">'\n'</font>; 00971 write(conffd, &ch, 1); 00972 close(modfd); 00973 <font class="keywordflow">return</font> 0; 00974 } 00975 00976 <a name="l00977"></a><a class="code" href="class_s_w_mgr.html#a6">00977</a> <font class="keywordtype">void</font> <a class="code" href="class_s_w_mgr.html#a6">SWMgr::setGlobalOption</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *option, <font class="keyword">const</font> <font class="keywordtype">char</font> *value) 00978 { 00979 <font class="keywordflow">for</font> (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { 00980 <font class="keywordflow">if</font> ((*it).second->getOptionName()) { 00981 <font class="keywordflow">if</font> (!stricmp(option, (*it).second->getOptionName())) 00982 (*it).second->setOptionValue(value); 00983 } 00984 } 00985 } 00986 00987 <a name="l00988"></a><a class="code" href="class_s_w_mgr.html#a7">00988</a> <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="class_s_w_mgr.html#a7">SWMgr::getGlobalOption</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *option) 00989 { 00990 <font class="keywordflow">for</font> (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { 00991 <font class="keywordflow">if</font> ((*it).second->getOptionName()) { 00992 <font class="keywordflow">if</font> (!stricmp(option, (*it).second->getOptionName())) 00993 <font class="keywordflow">return</font> (*it).second->getOptionValue(); 00994 } 00995 } 00996 <font class="keywordflow">return</font> 0; 00997 } 00998 00999 <a name="l01000"></a><a class="code" href="class_s_w_mgr.html#a8">01000</a> <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="class_s_w_mgr.html#a8">SWMgr::getGlobalOptionTip</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *option) 01001 { 01002 <font class="keywordflow">for</font> (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { 01003 <font class="keywordflow">if</font> ((*it).second->getOptionName()) { 01004 <font class="keywordflow">if</font> (!stricmp(option, (*it).second->getOptionName())) 01005 <font class="keywordflow">return</font> (*it).second->getOptionTip(); 01006 } 01007 } 01008 <font class="keywordflow">return</font> 0; 01009 } 01010 01011 <a name="l01012"></a><a class="code" href="class_s_w_mgr.html#a9">01012</a> OptionsList <a class="code" href="class_s_w_mgr.html#a9">SWMgr::getGlobalOptions</a>() 01013 { 01014 <font class="keywordflow">return</font> options; 01015 } 01016 01017 01018 OptionsList SWMgr::getGlobalOptionValues(<font class="keyword">const</font> <font class="keywordtype">char</font> *option) 01019 { 01020 OptionsList options; 01021 <font class="keywordflow">for</font> (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { 01022 <font class="keywordflow">if</font> ((*it).second->getOptionName()) { 01023 <font class="keywordflow">if</font> (!stricmp(option, (*it).second->getOptionName())) { 01024 options = (*it).second->getOptionValues(); 01025 <font class="keywordflow">break</font>; <font class="comment">// just find the first one. All option filters with the same option name should expect the same values</font> 01026 } 01027 } 01028 } 01029 <font class="keywordflow">return</font> options; 01030 } 01031 01032 <a name="l01033"></a><a class="code" href="class_s_w_mgr.html#a11">01033</a> <font class="keywordtype">signed</font> <font class="keywordtype">char</font> <a class="code" href="class_s_w_mgr.html#a11">SWMgr::setCipherKey</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *modName, <font class="keyword">const</font> <font class="keywordtype">char</font> *key) { 01034 FilterMap::iterator it; 01035 ModMap::iterator it2; 01036 01037 <font class="comment">// check for filter that already exists</font> 01038 it = cipherFilters.find(modName); 01039 <font class="keywordflow">if</font> (it != cipherFilters.end()) { 01040 ((CipherFilter *)(*it).second)->getCipher()->setCipherKey(key); 01041 <font class="keywordflow">return</font> 0; 01042 } 01043 <font class="comment">// check if module exists</font> 01044 <font class="keywordflow">else</font> { 01045 it2 = <a class="code" href="class_s_w_mgr.html#m2">Modules</a>.find(modName); 01046 <font class="keywordflow">if</font> (it2 != <a class="code" href="class_s_w_mgr.html#m2">Modules</a>.end()) { 01047 SWFilter *cipherFilter = <font class="keyword">new</font> CipherFilter(key); 01048 cipherFilters.insert(FilterMap::value_type(modName, cipherFilter)); 01049 cleanupFilters.push_back(cipherFilter); 01050 (*it2).second->AddRawFilter(cipherFilter); 01051 <font class="keywordflow">return</font> 0; 01052 } 01053 } 01054 <font class="keywordflow">return</font> -1; 01055 } </pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:13:00 2002 for The Sword Project by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.15 </small></address> </body> </html>