diff options
Diffstat (limited to 'src/modules/comments/zcom/zcom.cpp')
-rw-r--r-- | src/modules/comments/zcom/zcom.cpp | 73 |
1 files changed, 51 insertions, 22 deletions
diff --git a/src/modules/comments/zcom/zcom.cpp b/src/modules/comments/zcom/zcom.cpp index cdaea02..35b8946 100644 --- a/src/modules/comments/zcom/zcom.cpp +++ b/src/modules/comments/zcom/zcom.cpp @@ -1,9 +1,24 @@ /****************************************************************************** * rawcom.cpp - code for class 'zCom'- a module that reads raw commentary * files: ot and nt using indexs ??.bks ??.cps ??.vss + * + * + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * */ - #include <ctype.h> #include <stdio.h> #include <fcntl.h> @@ -26,7 +41,7 @@ SWORD_NAMESPACE_START * idisp - Display object to use for displaying */ -zCom::zCom(const char *ipath, const char *iname, const char *idesc, int iblockType, SWCompress *icomp, SWDisplay *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, const char* ilang) : zVerse(ipath, -1, iblockType, icomp), SWCom(iname, idesc, idisp, enc, dir, mark, ilang)/*, SWCompress()*/ +zCom::zCom(const char *ipath, const char *iname, const char *idesc, int iblockType, SWCompress *icomp, SWDisplay *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, const char *ilang, const char *versification) : zVerse(ipath, -1, iblockType, icomp), SWCom(iname, idesc, idisp, enc, dir, mark, ilang, versification)/*, SWCompress()*/ { blockType = iblockType; lastWriteKey = 0; @@ -58,13 +73,14 @@ bool zCom::isWritable() { SWBuf &zCom::getRawEntryBuf() { long start = 0; unsigned short size = 0; + unsigned long buffnum; VerseKey *key = &getVerseKey(); - findOffset(key->Testament(), key->Index(), &start, &size); + findOffset(key->Testament(), key->TestamentIndex(), &start, &size, &buffnum); entrySize = size; // support getEntrySize call entryBuf = ""; - zReadText(key->Testament(), start, size, entryBuf); + zReadText(key->Testament(), start, size, buffnum, entryBuf); rawFilter(entryBuf, key); @@ -104,7 +120,7 @@ void zCom::setEntry(const char *inbuf, long len) { delete lastWriteKey; } - doSetText(key->Testament(), key->Index(), inbuf, len); + doSetText(key->Testament(), key->TestamentIndex(), inbuf, len); lastWriteKey = (VerseKey *)key->clone(); // must delete } @@ -112,19 +128,9 @@ void zCom::setEntry(const char *inbuf, long len) { void zCom::linkEntry(const SWKey *inkey) { VerseKey *destkey = &getVerseKey(); - const VerseKey *srckey = 0; - - // see if we have a VerseKey * or decendant - SWTRY { - srckey = (const VerseKey *) SWDYNAMIC_CAST(VerseKey, inkey); - } - SWCATCH ( ... ) { - } - // if we don't have a VerseKey * decendant, create our own - if (!srckey) - srckey = new VerseKey(inkey); + const VerseKey *srckey = &getVerseKey(inkey); - doLinkEntry(destkey->Testament(), destkey->Index(), srckey->Index()); + doLinkEntry(destkey->Testament(), destkey->TestamentIndex(), srckey->TestamentIndex()); if (inkey != srckey) // free our key if we created a VerseKey delete srckey; @@ -139,7 +145,7 @@ void zCom::linkEntry(const SWKey *inkey) { void zCom::deleteEntry() { VerseKey *key = &getVerseKey(); - doSetText(key->Testament(), key->Index(), ""); + doSetText(key->Testament(), key->TestamentIndex(), ""); } @@ -154,24 +160,25 @@ void zCom::deleteEntry() { void zCom::increment(int steps) { long start; unsigned short size; + unsigned long buffnum; VerseKey *tmpkey = &getVerseKey(); - findOffset(tmpkey->Testament(), tmpkey->Index(), &start, &size); + findOffset(tmpkey->Testament(), tmpkey->TestamentIndex(), &start, &size, &buffnum); SWKey lastgood = *tmpkey; while (steps) { long laststart = start; unsigned short lastsize = size; SWKey lasttry = *tmpkey; - (steps > 0) ? (*key)++ : (*key)--; + (steps > 0) ? ++(*key) : --(*key); tmpkey = &getVerseKey(); if ((error = key->Error())) { *key = lastgood; break; } - long index = tmpkey->Index(); - findOffset(tmpkey->Testament(), index, &start, &size); + long index = tmpkey->TestamentIndex(); + findOffset(tmpkey->Testament(), index, &start, &size, &buffnum); if ( (((laststart != start) || (lastsize != size)) // we're a different entry // && (start > 0) @@ -184,5 +191,27 @@ void zCom::increment(int steps) { error = (error) ? KEYERR_OUTOFBOUNDS : 0; } +bool zCom::isLinked(const SWKey *k1, const SWKey *k2) const { + long start1, start2; + unsigned short size1, size2; + unsigned long buffnum1, buffnum2; + VerseKey *vk1 = &getVerseKey(k1); + VerseKey *vk2 = &getVerseKey(k2); + if (vk1->Testament() != vk2->Testament()) return false; + + findOffset(vk1->Testament(), vk1->TestamentIndex(), &start1, &size1, &buffnum1); + findOffset(vk2->Testament(), vk2->TestamentIndex(), &start2, &size2, &buffnum2); + return start1 == start2 && buffnum1 == buffnum2; +} + +bool zCom::hasEntry(const SWKey *k) const { + long start; + unsigned short size; + unsigned long buffnum; + VerseKey *vk = &getVerseKey(k); + + findOffset(vk->Testament(), vk->TestamentIndex(), &start, &size, &buffnum); + return size; +} SWORD_NAMESPACE_END |