~ubuntu-branches/debian/squeeze/sword/squeeze

« back to all changes in this revision

Viewing changes to src/mgr/swmgr.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Glassey
  • Date: 2004-01-15 15:50:07 UTC
  • Revision ID: james.westby@ubuntu.com-20040115155007-n9mz4x0zxrs1isd3
Tags: upstream-1.5.7
ImportĀ upstreamĀ versionĀ 1.5.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 *  swmgr.cpp   - implementaion of class SWMgr used to interact with an install
 
3
 *                              base of sword modules.
 
4
 *
 
5
 * $Id: swmgr.cpp,v 1.96 2003/12/05 21:44:33 scribe Exp $
 
6
 *
 
7
 * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
 
8
 *      CrossWire Bible Society
 
9
 *      P. O. Box 2528
 
10
 *      Tempe, AZ  85280-2528
 
11
 *
 
12
 * This program is free software; you can redistribute it and/or modify it
 
13
 * under the terms of the GNU General Public License as published by the
 
14
 * Free Software Foundation version 2.
 
15
 *
 
16
 * This program is distributed in the hope that it will be useful, but
 
17
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
19
 * General Public License for more details.
 
20
 *
 
21
 */
 
22
 
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
#include <fcntl.h>
 
26
 
 
27
#ifndef __GNUC__
 
28
#include <io.h>
 
29
#else
 
30
#include <unistd.h>
 
31
#include <unixstr.h>
 
32
#endif
 
33
#include <sys/stat.h>
 
34
#ifndef _MSC_VER
 
35
#include <iostream>
 
36
#endif
 
37
#include <dirent.h>
 
38
 
 
39
#include <swmgr.h>
 
40
#include <rawtext.h>
 
41
#include <rawgenbook.h>
 
42
#include <rawcom.h>
 
43
#include <hrefcom.h>
 
44
#include <rawld.h>
 
45
#include <rawld4.h>
 
46
#include <utilfuns.h>
 
47
#include <gbfplain.h>
 
48
#include <thmlplain.h>
 
49
#include <osisplain.h>
 
50
#include <gbfstrongs.h>
 
51
#include <gbffootnotes.h>
 
52
#include <gbfheadings.h>
 
53
#include <gbfredletterwords.h>
 
54
#include <gbfmorph.h>
 
55
#include <osisheadings.h>
 
56
#include <osisfootnotes.h>
 
57
#include <osisstrongs.h>
 
58
#include <osismorph.h>
 
59
#include <osislemma.h>
 
60
#include <osisredletterwords.h>
 
61
#include <osisscripref.h>
 
62
#include <thmlstrongs.h>
 
63
#include <thmlfootnotes.h>
 
64
#include <thmlheadings.h>
 
65
#include <thmlmorph.h>
 
66
#include <thmlvariants.h>
 
67
#include <thmllemma.h>
 
68
#include <thmlscripref.h>
 
69
#include <cipherfil.h>
 
70
#include <rawfiles.h>
 
71
#include <ztext.h>
 
72
#include <zld.h>
 
73
#include <zcom.h>
 
74
#include <lzsscomprs.h>
 
75
#include <utf8greekaccents.h>
 
76
#include <utf8cantillation.h>
 
77
#include <utf8hebrewpoints.h>
 
78
#include <greeklexattribs.h>
 
79
#include <swfiltermgr.h>
 
80
#ifndef EXCLUDEZLIB
 
81
#include "zipcomprs.h"
 
82
#endif
 
83
 
 
84
 
 
85
#ifdef _ICU_
 
86
#include <utf8transliterator.h>
 
87
#endif
 
88
 
 
89
SWORD_NAMESPACE_START
 
90
 
 
91
#ifdef _ICU_
 
92
bool SWMgr::isICU = true;
 
93
#else
 
94
bool SWMgr::isICU = false;
 
95
#endif
 
96
 
 
97
 
 
98
bool SWMgr::debug = false;
 
99
 
 
100
#ifdef GLOBCONFPATH
 
101
const char *SWMgr::globalConfPath = GLOBCONFPATH;
 
102
#else
 
103
const char *SWMgr::globalConfPath = "/etc/sword.conf:/usr/local/etc/sword.conf";
 
104
#endif
 
