diff options
author | Roberto C. Sanchez <roberto@connexer.com> | 2014-03-29 10:53:59 -0400 |
---|---|---|
committer | Roberto C. Sanchez <roberto@connexer.com> | 2014-03-29 10:53:59 -0400 |
commit | 03134fa5f6f25d92724ce4c183f9bbe12a9e37dc (patch) | |
tree | 847326a4de82f0241ac87cbbc427a1b92a696a02 /src/modules/comments | |
parent | d7469385b05b9510338407fa123e9ad090f80af6 (diff) |
Imported Upstream version 1.5.11
Diffstat (limited to 'src/modules/comments')
-rw-r--r-- | src/modules/comments/Makefile | 5 | ||||
-rw-r--r-- | src/modules/comments/Makefile.am | 9 | ||||
-rw-r--r-- | src/modules/comments/hrefcom/Makefile | 5 | ||||
-rw-r--r-- | src/modules/comments/hrefcom/Makefile.am | 2 | ||||
-rw-r--r-- | src/modules/comments/hrefcom/hrefcom.cpp | 82 | ||||
-rw-r--r-- | src/modules/comments/rawcom/Makefile | 5 | ||||
-rw-r--r-- | src/modules/comments/rawcom/Makefile.am | 2 | ||||
-rw-r--r-- | src/modules/comments/rawcom/rawcom.cpp | 153 | ||||
-rw-r--r-- | src/modules/comments/rawcom4/Makefile.am | 2 | ||||
-rw-r--r-- | src/modules/comments/rawcom4/rawcom4.cpp | 153 | ||||
-rw-r--r-- | src/modules/comments/rawfiles/Makefile | 5 | ||||
-rw-r--r-- | src/modules/comments/rawfiles/Makefile.am | 2 | ||||
-rw-r--r-- | src/modules/comments/rawfiles/rawfiles.cpp | 257 | ||||
-rw-r--r-- | src/modules/comments/swcom.cpp | 105 | ||||
-rw-r--r-- | src/modules/comments/zcom/Makefile | 5 | ||||
-rw-r--r-- | src/modules/comments/zcom/Makefile.am | 2 | ||||
-rw-r--r-- | src/modules/comments/zcom/zcom.cpp | 188 |
17 files changed, 982 insertions, 0 deletions
diff --git a/src/modules/comments/Makefile b/src/modules/comments/Makefile new file mode 100644 index 0000000..1a2d00d --- /dev/null +++ b/src/modules/comments/Makefile @@ -0,0 +1,5 @@ + +root := ../../.. + +all: + make -C ${root} diff --git a/src/modules/comments/Makefile.am b/src/modules/comments/Makefile.am new file mode 100644 index 0000000..7139cf8 --- /dev/null +++ b/src/modules/comments/Makefile.am @@ -0,0 +1,9 @@ +commentsdir = $(top_srcdir)/src/modules/comments + +libsword_la_SOURCES += $(commentsdir)/swcom.cpp + +include ../src/modules/comments/rawcom/Makefile.am +include ../src/modules/comments/rawcom4/Makefile.am +include ../src/modules/comments/rawfiles/Makefile.am +include ../src/modules/comments/zcom/Makefile.am +include ../src/modules/comments/hrefcom/Makefile.am diff --git a/src/modules/comments/hrefcom/Makefile b/src/modules/comments/hrefcom/Makefile new file mode 100644 index 0000000..35d6648 --- /dev/null +++ b/src/modules/comments/hrefcom/Makefile @@ -0,0 +1,5 @@ + +root := ../../../.. + +all: + make -C ${root} diff --git a/src/modules/comments/hrefcom/Makefile.am b/src/modules/comments/hrefcom/Makefile.am new file mode 100644 index 0000000..dba4294 --- /dev/null +++ b/src/modules/comments/hrefcom/Makefile.am @@ -0,0 +1,2 @@ +hrefcomdir = $(top_srcdir)/src/modules/comments/hrefcom +libsword_la_SOURCES += $(hrefcomdir)/hrefcom.cpp diff --git a/src/modules/comments/hrefcom/hrefcom.cpp b/src/modules/comments/hrefcom/hrefcom.cpp new file mode 100644 index 0000000..7791da2 --- /dev/null +++ b/src/modules/comments/hrefcom/hrefcom.cpp @@ -0,0 +1,82 @@ +/****************************************************************************** + * hrefcom.cpp - code for class 'HREFCom'- a module that produces HTML HREFs + * pointing to actual text desired. Uses standard + * files: ot and nt using indexs ??.bks ??.cps ??.vss + */ + + +#include <ctype.h> +#include <stdio.h> +#include <fcntl.h> + +#include <utilstr.h> +#include <rawverse.h> +#include <hrefcom.h> +#include <swbuf.h> +#include <versekey.h> + +SWORD_NAMESPACE_START + + /****************************************************************************** + * HREFCom Constructor - Initializes data for instance of HREFCom + * + * ENT: iname - Internal name for module + * iprefix - string to prepend to each HREF (e.g. "file://mods/com/jfb/") + * idesc - Name to display to user for module + * idisp - Display object to use for displaying + */ + +HREFCom::HREFCom(const char *ipath, const char *iprefix, const char *iname, const char *idesc, SWDisplay *idisp) : RawVerse(ipath), SWCom(iname, idesc, idisp) +{ + prefix = 0; + stdstr(&prefix, iprefix); +} + + +/****************************************************************************** + * HREFCom Destructor - Cleans up instance of HREFCom + */ + +HREFCom::~HREFCom() +{ + if (prefix) + delete [] prefix; +} + + +/****************************************************************************** + * HREFCom::operator char * - Returns the correct verse when char * cast + * is requested + * + * RET: string buffer with verse + */ + +SWBuf &HREFCom::getRawEntryBuf() { + long start; + unsigned short size; + VerseKey *key = 0; + + SWTRY { + key = SWDYNAMIC_CAST(VerseKey, this->key); + } + SWCATCH ( ... ) {} + if (!key) + key = new VerseKey(this->key); + + findOffset(key->Testament(), key->Index(), &start, &size); + entrySize = size; // support getEntrySize call + + SWBuf tmpbuf; + + readText(key->Testament(), start, size, tmpbuf); + entryBuf = prefix; + entryBuf += tmpbuf.c_str(); + prepText(entryBuf); + + if (key != this->key) + delete key; + + return entryBuf; +} + +SWORD_NAMESPACE_END diff --git a/src/modules/comments/rawcom/Makefile b/src/modules/comments/rawcom/Makefile new file mode 100644 index 0000000..35d6648 --- /dev/null +++ b/src/modules/comments/rawcom/Makefile @@ -0,0 +1,5 @@ + +root := ../../../.. + +all: + make -C ${root} diff --git a/src/modules/comments/rawcom/Makefile.am b/src/modules/comments/rawcom/Makefile.am new file mode 100644 index 0000000..116d706 --- /dev/null +++ b/src/modules/comments/rawcom/Makefile.am @@ -0,0 +1,2 @@ +rawcomdir = $(top_srcdir)/src/modules/comments/rawcom +libsword_la_SOURCES += $(rawcomdir)/rawcom.cpp diff --git a/src/modules/comments/rawcom/rawcom.cpp b/src/modules/comments/rawcom/rawcom.cpp new file mode 100644 index 0000000..fd01c24 --- /dev/null +++ b/src/modules/comments/rawcom/rawcom.cpp @@ -0,0 +1,153 @@ +/****************************************************************************** + * rawcom.cpp - code for class 'RawCom'- a module that reads raw commentary + * files: ot and nt using indexs ??.bks ??.cps ??.vss + */ + + +#include <ctype.h> +#include <stdio.h> +#include <fcntl.h> + +#include <filemgr.h> +#include <rawverse.h> +#include <rawcom.h> +#include <versekey.h> + +SWORD_NAMESPACE_START + + /****************************************************************************** + * RawCom Constructor - Initializes data for instance of RawCom + * + * ENT: iname - Internal name for module + * idesc - Name to display to user for module + * idisp - Display object to use for displaying + */ + +RawCom::RawCom(const char *ipath, const char *iname, const char *idesc, SWDisplay *idisp, SWTextEncoding encoding, SWTextDirection dir, SWTextMarkup markup, const char* ilang) + : RawVerse(ipath), + SWCom(iname, idesc, idisp, encoding, dir, markup, ilang){ +} + + +/****************************************************************************** + * RawCom Destructor - Cleans up instance of RawCom + */ + +RawCom::~RawCom() +{ +} + + +bool RawCom::isWritable() { + return ((idxfp[0]->getFd() > 0) && ((idxfp[0]->mode & FileMgr::RDWR) == FileMgr::RDWR)); +} +/****************************************************************************** + * RawCom::getRawEntry() - Returns the correct verse when char * cast + * is requested + * + * RET: string buffer with verse + */ + +SWBuf &RawCom::getRawEntryBuf() { + long start = 0; + unsigned short size = 0; + VerseKey *key = &getVerseKey(); + + findOffset(key->Testament(), key->Index(), &start, &size); + entrySize = size; // support getEntrySize call + + entryBuf = ""; + readText(key->Testament(), start, size, entryBuf); + + rawFilter(entryBuf, 0); // hack, decipher + rawFilter(entryBuf, key); + +// if (!isUnicode()) + prepText(entryBuf); + + return entryBuf; +} + + +/****************************************************************************** + * RawCom::increment - Increments module key a number of entries + * + * ENT: steps - Number of entries to jump forward + * + * RET: *this + */ + +void RawCom::increment(int steps) { + long start; + unsigned short size; + VerseKey *tmpkey = &getVerseKey(); + + findOffset(tmpkey->Testament(), tmpkey->Index(), &start, &size); + + SWKey lastgood = *tmpkey; + while (steps) { + long laststart = start; + unsigned short lastsize = size; + SWKey lasttry = *tmpkey; + (steps > 0) ? (*key)++ : (*key)--; + tmpkey = &getVerseKey(); + + if ((error = key->Error())) { + *key = lastgood; + break; + } + long index = tmpkey->Index(); + findOffset(tmpkey->Testament(), index, &start, &size); + if ( + (((laststart != start) || (lastsize != size)) // we're a different entry +// && (start > 0) + && (size)) // and we actually have a size + ||(!skipConsecutiveLinks)) { // or we don't want to skip consecutive links + steps += (steps < 0) ? 1 : -1; + lastgood = *tmpkey; + } + } + error = (error) ? KEYERR_OUTOFBOUNDS : 0; +} + + +void RawCom::setEntry(const char *inbuf, long len) { + VerseKey *key = &getVerseKey(); + doSetText(key->Testament(), key->Index(), inbuf, len); +} + + +void RawCom::linkEntry(const SWKey *inkey) { + VerseKey *destkey = &getVerseKey(); + const VerseKey *srckey = 0; + + // see if we have a VerseKey * or decendant + SWTRY { + srckey = SWDYNAMIC_CAST(VerseKey, inkey); + } + SWCATCH ( ... ) {} + // if we don't have a VerseKey * decendant, create our own + if (!srckey) + srckey = new VerseKey(inkey); + + doLinkEntry(destkey->Testament(), destkey->Index(), srckey->Index()); + + if (inkey != srckey) // free our key if we created a VerseKey + delete srckey; +} + + +/****************************************************************************** + * RawCom::deleteEntry - deletes this entry + * + * RET: *this + */ + +void RawCom::deleteEntry() { + + VerseKey *key = &getVerseKey(); + doSetText(key->Testament(), key->Index(), ""); +} + + +SWORD_NAMESPACE_END diff --git a/src/modules/comments/rawcom4/Makefile.am b/src/modules/comments/rawcom4/Makefile.am new file mode 100644 index 0000000..346dbc5 --- /dev/null +++ b/src/modules/comments/rawcom4/Makefile.am @@ -0,0 +1,2 @@ +rawcom4dir = $(top_srcdir)/src/modules/comments/rawcom4 +libsword_la_SOURCES += $(rawcom4dir)/rawcom4.cpp diff --git a/src/modules/comments/rawcom4/rawcom4.cpp b/src/modules/comments/rawcom4/rawcom4.cpp new file mode 100644 index 0000000..e59ee39 --- /dev/null +++ b/src/modules/comments/rawcom4/rawcom4.cpp @@ -0,0 +1,153 @@ +/****************************************************************************** + * rawcom4.cpp - code for class 'RawCom4'- a module that reads raw commentary + * files: ot and nt using indexs ??.bks ??.cps ??.vss + */ + + +#include <ctype.h> +#include <stdio.h> +#include <fcntl.h> + +#include <filemgr.h> +#include <rawverse4.h> +#include <rawcom4.h> +#include <versekey.h> + +SWORD_NAMESPACE_START + + /****************************************************************************** + * RawCom4 Constructor - Initializes data for instance of RawCom4 + * + * ENT: iname - Internal name for module + * idesc - Name to display to user for module + * idisp - Display object to use for displaying + */ + +RawCom4::RawCom4(const char *ipath, const char *iname, const char *idesc, SWDisplay *idisp, SWTextEncoding encoding, SWTextDirection dir, SWTextMarkup markup, const char* ilang) + : RawVerse4(ipath), + SWCom(iname, idesc, idisp, encoding, dir, markup, ilang){ +} + + +/****************************************************************************** + * RawCom4 Destructor - Cleans up instance of RawCom4 + */ + +RawCom4::~RawCom4() +{ +} + + +bool RawCom4::isWritable() { + return ((idxfp[0]->getFd() > 0) && ((idxfp[0]->mode & FileMgr::RDWR) == FileMgr::RDWR)); +} +/****************************************************************************** + * RawCom4::getRawEntry() - Returns the correct verse when char * cast + * is requested + * + * RET: string buffer with verse + */ + +SWBuf &RawCom4::getRawEntryBuf() { + long start = 0; + unsigned long size = 0; + VerseKey *key = &getVerseKey(); + + findOffset(key->Testament(), key->Index(), &start, &size); + entrySize = size; // support getEntrySize call + + entryBuf = ""; + readText(key->Testament(), start, size, entryBuf); + + rawFilter(entryBuf, 0); // hack, decipher + rawFilter(entryBuf, key); + +// if (!isUnicode()) + prepText(entryBuf); + + return entryBuf; +} + + +/****************************************************************************** + * RawCom4::increment - Increments module key a number of entries + * + * ENT: steps - Number of entries to jump forward + * + * RET: *this + */ + +void RawCom4::increment(int steps) { + long start; + unsigned long size; + VerseKey *tmpkey = &getVerseKey(); + + findOffset(tmpkey->Testament(), tmpkey->Index(), &start, &size); + + SWKey lastgood = *tmpkey; + while (steps) { + long laststart = start; + unsigned long lastsize = size; + SWKey lasttry = *tmpkey; + (steps > 0) ? (*key)++ : (*key)--; + tmpkey = &getVerseKey(); + + if ((error = key->Error())) { + *key = lastgood; + break; + } + long index = tmpkey->Index(); + findOffset(tmpkey->Testament(), index, &start, &size); + if ( + (((laststart != start) || (lastsize != size)) // we're a different entry +// && (start > 0) + && (size)) // and we actually have a size + ||(!skipConsecutiveLinks)) { // or we don't want to skip consecutive links + steps += (steps < 0) ? 1 : -1; + lastgood = *tmpkey; + } + } + error = (error) ? KEYERR_OUTOFBOUNDS : 0; +} + + +void RawCom4::setEntry(const char *inbuf, long len) { + VerseKey *key = &getVerseKey(); + doSetText(key->Testament(), key->Index(), inbuf, len); +} + + +void RawCom4::linkEntry(const SWKey *inkey) { + VerseKey *destkey = &getVerseKey(); + const VerseKey *srckey = 0; + + // see if we have a VerseKey * or decendant + SWTRY { + srckey = SWDYNAMIC_CAST(VerseKey, inkey); + } + SWCATCH ( ... ) {} + // if we don't have a VerseKey * decendant, create our own + if (!srckey) + srckey = new VerseKey(inkey); + + doLinkEntry(destkey->Testament(), destkey->Index(), srckey->Index()); + + if (inkey != srckey) // free our key if we created a VerseKey + delete srckey; +} + + +/****************************************************************************** + * RawCom4::deleteEntry - deletes this entry + * + * RET: *this + */ + +void RawCom4::deleteEntry() { + + VerseKey *key = &getVerseKey(); + doSetText(key->Testament(), key->Index(), ""); +} + + +SWORD_NAMESPACE_END diff --git a/src/modules/comments/rawfiles/Makefile b/src/modules/comments/rawfiles/Makefile new file mode 100644 index 0000000..35d6648 --- /dev/null +++ b/src/modules/comments/rawfiles/Makefile @@ -0,0 +1,5 @@ + +root := ../../../.. + +all: + make -C ${root} diff --git a/src/modules/comments/rawfiles/Makefile.am b/src/modules/comments/rawfiles/Makefile.am new file mode 100644 index 0000000..a9b7dbe --- /dev/null +++ b/src/modules/comments/rawfiles/Makefile.am @@ -0,0 +1,2 @@ +rawfilesdir = $(top_srcdir)/src/modules/comments/rawfiles +libsword_la_SOURCES += $(rawfilesdir)/rawfiles.cpp diff --git a/src/modules/comments/rawfiles/rawfiles.cpp b/src/modules/comments/rawfiles/rawfiles.cpp new file mode 100644 index 0000000..3b614d9 --- /dev/null +++ b/src/modules/comments/rawfiles/rawfiles.cpp @@ -0,0 +1,257 @@ +/****************************************************************************** + * rawfiles.cpp - code for class 'RawFiles'- a module that produces HTML HREFs + * pointing to actual text desired. Uses standard + * files: ot and nt using indexs ??.bks ??.cps ??.vss + */ + + +#include <ctype.h> +#include <stdio.h> +#include <fcntl.h> + +#include <rawverse.h> +#include <rawfiles.h> +#include <filemgr.h> +#include <versekey.h> + +SWORD_NAMESPACE_START + + /****************************************************************************** + * RawFiles Constructor - Initializes data for instance of RawFiles + * + * ENT: iname - Internal name for module + * idesc - Name to display to user for module + * idisp - Display object to use for displaying + */ + +RawFiles::RawFiles(const char *ipath, const char *iname, const char *idesc, SWDisplay *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, const char* ilang) : RawVerse(ipath, FileMgr::RDWR), SWCom(iname, idesc, idisp, enc, dir, mark, ilang) +{ +} + + +/****************************************************************************** + * RawFiles Destructor - Cleans up instance of RawFiles + */ + +RawFiles::~RawFiles() +{ +} + + +/** Is the module writable? :) +* @return yes or no +*/ +bool RawFiles::isWritable() { + return ((idxfp[0]->getFd() > 0) && ((idxfp[0]->mode & FileMgr::RDWR) == FileMgr::RDWR)); +} + + +/****************************************************************************** + * RawFiles::getRawEntry - Returns the correct verse when char * cast + * is requested + * + * RET: string buffer with verse + */ + +SWBuf &RawFiles::getRawEntryBuf() { + FileDesc *datafile; + long start = 0; + unsigned short size = 0; + VerseKey *key = 0; + + SWTRY { + key = SWDYNAMIC_CAST(VerseKey, this->key); + } + SWCATCH ( ... ) {} + if (!key) + key = new VerseKey(this->key); + + findOffset(key->Testament(), key->Index(), &start, &size); + + entryBuf = ""; + if (size) { + SWBuf tmpbuf = path; + tmpbuf += '/'; + readText(key->Testament(), start, size, entryBuf); + tmpbuf += entryBuf; + entryBuf = ""; + datafile = FileMgr::getSystemFileMgr()->open(tmpbuf.c_str(), FileMgr::RDONLY); + if (datafile->getFd() > 0) { + size = datafile->seek(0, SEEK_END); + char *tmpBuf = new char [ size + 1 ]; + memset(tmpBuf, 0, size + 1); + datafile->seek(0, SEEK_SET); + datafile->read(tmpBuf, size); + entryBuf = tmpBuf; + delete [] tmpBuf; +// preptext(entrybuf); + } + FileMgr::getSystemFileMgr()->close(datafile); + } + + if (key != this->key) + delete key; + + return entryBuf; +} + + +/****************************************************************************** + * RawFiles::setEntry(char *)- Update the modules current key entry with + * provided text + */ + +void RawFiles::setEntry(const char *inbuf, long len) { + FileDesc *datafile; + long start; + unsigned short size; + VerseKey *key = 0; + + len = (len<0)?strlen(inbuf):len; + SWTRY { + key = SWDYNAMIC_CAST(VerseKey, this->key); + } + SWCATCH ( ... ) {} + if (!key) + key = new VerseKey(this->key); + + findOffset(key->Testament(), key->Index(), &start, &size); + + if (size) { + SWBuf tmpbuf; + entryBuf = path; + entryBuf += '/'; + readText(key->Testament(), start, size, tmpbuf); + entryBuf += tmpbuf; + } + else { + SWBuf tmpbuf; + entryBuf = path; + entryBuf += '/'; + tmpbuf = getNextFilename(); + doSetText(key->Testament(), key->Index(), tmpbuf); + entryBuf += tmpbuf; + } + datafile = FileMgr::getSystemFileMgr()->open(entryBuf, FileMgr::CREAT|FileMgr::WRONLY|FileMgr::TRUNC); + if (datafile->getFd() > 0) { + datafile->write(inbuf, len); + } + FileMgr::getSystemFileMgr()->close(datafile); + + if (key != this->key) + delete key; +} + + +/****************************************************************************** + * RawFiles::linkEntry(SWKey *)- Link the modules current key entry with + * another module entry + * + * RET: *this + */ + +void RawFiles::linkEntry(const SWKey *inkey) { + + long start; + unsigned short size; + const VerseKey *key = 0; + + SWTRY { + key = SWDYNAMIC_CAST(VerseKey, inkey); + } + SWCATCH ( ... ) {} + if (!key) + key = new VerseKey(this->key); + + findOffset(key->Testament(), key->Index(), &start, &size); + + if (size) { + SWBuf tmpbuf; + readText(key->Testament(), start, size + 2, tmpbuf); + + if (key != inkey) + delete key; + key = 0; + + SWTRY { + key = SWDYNAMIC_CAST(VerseKey, inkey); + } + SWCATCH ( ... ) {} + if (!key) + key = new VerseKey(this->key); + doSetText(key->Testament(), key->Index(), tmpbuf.c_str()); + } + + if (key != inkey) + delete key; +} + + +/****************************************************************************** + * RawFiles::deleteEntry - deletes this entry + * + * RET: *this + */ + +void RawFiles::deleteEntry() { + + VerseKey *key = 0; + + SWTRY { + key = SWDYNAMIC_CAST(VerseKey, this->key); + } + SWCATCH ( ... ) {} + if (!key) + key = new VerseKey(this->key); + + doSetText(key->Testament(), key->Index(), ""); + + if (key != this->key) + delete key; +} + + +/****************************************************************************** + * RawFiles::getNextfilename - generates a valid filename in which to store + * an entry + * + * RET: filename + */ + +char *RawFiles::getNextFilename() { + static char incfile[255]; + long number; + FileDesc *datafile; + + sprintf(incfile, "%s/incfile", path); + datafile = FileMgr::getSystemFileMgr()->open(incfile, FileMgr::RDONLY); + if (datafile->read(&number, 4) != 4) + number = 0; + number++; + FileMgr::getSystemFileMgr()->close(datafile); + + datafile = FileMgr::getSystemFileMgr()->open(incfile, FileMgr::CREAT|FileMgr::WRONLY|FileMgr::TRUNC); + datafile->write(&number, 4); + FileMgr::getSystemFileMgr()->close(datafile); + sprintf(incfile, "%.7ld", number-1); + return incfile; +} + + +char RawFiles::createModule (const char *path) { + char *incfile = new char [ strlen (path) + 16 ]; + static long zero = 0; + FileDesc *datafile; + + sprintf(incfile, "%s/incfile", path); + datafile = FileMgr::getSystemFileMgr()->open(incfile, FileMgr::CREAT|FileMgr::WRONLY|FileMgr::TRUNC); + delete [] incfile; + datafile->write(&zero, 4); + FileMgr::getSystemFileMgr()->close(datafile); + + return RawVerse::createModule (path); +} + + + +SWORD_NAMESPACE_END diff --git a/src/modules/comments/swcom.cpp b/src/modules/comments/swcom.cpp new file mode 100644 index 0000000..94f92c9 --- /dev/null +++ b/src/modules/comments/swcom.cpp @@ -0,0 +1,105 @@ +/****************************************************************************** + * swcom.cpp - code for base class 'SWCom'- The basis for all commentary + * modules + */ + +#include <swcom.h> +#include <localemgr.h> +#include <versekey.h> + +SWORD_NAMESPACE_START + +/****************************************************************************** + * SWCom Constructor - Initializes data for instance of SWCom + * + * ENT: imodname - Internal name for module + * imoddesc - Name to display to user for module + * idisp - Display object to use for displaying + */ + +SWCom::SWCom(const char *imodname, const char *imoddesc, SWDisplay *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, const char* ilang): SWModule(imodname, imoddesc, idisp, (char *)"Commentaries", enc, dir, mark, ilang) { + delete key; + key = CreateKey(); + tmpVK = new VerseKey(); +} + + +/****************************************************************************** + * SWCom Destructor - Cleans up instance of SWCom + */ + +SWCom::~SWCom() { + delete tmpVK; +} + + +SWKey *SWCom::CreateKey() { return new VerseKey(); } + + +long SWCom::Index() const { + VerseKey *key = 0; + SWTRY { + key = SWDYNAMIC_CAST(VerseKey, this->key); + } + SWCATCH ( ... ) {} + if (!key) + key = new VerseKey(this->key); + + entryIndex = key->NewIndex(); + + if (key != this->key) + delete key; + + return entryIndex; +} + +long SWCom::Index(long iindex) { + VerseKey *key = 0; + SWTRY { + key = SWDYNAMIC_CAST(VerseKey, this->key); + } + SWCATCH ( ... ) {} + if (!key) + key = new VerseKey(this->key); + + key->Testament(1); + key->Index(iindex); + + if (key != this->key) { + this->key->copyFrom(*key); + delete key; + } + + return Index(); +} + + +VerseKey &SWCom::getVerseKey() const { + VerseKey *key = NULL; + // see if we have a VerseKey * or decendant + SWTRY { + key = SWDYNAMIC_CAST(VerseKey, this->key); + } + SWCATCH ( ... ) { } + if (!key) { + ListKey *lkTest = 0; + SWTRY { + lkTest = SWDYNAMIC_CAST(ListKey, this->key); + } + SWCATCH ( ... ) { } + if (lkTest) { + SWTRY { + key = SWDYNAMIC_CAST(VerseKey, lkTest->GetElement()); + } + SWCATCH ( ... ) { } + } + } + if (!key) { + tmpVK->setLocale(LocaleMgr::getSystemLocaleMgr()->getDefaultLocaleName()); + (*tmpVK) = *(this->key); + return (*tmpVK); + } + else return *key; +} + +SWORD_NAMESPACE_END diff --git a/src/modules/comments/zcom/Makefile b/src/modules/comments/zcom/Makefile new file mode 100644 index 0000000..35d6648 --- /dev/null +++ b/src/modules/comments/zcom/Makefile @@ -0,0 +1,5 @@ + +root := ../../../.. + +all: + make -C ${root} diff --git a/src/modules/comments/zcom/Makefile.am b/src/modules/comments/zcom/Makefile.am new file mode 100644 index 0000000..f22700c --- /dev/null +++ b/src/modules/comments/zcom/Makefile.am @@ -0,0 +1,2 @@ +zcomdir = $(top_srcdir)/src/modules/comments/zcom +libsword_la_SOURCES += $(zcomdir)/zcom.cpp diff --git a/src/modules/comments/zcom/zcom.cpp b/src/modules/comments/zcom/zcom.cpp new file mode 100644 index 0000000..cdaea02 --- /dev/null +++ b/src/modules/comments/zcom/zcom.cpp @@ -0,0 +1,188 @@ +/****************************************************************************** + * rawcom.cpp - code for class 'zCom'- a module that reads raw commentary + * files: ot and nt using indexs ??.bks ??.cps ??.vss + */ + + +#include <ctype.h> +#include <stdio.h> +#include <fcntl.h> + +#include <zverse.h> +#include <versekey.h> +#include <zcom.h> +#include <filemgr.h> + +SWORD_NAMESPACE_START + +/****************************************************************************** + * zCom Constructor - Initializes data for instance of zCom + * + * ENT: ipath - path to data files + * iname - Internal name for module + * idesc - Name to display to user for module + * iblockType - verse, chapter, book, etc. of index chunks + * icomp - Compressor object + * 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()*/ +{ + blockType = iblockType; + lastWriteKey = 0; +} + +/****************************************************************************** + * zCom Destructor - Cleans up instance of zCom + */ + +zCom::~zCom() { + flushCache(); + + if (lastWriteKey) + delete lastWriteKey; +} + + +bool zCom::isWritable() { + return ((idxfp[0]->getFd() > 0) && ((idxfp[0]->mode & FileMgr::RDWR) == FileMgr::RDWR)); +} + + +/****************************************************************************** + * zCom::getRawEntry - Returns the correct verse when char * cast + * is requested + * + * RET: string buffer with verse + */ +SWBuf &zCom::getRawEntryBuf() { + long start = 0; + unsigned short size = 0; + VerseKey *key = &getVerseKey(); + + findOffset(key->Testament(), key->Index(), &start, &size); + entrySize = size; // support getEntrySize call + + entryBuf = ""; + zReadText(key->Testament(), start, size, entryBuf); + + rawFilter(entryBuf, key); + +// if (!isUnicode()) + prepText(entryBuf); + + return entryBuf; +} + + +bool zCom::sameBlock(VerseKey *k1, VerseKey *k2) { + if (k1->Testament() != k2->Testament()) + return false; + + switch (blockType) { + case VERSEBLOCKS: + if (k1->Verse() != k2->Verse()) + return false; + case CHAPTERBLOCKS: + if (k1->Chapter() != k2->Chapter()) + return false; + case BOOKBLOCKS: + if (k1->Book() != k2->Book()) + return false; + } + return true; +} + +void zCom::setEntry(const char *inbuf, long len) { + VerseKey *key = &getVerseKey(); + + // see if we've jumped across blocks since last write + if (lastWriteKey) { + if (!sameBlock(lastWriteKey, key)) { + flushCache(); + } + delete lastWriteKey; + } + + doSetText(key->Testament(), key->Index(), inbuf, len); + + lastWriteKey = (VerseKey *)key->clone(); // must delete +} + + +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); + + doLinkEntry(destkey->Testament(), destkey->Index(), srckey->Index()); + + if (inkey != srckey) // free our key if we created a VerseKey + delete srckey; +} + +/****************************************************************************** + * zCom::deleteEntry - deletes this entry + * + * RET: *this + */ + +void zCom::deleteEntry() { + + VerseKey *key = &getVerseKey(); + doSetText(key->Testament(), key->Index(), ""); +} + + +/****************************************************************************** + * zCom::increment - Increments module key a number of entries + * + * ENT: increment - Number of entries to jump forward + * + * RET: *this + */ + +void zCom::increment(int steps) { + long start; + unsigned short size; + VerseKey *tmpkey = &getVerseKey(); + + findOffset(tmpkey->Testament(), tmpkey->Index(), &start, &size); + + SWKey lastgood = *tmpkey; + while (steps) { + long laststart = start; + unsigned short lastsize = size; + SWKey lasttry = *tmpkey; + (steps > 0) ? (*key)++ : (*key)--; + tmpkey = &getVerseKey(); + + if ((error = key->Error())) { + *key = lastgood; + break; + } + long index = tmpkey->Index(); + findOffset(tmpkey->Testament(), index, &start, &size); + if ( + (((laststart != start) || (lastsize != size)) // we're a different entry +// && (start > 0) + && (size)) // and we actually have a size + ||(!skipConsecutiveLinks)) { // or we don't want to skip consecutive links + steps += (steps < 0) ? 1 : -1; + lastgood = *tmpkey; + } + } + error = (error) ? KEYERR_OUTOFBOUNDS : 0; +} + + +SWORD_NAMESPACE_END |