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

« back to all changes in this revision

Viewing changes to src/modules/comments/rawfiles/rawfiles.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
 *  rawfiles.cpp - code for class 'RawFiles'- a module that produces HTML HREFs
 
3
 *                      pointing to actual text desired.  Uses standard
 
4
 *                      files:  ot and nt using indexs ??.bks ??.cps ??.vss
 
5
 *
 
6
 *
 
7
 * Copyright 2009 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 <ctype.h>
 
24
#include <stdio.h>
 
25
#include <fcntl.h>
 
26
 
 
27
#include <rawverse.h>
 
28
#include <rawfiles.h>
 
29
#include <filemgr.h>
 
30
#include <versekey.h>
 
31
#include <sysdata.h>
 
32
 
 
33
SWORD_NAMESPACE_START
 
34
 
 
35
 /******************************************************************************
 
36
 * RawFiles Constructor - Initializes data for instance of RawFiles
 
37
 *
 
38
 * ENT: iname - Internal name for module
 
39
 *      idesc - Name to display to user for module
 
40
 *      idisp    - Display object to use for displaying
 
41
 */
 
42
 
 
43
RawFiles::RawFiles(const char *ipath, const char *iname, const char *idesc, SWDisplay *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, const char* ilang) : RawVerse(ipath, FileMgr::RDWR), SWCom(iname, idesc, idisp, enc, dir, mark, ilang)
 
44
{
 
45
}
 
46
 
 
47
 
 
48
/******************************************************************************
 
49
 * RawFiles Destructor - Cleans up instance of RawFiles
 
50
 */
 
51
 
 
52
RawFiles::~RawFiles()
 
53
{
 
54
}
 
55
 
 
56
 
 
57
/** Is the module writable? :)
 
58
* @return yes or no
 
59
*/
 
60
bool RawFiles::isWritable() {
 
61
        return ((idxfp[0]->getFd() > 0) && ((idxfp[0]->mode & FileMgr::RDWR) == FileMgr::RDWR));
 
62
}
 
63
 
 
64
 
 
65
/******************************************************************************
 
66
 * RawFiles::getRawEntry        - Returns the correct verse when char * cast
 
67
 *                                      is requested
 
68
 *
 
69
 * RET: string buffer with verse
 
70
 */
 
71
 
 
72
SWBuf &RawFiles::getRawEntryBuf() {
 
73
        FileDesc *datafile;
 
74
        long  start = 0;
 
75
        unsigned short size = 0;
 
76
        VerseKey *key = &getVerseKey();
 
77
 
 
78
        findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
 
79
 
 
80
        entryBuf = "";
 
81
        if (size) {
 
82
                SWBuf tmpbuf = path;
 
83
                tmpbuf += '/';
 
84
                readText(key->Testament(), start, size, entryBuf);
 
85
                tmpbuf += entryBuf;
 
86
                entryBuf = "";
 
87
                datafile = FileMgr::getSystemFileMgr()->open(tmpbuf.c_str(), FileMgr::RDONLY);
 
88
                if (datafile->getFd() > 0) {
 
89
                        size = datafile->seek(0, SEEK_END);
 
90
                        char *tmpBuf = new char [ size + 1 ];
 
91
                        memset(tmpBuf, 0, size + 1);
 
92
                        datafile->seek(0, SEEK_SET);
 
93
                        datafile->read(tmpBuf, size);
 
94
                        entryBuf = tmpBuf;
 
95
                        delete [] tmpBuf;
 
96
//                      preptext(entrybuf);
 
97
                }
 
98
                FileMgr::getSystemFileMgr()->close(datafile);
 
99
        }
 
100
        return entryBuf;
 
101
}
 
102
 
 
103
 
 
104
/******************************************************************************
 
105
 * RawFiles::setEntry(char *)- Update the modules current key entry with
 
106
 *                              provided text
 
107
 */
 
