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

« back to all changes in this revision

Viewing changes to src/mgr/swconfig.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Marsden, Jonathan Marsden, Dmitrijs Ledkovs, Closed Bugs
  • Date: 2009-05-30 11:55:55 UTC
  • mfrom: (1.3.1 upstream) (6.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090530115555-r427zsn3amivdpfu
Tags: 1.6.0+dfsg-1
[ Jonathan Marsden ]
* New upstream release. (Closes: #507960) (LP: #320558)
* debian/patches/02_libver.diff:
  - Bump SONAME to 8 -- SWORD 1.6 is not backward compatible with 1.5.11.
* debian/patches/series:
  - Remove 10_diatheke.diff -- included in upstream source.
* debian/patches/:
  - Remove several old unused .diff files.
  - Add 11_regex_only_when_needed.diff to conditionally include regex lib.
  - Add 12_fix_compiler_warnings.diff to remove all compiler warnings.
  - Add 13_fix_osis2mod_compression_default.diff from upstream svn.
  - Add 14_closing_section_not_chapter.diff from upstream svn.
* debian/libsword7.*: 
  - Rename to libsword8.*
  - Change libsword7 to libsword8 within files.
* debian/rules: 
  - SONAME bump to 8.
  - Set library version check to >= 1.6
* debian/control:
  - Change libsword7 to libsword8.
  - Add libsword7 to Conflicts.
  - Fix case of sword to SWORD in package descriptions.
  - Bump Standards-Version to 3.8.1 (no changes needed).
  - Fix section for libsword-dbg to avoid lintian warning.
* debian/rules:
  - Add DFSG get-orig-source target.
* debian/copyright:
  - Fix various mistakes in initial attempt to document copyrights.

[ Dmitrijs Ledkovs ]
* debian/rules: Added utils.mk to use missing-files target and call it on
  each build.
* debian/libsword-dev.install: Added libsword.la, previously missing.
* debian/libsword7.install: Added missing libicu translit files.
* debian/control:
  - Updated all uses of SWORD version to 1.6
  - Added libsword-dbg package
* debian/watch: Fixed a small mistake which was resulting in extra "."
  in final version name.
* debian/rules: simplified manpage processing.
* debian/libsword8.lintian-overrides: added override for module
  installation directory.
* debian/copyright: Updated with information about everyfile.
  Closes: #513448 LP: #322638
* debian/diatheke.examples: moved examples here from the diatheke.install
* debian/rules:
  - enabled shell script based testsuite
  - added commented out cppunit testsuite
* debian/patches/40_missing_includes.diff: 
  - added several missing stdio.h includes to prevent FTBFS of testsuite.

[ Closed Bugs ]
* FTBFS on intrepid (LP: #305172)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 *  swconfig.cpp   - implementation of Class SWConfig used for saving and
 
3
 *                      retrieval of configuration information
 
4
 *
 
5
 * $Id: swconfig.cpp 2218 2008-12-23 09:33:38Z scribe $
 
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 <swconfig.h>
 
24
#include <utilstr.h>
 
25
#include <filemgr.h>
 
26
#include <fcntl.h>
 
27
 
 
28
 
 
29
SWORD_NAMESPACE_START
 
30
 
 
31
SWConfig::SWConfig() {
 
32
}
 
33
 
 
34
SWConfig::SWConfig(const char * ifilename) {
 
35
        filename = ifilename;
 
36
        Load();
 
37
}
 
38
 
 
39
 
 
40
SWConfig::~SWConfig() {
 
41
}
 
42
 
 
43
void SWConfig::Load() {
 
44
 
 
45
        if (!filename.size()) return;   // assert we have a filename
 
46
 
 
47
        FileDesc *cfile;
 
48
        char *buf, *data;
 
49
        SWBuf line;
 
50
        ConfigEntMap cursect;
 
51
        SWBuf sectname;
 
52
        bool first = true;
 
53
        
 
54
        Sections.erase(Sections.begin(), Sections.end());
 
55
        
 
56
        cfile = FileMgr::getSystemFileMgr()->open(filename.c_str(), FileMgr::RDONLY);
 
57
        if (cfile->getFd() > 0) {
 
58
                bool goodLine = FileMgr::getLine(cfile, line);
 
59
 
 
60
                // clean UTF encoding tags at start of file
 
61
                while (goodLine && line.length() && 
 
62
                                ((((unsigned char)line[0]) == 0xEF) ||
 
63
                                 (((unsigned char)line[0]) == 0xBB) ||
 
64
                                 (((unsigned char)line[0]) == 0xBF))) {
 
65
                        line << 1;
 
66
                }
 
67
                
 
68
                while (goodLine) {
 
69
                        // ignore commented lines
 
70
                        if (!line.startsWith("#")) {
 
71
                                buf = new char [ line.length() + 1 ];
 
72
                                strcpy(buf, line.c_str());
 
73
                                if (*strstrip(buf) == '[') {
 
74
                                        if (!first)
 
75
                                                Sections.insert(SectionMap::value_type(sectname, cursect));
 
76
                                        else first = false;
 
77
                                        
 
78
                                        cursect.erase(cursect.begin(), cursect.end());
 
79
 
 
80
                                        strtok(buf, "]");
 
81
                                        sectname = buf+1;
 
82
                                }
 
83
                                else {
 
84
                                        strtok(buf, "=");
 
85
                                        if ((*buf) && (*buf != '=')) {
 
86
                                                if ((data = strtok(NULL, "")))
 
87
                                                        cursect.insert(ConfigEntMap::value_type(buf, strstrip(data)));
 
88
                                                else cursect.insert(ConfigEntMap::value_type(buf, ""));
 
89
                                        }
 
90
                                }
 
91
                                delete [] buf;
 
92
                        }
 
93
                        goodLine = FileMgr::getLine(cfile, line);
 
94
                }
 
95
                if (!first)
 
96
                        Sections.insert(SectionMap::value_type(sectname, cursect));
 
97
 
 
98
                FileMgr::getSystemFileMgr()->close(cfile);
 
99
        }
 
100
}
 
101
 
 
102
 
 
103
void SWConfig::Save() {
 
104
 
 
105
        if (!filename.size()) return;   // assert we have a filename
 
106
 
 
107
        FileDesc *cfile;
 
108
        SWBuf buf;
 
109
        SectionMap::iterator sit;
 
110
        ConfigEntMap::iterator entry;
 
111
        SWBuf sectname;
 
112
        
 
113
        cfile = FileMgr::getSystemFileMgr()->open(filename.c_str(), FileMgr::RDWR|FileMgr::CREAT|FileMgr::TRUNC);
 
114
        if (cfile->getFd() > 0) {
 
115
                
 
116
                for (sit = Sections.begin(); sit != Sections.end(); sit++) {
 
117
                        buf =  "\n[";
 
118
                        buf += (*sit).first.c_str();
 
119
                        buf += "]\n";
 
120
                        cfile->write(buf.c_str(), buf.length());
 
121
                        for (entry = (*sit).second.begin(); entry != (*sit).second.end(); entry++) {
 
122
                                buf = (*entry).first.c_str();
 
123
                                buf += "=";
 
124
                                buf += (*entry).second.c_str();
 
125
                                buf += "\n";
 
126
                                cfile->write(buf.c_str(), buf.length());
 
127
                        }
 
128
                }
 
129
                buf = "\n";
 
130
                cfile->write(buf.c_str(), buf.length());
 
131
                FileMgr::getSystemFileMgr()->close(cfile);
 
132
        }
 
133
}
 
134
 
 
135
 
 
136
void SWConfig::augment(SWConfig &addFrom) {
 
137
 
 
138
        SectionMap::iterator section;
 
139
        ConfigEntMap::iterator entry, start, end;
 
140
 
 
141
        for (section = addFrom.Sections.begin(); section != addFrom.Sections.end(); section++) {
 
142
                for (entry = (*section).second.begin(); entry != (*section).second.end(); entry++) {
 
143
                        start = Sections[section->first].lower_bound(entry->first);
 
144
                        end   = Sections[section->first].upper_bound(entry->first);
 
145
                        if (start != end) {
 
146
                                if (((++start) != end)
 
147
                                                || ((++(addFrom.Sections[section->first].lower_bound(entry->first))) != addFrom.Sections[section->first].upper_bound(entry->first))) {
 
148
                                        for (--start; start != end; start++) {
 
149
                                                if (!strcmp(start->second.c_str(), entry->second.c_str()))
 
150
                                                        break;
 
151
                                        }
 
152
                                        if (start == end)
 
153
                                                Sections[(*section).first].insert(ConfigEntMap::value_type((*entry).first, (*entry).second));
 
154
                                }
 
155
                                else    Sections[section->first][entry->first.c_str()] = entry->second.c_str();
 
156
                        }               
 
157
                        else    Sections[section->first][entry->first.c_str()] = entry->second.c_str();
 
158
                }
 
159
        }
 
160
}
 
161
 
 
162
 
 
163
ConfigEntMap & SWConfig::operator [] (const char *section) {
 
164
    return Sections[section];
 
165
}
 
166
 
 
167
SWORD_NAMESPACE_END