105
 
 
106
void SWMgr::init() {
 
107
        SWFilter *tmpFilter = 0;
 
108
        configPath  = 0;
 
109
        prefixPath  = 0;
 
110
        configType  = 0;
 
111
        myconfig    = 0;
 
112
        mysysconfig = 0;
 
113
        homeConfig = 0;
 
114
 
 
115
 
 
116
        cipherFilters.clear();
 
117
        optionFilters.clear();
 
118
        cleanupFilters.clear();
 
119
 
 
120
        tmpFilter = new ThMLVariants();
 
121
        optionFilters.insert(FilterMap::value_type("ThMLVariants", tmpFilter));
 
122
        cleanupFilters.push_back(tmpFilter);
 
123
 
 
124
        tmpFilter = new GBFStrongs();
 
125
        optionFilters.insert(FilterMap::value_type("GBFStrongs", tmpFilter));
 
126
        cleanupFilters.push_back(tmpFilter);
 
127
 
 
128
        tmpFilter = new GBFFootnotes();
 
129
        optionFilters.insert(FilterMap::value_type("GBFFootnotes", tmpFilter));
 
130
        cleanupFilters.push_back(tmpFilter);
 
131
 
 
132
        tmpFilter = new GBFRedLetterWords();
 
133
        optionFilters.insert(FilterMap::value_type("GBFRedLetterWords", tmpFilter));
 
134
        cleanupFilters.push_back(tmpFilter);
 
135
 
 
136
        tmpFilter = new GBFMorph();
 
137
        optionFilters.insert(FilterMap::value_type("GBFMorph", tmpFilter));
 
138
        cleanupFilters.push_back(tmpFilter);
 
139
 
 
140
        tmpFilter = new GBFHeadings();
 
141
        optionFilters.insert(FilterMap::value_type("GBFHeadings", tmpFilter));
 
142
        cleanupFilters.push_back(tmpFilter);
 
143
 
 
144
        tmpFilter = new OSISHeadings();
 
145
        optionFilters.insert(FilterMap::value_type("OSISHeadings", tmpFilter));
 
146
        cleanupFilters.push_back(tmpFilter);
 
147
 
 
148
        tmpFilter = new OSISStrongs();
 
149
        optionFilters.insert(FilterMap::value_type("OSISStrongs", tmpFilter));
 
150
        cleanupFilters.push_back(tmpFilter);
 
151
 
 
152
        tmpFilter = new OSISMorph();
 
153
        optionFilters.insert(FilterMap::value_type("OSISMorph", tmpFilter));
 
154
        cleanupFilters.push_back(tmpFilter);
 
155
 
 
156
        tmpFilter = new OSISLemma();
 
157
        optionFilters.insert(FilterMap::value_type("OSISLemma", tmpFilter));
 
158
        cleanupFilters.push_back(tmpFilter);
 
159
 
 
160
        tmpFilter = new OSISFootnotes();
 
161
        optionFilters.insert(FilterMap::value_type("OSISFootnotes", tmpFilter));
 
162
        cleanupFilters.push_back(tmpFilter);
 
163
 
 
164
        tmpFilter = new OSISScripref();
 
165
        optionFilters.insert(FilterMap::value_type("OSISScripref", tmpFilter));
 
166
        cleanupFilters.push_back(tmpFilter);
 
167
 
 
168
        tmpFilter = new OSISRedLetterWords();
 
169
        optionFilters.insert(FilterMap::value_type("OSISRedLetterWords", tmpFilter));
 
170
        cleanupFilters.push_back(tmpFilter);
 
171
 
 
172
        tmpFilter = new ThMLStrongs();
 
173
        optionFilters.insert(FilterMap::value_type("ThMLStrongs", tmpFilter));
 
174
        cleanupFilters.push_back(tmpFilter);
 
175
 
 
176
        tmpFilter = new ThMLFootnotes();
 
177
        optionFilters.insert(FilterMap::value_type("ThMLFootnotes", tmpFilter));
 
178
        cleanupFilters.push_back(tmpFilter);
 
179
 
 
180
        tmpFilter = new ThMLMorph();
 
181
        optionFilters.insert(FilterMap::value_type("ThMLMorph", tmpFilter));
 
182
        cleanupFilters.push_back(tmpFilter);
 
183
 
 
184
        tmpFilter = new ThMLHeadings();
 
185
        optionFilters.insert(FilterMap::value_type("ThMLHeadings", tmpFilter));
 
186
        cleanupFilters.push_back(tmpFilter);
 
187
 
 
188
        tmpFilter = new ThMLLemma();
 
189
        optionFilters.insert(FilterMap::value_type("ThMLLemma", tmpFilter));
 
190
        cleanupFilters.push_back(tmpFilter);
 
191
 
 
192
        tmpFilter = new ThMLScripref();
 
193
        optionFilters.insert(FilterMap::value_type("ThMLScripref", tmpFilter));
 
194
        cleanupFilters.push_back(tmpFilter);
 
195
 
 
196
        tmpFilter = new UTF8GreekAccents();
 
197
        optionFilters.insert(FilterMap::value_type("UTF8GreekAccents", tmpFilter));
 
198
        cleanupFilters.push_back(tmpFilter);
 
199
 
 
200
        tmpFilter = new UTF8HebrewPoints();
 
201
        optionFilters.insert(FilterMap::value_type("UTF8HebrewPoints", tmpFilter));
 
202
        cleanupFilters.push_back(tmpFilter);
 
203
 
 
204
        tmpFilter = new UTF8Cantillation();
 
205
        optionFilters.insert(FilterMap::value_type("UTF8Cantillation", tmpFilter));
 
206
        cleanupFilters.push_back(tmpFilter);
 
207
 
 
208
        tmpFilter = new GreekLexAttribs();
 
209
        optionFilters.insert(FilterMap::value_type("GreekLexAttribs", tmpFilter));
 
210
        cleanupFilters.push_back(tmpFilter);
 
211
 
 
212
// UTF8Transliterator needs to be handled differently because it should always available as an option, for all modules
 
213
#ifdef _ICU_
 
214
        transliterator = new UTF8Transliterator();
 
215
        optionFilters.insert(FilterMap::value_type("UTF8Transliterator", transliterator));
 
216
        options.push_back(transliterator->getOptionName());
 
217
        cleanupFilters.push_back(transliterator);
 
218
#endif
 
219
 
 
220
        gbfplain = new GBFPlain();
 
221
        cleanupFilters.push_back(gbfplain);
 
222
 
 
223
        thmlplain = new ThMLPlain();
 
224
        cleanupFilters.push_back(thmlplain);
 
225
 
 
226
        osisplain = new OSISPlain();
 
227
        cleanupFilters.push_back(osisplain);
 
228
}
 
229
 
 
230
 
 
231
SWMgr::SWMgr(SWFilterMgr *filterMgr) {
 
232
        commonInit(0, 0, true, filterMgr);
 
233
}
 
234
 
 
235
 
 
236
SWMgr::SWMgr(SWConfig *iconfig, SWConfig *isysconfig, bool autoload, SWFilterMgr *filterMgr) {
 
237
        commonInit(iconfig, isysconfig, autoload, filterMgr);
 
238
}
 
239
 
 
240
 
 
241
void SWMgr::commonInit(SWConfig * iconfig, SWConfig * isysconfig, bool autoload, SWFilterMgr *filterMgr) {
 
242
        this->filterMgr = filterMgr;
 
243
        if (filterMgr)
 
244
                filterMgr->setParentMgr(this);
 
245
 
 
246
        init();
 
247
        
 
248
        if (iconfig) {
 
249
                config   = iconfig;
 
250
                myconfig = 0;
 
251
        }
 
252
        else config = 0;
 
253
        if (isysconfig) {
 
254
                sysconfig   = isysconfig;
 
255
                mysysconfig = 0;
 
256
        }
 
257
        else sysconfig = 0;
 
258
 
 
259
        if (autoload)
 
260
                Load();
 
261
}
 
262
 
 
263
 
 
264
SWMgr::SWMgr(const char *iConfigPath, bool autoload, SWFilterMgr *filterMgr) {
 
265
 
 
266
        SWBuf path;
 
267
        
 
268
        this->filterMgr = filterMgr;
 
269
        if (filterMgr)
 
270
                filterMgr->setParentMgr(this);
 
271
 
 
272
        init();
 
273
        
 
274
        path = iConfigPath;
 
275
        int len = path.length();
 
276
        if ((len < 1) || (iConfigPath[len-1] != '\\') && (iConfigPath[len-1] != '/'))
 
277
                path += "/";
 
278
        if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
 
279
                stdstr(&prefixPath, path.c_str());
 
280
                path += "mods.conf";
 
281
                stdstr(&configPath, path.c_str());
 
282
        }
 
