aboutsummaryrefslogtreecommitdiffstats
path: root/doc/api-documentation/html/rawfiles_8cpp-source.html
blob: 7384a2328d2ce8ca5d019d356bc4b93a99ba2620 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<!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>rawfiles.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> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; </center>
<hr><h1>rawfiles.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> *  rawfiles.cpp - code for class 'RawFiles'- a module that produces HTML HREFs</font>
00003 <font class="comment"> *                      pointing to actual text desired.  Uses standard</font>
00004 <font class="comment"> *                      files:  ot and nt using indexs ??.bks ??.cps ??.vss</font>
00005 <font class="comment"> */</font>
00006 
00007 
00008 <font class="preprocessor">#include &lt;ctype.h&gt;</font>
00009 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
00010 <font class="preprocessor">#include &lt;fcntl.h&gt;</font>
00011 
00012 <font class="preprocessor">#ifndef __GNUC__</font>
00013 <font class="preprocessor"></font><font class="preprocessor">#include &lt;io.h&gt;</font>
00014 <font class="preprocessor">#else</font>
00015 <font class="preprocessor"></font><font class="preprocessor">#include &lt;unistd.h&gt;</font>
00016 <font class="preprocessor">#endif</font>
00017 <font class="preprocessor"></font>
00018 <font class="preprocessor">#include &lt;string.h&gt;</font>
00019 <font class="preprocessor">#include &lt;utilfuns.h&gt;</font>
00020 <font class="preprocessor">#include &lt;rawverse.h&gt;</font>
00021 <font class="preprocessor">#include &lt;rawfiles.h&gt;</font>
00022 <font class="preprocessor">#include &lt;filemgr.h&gt;</font>
00023 
00024 <font class="preprocessor">#ifndef O_BINARY                // O_BINARY is needed in Borland C++ 4.53</font>
00025 <font class="preprocessor"></font><font class="preprocessor">#define O_BINARY 0              // If it hasn't been defined than we probably</font>
00026 <font class="preprocessor"></font><font class="preprocessor">#endif                          // don't need it.</font>
00027 <font class="preprocessor"></font>
00028 
00029  <font class="comment">/******************************************************************************</font>
00030 <font class="comment"> * RawFiles Constructor - Initializes data for instance of RawFiles</font>
00031 <font class="comment"> *</font>
00032 <font class="comment"> * ENT: iname - Internal name for module</font>
00033 <font class="comment"> *      idesc - Name to display to user for module</font>
00034 <font class="comment"> *      idisp    - Display object to use for displaying</font>
00035 <font class="comment"> */</font>
00036 
00037 RawFiles::RawFiles(<font class="keyword">const</font> <font class="keywordtype">char</font> *ipath, <font class="keyword">const</font> <font class="keywordtype">char</font> *iname, <font class="keyword">const</font> <font class="keywordtype">char</font> *idesc, <a class="code" href="class_s_w_display.html">SWDisplay</a> *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, <font class="keyword">const</font> <font class="keywordtype">char</font>* ilang) : RawVerse(ipath, O_RDWR), <a class="code" href="class_s_w_com.html">SWCom</a>(iname, idesc, idisp, enc, dir, mark, ilang)
00038 {
00039 }
00040 
00041 
00042 <font class="comment">/******************************************************************************</font>
00043 <font class="comment"> * RawFiles Destructor - Cleans up instance of RawFiles</font>
00044 <font class="comment"> */</font>
00045 
00046 RawFiles::~RawFiles()
00047 {
00048 }
00049 
00050 
00051 <font class="comment">/******************************************************************************</font>
00052 <font class="comment"> * RawFiles::operator char *    - Returns the correct verse when char * cast</font>
00053 <font class="comment"> *                                      is requested</font>
00054 <font class="comment"> *</font>
00055 <font class="comment"> * RET: string buffer with verse</font>
00056 <font class="comment"> */</font>
00057 
00058 <font class="keywordtype">char</font> *RawFiles::getRawEntry() {
00059         FileDesc *datafile;
00060         <font class="keywordtype">long</font>  start = 0;
00061         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size = 0;
00062         <font class="keywordtype">char</font> *tmpbuf;
00063         <a class="code" href="class_verse_key.html">VerseKey</a> *key = 0;
00064 
00065 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00066 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00067 <font class="preprocessor">#endif</font>
00068 <font class="preprocessor"></font>                key = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, this-&gt;key);
00069 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00070 <font class="preprocessor"></font>        }
00071         <font class="keywordflow">catch</font> ( ... ) {}
00072 <font class="preprocessor">#endif</font>
00073 <font class="preprocessor"></font>        <font class="keywordflow">if</font> (!key)
00074                 key = <font class="keyword">new</font> <a class="code" href="class_verse_key.html">VerseKey</a>(this-&gt;key);
00075 
00076         findoffset(key-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), key-&gt;<a class="code" href="class_verse_key.html#a34">Index</a>(), &amp;start, &amp;size);
00077 
00078         <font class="keywordflow">if</font> (entrybuf)
00079                 <font class="keyword">delete</font> [] entrybuf;
00080 
00081         <font class="keywordflow">if</font> (size) {
00082                 tmpbuf   = <font class="keyword">new</font> <font class="keywordtype">char</font> [ (size + 2) + strlen(path) + 5 ];
00083                 sprintf(tmpbuf,<font class="stringliteral">"%s/"</font>,path);
00084                 gettext(key-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), start, (size + 2), tmpbuf+strlen(tmpbuf));
00085                 datafile = FileMgr::systemFileMgr.open(tmpbuf, O_RDONLY|O_BINARY);
00086                 <font class="keyword">delete</font> [] tmpbuf;
00087                 <font class="keywordflow">if</font> (datafile-&gt;getFd() &gt; 0) {
00088                         size = lseek(datafile-&gt;getFd(), 0, SEEK_END);
00089                         entrybuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ size * FILTERPAD ];
00090                         memset(entrybuf, 0, size * FILTERPAD);
00091                         lseek(datafile-&gt;getFd(), 0, SEEK_SET);
00092                         read(datafile-&gt;getFd(), entrybuf, size);
00093 <font class="comment">//                      preptext(entrybuf);</font>
00094                 }
00095                 <font class="keywordflow">else</font> {
00096                         entrybuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [2];
00097                         entrybuf[0] = 0;
00098                         entrybuf[1] = 0;
00099                 }
00100                 FileMgr::systemFileMgr.close(datafile);
00101         }
00102         <font class="keywordflow">else</font> {
00103                 entrybuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [2];
00104                 entrybuf[0] = 0;
00105                 entrybuf[1] = 0;
00106         }
00107 
00108         <font class="keywordflow">if</font> (key != this-&gt;key)
00109                 <font class="keyword">delete</font> key;
00110 
00111         <font class="keywordflow">return</font> entrybuf;
00112 }
00113 
00114 
00115 <font class="comment">/******************************************************************************</font>
00116 <font class="comment"> * RawFiles::operator &lt;&lt; (char *)- Update the modules current key entry with</font>
00117 <font class="comment"> *                              provided text</font>
00118 <font class="comment"> *</font>
00119 <font class="comment"> * RET: *this</font>
00120 <font class="comment"> */</font>
00121 
00122 <a class="code" href="class_s_w_module.html">SWModule</a> &amp;RawFiles::operator &lt;&lt;(<font class="keyword">const</font> <font class="keywordtype">char</font> *inbuf) {
00123         FileDesc *datafile;
00124         <font class="keywordtype">long</font>  start;
00125         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size;
00126         <font class="keywordtype">char</font> *tmpbuf;
00127         <a class="code" href="class_verse_key.html">VerseKey</a> *key = 0;
00128 
00129 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00130 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00131 <font class="preprocessor">#endif</font>
00132 <font class="preprocessor"></font>                key = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, this-&gt;key);
00133 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00134 <font class="preprocessor"></font>        }
00135         <font class="keywordflow">catch</font> ( ... ) {}
00136 <font class="preprocessor">#endif</font>
00137 <font class="preprocessor"></font>        <font class="keywordflow">if</font> (!key)
00138                 key = <font class="keyword">new</font> <a class="code" href="class_verse_key.html">VerseKey</a>(this-&gt;key);
00139 
00140         findoffset(key-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), key-&gt;<a class="code" href="class_verse_key.html#a34">Index</a>(), &amp;start, &amp;size);
00141 
00142         <font class="keywordflow">if</font> (size) {
00143                 tmpbuf   = <font class="keyword">new</font> <font class="keywordtype">char</font> [ (size + 2) + strlen(path) + 1 ];
00144                 sprintf(tmpbuf, <font class="stringliteral">"%s/"</font>, path);
00145                 gettext(key-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), start, (size + 2), tmpbuf+strlen(tmpbuf));
00146         }
00147         <font class="keywordflow">else</font> {
00148                 tmpbuf   = <font class="keyword">new</font> <font class="keywordtype">char</font> [ 16 + strlen(path) + 1 ];
00149                 sprintf(tmpbuf, <font class="stringliteral">"%s/%s"</font>, path, getnextfilename());
00150                 settext(key-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), key-&gt;<a class="code" href="class_verse_key.html#a34">Index</a>(), tmpbuf+strlen(path)+1);
00151         }
00152         datafile = FileMgr::systemFileMgr.open(tmpbuf, O_CREAT|O_WRONLY|O_BINARY|O_TRUNC);
00153         <font class="keyword">delete</font> [] tmpbuf;
00154         <font class="keywordflow">if</font> (datafile-&gt;getFd() &gt; 0) {
00155                 write(datafile-&gt;getFd(), inbuf, strlen(inbuf));
00156         }
00157         FileMgr::systemFileMgr.close(datafile);
00158         
00159         <font class="keywordflow">if</font> (key != this-&gt;key)
00160                 <font class="keyword">delete</font> key;
00161 
00162         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00163 }
00164 
00165 
00166 <font class="comment">/******************************************************************************</font>
00167 <font class="comment"> * RawFiles::operator &lt;&lt; (SWKey *)- Link the modules current key entry with</font>
00168 <font class="comment"> *                              another module entry</font>
00169 <font class="comment"> *</font>
00170 <font class="comment"> * RET: *this</font>
00171 <font class="comment"> */</font>
00172 
00173 <a class="code" href="class_s_w_module.html">SWModule</a> &amp;RawFiles::operator &lt;&lt;(<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> *inkey) {
00174 
00175         <font class="keywordtype">long</font>  start;
00176         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size;
00177         <font class="keywordtype">char</font> *tmpbuf;
00178         <font class="keyword">const</font> <a class="code" href="class_verse_key.html">VerseKey</a> *key = 0;
00179 
00180 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00181 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00182 <font class="preprocessor">#endif</font>
00183 <font class="preprocessor"></font>                key = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, inkey);
00184 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00185 <font class="preprocessor"></font>        }
00186         <font class="keywordflow">catch</font> ( ... ) {}
00187 <font class="preprocessor">#endif</font>
00188 <font class="preprocessor"></font>        <font class="keywordflow">if</font> (!key)
00189                 key = <font class="keyword">new</font> <a class="code" href="class_verse_key.html">VerseKey</a>(this-&gt;key);
00190 
00191         findoffset(key-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), key-&gt;<a class="code" href="class_verse_key.html#a34">Index</a>(), &amp;start, &amp;size);
00192 
00193         <font class="keywordflow">if</font> (size) {
00194                 tmpbuf   = <font class="keyword">new</font> <font class="keywordtype">char</font> [ size + 2];
00195                 gettext(key-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), start, size + 2, tmpbuf);
00196 
00197                 <font class="keywordflow">if</font> (key != inkey)
00198                         <font class="keyword">delete</font> key;
00199                 key = 0;
00200 
00201 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00202 <font class="preprocessor"></font>                <font class="keywordflow">try</font> {
00203 <font class="preprocessor">#endif</font>
00204 <font class="preprocessor"></font>                        key = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, inkey);
00205 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00206 <font class="preprocessor"></font>                }
00207                 <font class="keywordflow">catch</font> ( ... ) {}
00208 <font class="preprocessor">#endif</font>
00209 <font class="preprocessor"></font>                <font class="keywordflow">if</font> (!key)
00210                         key = <font class="keyword">new</font> <a class="code" href="class_verse_key.html">VerseKey</a>(this-&gt;key);
00211                 settext(key-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), key-&gt;<a class="code" href="class_verse_key.html#a34">Index</a>(), tmpbuf);
00212         }
00213         
00214         <font class="keywordflow">if</font> (key != inkey)
00215                 <font class="keyword">delete</font> key;
00216 
00217         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00218 }
00219 
00220 
00221 <font class="comment">/******************************************************************************</font>
00222 <font class="comment"> * RawFiles::deleteEntry        - deletes this entry</font>
00223 <font class="comment"> *</font>
00224 <font class="comment"> * RET: *this</font>
00225 <font class="comment"> */</font>
00226 
00227 <font class="keywordtype">void</font> RawFiles::deleteEntry() {
00228 
00229         <a class="code" href="class_verse_key.html">VerseKey</a> *key = 0;
00230 
00231 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00232 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00233 <font class="preprocessor">#endif</font>
00234 <font class="preprocessor"></font>                key = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, this-&gt;key);
00235 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00236 <font class="preprocessor"></font>        }
00237         <font class="keywordflow">catch</font> ( ... ) {}
00238 <font class="preprocessor">#endif</font>
00239 <font class="preprocessor"></font>        <font class="keywordflow">if</font> (!key)
00240                 key = <font class="keyword">new</font> <a class="code" href="class_verse_key.html">VerseKey</a>(this-&gt;key);
00241 
00242         settext(key-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), key-&gt;<a class="code" href="class_verse_key.html#a34">Index</a>(), <font class="stringliteral">""</font>);
00243 
00244         <font class="keywordflow">if</font> (key != this-&gt;key)
00245                 <font class="keyword">delete</font> key;
00246 }
00247 
00248 
00249 <font class="comment">/******************************************************************************</font>
00250 <font class="comment"> * RawFiles::getnextfilename - generates a valid filename in which to store</font>
00251 <font class="comment"> *                              an entry</font>
00252 <font class="comment"> *</font>
00253 <font class="comment"> * RET: filename</font>
00254 <font class="comment"> */</font>
00255 
00256 <font class="keywordtype">char</font> *RawFiles::getnextfilename() {
00257         <font class="keyword">static</font> <font class="keywordtype">char</font> incfile[255];
00258         <font class="keywordtype">long</font> number;
00259         FileDesc *datafile;
00260 
00261         sprintf(incfile, <font class="stringliteral">"%s/incfile"</font>, path);
00262         datafile = FileMgr::systemFileMgr.open(incfile, O_RDONLY|O_BINARY);
00263         <font class="keywordflow">if</font> (read(datafile-&gt;getFd(), &amp;number, 4) != 4)
00264                 number = 0;
00265         number++;
00266         FileMgr::systemFileMgr.close(datafile);
00267         
00268         datafile = FileMgr::systemFileMgr.open(incfile, O_CREAT|O_WRONLY|O_BINARY|O_TRUNC);
00269         write(datafile-&gt;getFd(), &amp;number, 4);
00270         FileMgr::systemFileMgr.close(datafile);
00271         sprintf(incfile, <font class="stringliteral">"%.7ld"</font>, number-1);
00272         <font class="keywordflow">return</font> incfile;
00273 }
00274 
00275 
00276 <font class="keywordtype">char</font> RawFiles::createModule (<font class="keyword">const</font> <font class="keywordtype">char</font> *path) {
00277         <font class="keywordtype">char</font> *incfile = <font class="keyword">new</font> <font class="keywordtype">char</font> [ strlen (path) + 16 ];
00278     <font class="keyword">static</font> <font class="keywordtype">long</font> zero = 0;
00279         FileDesc *datafile;
00280 
00281         sprintf(incfile, <font class="stringliteral">"%s/incfile"</font>, path);
00282         datafile = FileMgr::systemFileMgr.open(incfile, O_CREAT|O_WRONLY|O_BINARY|O_TRUNC);
00283     <font class="keyword">delete</font> [] incfile;
00284         write(datafile-&gt;getFd(), &amp;zero, 4);
00285         FileMgr::systemFileMgr.close(datafile);
00286 
00287     <font class="keywordflow">return</font> RawVerse::createModule (path);
00288 }
00289 
00290 
00291 
</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>