00001
00002
00003
00004
00005
00006
00007 #include <ctype.h>
00008 #include <stdio.h>
00009 #include <fcntl.h>
00010
00011 #ifndef __GNUC__
00012 #include <io.h>
00013 #else
00014 #include <unistd.h>
00015 #endif
00016
00017 #include <string.h>
00018 #include <utilfuns.h>
00019 #include <rawverse.h>
00020 #include <rawcom.h>
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 RawCom::RawCom(const char *ipath, const char *iname, const char *idesc, SWDisplay *idisp, SWTextEncoding encoding, SWTextDirection dir, SWTextMarkup markup, const char* ilang)
00032 : RawVerse(ipath),
00033 SWCom(iname, idesc, idisp, encoding, dir, markup, ilang){
00034 }
00035
00036
00037
00038
00039
00040
00041 RawCom::~RawCom()
00042 {
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 char *RawCom::getRawEntry() {
00054 long start = 0;
00055 unsigned short size = 0;
00056 VerseKey *key = 0;
00057
00058 #ifndef _WIN32_WCE
00059 try {
00060 #endif
00061 key = SWDYNAMIC_CAST(VerseKey, this->key);
00062 #ifndef _WIN32_WCE
00063 }
00064 catch ( ... ) {}
00065 #endif
00066 if (!key)
00067 key = new VerseKey(this->key);
00068
00069
00070 findoffset(key->Testament(), key->Index(), &start, &size);
00071 entrySize = size;
00072
00073 unsigned long newsize = (size + 2) * FILTERPAD;
00074 if (newsize > entrybufallocsize) {
00075 if (entrybuf)
00076 delete [] entrybuf;
00077 entrybuf = new char [ newsize ];
00078 entrybufallocsize = newsize;
00079 }
00080 *entrybuf = 0;
00081
00082 gettext(key->Testament(), start, (size + 2), entrybuf);
00083
00084 rawFilter(entrybuf, size, key);
00085
00086 if (!isUnicode())
00087 preptext(entrybuf);
00088
00089 if (key != this->key)
00090 delete key;
00091
00092 return entrybuf;
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 SWModule &RawCom::operator +=(int increment)
00105 {
00106 long start;
00107 unsigned short size;
00108 VerseKey *tmpkey = 0;
00109
00110 #ifndef _WIN32_WCE
00111 try {
00112 #endif
00113 tmpkey = SWDYNAMIC_CAST(VerseKey, key);
00114 #ifndef _WIN32_WCE
00115 }
00116 catch ( ... ) {}
00117 #endif
00118 if (!tmpkey)
00119 tmpkey = new VerseKey(key);
00120
00121 findoffset(tmpkey->Testament(), tmpkey->Index(), &start, &size);
00122
00123 SWKey lastgood = *tmpkey;
00124 while (increment) {
00125 long laststart = start;
00126 unsigned short lastsize = size;
00127 SWKey lasttry = *tmpkey;
00128 (increment > 0) ? (*key)++ : (*key)--;
00129 if (tmpkey != key)
00130 delete tmpkey;
00131 tmpkey = 0;
00132 #ifndef _WIN32_WCE
00133 try {
00134 #endif
00135 tmpkey = SWDYNAMIC_CAST(VerseKey, key);
00136 #ifndef _WIN32_WCE
00137 }
00138 catch ( ... ) {}
00139 #endif
00140 if (!tmpkey)
00141 tmpkey = new VerseKey(key);
00142
00143 if ((error = key->Error())) {
00144 *key = lastgood;
00145 break;
00146 }
00147 long index = tmpkey->Index();
00148 findoffset(tmpkey->Testament(), index, &start, &size);
00149 if ((((laststart != start) || (lastsize != size))||(!skipConsecutiveLinks)) && (start >= 0) && (size)) {
00150 increment += (increment < 0) ? 1 : -1;
00151 lastgood = *tmpkey;
00152 }
00153 }
00154 error = (error) ? KEYERR_OUTOFBOUNDS : 0;
00155
00156 if (tmpkey != key)
00157 delete tmpkey;
00158
00159 return *this;
00160 }
00161
00162 SWModule &RawCom::setentry(const char *inbuf, long len) {
00163 VerseKey *key = 0;
00164
00165 #ifndef _WIN32_WCE
00166 try {
00167 #endif
00168 key = SWDYNAMIC_CAST(VerseKey, this->key);
00169 #ifndef _WIN32_WCE
00170 }
00171 catch ( ... ) {}
00172 #endif
00173
00174 if (!key)
00175 key = new VerseKey(this->key);
00176
00177 settext(key->Testament(), key->Index(), inbuf, len);
00178
00179 if (this->key != key)
00180 delete key;
00181
00182 return *this;
00183 }
00184
00185 SWModule &RawCom::operator <<(const char *inbuf) {
00186 VerseKey *key = 0;
00187
00188 #ifndef _WIN32_WCE
00189 try {
00190 #endif
00191 key = SWDYNAMIC_CAST(VerseKey, this->key);
00192 #ifndef _WIN32_WCE
00193 }
00194 catch ( ... ) {}
00195 #endif
00196
00197 if (!key)
00198 key = new VerseKey(this->key);
00199
00200 settext(key->Testament(), key->Index(), inbuf);
00201
00202 if (this->key != key)
00203 delete key;
00204
00205 return *this;
00206 }
00207
00208
00209 SWModule &RawCom::operator <<(const SWKey *inkey) {
00210 VerseKey *destkey = 0;
00211 const VerseKey *srckey = 0;
00212
00213 #ifndef _WIN32_WCE
00214 try {
00215 #endif
00216 destkey = SWDYNAMIC_CAST(VerseKey, this->key);
00217 #ifndef _WIN32_WCE
00218 }
00219 catch ( ... ) {}
00220 #endif
00221
00222 if (!destkey)
00223 destkey = new VerseKey(this->key);
00224
00225
00226 #ifndef _WIN32_WCE
00227 try {
00228 #endif
00229 srckey = SWDYNAMIC_CAST(VerseKey, inkey);
00230 #ifndef _WIN32_WCE
00231 }
00232 catch ( ... ) {}
00233 #endif
00234
00235 if (!srckey)
00236 srckey = new VerseKey(inkey);
00237
00238 linkentry(destkey->Testament(), destkey->Index(), srckey->Index());
00239
00240 if (this->key != destkey)
00241 delete destkey;
00242
00243 if (inkey != srckey)
00244 delete srckey;
00245
00246 return *this;
00247 }
00248
00249
00250
00251
00252
00253
00254
00255
00256 void RawCom::deleteEntry() {
00257
00258 VerseKey *key = 0;
00259
00260 #ifndef _WIN32_WCE
00261 try {
00262 #endif
00263 key = SWDYNAMIC_CAST(VerseKey, this->key);
00264 #ifndef _WIN32_WCE
00265 }
00266 catch ( ... ) {}
00267 #endif
00268 if (!key)
00269 key = new VerseKey(this->key);
00270
00271 settext(key->Testament(), key->Index(), "");
00272
00273 if (key != this->key)
00274 delete key;
00275 }