283
        else {
 
284
                if (FileMgr::existsDir(path.c_str(), "mods.d")) {
 
285
                        stdstr(&prefixPath, path.c_str());
 
286
                        path += "mods.d";
 
287
                        stdstr(&configPath, path.c_str());
 
288
                        configType = 1;
 
289
                }
 
290
        }
 
291
 
 
292
        config = 0;
 
293
        sysconfig = 0;
 
294
 
 
295
        if (autoload && configPath)
 
296
                Load();
 
297
}
 
298
 
 
299
 
 
300
SWMgr::~SWMgr() {
 
301
 
 
302
        DeleteMods();
 
303
 
 
304
        for (FilterList::iterator it = cleanupFilters.begin(); it != cleanupFilters.end(); it++)
 
305
                delete (*it);
 
306
                        
 
307
        if (homeConfig)
 
308
                delete homeConfig;
 
309
 
 
310
        if (myconfig)
 
311
                delete myconfig;
 
312
 
 
313
        if (prefixPath)
 
314
                delete [] prefixPath;
 
315
 
 
316
        if (configPath)
 
317
                delete [] configPath;
 
318
 
 
319
        if (filterMgr)
 
320
                delete filterMgr;
 
321
}
 
322
 
 
323
 
 
324
void SWMgr::findConfig(char *configType, char **prefixPath, char **configPath, std::list<SWBuf> *augPaths) {
 
325
        SWBuf path;
 
326
        ConfigEntMap::iterator entry;
 
327
        ConfigEntMap::iterator lastEntry;
 
328
 
 
329
        char *envsworddir = getenv ("SWORD_PATH");
 
330
        char *envhomedir  = getenv ("HOME");
 
331
 
 
332
        *configType = 0;
 
333
 
 
334
#ifndef _MSC_VER
 
335
        // check working directory
 
336
if (debug)
 
337
        std::cerr << "Checking working directory for mods.conf...";
 
338
#endif
 
339
 
 
340
        if (FileMgr::existsFile(".", "mods.conf")) {
 
341
 
 
342
#ifndef _MSC_VER
 
343
if (debug)
 
344
        std::cerr << "found\n";
 
345
#endif
 
346
 
 
347
                stdstr(prefixPath, "./");
 
348
                stdstr(configPath, "./mods.conf");
 
349
                return;
 
350
        }
 
351
 
 
352
#ifndef _MSC_VER
 
353
if (debug)
 
354
        std::cerr << "\nChecking working directory for mods.d...";
 
355
#endif
 
356
 
 
357
        if (FileMgr::existsDir(".", "mods.d")) {
 
358
 
 
359
#ifndef _MSC_VER
 
360
if (debug)
 
361
        std::cerr << "found\n";
 
362
#endif
 
363
 
 
364
                stdstr(prefixPath, "./");
 
365
                stdstr(configPath, "./mods.d");
 
366
                *configType = 1;
 
367
                return;
 
368
        }
 
369
 
 
370
 
 
371
        // check environment variable SWORD_PATH
 
372
#ifndef _MSC_VER
 
373
if (debug)
 
374
        std::cerr << "\nChecking SWORD_PATH...";
 
375
#endif
 
376
 
 
377
        if (envsworddir != NULL) {
 
378
 
 
379
#ifndef _MSC_VER
 
380
if (debug)
 
381
        std::cerr << "found (" << envsworddir << ")\n";
 
382
#endif
 
383
 
 
384
                path = envsworddir;
 
385
                if ((envsworddir[strlen(envsworddir)-1] != '\\') && (envsworddir[strlen(envsworddir)-1] != '/'))
 
386
                        path += "/";
 
387
 
 
388
#ifndef _MSC_VER
 
389
if (debug)
 
390
        std::cerr << "\nChecking $SWORD_PATH for mods.conf...";
 
391
#endif
 
392
 
 
393
                if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
 
394
 
 
395
#ifndef _MSC_VER
 
396
if (debug)
 
397
        std::cerr << "found\n";
 
398
#endif
 
399
 
 
400
                        stdstr(prefixPath, path.c_str());
 
401
                        path += "mods.conf";
 
402
                        stdstr(configPath, path.c_str());
 
403
                        return;
 
404
                }
 
405
 
 
406
#ifndef _MSC_VER
 
407
if (debug)
 
408
        std::cerr << "\nChecking $SWORD_PATH for mods.d...";
 
409
#endif
 
410
 
 
411
                if (FileMgr::existsDir(path.c_str(), "mods.d")) {
 
412
 
 
413
#ifndef _MSC_VER
 
414
if (debug)
 
415
        std::cerr << "found\n";
 
416
#endif
 
417
 
 
418
                        stdstr(prefixPath, path.c_str());
 
419
                        path += "mods.d";
 
420
                        stdstr(configPath, path.c_str());
 
421
                        *configType = 1;
 
422
                        return;
 
423
                }
 
424
        }
 
425
 
 
426
 
 
427
        // check for systemwide globalConfPath
 
428
 
 
429
#ifndef _MSC_VER
 
430
if (debug)
 
431
        std::cerr << "\nParsing " << globalConfPath << "...";
 
432
#endif
 
433
 
 
434
        char *globPaths = 0;
 
435
        char *gfp;
 
436
        stdstr(&globPaths, globalConfPath);
 
437
        for (gfp = strtok(globPaths, ":"); gfp; gfp = strtok(0, ":")) {
 
438
 
 
439
#ifndef _MSC_VER
 
440
if (debug)
 
441
        std::cerr << "\nChecking for " << gfp << "...";
 
442
#endif
 
443
 
 
444
                if (FileMgr::existsFile(gfp))
 
445
                        break;
 
446
        }
 
447
        SWBuf sysConfPath;
 
448
        if (gfp)
 
449
                sysConfPath = gfp;
 
450
 
 
451
        SWBuf homeDir  = getenv ("HOME");
 
452
        if (homeDir.size() > 0) {
 
453
                if ((homeDir[homeDir.size()-1] != '\\') && (homeDir[homeDir.size()-1] != '/'))
 
454
                        homeDir += "/";
 
455
                homeDir += ".sword/sword.conf";
 
456
                if (FileMgr::existsFile(homeDir)) {
 
457
#ifndef _MSC_VER
 
458
if (debug)
 
459
        std::cerr << "\nOverriding any systemwide sword.conf with one found in users home directory." << gfp << "...";
 
460
#endif
 
461
                        sysConfPath = homeDir;
 
462
                }
 
463
        }
 