108
 
 
109
void RawFiles::setEntry(const char *inbuf, long len) {
 
110
        FileDesc *datafile;
 
111
        long  start;
 
112
        unsigned short size;
 
113
        VerseKey *key = &getVerseKey();
 
114
 
 
115
        len = (len<0)?strlen(inbuf):len;
 
116
 
 
117
        findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
 
118
 
 
119
        if (size) {
 
120
                SWBuf tmpbuf;
 
121
                entryBuf = path;
 
122
                entryBuf += '/';
 
123
                readText(key->Testament(), start, size, tmpbuf);
 
124
                entryBuf += tmpbuf;
 
125
        }
 
126
        else {
 
127
                SWBuf tmpbuf;
 
128
                entryBuf = path;
 
129
                entryBuf += '/';
 
130
                tmpbuf = getNextFilename();
 
131
                doSetText(key->Testament(), key->TestamentIndex(), tmpbuf);
 
132
                entryBuf += tmpbuf;
 
133
        }
 
134
        datafile = FileMgr::getSystemFileMgr()->open(entryBuf, FileMgr::CREAT|FileMgr::WRONLY|FileMgr::TRUNC);
 
135
        if (datafile->getFd() > 0) {
 
136
                datafile->write(inbuf, len);
 
137
        }
 
138
        FileMgr::getSystemFileMgr()->close(datafile);
 
139
}
 
140
 
 
141
 
 
142
/******************************************************************************
 
143
 * RawFiles::linkEntry(SWKey *)- Link the modules current key entry with
 
144
 *                              another module entry
 
145
 *
 
146
 * RET: *this
 
147
 */
 
148
 
 
149
void RawFiles::linkEntry(const SWKey *inkey) {
 
150
 
 
151
        long  start;
 
152
        unsigned short size;
 
153
        const VerseKey *key = &getVerseKey();
 
154
 
 
155
        findOffset(key->Testament(), key->TestamentIndex(), &start, &size);
 
156
 
 
157
        if (size) {
 
158
                SWBuf tmpbuf;
 
159
                readText(key->Testament(), start, size + 2, tmpbuf);
 
160
 
 
161
                key = &getVerseKey(inkey);
 
162
                doSetText(key->Testament(), key->TestamentIndex(), tmpbuf.c_str());
 
163
        }
 
164
}
 
165
 
 
166
 
 
167
/******************************************************************************
 
168
 * RawFiles::deleteEntry        - deletes this entry
 
169
 *
 
170
 * RET: *this
 
171
 */
 
172
 
 
173
void RawFiles::deleteEntry() {
 
174
        VerseKey *key = &getVerseKey();
 
175
        doSetText(key->Testament(), key->TestamentIndex(), "");
 
176
}
 
177
 
 
178
 
 
179
/******************************************************************************
 
180
 * RawFiles::getNextfilename - generates a valid filename in which to store
 
181
 *                              an entry
 
182
 *
 
183
 * RET: filename
 
184
 */
 
185
 
 
186
char *RawFiles::getNextFilename() {
 
187
        static char incfile[255];
 
188
        __u32 number;
 
189
        FileDesc *datafile;
 
190
 
 
191
        sprintf(incfile, "%s/incfile", path);
 
192
        datafile = FileMgr::getSystemFileMgr()->open(incfile, FileMgr::RDONLY);
 
193
 
 
194
        if (datafile->read(&number, 4) != 4) number = 0;
 
195
        number = swordtoarch32(number);
 
196
 
 
197
        number++;
 
198
        FileMgr::getSystemFileMgr()->close(datafile);
 
199
        
 
200
        datafile = FileMgr::getSystemFileMgr()->open(incfile, FileMgr::CREAT|FileMgr::WRONLY|FileMgr::TRUNC);
 
201
        sprintf(incfile, "%.7d", number-1);
 
202
 
 
203
        number = archtosword32(number);
 
204
        datafile->write(&number, 4);
 
205
 
 
206
        FileMgr::getSystemFileMgr()->close(datafile);
 
207
        return incfile;
 
208
}
 
209
 
 
210
 
 
211
char RawFiles::createModule (const char *path) {
 
212
        char *incfile = new char [ strlen (path) + 16 ];
 
213
 
 
214
        __u32 zero = 0;
 
215
        zero = archtosword32(zero);
 
216
 
 
217
        FileDesc *datafile;
 
218
 
 
219
        sprintf(incfile, "%s/incfile", path);
 
220
        datafile = FileMgr::getSystemFileMgr()->open(incfile, FileMgr::CREAT|FileMgr::WRONLY|FileMgr::TRUNC);
 
221
        delete [] incfile;
 
222
        datafile->write(&zero, 4);
 
223
        FileMgr::getSystemFileMgr()->close(datafile);
 
224
 
 
225
    return RawVerse::createModule (path);
 
226
}
 
227
 
 
228
 
 
229
 
 
230
SWORD_NAMESPACE_END