The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rawcom4.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * rawcom4.cpp - code for class 'RawCom4'- a module that reads raw
4  * commentary files:
5  * ot and nt using indexs ??.bks ??.cps ??.vss
6  *
7  * $Id: rawcom4.cpp 3821 2020-11-02 18:33:02Z scribe $
8  *
9  * Copyright 2007-2013 CrossWire Bible Society (http://www.crosswire.org)
10  * CrossWire Bible Society
11  * P. O. Box 2528
12  * Tempe, AZ 85280-2528
13  *
14  * This program is free software; you can redistribute it and/or modify it
15  * under the terms of the GNU General Public License as published by the
16  * Free Software Foundation version 2.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * General Public License for more details.
22  *
23  */
24 
25 #include <ctype.h>
26 #include <stdio.h>
27 #include <fcntl.h>
28 
29 #include <filemgr.h>
30 #include <rawverse4.h>
31 #include <rawcom4.h>
32 #include <versekey.h>
33 
35 
36  /******************************************************************************
37  * RawCom4 Constructor - Initializes data for instance of RawCom4
38  *
39  * ENT: iname - Internal name for module
40  * idesc - Name to display to user for module
41  * idisp - Display object to use for displaying
42  */
43 
44 RawCom4::RawCom4(const char *ipath, const char *iname, const char *idesc, SWDisplay *idisp, SWTextEncoding encoding, SWTextDirection dir, SWTextMarkup markup, const char *ilang, const char *versification)
45  : RawVerse4(ipath),
46  SWCom(iname, idesc, idisp, encoding, dir, markup, ilang, versification) {
47 }
48 
49 
50 /******************************************************************************
51  * RawCom4 Destructor - Cleans up instance of RawCom4
52  */
53 
55 {
56 }
57 
58 
59 bool RawCom4::isWritable() const {
60  return ((idxfp[0]->getFd() > 0) && ((idxfp[0]->mode & FileMgr::RDWR) == FileMgr::RDWR));
61 }
62 /******************************************************************************
63  * RawCom4::getRawEntry() - Returns the correct verse when char * cast
64  * is requested
65  *
66  * RET: string buffer with verse
67  */
68 
70  long start = 0;
71  unsigned long size = 0;
72  const VerseKey *key = &getVerseKey();
73 
74  findOffset(key->getTestament(), key->getTestamentIndex(), &start, &size);
75  entrySize = (int)size; // support getEntrySize call
76 
77  entryBuf = "";
78  readText(key->getTestament(), start, size, entryBuf);
79 
80  rawFilter(entryBuf, 0); // hack, decipher
81  rawFilter(entryBuf, key);
82 
83 // if (!isUnicode())
85 
86  return entryBuf;
87 }
88 
89 
90 /******************************************************************************
91  * RawCom4::increment - Increments module key a number of entries
92  *
93  * ENT: steps - Number of entries to jump forward
94  *
95  * RET: *this
96  */
97 
98 void RawCom4::increment(int steps) {
99  long start;
100  unsigned long size;
101  VerseKey *tmpkey = &getVerseKey();
102 
103  findOffset(tmpkey->getTestament(), tmpkey->getTestamentIndex(), &start, &size);
104 
105  SWKey lastgood = *tmpkey;
106  while (steps) {
107  long laststart = start;
108  unsigned long lastsize = size;
109  SWKey lasttry = *tmpkey;
110  (steps > 0) ? ++(*key) : --(*key);
111  tmpkey = &getVerseKey();
112 
113  if ((error = key->popError())) {
114  *key = lastgood;
115  break;
116  }
117  long index = tmpkey->getTestamentIndex();
118  findOffset(tmpkey->getTestament(), index, &start, &size);
119  if (
120  (((laststart != start) || (lastsize != size)) // we're a different entry
121 // && (start > 0)
122  && (size)) // and we actually have a size
123  ||(!skipConsecutiveLinks)) { // or we don't want to skip consecutive links
124  steps += (steps < 0) ? 1 : -1;
125  lastgood = *tmpkey;
126  }
127  }
128  error = (error) ? KEYERR_OUTOFBOUNDS : 0;
129 }
130 
131 
132 void RawCom4::setEntry(const char *inbuf, long len) {
133  VerseKey *key = &getVerseKey();
134  doSetText(key->getTestament(), key->getTestamentIndex(), inbuf, len);
135 }
136 
137 
138 void RawCom4::linkEntry(const SWKey *inkey) {
139  VerseKey *destkey = &getVerseKey();
140  const VerseKey *srckey = &getVerseKeyConst(inkey);
141  doLinkEntry(destkey->getTestament(), destkey->getTestamentIndex(), srckey->getTestamentIndex());
142 }
143 
144 
145 /******************************************************************************
146  * RawCom4::deleteEntry - deletes this entry
147  *
148  * RET: *this
149  */
150 
152 
153  VerseKey *key = &getVerseKey();
154  doSetText(key->getTestament(), key->getTestamentIndex(), "");
155 }
156 
157 bool RawCom4::isLinked(const SWKey *k1, const SWKey *k2) const {
158  long start1, start2;
159  unsigned long size1, size2;
160  const VerseKey *vk1 = &getVerseKey(k1);
161  const VerseKey *vk2 = &getVerseKey(k2);
162  if (vk1->getTestament() != vk2->getTestament()) return false;
163 
164  findOffset(vk1->getTestament(), vk1->getTestamentIndex(), &start1, &size1);
165  findOffset(vk2->getTestament(), vk2->getTestamentIndex(), &start2, &size2);
166  if (!size1 || !size2) return false;
167  return start1 == start2;
168 }
169 
170 bool RawCom4::hasEntry(const SWKey *k) const {
171  long start;
172  unsigned long size;
173  const VerseKey *vk = &getVerseKey(k);
174 
175  findOffset(vk->getTestament(), vk->getTestamentIndex(), &start, &size);
176  return size;
177 }
178 
#define SWTextEncoding
Definition: swmodule.h:78
#define SWORD_NAMESPACE_START
Definition: defs.h:39
void doSetText(char testmt, long idxoff, const char *buf, long len=-1)
Definition: rawverse4.cpp:179
Definition: swbuf.h:47
const VerseKey & getVerseKeyConst(const SWKey *key=0) const
Definition: swcom.cpp:90
virtual void linkEntry(const SWKey *linkKey)
Definition: rawcom4.cpp:138
static void prepText(SWBuf &buf)
Definition: swmodule.cpp:1695
virtual void rawFilter(SWBuf &buf, const SWKey *key) const
Definition: swmodule.h:716
virtual bool isWritable() const
Definition: rawcom4.cpp:59
virtual SWBuf & getRawEntryBuf() const
Definition: rawcom4.cpp:69
static unsigned int RDWR
Definition: filemgr.h:76
void doLinkEntry(char testmt, long destidxoff, long srcidxoff)
Definition: rawverse4.cpp:220
virtual void setEntry(const char *inbuf, long len=-1)
Definition: rawcom4.cpp:132
int size2
Definition: regex.c:5079
char error
Definition: swmodule.h:120
virtual ~RawCom4()
Definition: rawcom4.cpp:54
RawCom4(const char *ipath, const char *iname=0, const char *idesc=0, SWDisplay *idisp=0, SWTextEncoding encoding=ENC_UNKNOWN, SWTextDirection dir=DIRECTION_LTR, SWTextMarkup markup=FMT_UNKNOWN, const char *ilang=0, const char *versification="KJV")
Definition: rawcom4.cpp:44
bool skipConsecutiveLinks
Definition: swmodule.h:121
Definition: swcom.h:49
virtual void increment(int steps=1)
Definition: rawcom4.cpp:98
virtual bool hasEntry(const SWKey *k) const
Definition: rawcom4.cpp:170
#define KEYERR_OUTOFBOUNDS
Definition: swkey.h:35
int entrySize
Definition: swmodule.h:157
virtual char popError()
Definition: swkey.cpp:147
void readText(char testmt, long start, unsigned long size, SWBuf &buf) const
Definition: rawverse4.cpp:155
int size
Definition: regex.c:5043
virtual void deleteEntry()
Definition: rawcom4.cpp:151
SWBuf entryBuf
Definition: swmodule.h:140
virtual long getTestamentIndex() const
Definition: versekey.cpp:1704
#define SWTextDirection
Definition: swmodule.h:77
SWKey * key
Definition: swmodule.h:124
#define SWORD_NAMESPACE_END
Definition: defs.h:40
virtual bool isLinked(const SWKey *k1, const SWKey *k2) const
Definition: rawcom4.cpp:157
Definition: swkey.h:77
FileDesc * idxfp[2]
Definition: rawverse4.h:43
#define SWTextMarkup
Definition: swmodule.h:79
void findOffset(char testmt, long idxoff, long *start, unsigned long *end) const
Definition: rawverse4.cpp:119
VerseKey & getVerseKey(SWKey *key=0)
Definition: swcom.cpp:123
int size1
Definition: regex.c:5079
virtual char getTestament() const
Definition: versekey.cpp:1498