464
 
 
465
 
 
466
        if (sysConfPath.size()) {
 
467
 
 
468
#ifndef _MSC_VER
 
469
if (debug)
 
470
        std::cerr << "found\n";
 
471
#endif
 
472
 
 
473
                SWConfig etcconf(sysConfPath);
 
474
                if ((entry = etcconf.Sections["Install"].find("DataPath")) != etcconf.Sections["Install"].end()) {
 
475
                        path = (*entry).second;
 
476
                        if (((*entry).second.c_str()[strlen((*entry).second.c_str())-1] != '\\') && ((*entry).second.c_str()[strlen((*entry).second.c_str())-1] != '/'))
 
477
                                path += "/";
 
478
 
 
479
#ifndef _MSC_VER
 
480
if (debug)
 
481
        std::cerr << "DataPath in " << sysConfPath << " is set to: " << path;
 
482
#endif
 
483
 
 
484
#ifndef _MSC_VER
 
485
if (debug)
 
486
        std::cerr << "\nChecking for mods.conf in DataPath ";
 
487
#endif
 
488
                        if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
 
489
 
 
490
#ifndef _MSC_VER
 
491
if (debug)
 
492
        std::cerr << "found\n";
 
493
#endif
 
494
 
 
495
                                stdstr(prefixPath, path.c_str());
 
496
                                path += "mods.conf";
 
497
                                stdstr(configPath, path.c_str());
 
498
                                *configType = 1;
 
499
                        }
 
500
 
 
501
#ifndef _MSC_VER
 
502
if (debug)
 
503
        std::cerr << "\nChecking for mods.d in DataPath ";
 
504
#endif
 
505
 
 
506
                        if (FileMgr::existsDir(path.c_str(), "mods.d")) {
 
507
 
 
508
#ifndef _MSC_VER
 
509
if (debug)
 
510
        std::cerr << "found\n";
 
511
#endif
 
512
 
 
513
                                stdstr(prefixPath, path.c_str());
 
514
                                path += "mods.d";
 
515
                                stdstr(configPath, path.c_str());
 
516
                                *configType = 1;
 
517
                        }
 
518
                }
 
519
                if (augPaths) {
 
520
                        augPaths->clear();
 
521
                        entry     = etcconf.Sections["Install"].lower_bound("AugmentPath");
 
522
                        lastEntry = etcconf.Sections["Install"].upper_bound("AugmentPath");
 
523
                        for (;entry != lastEntry; entry++) {
 
524
                                path = entry->second;
 
525
                                if ((entry->second.c_str()[strlen(entry->second.c_str())-1] != '\\') && (entry->second.c_str()[strlen(entry->second.c_str())-1] != '/'))
 
526
                                        path += "/";
 
527
                                augPaths->push_back(path);
 
528
                        }
 
529
                }
 
530
        }
 
531
 
 
532
        delete [] globPaths;
 
533
        if (*configType)
 
534
                return;
 
535
 
 
536
        // check ~/.sword/
 
537
 
 
538
#ifndef _MSC_VER
 
539
if (debug)
 
540
        std::cerr << "\nChecking home directory for ~/.sword/mods.conf" << path;
 
541
#endif
 
542
 
 
543
        if (envhomedir != NULL) {
 
544
                path = envhomedir;
 
545
                if ((envhomedir[strlen(envhomedir)-1] != '\\') && (envhomedir[strlen(envhomedir)-1] != '/'))
 
546
                        path += "/";
 
547
                path += ".sword/";
 
548
                if (FileMgr::existsFile(path.c_str(), "mods.conf")) {
 
549
 
 
550
#ifndef _MSC_VER
 
551
if (debug)
 
552
        std::cerr << " found\n";
 
553
#endif
 
554
 
 
555
                        stdstr(prefixPath, path.c_str());
 
556
                        path += "mods.conf";
 
557
                        stdstr(configPath, path.c_str());
 
558
                        return;
 
559
                }
 
560
 
 
561
#ifndef _MSC_VER
 
562
if (debug)
 
563
        std::cerr << "\nChecking home directory for ~/.sword/mods.d" << path;
 
564
#endif
 
565
 
 
566
                if (FileMgr::existsDir(path.c_str(), "mods.d")) {
 
567
 
 
568
#ifndef _MSC_VER
 
569
if (debug)
 
570
        std::cerr << "found\n";
 
571
#endif
 
572
 
 
573
                        stdstr(prefixPath, path.c_str());
 
574
                        path += "mods.d";
 
575
                        stdstr(configPath, path.c_str());
 
576
                        *configType = 2;
 
577
                        return;
 
578
                }
 
579
        }
 
580
}
 
581
 
 
582
 
 
583
void SWMgr::loadConfigDir(const char *ipath)
 
584
{
 
585
   DIR *dir;
 
586
   struct dirent *ent;
 
587
   SWBuf newmodfile;
 
588
 
 
589
        if ((dir = opendir(ipath))) {
 
590
                rewinddir(dir);
 
591
                while ((ent = readdir(dir))) {
 
592
                        if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
 
593
                                newmodfile = ipath;
 
594
                                if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/'))
 
595
                                        newmodfile += "/";
 
596
                                newmodfile += ent->d_name;
 
597
                                if (config) {
 
598
                                        SWConfig tmpConfig(newmodfile.c_str());
 
599
                                        *config += tmpConfig;
 
600
                                }
 
601
                                else    config = myconfig = new SWConfig(newmodfile.c_str());
 
602
                        }
 
603
                }
 
604
                closedir(dir);
 
605
                if (!config) {  // if no .conf file exist yet, create a default
 
606
                        newmodfile = ipath;
 
607
                        if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/'))
 
608
                                newmodfile += "/";
 
609
                        newmodfile += "globals.conf";
 
610
                        config = myconfig = new SWConfig(newmodfile.c_str());
 
611
                }
 
612
        }
 
613
}
 
