aboutsummaryrefslogtreecommitdiffstats
path: root/doc/api-documentation/html/rawtext_8cpp-source.html
blob: 599021edd7aafd553284f98671d2fb3a76666f9e (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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
<!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>rawtext.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>rawtext.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> *  rawtext.cpp - code for class 'RawText'- a module that reads raw text files:</font>
00003 <font class="comment"> *                ot and nt using indexs ??.bks ??.cps ??.vss</font>
00004 <font class="comment"> */</font>
00005 
00006 
00007 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
00008 <font class="preprocessor">#include &lt;fcntl.h&gt;</font>
00009 
00010 <font class="preprocessor">#ifndef __GNUC__</font>
00011 <font class="preprocessor"></font><font class="preprocessor">#include &lt;io.h&gt;</font>
00012 <font class="preprocessor">#else</font>
00013 <font class="preprocessor"></font><font class="preprocessor">#include &lt;unistd.h&gt;</font>
00014 <font class="preprocessor">#endif</font>
00015 <font class="preprocessor"></font>
00016 <font class="preprocessor">#include &lt;string.h&gt;</font>
00017 <font class="preprocessor">#include &lt;utilfuns.h&gt;</font>
00018 <font class="preprocessor">#include &lt;rawverse.h&gt;</font>
00019 <font class="preprocessor">#include &lt;rawtext.h&gt;</font>
00020 
00021 <font class="preprocessor">#include &lt;map&gt;</font>
00022 <font class="preprocessor">#include &lt;list&gt;</font>
00023 <font class="preprocessor">#include &lt;algorithm&gt;</font>
00024 <font class="preprocessor">#include &lt;regex.h&gt;</font>      <font class="comment">// GNU</font>
00025 
00026 <font class="preprocessor">#ifndef O_BINARY</font>
00027 <font class="preprocessor"></font><font class="preprocessor">#define O_BINARY 0</font>
00028 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00029 <font class="preprocessor"></font>
00030 <font class="comment">/******************************************************************************</font>
00031 <font class="comment"> * RawText Constructor - Initializes data for instance of RawText</font>
00032 <font class="comment"> *</font>
00033 <font class="comment"> * ENT: iname - Internal name for module</font>
00034 <font class="comment"> *      idesc - Name to display to user for module</font>
00035 <font class="comment"> *      idisp    - Display object to use for displaying</font>
00036 <font class="comment"> */</font>
00037 
00038 RawText::RawText(<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)
00039                 : <a class="code" href="class_s_w_text.html">SWText</a>(iname, idesc, idisp, enc, dir, mark, ilang),
00040           RawVerse(ipath) {
00041           
00042         string fname;
00043         fname = path;
00044         <font class="keywordtype">char</font> ch = fname.c_str()[strlen(fname.c_str())-1];
00045         <font class="keywordflow">if</font> ((ch != <font class="charliteral">'/'</font>) &amp;&amp; (ch != <font class="charliteral">'\\'</font>))
00046                 fname += <font class="stringliteral">"/"</font>;
00047         
00048         <font class="keywordflow">for</font> (<font class="keywordtype">int</font> loop = 0; loop &lt; 2; loop++) {
00049         fastSearch[loop] = 0;
00050                 string fastidxname =(fname + ((loop)?<font class="stringliteral">"ntwords.dat"</font>:<font class="stringliteral">"otwords.dat"</font>));
00051                 <font class="keywordflow">if</font> (!access(fastidxname.c_str(), 04)) {
00052                         fastidxname = (fname + ((loop)?<font class="stringliteral">"ntwords.idx"</font>:<font class="stringliteral">"otwords.idx"</font>));
00053                         <font class="keywordflow">if</font> (!access(fastidxname.c_str(), 04))
00054                                 fastSearch[loop] = <font class="keyword">new</font> RawStr((fname + ((loop)?<font class="stringliteral">"ntwords"</font>:<font class="stringliteral">"otwords"</font>)).c_str());
00055                 }
00056         }
00057 }
00058 
00059 
00060 <font class="comment">/******************************************************************************</font>
00061 <font class="comment"> * RawText Destructor - Cleans up instance of RawText</font>
00062 <font class="comment"> */</font>
00063 
00064 RawText::~RawText()
00065 {
00066         <font class="keywordflow">if</font> (fastSearch[0])
00067                 <font class="keyword">delete</font> fastSearch[0];
00068 
00069         <font class="keywordflow">if</font> (fastSearch[1])
00070                 <font class="keyword">delete</font> fastSearch[1];
00071 }
00072 
00073 
00074 <font class="comment">/******************************************************************************</font>
00075 <font class="comment"> * RawText::operator char *     - Returns the correct verse when char * cast</font>
00076 <font class="comment"> *                                      is requested</font>
00077 <font class="comment"> *</font>
00078 <font class="comment"> * RET: string buffer with verse</font>
00079 <font class="comment"> */</font>
00080 
00081 <font class="keywordtype">char</font> *RawText::getRawEntry() {
00082         <font class="keywordtype">long</font>  start = 0;
00083         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size = 0;
00084         <a class="code" href="class_verse_key.html">VerseKey</a> *key = 0;
00085 
00086         <font class="comment">// see if we have a VerseKey * or decendant</font>
00087 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00088 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00089 <font class="preprocessor">#endif</font>
00090 <font class="preprocessor"></font>                key = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, this-&gt;key);
00091 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00092 <font class="preprocessor"></font>        }
00093         <font class="keywordflow">catch</font> ( ... ) { }
00094 <font class="preprocessor">#endif</font>
00095 <font class="preprocessor"></font>        <font class="comment">// if we don't have a VerseKey * decendant, create our own</font>
00096         <font class="keywordflow">if</font> (!key)
00097                 key = <font class="keyword">new</font> <a class="code" href="class_verse_key.html">VerseKey</a>(this-&gt;key);
00098 
00099         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);
00100         entrySize = size;        <font class="comment">// support getEntrySize call</font>
00101 
00102         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> newsize = (size + 2) * FILTERPAD;
00103         <font class="keywordflow">if</font> (newsize &gt; entrybufallocsize) {
00104                 <font class="keywordflow">if</font> (entrybuf)
00105                         <font class="keyword">delete</font> [] entrybuf;
00106                 entrybuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ newsize ];
00107                 entrybufallocsize = newsize;
00108         }
00109         *entrybuf = 0;
00110 
00111         gettext(key-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), start, (size + 2), entrybuf);
00112 
00113         rawFilter(entrybuf, size, key);
00114 
00115         <font class="keywordflow">if</font> (!isUnicode())
00116                 preptext(entrybuf);
00117 
00118         <font class="keywordflow">if</font> (this-&gt;key != key) <font class="comment">// free our key if we created a VerseKey</font>
00119                 <font class="keyword">delete</font> key;
00120 
00121         <font class="keywordflow">return</font> entrybuf;
00122 }
00123 
00124 
00125 <font class="keywordtype">signed</font> <font class="keywordtype">char</font> RawText::createSearchFramework() {
00126         <a class="code" href="class_s_w_key.html">SWKey</a> *savekey = 0;
00127         <a class="code" href="class_s_w_key.html">SWKey</a> *searchkey = 0;
00128         <a class="code" href="class_s_w_key.html">SWKey</a> textkey;
00129         <font class="keywordtype">char</font> *word = 0;
00130         <font class="keywordtype">char</font> *wordBuf = 0;
00131 
00132         <font class="comment">// dictionary holds words associated with a list</font>
00133         <font class="comment">// containing every module position that contains</font>
00134         <font class="comment">// the word.  [0] Old Testament; [1] NT</font>
00135         map &lt; string, list&lt;long&gt; &gt; dictionary[2];
00136 
00137 
00138         <font class="comment">// save key information so as not to disrupt original</font>
00139         <font class="comment">// module position</font>
00140         <font class="keywordflow">if</font> (!key-&gt;Persist()) {
00141                 savekey = CreateKey();
00142                 *savekey = *key;
00143         }
00144         <font class="keywordflow">else</font>    savekey = key;
00145 
00146         searchkey = (key-&gt;Persist())?key-&gt;<a class="code" href="class_s_w_key.html#a3">clone</a>():0;
00147         <font class="keywordflow">if</font> (searchkey) {
00148                 searchkey-&gt;<a class="code" href="class_s_w_key.html#a4">Persist</a>(1);
00149                 SetKey(*searchkey);
00150         }
00151 
00152         <font class="comment">// position module at the beginning</font>
00153         *<font class="keyword">this</font> = TOP;
00154 
00155         <a class="code" href="class_verse_key.html">VerseKey</a> *lkey = (<a class="code" href="class_verse_key.html">VerseKey</a> *)key;
00156 
00157         <font class="comment">// iterate thru each entry in module</font>
00158         <font class="keywordflow">while</font> (!Error()) {
00159                 <font class="keywordtype">long</font> index = lkey-&gt;<a class="code" href="class_verse_key.html#a34">Index</a>();
00160                 wordBuf = (<font class="keywordtype">char</font> *)calloc(<font class="keyword">sizeof</font>(<font class="keywordtype">char</font>), strlen(StripText()) + 1);
00161                 strcpy(wordBuf, StripText());
00162 
00163                 <font class="comment">// grab each word from the text</font>
00164                 word = strtok(wordBuf, <font class="stringliteral">" !.,?;:()-=+/\\|{}[]\"&lt;&gt;"</font>);
00165                 <font class="keywordflow">while</font> (word) {
00166 
00167                         <font class="comment">// make work upper case</font>
00168                         <font class="keywordflow">for</font> (<font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> i = 0; i &lt; strlen(word); i++)
00169                                 word[i] = SW_toupper(word[i]);
00170 
00171                         <font class="comment">// lookup word in dictionary (or make entry in dictionary</font>
00172                         <font class="comment">// for this word) and add this module position (index) to</font>
00173                         <font class="comment">// the word's associated list of module positions</font>
00174                         dictionary[lkey-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>()-1][word].push_back(index);
00175                         word = strtok(NULL, <font class="stringliteral">" !.,?;:()-=+/\\|{}[]\"&lt;&gt;"</font>);
00176                 }
00177                 free(wordBuf);
00178                 (*this)++;
00179         }
00180 
00181         <font class="comment">// reposition module back to where it was before we were called</font>
00182         SetKey(*savekey);
00183 
00184         <font class="keywordflow">if</font> (!savekey-&gt;<a class="code" href="class_s_w_key.html#a4">Persist</a>())
00185                 <font class="keyword">delete</font> savekey;
00186 
00187         <font class="keywordflow">if</font> (searchkey)
00188                 <font class="keyword">delete</font> searchkey;
00189 
00190         
00191         <font class="comment">// --------- Let's output an index from our dictionary -----------</font>
00192         <font class="keywordtype">int</font> datfd;
00193         <font class="keywordtype">int</font> idxfd;
00194         map &lt; string, list&lt;long&gt; &gt;::iterator it;
00195         list&lt;long&gt;::iterator it2;
00196         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> offset, entryoff;
00197         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size;
00198 
00199         string fname;
00200         fname = path;
00201         <font class="keywordtype">char</font> ch = fname.c_str()[strlen(fname.c_str())-1];
00202         <font class="keywordflow">if</font> ((ch != <font class="charliteral">'/'</font>) &amp;&amp; (ch != <font class="charliteral">'\\'</font>))
00203                 fname += <font class="stringliteral">"/"</font>;
00204 
00205         <font class="comment">// for old and new testament do...</font>
00206         <font class="keywordflow">for</font> (<font class="keywordtype">int</font> loop = 0; loop &lt; 2; loop++) {
00207                 <font class="keywordflow">if</font> ((datfd = open((fname + ((loop)?<font class="stringliteral">"ntwords.dat"</font>:<font class="stringliteral">"otwords.dat"</font>)).c_str(), O_CREAT|O_WRONLY|O_BINARY, 00644 )) == -1)
00208                         <font class="keywordflow">return</font> -1;
00209                 <font class="keywordflow">if</font> ((idxfd = open((fname + ((loop)?<font class="stringliteral">"ntwords.idx"</font>:<font class="stringliteral">"otwords.idx"</font>)).c_str(), O_CREAT|O_WRONLY|O_BINARY, 00644 )) == -1) {
00210                         close(datfd);
00211                         <font class="keywordflow">return</font> -1;
00212                 }
00213 
00214                 <font class="comment">// iterate thru each word in the dictionary</font>
00215                 <font class="keywordflow">for</font> (it = dictionary[loop].begin(); it != dictionary[loop].end(); it++) {
00216                         printf(<font class="stringliteral">"%s: "</font>, it-&gt;first.c_str());
00217 
00218                         <font class="comment">// get our current offset in our word.dat file and write this as the start</font>
00219                         <font class="comment">// of the next entry in our database</font>
00220                         offset = lseek(datfd, 0, SEEK_CUR);
00221                         write(idxfd, &amp;offset, 4);
00222 
00223                         <font class="comment">// write our word out to the word.dat file, delineating with a \n</font>
00224                         write(datfd, it-&gt;first.c_str(), strlen(it-&gt;first.c_str()));
00225                         write(datfd, <font class="stringliteral">"\n"</font>, 1);
00226 
00227                         <font class="comment">// force our mod position list for this word to be unique (remove</font>
00228                         <font class="comment">// duplicates that may exist if the word was found more than once</font>
00229                         <font class="comment">// in the verse</font>
00230                         it-&gt;second.unique();
00231 
00232                         <font class="comment">// iterate thru each mod position for this word and output it to</font>
00233                         <font class="comment">// our database</font>
00234                         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> count = 0;
00235                         <font class="keywordflow">for</font> (it2 = it-&gt;second.begin(); it2 != it-&gt;second.end(); it2++) {
00236                                 entryoff= *it2;
00237                                 write(datfd, &amp;entryoff, 4);
00238                                 count++;
00239                         }
00240                         
00241                         <font class="comment">// now see what our new position is in our word.dat file and</font>
00242                         <font class="comment">// determine the size of this database entry</font>
00243                         size = lseek(datfd, 0, SEEK_CUR) - offset;
00244 
00245                         <font class="comment">// store the size of this database entry</font>
00246                         write(idxfd, &amp;size, 2);
00247                         printf(<font class="stringliteral">"%d entries (size: %d)\n"</font>, count, size);
00248                 }
00249                 close(datfd);
00250                 close(idxfd);
00251         }
00252         <font class="keywordflow">return</font> 0;
00253 }
00254 
00255 
00256 <font class="comment">/******************************************************************************</font>
00257 <font class="comment"> * SWModule::Search     - Searches a module for a string</font>
00258 <font class="comment"> *</font>
00259 <font class="comment"> * ENT: istr            - string for which to search</font>
00260 <font class="comment"> *      searchType      - type of search to perform</font>
00261 <font class="comment"> *                              &gt;=0 - regex</font>
00262 <font class="comment"> *                              -1  - phrase</font>
00263 <font class="comment"> *                              -2  - multiword</font>
00264 <font class="comment"> *      flags           - options flags for search</font>
00265 <font class="comment"> *      justCheckIfSupported    - if set, don't search, only tell if this</font>
00266 <font class="comment"> *                                                      function supports requested search.</font>
00267 <font class="comment"> *</font>
00268 <font class="comment"> * RET: listkey set to verses that contain istr</font>
00269 <font class="comment"> */</font>
00270 
00271 <a class="code" href="class_list_key.html">ListKey</a> &amp;RawText::Search(<font class="keyword">const</font> <font class="keywordtype">char</font> *istr, <font class="keywordtype">int</font> searchType, <font class="keywordtype">int</font> flags, <a class="code" href="class_s_w_key.html">SWKey</a> *scope, <font class="keywordtype">bool</font> *justCheckIfSupported, <font class="keywordtype">void</font> (*percent)(<font class="keywordtype">char</font>, <font class="keywordtype">void</font> *), <font class="keywordtype">void</font> *percentUserData)
00272 {
00273         listkey.ClearList();
00274 
00275         <font class="keywordflow">if</font> ((fastSearch[0]) &amp;&amp; (fastSearch[1])) {
00276 
00277                 <font class="keywordflow">switch</font> (searchType) {
00278                 <font class="keywordflow">case</font> -2: {
00279 
00280                         <font class="keywordflow">if</font> ((flags &amp; REG_ICASE) != REG_ICASE)   <font class="comment">// if haven't chosen to</font>
00281                                                                                         <font class="comment">// ignore case</font>
00282                                 <font class="keywordflow">break</font>; <font class="comment">// can't handle fast case sensitive searches</font>
00283 
00284                         <font class="comment">// test to see if our scope for this search is bounded by a</font>
00285                         <font class="comment">// VerseKey</font>
00286                         <a class="code" href="class_verse_key.html">VerseKey</a> *testKeyType = 0;
00287 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00288 <font class="preprocessor"></font>                        <font class="keywordflow">try</font> {
00289 <font class="preprocessor">#endif</font>
00290 <font class="preprocessor"></font>                                testKeyType = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, ((scope)?scope:key));
00291 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00292 <font class="preprocessor"></font>                        }
00293                         <font class="keywordflow">catch</font> ( ... ) {}
00294 <font class="preprocessor">#endif</font>
00295 <font class="preprocessor"></font>                        <font class="comment">// if we don't have a VerseKey * decendant we can't handle</font>
00296                         <font class="comment">// because of scope.</font>
00297                         <font class="comment">// In the future, add bool SWKey::isValid(const char *tryString);</font>
00298                         <font class="keywordflow">if</font> (!testKeyType)
00299                                 <font class="keywordflow">break</font>;
00300 
00301 
00302                         <font class="comment">// check if we just want to see if search is supported.</font>
00303                         <font class="comment">// If we've gotten this far, then it is supported.</font>
00304                         <font class="keywordflow">if</font> (justCheckIfSupported) {
00305                                 *justCheckIfSupported = <font class="keyword">true</font>;
00306                                 <font class="keywordflow">return</font> listkey;
00307                         }
00308 
00309                         <a class="code" href="class_s_w_key.html">SWKey</a> saveKey = *testKeyType; <font class="comment">// save current place</font>
00310 
00311                         <font class="keywordtype">char</font> error = 0;
00312                         <font class="keywordtype">char</font> **words = 0;
00313                         <font class="keywordtype">char</font> *wordBuf = 0;
00314                         <font class="keywordtype">int</font> wordCount = 0;
00315                         <font class="keywordtype">long</font> start;
00316                         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size;
00317                         <font class="keywordtype">char</font> *idxbuf = 0;
00318                         <font class="keywordtype">char</font> *datbuf = 0;
00319                         list &lt;long&gt; indexes;
00320                         list &lt;long&gt; indexes2;
00321                         <a class="code" href="class_verse_key.html">VerseKey</a> vk;
00322                         vk = TOP;
00323 
00324                         (*percent)(10, percentUserData);
00325 
00326                         <font class="comment">// toupper our copy of search string</font>
00327                         stdstr(&amp;wordBuf, istr);
00328                         <font class="keywordflow">for</font> (<font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> i = 0; i &lt; strlen(wordBuf); i++)
00329                                 wordBuf[i] = SW_toupper(wordBuf[i]);
00330 
00331                         <font class="comment">// get list of individual words</font>
00332                         words = (<font class="keywordtype">char</font> **)calloc(<font class="keyword">sizeof</font>(<font class="keywordtype">char</font> *), 10);
00333                         <font class="keywordtype">int</font> allocWords = 10;
00334                         words[wordCount] = strtok(wordBuf, <font class="stringliteral">" "</font>);
00335                         <font class="keywordflow">while</font> (words[wordCount]) {
00336                                 wordCount++;
00337                                 <font class="keywordflow">if</font> (wordCount == allocWords) {
00338                                         allocWords+=10;
00339                                         words = (<font class="keywordtype">char</font> **)realloc(words, <font class="keyword">sizeof</font>(<font class="keywordtype">char</font> *)*allocWords);
00340                                 }
00341                                 words[wordCount] = strtok(NULL, <font class="stringliteral">" "</font>);
00342                         }
00343 
00344                         (*percent)(20, percentUserData);
00345 
00346                         <font class="comment">// clear our result set</font>
00347                         indexes.erase(indexes.begin(), indexes.end());
00348 
00349                         <font class="comment">// search both old and new testament indexes</font>
00350                         <font class="keywordflow">for</font> (<font class="keywordtype">int</font> j = 0; j &lt; 2; j++) {
00351                                 <font class="comment">// iterate thru each word the user passed to us.</font>
00352                                 <font class="keywordflow">for</font> (<font class="keywordtype">int</font> i = 0; i &lt; wordCount; i++) {
00353 
00354                                         <font class="comment">// clear this word's result set</font>
00355                                         indexes2.erase(indexes2.begin(), indexes2.end());
00356                                         error = 0;
00357 
00358                                         <font class="comment">// iterate thru every word in the database that starts</font>
00359                                         <font class="comment">// with our search word</font>
00360                                         <font class="keywordflow">for</font> (<font class="keywordtype">int</font> away = 0; !error; away++) {
00361                                                 idxbuf = 0;
00362                                                 
00363                                                 <font class="comment">// find our word in the database and jump ahead _away_</font>
00364                                                 error = fastSearch[j]-&gt;findoffset(words[i], &amp;start, &amp;size, away);
00365 
00366                                                 <font class="comment">// get the word from the database</font>
00367                                                 fastSearch[j]-&gt;getidxbufdat(start, &amp;idxbuf);
00368 
00369                                                 <font class="comment">// check to see if it starts with our target word</font>
00370                                                 <font class="keywordflow">if</font> (strlen(idxbuf) &gt; strlen(words[i]))
00371                                                         idxbuf[strlen(words[i])] = 0;
00372 <font class="comment">//                                              else    words[i][strlen(idxbuf)] = 0;</font>
00373                                                 <font class="keywordflow">if</font> (!strcmp(idxbuf, words[i])) {
00374 
00375                                                         <font class="comment">// get data for this word from database</font>
00376                                                         free(idxbuf);
00377                                                         idxbuf = (<font class="keywordtype">char</font> *)calloc(size+2, 1);
00378                                                         datbuf = (<font class="keywordtype">char</font> *)calloc(size+2, 1);
00379                                                         fastSearch[j]-&gt;gettext(start, size + 2, idxbuf, datbuf);
00380 
00381                                                         <font class="comment">// we know that the data consists of sizof(long)</font>
00382                                                         <font class="comment">// records each a valid module position that constains</font>
00383                                                         <font class="comment">// this word</font>
00384                                                         <font class="comment">//</font>
00385                                                         <font class="comment">// iterate thru each of these module positions</font>
00386                                                         <font class="keywordtype">long</font> *keyindex = (<font class="keywordtype">long</font> *)datbuf;
00387                                                         <font class="keywordflow">while</font> (keyindex &lt; (<font class="keywordtype">long</font> *)(datbuf + size - (strlen(idxbuf) + 1))) {
00388                                                                 <font class="keywordflow">if</font> (i) {        <font class="comment">// if we're not on our first word</font>
00389 
00390                                                                         <font class="comment">// check to see if this word is already in the result set.</font>
00391                                                                         <font class="comment">// This is our AND functionality</font>
00392                                                                         <font class="keywordflow">if</font> (find(indexes.begin(), indexes.end(), *keyindex) != indexes.end())
00393                                                                                 <font class="comment">// add to new result set</font>
00394                                                                                 indexes2.push_back(*keyindex);
00395                                                                 }
00396                                                                 <font class="keywordflow">else</font>    indexes2.push_back(*keyindex);
00397                                                                 keyindex++;
00398                                                         }
00399                                                         free(datbuf);
00400                                                 }
00401                                                 <font class="keywordflow">else</font> error = 1; <font class="comment">// no more matches</font>
00402                                                 free(idxbuf);
00403                                         }
00404 
00405                                         <font class="comment">// make new result set final result set</font>
00406                                         indexes = indexes2;
00407 
00408                                         percent((<font class="keywordtype">char</font>)(20 + (<font class="keywordtype">float</font>)((j*wordCount)+i)/(wordCount * 2) * 78), percentUserData);
00409                                 }
00410 
00411                                 <font class="comment">// indexes contains our good verses, lets return them in a listkey</font>
00412                                 indexes.sort();
00413 
00414                                 <font class="comment">// iterate thru each good module position that meets the search</font>
00415                                 <font class="keywordflow">for</font> (list &lt;long&gt;::iterator it = indexes.begin(); it != indexes.end(); it++) {
00416 
00417                                         <font class="comment">// set a temporary verse key to this module position</font>
00418                                         vk.<a class="code" href="class_verse_key.html#a22">Testament</a>(j+1);
00419                                         vk.<a class="code" href="class_s_w_key.html#a6">Error</a>();
00420                                         vk.<a class="code" href="class_verse_key.html#a34">Index</a>(*it);
00421 
00422                                         <font class="comment">// check scope</font>
00423                                         <font class="comment">// Try to set our scope key to this verse key</font>
00424                                         <font class="keywordflow">if</font> (scope) {
00425                                                 *testKeyType = vk;
00426 
00427                                                 <font class="comment">// check to see if it set ok and if so, add to our return list</font>
00428                                                 <font class="keywordflow">if</font> (*testKeyType == vk)
00429                                                         listkey &lt;&lt; (<font class="keyword">const</font> <font class="keywordtype">char</font> *) vk;
00430                                         }
00431                                         <font class="keywordflow">else</font> listkey &lt;&lt; (<font class="keyword">const</font> <font class="keywordtype">char</font>*) vk;
00432                                 }
00433                         }
00434                         (*percent)(98, percentUserData);
00435 
00436                         free(words);
00437                         free(wordBuf);
00438 
00439                         *testKeyType = saveKey; <font class="comment">// set current place back to original</font>
00440 
00441                         listkey = TOP;
00442                         (*percent)(100, percentUserData);
00443                         <font class="keywordflow">return</font> listkey;
00444                 }
00445 
00446                 <font class="keywordflow">default</font>:
00447                         <font class="keywordflow">break</font>;
00448                 }
00449         }
00450 
00451         <font class="comment">// check if we just want to see if search is supported</font>
00452         <font class="keywordflow">if</font> (justCheckIfSupported) {
00453                 *justCheckIfSupported = <font class="keyword">false</font>;
00454                 <font class="keywordflow">return</font> listkey;
00455         }
00456 
00457         <font class="comment">// if we don't support this search, fall back to base class</font>
00458         <font class="keywordflow">return</font> <a class="code" href="class_s_w_module.html#a22">SWModule::Search</a>(istr, searchType, flags, scope, justCheckIfSupported, percent, percentUserData);
00459 }
00460 
00461 <font class="preprocessor">#ifdef _MSC_VER</font>
00462 <font class="preprocessor"></font><a class="code" href="class_s_w_module.html">SWModule</a> &amp;RawText::operator =(SW_POSITION p) {
00463 <font class="preprocessor">#else</font>
00464 <font class="preprocessor"></font>RawText &amp;RawText::operator =(SW_POSITION p) {
00465 <font class="preprocessor">#endif</font>
00466 <font class="preprocessor"></font>        <a class="code" href="class_s_w_module.html#a40">SWModule::operator =</a>(p);
00467         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00468 }
00469 
00470 <a class="code" href="class_s_w_module.html">SWModule</a> &amp;RawText::setentry(<font class="keyword">const</font> <font class="keywordtype">char</font> *inbuf, <font class="keywordtype">long</font> len) {
00471         <a class="code" href="class_verse_key.html">VerseKey</a> *key = 0;
00472         <font class="comment">// see if we have a VerseKey * or decendant</font>
00473 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00474 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00475 <font class="preprocessor">#endif</font>
00476 <font class="preprocessor"></font>                key = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, this-&gt;key);
00477 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00478 <font class="preprocessor"></font>        }
00479         <font class="keywordflow">catch</font> ( ... ) {}
00480 <font class="preprocessor">#endif</font>
00481 <font class="preprocessor"></font>        <font class="comment">// if we don't have a VerseKey * decendant, create our own</font>
00482         <font class="keywordflow">if</font> (!key)
00483                 key = <font class="keyword">new</font> <a class="code" href="class_verse_key.html">VerseKey</a>(this-&gt;key);
00484 
00485         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>(), inbuf, len);
00486 
00487         <font class="keywordflow">if</font> (this-&gt;key != key) <font class="comment">// free our key if we created a VerseKey</font>
00488                 <font class="keyword">delete</font> key;
00489 
00490         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00491 }
00492 
00493 <a class="code" href="class_s_w_module.html">SWModule</a> &amp;RawText::operator &lt;&lt;(<font class="keyword">const</font> <font class="keywordtype">char</font> *inbuf) {
00494         <font class="keywordflow">return</font> setentry(inbuf, 0);
00495 }
00496 
00497 
00498 <a class="code" href="class_s_w_module.html">SWModule</a> &amp;RawText::operator &lt;&lt;(<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> *inkey) {
00499         <a class="code" href="class_verse_key.html">VerseKey</a> *destkey = 0;
00500         <font class="keyword">const</font> <a class="code" href="class_verse_key.html">VerseKey</a> *srckey = 0;
00501         <font class="comment">// see if we have a VerseKey * or decendant</font>
00502 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00503 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00504 <font class="preprocessor">#endif</font>
00505 <font class="preprocessor"></font>                destkey = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, this-&gt;key);
00506 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00507 <font class="preprocessor"></font>        }
00508         <font class="keywordflow">catch</font> ( ... ) {}
00509 <font class="preprocessor">#endif</font>
00510 <font class="preprocessor"></font>        <font class="comment">// if we don't have a VerseKey * decendant, create our own</font>
00511         <font class="keywordflow">if</font> (!destkey)
00512                 destkey = <font class="keyword">new</font> <a class="code" href="class_verse_key.html">VerseKey</a>(this-&gt;key);
00513 
00514         <font class="comment">// see if we have a VerseKey * or decendant</font>
00515 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00516 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00517 <font class="preprocessor">#endif</font>
00518 <font class="preprocessor"></font>                srckey = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, inkey);
00519 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00520 <font class="preprocessor"></font>        }
00521         <font class="keywordflow">catch</font> ( ... ) {}
00522 <font class="preprocessor">#endif</font>
00523 <font class="preprocessor"></font>        <font class="comment">// if we don't have a VerseKey * decendant, create our own</font>
00524         <font class="keywordflow">if</font> (!srckey)
00525                 srckey = <font class="keyword">new</font> <a class="code" href="class_verse_key.html">VerseKey</a>(inkey);
00526 
00527         linkentry(destkey-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), destkey-&gt;<a class="code" href="class_verse_key.html#a34">Index</a>(), srckey-&gt;<a class="code" href="class_verse_key.html#a34">Index</a>());
00528 
00529         <font class="keywordflow">if</font> (this-&gt;key != destkey) <font class="comment">// free our key if we created a VerseKey</font>
00530                 <font class="keyword">delete</font> destkey;
00531 
00532         <font class="keywordflow">if</font> (inkey != srckey) <font class="comment">// free our key if we created a VerseKey</font>
00533                 <font class="keyword">delete</font> srckey;
00534 
00535         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00536 }
00537 
00538 
00539 <font class="comment">/******************************************************************************</font>
00540 <font class="comment"> * RawText::deleteEntry - deletes this entry</font>
00541 <font class="comment"> *</font>
00542 <font class="comment"> * RET: *this</font>
00543 <font class="comment"> */</font>
00544 
00545 <font class="keywordtype">void</font> RawText::deleteEntry() {
00546 
00547         <a class="code" href="class_verse_key.html">VerseKey</a> *key = 0;
00548 
00549 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00550 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00551 <font class="preprocessor">#endif</font>
00552 <font class="preprocessor"></font>                key = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, this-&gt;key);
00553 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00554 <font class="preprocessor"></font>        }
00555         <font class="keywordflow">catch</font> ( ... ) {}
00556 <font class="preprocessor">#endif</font>
00557 <font class="preprocessor"></font>        <font class="keywordflow">if</font> (!key)
00558                 key = <font class="keyword">new</font> <a class="code" href="class_verse_key.html">VerseKey</a>(this-&gt;key);
00559 
00560         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>);
00561 
00562         <font class="keywordflow">if</font> (key != this-&gt;key)
00563                 <font class="keyword">delete</font> key;
00564 }
00565 
00566 <font class="comment">/******************************************************************************</font>
00567 <font class="comment"> * RawText::operator += - Increments module key a number of entries</font>
00568 <font class="comment"> *</font>
00569 <font class="comment"> * ENT: increment       - Number of entries to jump forward</font>
00570 <font class="comment"> *</font>
00571 <font class="comment"> * RET: *this</font>
00572 <font class="comment"> */</font>
00573 
00574 <a class="code" href="class_s_w_module.html">SWModule</a> &amp;RawText::operator +=(<font class="keywordtype">int</font> increment)
00575 {
00576         <font class="keywordtype">long</font>  start;
00577         <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size;
00578         <a class="code" href="class_verse_key.html">VerseKey</a> *tmpkey = 0;
00579 
00580 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00581 <font class="preprocessor"></font>        <font class="keywordflow">try</font> {
00582 <font class="preprocessor">#endif</font>
00583 <font class="preprocessor"></font>                tmpkey = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, key);
00584 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00585 <font class="preprocessor"></font>        }
00586         <font class="keywordflow">catch</font> ( ... ) {}
00587 <font class="preprocessor">#endif</font>
00588 <font class="preprocessor"></font>        <font class="keywordflow">if</font> (!tmpkey)
00589                 tmpkey = <font class="keyword">new</font> <a class="code" href="class_verse_key.html">VerseKey</a>(key);
00590 
00591         findoffset(tmpkey-&gt;<a class="code" href="class_verse_key.html#a22">Testament</a>(), tmpkey-&gt;<a class="code" href="class_verse_key.html#a34">Index</a>(), &amp;start, &amp;size);
00592 
00593         <a class="code" href="class_s_w_key.html">SWKey</a> lastgood = *tmpkey;
00594         <font class="keywordflow">while</font> (increment) {
00595                 <font class="keywordtype">long</font> laststart = start;
00596                 <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> lastsize = size;
00597                 <a class="code" href="class_s_w_key.html">SWKey</a> lasttry = *tmpkey;
00598                 (increment &gt; 0) ? (*key)++ : (*key)--;
00599                 <font class="keywordflow">if</font> (tmpkey != key)
00600                         <font class="keyword">delete</font> tmpkey;
00601                 tmpkey = 0;
00602 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00603 <font class="preprocessor"></font>                <font class="keywordflow">try</font> {
00604 <font class="preprocessor">#endif</font>
00605 <font class="preprocessor"></font>                        tmpkey = SWDYNAMIC_CAST(<a class="code" href="class_verse_key.html">VerseKey</a>, key);
00606 <font class="preprocessor">#ifndef _WIN32_WCE</font>
00607 <font class="preprocessor"></font>                }
00608                 <font class="keywordflow">catch</font> ( ... ) {}
00609 <font class="preprocessor">#endif</font>
00610 <font class="preprocessor"></font>                <font class="keywordflow">if</font> (!tmpkey)
00611                         tmpkey = <font class="keyword">new</font> <a class="code" href="class_verse_key.html">VerseKey</a>(key);
00612 
00613                 <font class="keywordflow">if</font> ((error = key-&gt;Error())) {
00614                         *key = lastgood;
00615                         <font class="keywordflow">break</font>;
00616                 }
00617                 <font class="keywordtype">long</font> index = tmpkey-&gt;<a class="code" href="class_s_w_key.html#a17">Index</a>();
00618                 findoffset(tmpkey-&gt;Testament(), index, &amp;start, &amp;size);
00619                 <font class="keywordflow">if</font> ((((laststart != start) || (lastsize != size))||(!skipConsecutiveLinks)) &amp;&amp; (start &gt;= 0) &amp;&amp; (size)) {
00620                         increment += (increment &lt; 0) ? 1 : -1;
00621                         lastgood = *tmpkey;
00622                 }
00623         }
00624         error = (error) ? KEYERR_OUTOFBOUNDS : 0;
00625 
00626         <font class="keywordflow">if</font> (tmpkey != key)
00627                 <font class="keyword">delete</font> tmpkey;
00628 
00629         <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00630 }
</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>