614
 
 
615
 
 
616
void SWMgr::augmentModules(const char *ipath) {
 
617
        SWBuf path = ipath;
 
618
        if ((ipath[strlen(ipath)-1] != '\\') && (ipath[strlen(ipath)-1] != '/'))
 
619
                path += "/";
 
620
        if (FileMgr::existsDir(path.c_str(), "mods.d")) {
 
621
                char *savePrefixPath = 0;
 
622
                char *saveConfigPath = 0;
 
623
                SWConfig *saveConfig = 0;
 
624
                stdstr(&savePrefixPath, prefixPath);
 
625
                stdstr(&prefixPath, path.c_str());
 
626
                path += "mods.d";
 
627
                stdstr(&saveConfigPath, configPath);
 
628
                stdstr(&configPath, path.c_str());
 
629
                saveConfig = config;
 
630
                config = myconfig = 0;
 
631
                loadConfigDir(configPath);
 
632
 
 
633
                CreateMods();
 
634
 
 
635
                stdstr(&prefixPath, savePrefixPath);
 
636
                delete []savePrefixPath;
 
637
                stdstr(&configPath, saveConfigPath);
 
638
                delete []saveConfigPath;
 
639
                (*saveConfig) += *config;
 
640
                homeConfig = myconfig;
 
641
                config = myconfig = saveConfig;
 
642
        }
 
643
}
 
644
 
 
645
 
 
646
/***********************************************************************
 
647
 * SWMgr::Load - loads actual modules
 
648
 *
 
649
 * RET: status - 0 = ok; -1 no config found; 1 = no modules installed
 
650
 *
 
651
 */
 
652
 
 
653
signed char SWMgr::Load() {
 
654
        signed char ret = 0;
 
655
 
 
656
        if (!config) {  // If we weren't passed a config object at construction, find a config file
 
657
                if (!configPath)        // If we weren't passed a config path at construction...
 
658
                        findConfig(&configType, &prefixPath, &configPath, &augPaths);
 
659
                if (configPath) {
 
660
                        if (configType)
 
661
                                loadConfigDir(configPath);
 
662
                        else    config = myconfig = new SWConfig(configPath);
 
663
                }
 
664
        }
 
665
 
 
666
        if (config) {
 
667
                SectionMap::iterator Sectloop, Sectend;
 
668
                ConfigEntMap::iterator Entryloop, Entryend;
 
669
 
 
670
                DeleteMods();
 
671
 
 
672
                for (Sectloop = config->Sections.lower_bound("Globals"), Sectend = config->Sections.upper_bound("Globals"); Sectloop != Sectend; Sectloop++) {          // scan thru all 'Globals' sections
 
673
                        for (Entryloop = (*Sectloop).second.lower_bound("AutoInstall"), Entryend = (*Sectloop).second.upper_bound("AutoInstall"); Entryloop != Entryend; Entryloop++)   // scan thru all AutoInstall entries
 
674
                                InstallScan((*Entryloop).second.c_str());               // Scan AutoInstall entry directory for new modules and install
 
675
                }               
 
676
                if (configType) {       // force reload on config object because we may have installed new modules
 
677
                        delete myconfig;
 
678
                        config = myconfig = 0;
 
679
                        loadConfigDir(configPath);
 
680
                }
 
681
                else    config->Load();
 
682
 
 
683
                CreateMods();
 
684
 
 
685
                for (std::list<SWBuf>::iterator pathIt = augPaths.begin(); pathIt != augPaths.end(); pathIt++) {
 
686
                        augmentModules(pathIt->c_str());
 
687
                }
 
688
//      augment config with ~/.sword/mods.d if it exists ---------------------
 
689
                char *envhomedir  = getenv ("HOME");
 
690
                if (envhomedir != NULL && configType != 2) { // 2 = user only
 
691
                        SWBuf path = envhomedir;
 
692
                        if ((envhomedir[strlen(envhomedir)-1] != '\\') && (envhomedir[strlen(envhomedir)-1] != '/'))
 
693
                                path += "/";
 
694
                        path += ".sword/";
 
695
                        augmentModules(path.c_str());
 
696
                }
 
697
// -------------------------------------------------------------------------
 
698
                if ( !Modules.size() ) // config exists, but no modules
 
699
                        ret = 1;
 
700
 
 
701
        }
 
702
        else {
 
703
                SWLog::systemlog->LogError("SWMgr: Can't find 'mods.conf' or 'mods.d'.  Try setting:\n\tSWORD_PATH=<directory containing mods.conf>\n\tOr see the README file for a full description of setup options (%s)", (configPath) ? configPath : "<configPath is null>");
 
704
                ret = -1;
 
705
        }
 
706
 
 
707
        return ret;
 
708
}
 
709
 
 
710
SWModule *SWMgr::CreateMod(const char *name, const char *driver, ConfigEntMap &section)
 
711
{
 
712
        SWBuf description, datapath, misc1;
 
713
        ConfigEntMap::iterator entry;
 
714
        SWModule *newmod = 0;
 
715
        SWBuf lang, sourceformat, encoding;
 
716
        signed char direction, enc, markup;
 
717
 
 
718
        description  = ((entry = section.find("Description")) != section.end()) ? (*entry).second : (SWBuf)"";
 
719
        lang  = ((entry = section.find("Lang")) != section.end()) ? (*entry).second : (SWBuf)"en";
 
720
        sourceformat = ((entry = section.find("SourceType"))  != section.end()) ? (*entry).second : (SWBuf)"";
 
721
        encoding = ((entry = section.find("Encoding"))  != section.end()) ? (*entry).second : (SWBuf)"";
 
722
        datapath = prefixPath;
 
723
        if ((prefixPath[strlen(prefixPath)-1] != '\\') && (prefixPath[strlen(prefixPath)-1] != '/'))
 
724
                datapath += "/";
 
725
        misc1 += ((entry = section.find("DataPath")) != section.end()) ? (*entry).second : (SWBuf)"";
 
726
        char *buf = new char [ strlen(misc1.c_str()) + 1 ];
 
727
        char *buf2 = buf;
 
728
        strcpy(buf, misc1.c_str());
 
729
//      for (; ((*buf2) && ((*buf2 == '.') || (*buf2 == '/') || (*buf2 == '\\'))); buf2++);
 
730
        for (; ((*buf2) && ((*buf2 == '/') || (*buf2 == '\\'))); buf2++);
 
731
        if (!strncmp(buf2, "./", 2)) { //remove the leading ./ in the module data path to make it look better
 
732
                buf2 += 2;
 
733
        }
 
734
        if (*buf2)
 
735
                datapath += buf2;
 
736
        delete [] buf;
 
737
 
 
738
        section["AbsoluteDataPath"] = datapath;
 
739
 
 
740
        if (!stricmp(sourceformat.c_str(), "GBF"))
 
741
                markup = FMT_GBF;
 
742
        else if (!stricmp(sourceformat.c_str(), "ThML"))
 
743
                markup = FMT_THML;
 
744
        else if (!stricmp(sourceformat.c_str(), "OSIS"))
 
745
                markup = FMT_OSIS;
 
746
        else
 
747
                markup = FMT_GBF;
 
748
 
 
749
        if (!stricmp(encoding.c_str(), "SCSU"))
 
750
                enc = ENC_SCSU;
 
751
        else if (!stricmp(encoding.c_str(), "UTF-8")) {
 
752
                enc = ENC_UTF8;
 
753
        }
 
754
        else enc = ENC_LATIN1;
 
755
 
 
756
        if ((entry = section.find("Direction")) == section.end()) {
 
757
                direction = DIRECTION_LTR;
 
758
        }
 
759
        else if (!stricmp((*entry).second.c_str(), "rtol")) {
 
760
                direction = DIRECTION_RTL;
 
761
        }
 
762
        else if (!stricmp((*entry).second.c_str(), "bidi")) {
 
763
                direction = DIRECTION_BIDI;
 
764
        }
 
765
        else {
 
766
                direction = DIRECTION_LTR;
 
767
        }
 
768
 
 
769
        if ((!stricmp(driver, "zText")) || (!stricmp(driver, "zCom"))) {
 
770
                SWCompress *compress = 0;
 
771
                int blockType = CHAPTERBLOCKS;
 
772
                misc1 = ((entry = section.find("BlockType")) != section.end()) ? (*entry).second : (SWBuf)"CHAPTER";
 
773
                if (!stricmp(misc1.c_str(), "VERSE"))
 
774
                        blockType = VERSEBLOCKS;
 
775
                else if (!stricmp(misc1.c_str(), "CHAPTER"))
 
776
                        blockType = CHAPTERBLOCKS;
 
777
                else if (!stricmp(misc1.c_str(), "BOOK"))
 
778
                        blockType = BOOKBLOCKS;
 
779
 
 
780
                misc1 = ((entry = section.find("CompressType")) != section.end()) ? (*entry).second : (SWBuf)"LZSS";
 
781
#ifndef EXCLUDEZLIB
 
782
                if (!stricmp(misc1.c_str(), "ZIP"))
 
783
                        compress = new ZipCompress();
 
784
                else
 
785
#endif
 
786
                if (!stricmp(misc1.c_str(), "LZSS"))
 
787
                        compress = new LZSSCompress();
 
788
 
 
789
                if (compress) {
 
790
                        if (!stricmp(driver, "zText"))
 
791
                                newmod = new zText(datapath.c_str(), name, description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str());
 
792
                        else    newmod = new zCom(datapath.c_str(), name, description.c_str(), blockType, compress, 0, enc, direction, markup, lang.c_str());
 
793
                }
 
794
        }
 
795
 
 
796
        if (!stricmp(driver, "RawText")) {
 
797
                newmod = new RawText(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
 
798
        }
 
799
 
 
800
        // backward support old drivers
 
801
        if (!stricmp(driver, "RawGBF")) {
 
802
                newmod = new RawText(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
 
803
        }
 
804
 
 
805
        if (!stricmp(driver, "RawCom")) {
 
806
                newmod = new RawCom(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
 
807
        }
 
808
 
 
809
        if (!stricmp(driver, "RawFiles")) {
 
810
                newmod = new RawFiles(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
 
811
        }
 
812
 
 
813
        if (!stricmp(driver, "HREFCom")) {
 
814
                misc1 = ((entry = section.find("Prefix")) != section.end()) ? (*entry).second : (SWBuf)"";
 
815
                newmod = new HREFCom(datapath.c_str(), misc1.c_str(), name, description.c_str());
 
816
        }
 
817
 
 
818
        int pos;  //used for position of final / in AbsoluteDataPath, but also set to 1 for modules types that need to strip module name
 
819
        if (!stricmp(driver, "RawLD")) {
 
820
                newmod = new RawLD(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
 
821
                pos = 1;
 
822
        }
 
823
 
 
824
        if (!stricmp(driver, "RawLD4")) {
 
825
                newmod = new RawLD4(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
 
826
                pos = 1;
 
827
        }
 
828
 
 
829
        if (!stricmp(driver, "zLD")) {
 
830
                SWCompress *compress = 0;
 
831
                int blockCount;
 
832
                misc1 = ((entry = section.find("BlockCount")) != section.end()) ? (*entry).second : (SWBuf)"200";
 
833
                blockCount = atoi(misc1.c_str());
 
834
                blockCount = (blockCount) ? blockCount : 200;
 
835
 
 
836
                misc1 = ((entry = section.find("CompressType")) != section.end()) ? (*entry).second : (SWBuf)"LZSS";
 
837
#ifndef EXCLUDEZLIB
 
838
                if (!stricmp(misc1.c_str(), "ZIP"))
 
839
                        compress = new ZipCompress();
 
840
                else
 
841
#endif
 
842
                if (!stricmp(misc1.c_str(), "LZSS"))
 
843
                        compress = new LZSSCompress();
 
844
 
 
845
                if (compress) {
 
846
                        newmod = new zLD(datapath.c_str(), name, description.c_str(), blockCount, compress, 0, enc, direction, markup, lang.c_str());
 
847
                }
 
848
                pos = 1;
 
849
        }
 
850
 
 
851
        if (!stricmp(driver, "RawGenBook")) {
 
852
                newmod = new RawGenBook(datapath.c_str(), name, description.c_str(), 0, enc, direction, markup, lang.c_str());
 
853
                pos = 1;
 
854
        }
 
855
 
 
856
        if (pos == 1) {
 
857
                SWBuf &dp = section["AbsoluteDataPath"];
 
858
                for (int i = dp.length() - 1; i; i--) {
 
859
                        if (dp[i] == '/') {
 
860
                                dp.setSize(i);
 
861
                                break;
 
862
                        }
 
863
                }
 
864
        }
 
865
 
 
866
        // if a specific module type is set in the config, use this
 
867
        if ((entry = section.find("Type")) != section.end())
 
868
                newmod->Type(entry->second.c_str());
 
869
 
 
870
        newmod->setConfig(&section);
 
871
        return newmod;
 
872
}
 
873
 
 
874
 
 
875
void SWMgr::AddGlobalOptions(SWModule *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end) {
 
876
        for (;start != end; start++) {
 
877
                FilterMap::iterator it;
 
878
                it = optionFilters.find((*start).second);
 
879
                if (it != optionFilters.end()) {
 
880
                        module->AddOptionFilter((*it).second);  // add filter to module and option as a valid option
 
881
                        StringList::iterator loop;
 
882
                        for (loop = options.begin(); loop != options.end(); loop++) {
 
883
                                if (!strcmp((*loop).c_str(), (*it).second->getOptionName()))
 
884
                                        break;
 
885
                        }
 
886
                        if (loop == options.end())      // if we have not yet included the option
 
887
                                options.push_back((*it).second->getOptionName());
 
888
                }
 
889
        }
 
890
        if (filterMgr)
 
891
                filterMgr->AddGlobalOptions(module, section, start, end);
 
892
#ifdef _ICU_
 
893
           module->AddOptionFilter(transliterator);
 
894
#endif
 
895
}
 
896
 
 
897
 
 
898
void SWMgr::AddLocalOptions(SWModule *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end)
 
899
{
 
900
        for (;start != end; start++) {
 
901
                FilterMap::iterator it;
 
902
                it = optionFilters.find((*start).second);
 
903
                if (it != optionFilters.end()) {
 
904
                        module->AddOptionFilter((*it).second);  // add filter to module
 
905
                }
 
906
        }
 
907
 
 
908
        if (filterMgr)
 
909
                filterMgr->AddLocalOptions(module, section, start, end);
 
910
}
 
911
 
 
912
 
 
913
void SWMgr::AddRawFilters(SWModule *module, ConfigEntMap &section) {
 
914
        SWBuf sourceformat, cipherKey;
 
915
        ConfigEntMap::iterator entry;
 
916
 
 
917
        cipherKey = ((entry = section.find("CipherKey")) != section.end()) ? (*entry).second : (SWBuf)"";
 
918
        if (cipherKey.length()) {
 
919
                SWFilter *cipherFilter = new CipherFilter(cipherKey.c_str());
 
920
                cipherFilters.insert(FilterMap::value_type(module->Name(), cipherFilter));
 
921
                cleanupFilters.push_back(cipherFilter);
 
922
                module->AddRawFilter(cipherFilter);
 
923
        }
 
924
 
 
925
        if (filterMgr)
 
926
                filterMgr->AddRawFilters(module, section);
 
927
}
 
928
 
 
929
 
 
930
void SWMgr::AddEncodingFilters(SWModule *module, ConfigEntMap &section) {
 
931
        if (filterMgr)
 
932
                filterMgr->AddEncodingFilters(module, section);
 
933
}
 
934
 
 
935
 
 
936
void SWMgr::AddRenderFilters(SWModule *module, ConfigEntMap &section) {
 
937
        SWBuf sourceformat;
 
938
        ConfigEntMap::iterator entry;
 
939
 
 
940
        sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (SWBuf)"";
 
941
 
 
942
        // Temporary: To support old module types
 
943
        // TODO: Remove at 1.6.0 release?
 
944
        if (!sourceformat.length()) {
 
945
                sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)"";
 
946
                if (!stricmp(sourceformat.c_str(), "RawGBF"))
 
947
                        sourceformat = "GBF";
 
948
                else sourceformat = "";
 
949
        }
 
950
 
 
951
// process module       - eg. follows
 
952
//      if (!stricmp(sourceformat.c_str(), "GBF")) {
 
953
//              module->AddRenderFilter(gbftortf);
 
954
//      }
 
955
 
 
956
        if (filterMgr)
 
957
                filterMgr->AddRenderFilters(module, section);
 
958
 
 
959
}
 
960
 
 
961
 
 
962
void SWMgr::AddStripFilters(SWModule *module, ConfigEntMap &section)
 
963
{
 
964
        SWBuf sourceformat;
 
965
        ConfigEntMap::iterator entry;
 
966
 
 
967
        sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (SWBuf)"";
 
968
        // Temporary: To support old module types
 
969
        if (!sourceformat.length()) {
 
970
                sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)"";
 
971
                if (!stricmp(sourceformat.c_str(), "RawGBF"))
 
972
                        sourceformat = "GBF";
 
973
                else sourceformat = "";
 
974
        }
 
975
        
 
976
        if (!stricmp(sourceformat.c_str(), "GBF")) {
 
977
                module->AddStripFilter(gbfplain);
 
978
        }
 
979
        else if (!stricmp(sourceformat.c_str(), "ThML")) {
 
980
                module->AddStripFilter(thmlplain);
 
981
        }
 
982
        else if (!stricmp(sourceformat.c_str(), "OSIS")) {
 
983
                module->AddStripFilter(osisplain);
 
984
        }
 
985
 
 
986
        if (filterMgr)
 
987
                filterMgr->AddStripFilters(module, section);
 
988
 
 
989
}
 
990
 
 
991
 
 
992
void SWMgr::CreateMods() {
 
993
        SectionMap::iterator it;
 
994
        ConfigEntMap::iterator start;
 
995
        ConfigEntMap::iterator end;
 
996
        ConfigEntMap::iterator entry;
 
997
        SWModule *newmod;
 
998
        SWBuf driver, misc1;
 
999
        for (it = config->Sections.begin(); it != config->Sections.end(); it++) {
 
1000
                ConfigEntMap &section = (*it).second;
 
1001
                newmod = 0;
 
1002
                
 
1003
                driver = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (SWBuf)"";
 
1004
                if (driver.length()) {
 
1005
                        newmod = CreateMod((*it).first, driver, section);
 
1006
                        if (newmod) {
 
1007
                                start = (*it).second.lower_bound("GlobalOptionFilter");
 
1008
                                end   = (*it).second.upper_bound("GlobalOptionFilter");
 
1009
                                AddGlobalOptions(newmod, section, start, end);
 
1010
 
 
1011
                                start = (*it).second.lower_bound("LocalOptionFilter");
 
1012
                                end   = (*it).second.upper_bound("LocalOptionFilter");
 
1013
                                AddLocalOptions(newmod, section, start, end);
 
1014
 
 
1015
                                AddRawFilters(newmod, section);
 
1016
                                AddStripFilters(newmod, section);
 
1017
                                AddRenderFilters(newmod, section);
 
1018
                                AddEncodingFilters(newmod, section);
 
1019
                                
 
1020
                                Modules.insert(ModMap::value_type(newmod->Name(), newmod));
 
1021
                        }
 
1022
                }
 
1023
        }
 
1024
}
 
1025
 
 
1026
 
 
1027
void SWMgr::DeleteMods() {
 
1028
 
 
1029
        ModMap::iterator it;
 
1030
 
 
1031
        for (it = Modules.begin(); it != Modules.end(); it++)
 
1032
                delete (*it).second;
 
1033
 
 
1034
        Modules.clear();
 
1035
}
 
1036
 
 
1037
 
 
1038
void SWMgr::InstallScan(const char *dirname)
 
1039
{
 
1040
   DIR *dir;
 
1041
   struct dirent *ent;
 
1042
   int conffd = 0;
 
1043
   SWBuf newmodfile;
 
1044
   SWBuf targetName;
 
1045
 
 
1046
        if (!access(dirname, 04)) {
 
1047
          if ((dir = opendir(dirname))) {
 
1048
               rewinddir(dir);
 
1049
               while ((ent = readdir(dir))) {
 
1050
                    if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) {
 
1051
                         newmodfile = dirname;
 
1052
                         if ((dirname[strlen(dirname)-1] != '\\') && (dirname[strlen(dirname)-1] != '/'))
 
1053
                              newmodfile += "/";
 
1054
                         newmodfile += ent->d_name;
 
1055
                         if (configType) {
 
1056
                              if (config > 0)
 
1057
                                   close(conffd);
 
1058
                              targetName = configPath;
 
1059
                              if ((configPath[strlen(configPath)-1] != '\\') && (configPath[strlen(configPath)-1] != '/'))
 
1060
                                   targetName += "/";
 
1061
                              targetName += ent->d_name;
 
1062
                              conffd = open(targetName.c_str(), O_WRONLY|O_CREAT, S_IREAD|S_IWRITE);
 
1063
                         }
 
1064
                         else {
 
1065
                              if (conffd < 1) {
 
1066
                                   conffd = open(config->filename.c_str(), O_WRONLY|O_APPEND);
 
1067
                                   if (conffd > 0)
 
1068
                                        lseek(conffd, 0L, SEEK_END);
 
1069
                              }
 
1070
                         }
 
1071
                         AddModToConfig(conffd, newmodfile.c_str());
 
1072
                         unlink(newmodfile.c_str());
 
1073
                    }
 
1074
               }
 
1075
               if (conffd > 0)
 
1076
                    close(conffd);
 
1077
               closedir(dir);
 
1078
          }
 
1079
     }
 
1080
}
 
1081
 
 
1082
 
 
1083
char SWMgr::AddModToConfig(int conffd, const char *fname)
 
1084
{
 
1085
        int modfd;
 
1086
        char ch;
 
1087
 
 
1088
        SWLog::systemlog->LogTimedInformation("Found new module [%s]. Installing...", fname);
 
1089
        modfd = open(fname, O_RDONLY);
 
1090
        ch = '\n';
 
1091
        write(conffd, &ch, 1);
 
1092
        while (read(modfd, &ch, 1) == 1)
 
1093
                write(conffd, &ch, 1);
 
1094
        ch = '\n';
 
1095
        write(conffd, &ch, 1);
 
1096
        close(modfd);
 
1097
        return 0;
 
1098
}
 
1099
 
 
1100
 
 
1101
void SWMgr::setGlobalOption(const char *option, const char *value)
 
1102
{
 
1103
        for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
 
1104
                if ((*it).second->getOptionName()) {
 
1105
                        if (!stricmp(option, (*it).second->getOptionName()))
 
1106
                                (*it).second->setOptionValue(value);
 
1107
                }
 
1108
        }
 
1109
}
 
1110
 
 
1111
 
 
1112
const char *SWMgr::getGlobalOption(const char *option)
 
1113
{
 
1114
        for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
 
1115
                if ((*it).second->getOptionName()) {
 
1116
                        if (!stricmp(option, (*it).second->getOptionName()))
 
1117
                                return (*it).second->getOptionValue();
 
1118
                }
 
1119
        }
 
1120
        return 0;
 
1121
}
 
1122
 
 
1123
 
 
1124
const char *SWMgr::getGlobalOptionTip(const char *option)
 
1125
{
 
1126
        for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
 
1127
                if ((*it).second->getOptionName()) {
 
1128
                        if (!stricmp(option, (*it).second->getOptionName()))
 
1129
                                return (*it).second->getOptionTip();
 
1130
                }
 
1131
        }
 
1132
        return 0;
 
1133
}
 
1134
 
 
1135
 
 
1136
StringList SWMgr::getGlobalOptions()
 
1137
{
 
1138
        return options;
 
1139
}
 
1140
 
 
1141
 
 
1142
StringList SWMgr::getGlobalOptionValues(const char *option)
 
1143
{
 
1144
        StringList options;
 
1145
        for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) {
 
1146
                if ((*it).second->getOptionName()) {
 
1147
                        if (!stricmp(option, (*it).second->getOptionName())) {
 
1148
                                options = (*it).second->getOptionValues();
 
1149
                                break;  // just find the first one.  All option filters with the same option name should expect the same values
 
1150
                        }
 
1151
                }
 
1152
        }
 
1153
        return options;
 
1154
}
 
1155
 
 
1156
 
 
1157
signed char SWMgr::setCipherKey(const char *modName, const char *key) {
 
1158
        FilterMap::iterator it;
 
1159
        ModMap::iterator it2;
 
1160
 
 
1161
        // check for filter that already exists
 
1162
        it = cipherFilters.find(modName);
 
1163
        if (it != cipherFilters.end()) {
 
1164
                ((CipherFilter *)(*it).second)->getCipher()->setCipherKey(key);
 
1165
                return 0;
 
1166
        }
 
1167
        // check if module exists
 
1168
        else {
 
1169
                it2 = Modules.find(modName);
 
1170
                if (it2 != Modules.end()) {
 
1171
                        SWFilter *cipherFilter = new CipherFilter(key);
 
1172
                        cipherFilters.insert(FilterMap::value_type(modName, cipherFilter));
 
1173
                        cleanupFilters.push_back(cipherFilter);
 
1174
                        (*it2).second->AddRawFilter(cipherFilter);
 
1175
                        return 0;
 
1176
                }
 
1177
        }
 
1178
        return -1;
 
1179
}
 
1180
 
 
1181
SWORD_NAMESPACE_END