summaryrefslogtreecommitdiff
path: root/src/modules/comments
diff options
context:
space:
mode:
authorRoberto C. Sanchez <roberto@connexer.com>2014-03-29 10:53:33 -0400
committerRoberto C. Sanchez <roberto@connexer.com>2014-03-29 10:53:33 -0400
commit8d3fc864d094eeadc721f8e93436b37a5fab173e (patch)
tree05e201c67dca55b4ccdf90ad479a25d95e3b1e63 /src/modules/comments
Imported Upstream version 1.5.3
Diffstat (limited to 'src/modules/comments')
-rw-r--r--src/modules/comments/Makefile5
-rw-r--r--src/modules/comments/Makefile.am8
-rw-r--r--src/modules/comments/hrefcom/Makefile5
-rw-r--r--src/modules/comments/hrefcom/Makefile.am4
-rw-r--r--src/modules/comments/hrefcom/hrefcom.cpp97
-rw-r--r--src/modules/comments/hrefcom/jfbgen.cpp242
-rw-r--r--src/modules/comments/rawcom/Makefile5
-rw-r--r--src/modules/comments/rawcom/Makefile.am4
-rw-r--r--src/modules/comments/rawcom/mhcidx.cpp292
-rw-r--r--src/modules/comments/rawcom/rawcom.cpp275
-rw-r--r--src/modules/comments/rawcom/rtfidx.cpp292
-rw-r--r--src/modules/comments/rawcom/rwpidx.cpp266
-rw-r--r--src/modules/comments/rawfiles/Makefile5
-rw-r--r--src/modules/comments/rawfiles/Makefile.am3
-rw-r--r--src/modules/comments/rawfiles/rawfiles.cpp291
-rw-r--r--src/modules/comments/rawfiles/rawfilesgen.cpp236
-rw-r--r--src/modules/comments/swcom.cpp30
-rw-r--r--src/modules/comments/zcom/Makefile5
-rw-r--r--src/modules/comments/zcom/Makefile.am4
-rw-r--r--src/modules/comments/zcom/makeidx.c146
-rw-r--r--src/modules/comments/zcom/rawtxt2z.cpp83
-rw-r--r--src/modules/comments/zcom/zcom.cpp290
22 files changed, 2588 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..1568544
--- /dev/null
+++ b/src/modules/comments/Makefile.am
@@ -0,0 +1,8 @@
+commentsdir = $(top_srcdir)/src/modules/comments
+
+libsword_la_SOURCES += $(commentsdir)/swcom.cpp
+
+include ../src/modules/comments/rawcom/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..a6a2115
--- /dev/null
+++ b/src/modules/comments/hrefcom/Makefile.am
@@ -0,0 +1,4 @@
+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..a80e5b6
--- /dev/null
+++ b/src/modules/comments/hrefcom/hrefcom.cpp
@@ -0,0 +1,97 @@
+/******************************************************************************
+ * 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>
+
+#ifndef __GNUC__
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#include <string.h>
+#include <utilfuns.h>
+#include <rawverse.h>
+#include <hrefcom.h>
+
+
+ /******************************************************************************
+ * 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
+ */
+
+char *HREFCom::getRawEntry() {
+ long start;
+ unsigned short size;
+ char *tmpbuf;
+ VerseKey *key = 0;
+
+#ifndef _WIN32_WCE
+ try {
+#endif
+ key = SWDYNAMIC_CAST(VerseKey, this->key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ if (!key)
+ key = new VerseKey(this->key);
+
+ findoffset(key->Testament(), key->Index(), &start, &size);
+ entrySize = size; // support getEntrySize call
+
+ unsigned long newsize = ((size + 2) + strlen(prefix)) * FILTERPAD;
+ if (newsize > entrybufallocsize) {
+ if (entrybuf)
+ delete [] entrybuf;
+ entrybuf = new char [ newsize ];
+ entrybufallocsize = newsize;
+ }
+ tmpbuf = new char [ size + 10 ];
+
+ gettext(key->Testament(), start, size + 2, tmpbuf);
+ sprintf(entrybuf, "%s%s", prefix, tmpbuf);
+ preptext(entrybuf);
+
+ delete [] tmpbuf;
+
+ if (key != this->key)
+ delete key;
+
+ return entrybuf;
+}
diff --git a/src/modules/comments/hrefcom/jfbgen.cpp b/src/modules/comments/hrefcom/jfbgen.cpp
new file mode 100644
index 0000000..8b66a60
--- /dev/null
+++ b/src/modules/comments/hrefcom/jfbgen.cpp
@@ -0,0 +1,242 @@
+/*****************************************************************************
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#ifndef __GNUC__
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#include <fcntl.h>
+#include <versekey.h>
+
+#ifndef O_BINARY
+ #define O_BINARY 0
+#endif
+
+void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size);
+char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size);
+void openfiles();
+void checkparams(int argc, char **argv);
+void charsetconvert(char *data);
+
+
+VerseKey key1, key2, key3;
+int fp, vfp, cfp, bfp;
+long chapoffset;
+short chapsize;
+char testmnt;
+char startflag = 0;
+
+
+main(int argc, char **argv)
+{
+ long pos, offset;
+ int num1, num2, rangemax, curbook = 0, curchap = 0, curverse = 0;
+ char buf[127];
+ short size, tmp;
+ extern struct zonline online;
+
+ checkparams(argc, argv);
+
+ key1 = key2 = key3 = "Genesis 1:1";
+
+ openfiles();
+
+ num1 = key1.Chapter();
+ num2 = key1.Verse();
+
+ while(!findbreak(fp, &offset, &num1, &num2, &rangemax, &size)) {
+ if (!startflag) {
+ startflag = 1;
+ }
+ else {
+ if (num2 < key2.Verse()) { // new chapter
+ if (num1 <= key2.Chapter()) { // new book
+ key2.Verse(1);
+ key2.Chapter(1);
+ key2.Book(key2.Book()+1);
+ }
+ printf("Found Chapter Break: %d ('%s')\n", num1, (const char *)key2);
+ chapoffset = offset;
+ chapsize = size;
+// continue;
+ }
+ }
+ key2.Verse(1);
+ key2.Chapter(num1);
+ key2.Verse(num2);
+
+ key3 = key2;
+// key3 += (rangemax - key3.Verse());
+
+ writeidx(key1, key2, key3, offset, size);
+ }
+ close(vfp);
+ close(cfp);
+ close(bfp);
+ close(fp);
+}
+
+
+/**************************************************************************
+ * ENT: key1 - current location of index
+ * key2 - minimum keyval for which this offset is valid
+ * key3 - maximum keyval for which this offset is valid
+ */
+
+void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size)
+{
+ long pos;
+ short tmp;
+
+ if (key1.Verse() == 1) { // new chapter
+ if (key1.Chapter() == 1) { // new book
+ pos = lseek(cfp, 0, SEEK_CUR);
+ write(bfp, &pos, 4);
+ pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */
+ write(cfp, &pos, 4);
+ write(vfp, &chapoffset, 4); /* Book intro (vss) set to same as chap for now(it should be chap 1 which usually contains the book into anyway)*/
+ write(vfp, &chapsize, 2);
+ }
+ pos = lseek(vfp, 0, SEEK_CUR);
+ write(cfp, &pos, 4);
+ write(vfp, &chapoffset, 4); /* Chapter intro */
+ write(vfp, &chapsize, 2);
+ }
+ if (key1 >= key2) {
+ write(vfp, &offset, 4);
+ write(vfp, &size, 2);
+ }
+ else {
+ pos = 0;
+ tmp = 0;
+ write(vfp, &pos, 4);
+ write(vfp, &tmp, 2);
+ }
+ key1++;
+}
+
+
+static VerseKey inckey = "Genesis 1:1";
+
+char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size)
+{
+ char buf[7];
+ char buf2[20];
+ char ch;
+ char loop;
+ long offset2;
+ int ch2, vs2, rm2;
+ bool flag;
+ long chapstart = 0;
+ static int olbvnum = 0;
+ char data[256];
+ char *bookabrev[66] = {"Ge", "Ex", "Le", "Nu", "De", "Jos", "Jud", "Ru",
+ "1Sa", "2Sa", "1Ki", "2Ki", "1Ch", "2Ch", "Ezr", "Ne", "Es",
+ "Job", "Ps", "Pr", "Ec", "So", "Isa", "Jer", "La", "Eze", "Da",
+ "Ho", "Joe", "Am", "Ob", "Jon", "Mic", "Na", "Heb", "Zep",
+ "Hag", "Zec", "Mal",
+ "Mt", "Mr", "Lu", "Joh", "Ac", "Ro", "1Co", "2Co", "Ga",
+ "Eph", "Php", "Col", "1Th", "2Th", "1Ti", "2Ti", "Tit", "Phm",
+ "Heb", "Jas", "1Pe", "2Pe", "1Jo", "2Jo", "3Jo", "Jude", "Re" };
+
+ if (++olbvnum <= 31102) {
+
+ if (olbvnum == 23146) { // "Matthew 1:1"
+ close(vfp);
+ close(cfp);
+ close(bfp);
+ close(fp);
+ key1 = key2 = key3 = inckey = "Matthew 1:1";
+ openfiles();
+ startflag = 0;
+ }
+
+
+ *offset = lseek(fp, 0, SEEK_CUR);
+
+ if ((olbvnum!=1) && (olbvnum != 23146))
+ inckey++;
+
+ *num1 = inckey.Chapter();
+ *num2 = inckey.Verse();
+
+ sprintf(data, "JFB%.2d.htm#%s%d_%d", inckey.Book() + ((inckey.Testament()>1)?39:0), bookabrev[inckey.Book() + ((inckey.Testament()>1)?39:0)-1], inckey.Chapter(), inckey.Verse());
+ write(fp, data, strlen(data));
+
+ *size = lseek(fp, 0, SEEK_CUR) - *offset;
+ write(fp, "\n", 1);
+ return 0;
+ }
+ return 1;
+}
+
+
+void openfiles()
+{
+ char buf[255];
+ char fname[5];
+ long pos;
+ short size;
+
+ testmnt = key1.Testament();
+
+ strcpy(fname, (testmnt==2) ? "nt" : "ot");
+ unlink(fname);
+ if ((fp = open(fname, O_CREAT|O_RDWR|O_BINARY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", fname);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.vss", fname);
+ unlink(buf);
+ if ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.cps", fname);
+ unlink(buf);
+ if ((cfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.bks", fname);
+ unlink(buf);
+ if ((bfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+
+ pos = 0;
+ write(bfp, &pos, 4); /* Book offset for testament intros */
+ pos = 4;
+ write(cfp, &pos, 4); /* Chapter offset for testament intro */
+
+
+/* Right now just zero out intros until parsing correctly */
+ pos = 0;
+ size = 0;
+ write(vfp, &pos, 4); /* Module intro */
+ write(vfp, &size, 2);
+ write(vfp, &pos, 4); /* Testament intro */
+ write(vfp, &size, 2);
+
+}
+
+
+void checkparams(int argc, char **argv)
+{
+ if (argc !=1) {
+ fprintf(stderr, "usage: %s\n", argv[0]);
+ exit(1);
+ }
+}
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..901cf6b
--- /dev/null
+++ b/src/modules/comments/rawcom/Makefile.am
@@ -0,0 +1,4 @@
+rawcomdir = $(top_srcdir)/src/modules/comments/rawcom
+
+libsword_la_SOURCES += $(rawcomdir)/rawcom.cpp
+
diff --git a/src/modules/comments/rawcom/mhcidx.cpp b/src/modules/comments/rawcom/mhcidx.cpp
new file mode 100644
index 0000000..df16f55
--- /dev/null
+++ b/src/modules/comments/rawcom/mhcidx.cpp
@@ -0,0 +1,292 @@
+/*****************************************************************************
+ *
+ * This code wreaks but works (at least for MHC). Good luck!
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#ifndef __GNUC__
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#include <fcntl.h>
+#include <versekey.h>
+
+
+void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size);
+char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size);
+void openfiles(char *fname);
+void checkparams(int argc, char **argv);
+
+
+VerseKey key1, key2, key3;
+int fp, vfp, cfp, bfp;
+long chapoffset;
+short chapsize;
+char testmnt;
+
+
+main(int argc, char **argv)
+{
+ long pos, offset;
+ int num1, num2, rangemax, curbook = 0, curchap = 0, curverse = 0;
+ char buf[127], startflag = 0;
+ short size, tmp;
+
+ checkparams(argc, argv);
+
+ openfiles(argv[1]);
+
+ testmnt = key1.Testament();
+ pos = 0;
+ write(bfp, &pos, 4); /* Book offset for testament intros */
+ pos = 4;
+ write(cfp, &pos, 4); /* Chapter offset for testament intro */
+
+
+/* Right now just zero out intros until parsing correctly */
+ pos = 0;
+ size = 0;
+ write(vfp, &pos, 4); /* Module intro */
+ write(vfp, &size, 2);
+ write(vfp, &pos, 4); /* Testament intro */
+ write(vfp, &size, 2);
+
+ while(!findbreak(fp, &offset, &num1, &num2, &rangemax, &size)) {
+ if (num2) {
+ key2.Verse(1);
+ key2.Chapter(num1);
+ key2.Verse(num2);
+ }
+ else {
+ key2.Verse(1);
+ if (!startflag) {
+ startflag = 1;
+ }
+ else {
+ if (num1 <= key2.Chapter()) { // new book
+ key2.Chapter(1);
+ key2.Book(key2.Book()+1);
+ }
+ }
+ key2.Chapter(num1);
+ printf("Found Chapter Break: %d ('%s')\n", num1, (const char *)key2);
+ chapoffset = offset;
+ chapsize = size;
+ continue;
+ }
+
+ key3 = key2;
+ key3 += (rangemax - key3.Verse());
+
+ writeidx(key1, key2, key3, offset, size);
+ }
+ close(vfp);
+ close(cfp);
+ close(bfp);
+ close(fp);
+}
+
+
+/**************************************************************************
+ * ENT: key1 - current location of index
+ * key2 - minimum keyval for which this offset is valid
+ * key3 - maximum keyval for which this offset is valid
+ */
+
+void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size)
+{
+ long pos;
+ short tmp;
+
+ for (; ((key1 <= key3) && (key1.Error() != KEYERR_OUTOFBOUNDS) && (key1.Testament() == testmnt)); key1+=1) {
+ if (key1.Verse() == 1) { // new chapter
+ if (key1.Chapter() == 1) { // new book
+ pos = lseek(cfp, 0, SEEK_CUR);
+ write(bfp, &pos, 4);
+ pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */
+ write(cfp, &pos, 4);
+ write(vfp, &chapoffset, 4); /* Book intro (vss) set to same as chap for now(it should be chap 1 which usually contains the book into anyway)*/
+ write(vfp, &chapsize, 2);
+ }
+ pos = lseek(vfp, 0, SEEK_CUR);
+ write(cfp, &pos, 4);
+ write(vfp, &chapoffset, 4); /* Chapter intro */
+ write(vfp, &chapsize, 2);
+ }
+ if (key1 >= key2) {
+ write(vfp, &offset, 4);
+ write(vfp, &size, 2);
+ }
+ else {
+ pos = 0;
+ tmp = 0;
+ write(vfp, &pos, 4);
+ write(vfp, &tmp, 2);
+ }
+ }
+}
+
+
+char startentry(char *buf)
+{
+ char loop;
+
+ if (buf[0] != 10)
+ return 0;
+ if (buf[1] != '#')
+ return 0;
+ if (!isdigit(buf[2]))
+ return 0;
+ for (loop = 3; loop < 7; loop++) {
+ if (buf[loop] == ' ')
+ break;
+ if ((!isdigit(buf[loop])) && (buf[loop] != ',') && (buf[loop] != '-'))
+ return 0;
+ }
+ return 1;
+}
+
+
+char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size)
+{
+ char buf[7];
+ char buf2[20];
+ char ch;
+ char loop;
+ long offset2;
+ int ch2, vs2, rm2;
+
+ memset(buf, ' ', 7);
+
+ while (1) {
+ if (startentry(buf)) {
+ memset(buf, ' ', 2);
+ for (loop = 2; loop < 7; loop++) {
+ if ((buf[loop] == '-') || (buf[loop] == ',') || (buf[loop] == ' ')) {
+ buf[loop] = 0;
+ *num2 = atoi(buf);
+ break;
+ }
+ }
+ for (ch = loop + 1; ch < 7; ch++) {
+ if (buf[ch] == ' ') {
+ break;
+ }
+ }
+ buf[ch] = 0;
+ *rangemax = atoi(&buf[loop+1]);
+ if (!*rangemax)
+ *rangemax = *num2;
+ *offset = lseek(fp, 0, SEEK_CUR) - 5;
+ if (size) {
+ if (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
+ *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
+ }
+ else {
+ if (vs2) {
+ *size = (offset2 - (*offset)) - 3;
+ }
+ else {
+ sprintf(buf2, "$-$-$- XX:%d", ch2);
+ *size = (offset2 - (*offset)) - ((strlen(buf2) + 4));
+ }
+ }
+ lseek(fp, *offset, SEEK_SET);
+ }
+ return 0;
+ }
+
+ if (!strncmp(buf, "$-$-$-", 6)) {
+ memset(buf2, 0, 7);
+ loop = 0;
+ while ((read(fp, &buf2[loop], 1) == 1) && (loop < 7)) {
+ if ((buf2[loop] == 10) || (buf2[loop] == 13)) {
+ buf2[loop] = 0;
+ break;
+ }
+ loop++;
+ }
+ while (read(fp, &ch, 1) == 1) {
+ if (ch == '*')
+ break;
+ }
+
+ *offset = lseek(fp, 0, SEEK_CUR) - 1;
+ *num2 = 0;
+ for (loop = strlen(buf2) - 1; loop; loop--) {
+ if (buf2[loop] == ':')
+ break;
+ }
+ *num1 = atoi(&buf2[loop+1]);
+ printf("Chapter marker: %s\n", buf2);
+ if (size) {
+ if (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
+ *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
+ }
+ else {
+ if (vs2) {
+ *size = (offset2 - (*offset)) - 3;
+ }
+ else {
+ sprintf(buf2, "$-$-$- XX:%d", ch2);
+ *size = (offset2 - (*offset)) - ((strlen(buf2) + 4));
+ }
+ }
+ lseek(fp, *offset, SEEK_SET);
+ }
+ return 0;
+ }
+
+
+ memmove(buf, &buf[1], 6);
+ if (read(fp, &buf[6], 1) != 1)
+ return 1;
+ }
+}
+
+
+void openfiles(char *fname)
+{
+ char buf[255];
+
+ if ((fp = open(fname, O_RDONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", fname);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.vss", fname);
+ if ((vfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.cps", fname);
+ if ((cfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.bks", fname);
+ if ((bfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+}
+
+
+void checkparams(int argc, char **argv)
+{
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s <file to process> [nt - for new testmt file]\n", argv[0]);
+ exit(1);
+ }
+ if (argc == 3)
+ key1 = key2 = key3 = "Matthew 1:1";
+ else key1 = key2 = key3 = "Genesis 1:1";
+}
diff --git a/src/modules/comments/rawcom/rawcom.cpp b/src/modules/comments/rawcom/rawcom.cpp
new file mode 100644
index 0000000..ca93c64
--- /dev/null
+++ b/src/modules/comments/rawcom/rawcom.cpp
@@ -0,0 +1,275 @@
+/******************************************************************************
+ * 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>
+
+#ifndef __GNUC__
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#include <string.h>
+#include <utilfuns.h>
+#include <rawverse.h>
+#include <rawcom.h>
+
+
+ /******************************************************************************
+ * 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()
+{
+}
+
+
+/******************************************************************************
+ * RawCom::operator char * - Returns the correct verse when char * cast
+ * is requested
+ *
+ * RET: string buffer with verse
+ */
+
+char *RawCom::getRawEntry() {
+ long start = 0;
+ unsigned short size = 0;
+ VerseKey *key = 0;
+
+#ifndef _WIN32_WCE
+ try {
+#endif
+ key = SWDYNAMIC_CAST(VerseKey, this->key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ if (!key)
+ key = new VerseKey(this->key);
+
+
+ findoffset(key->Testament(), key->Index(), &start, &size);
+ entrySize = size; // support getEntrySize call
+
+ unsigned long newsize = (size + 2) * FILTERPAD;
+ if (newsize > entrybufallocsize) {
+ if (entrybuf)
+ delete [] entrybuf;
+ entrybuf = new char [ newsize ];
+ entrybufallocsize = newsize;
+ }
+ *entrybuf = 0;
+
+ gettext(key->Testament(), start, (size + 2), entrybuf);
+
+ rawFilter(entrybuf, size, key);
+
+ if (!isUnicode())
+ preptext(entrybuf);
+
+ if (key != this->key)
+ delete key;
+
+ return entrybuf;
+}
+
+
+/******************************************************************************
+ * RawCom::operator += - Increments module key a number of entries
+ *
+ * ENT: increment - Number of entries to jump forward
+ *
+ * RET: *this
+ */
+
+SWModule &RawCom::operator +=(int increment)
+{
+ long start;
+ unsigned short size;
+ VerseKey *tmpkey = 0;
+
+#ifndef _WIN32_WCE
+ try {
+#endif
+ tmpkey = SWDYNAMIC_CAST(VerseKey, key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ if (!tmpkey)
+ tmpkey = new VerseKey(key);
+
+ findoffset(tmpkey->Testament(), tmpkey->Index(), &start, &size);
+
+ SWKey lastgood = *tmpkey;
+ while (increment) {
+ long laststart = start;
+ unsigned short lastsize = size;
+ SWKey lasttry = *tmpkey;
+ (increment > 0) ? (*key)++ : (*key)--;
+ if (tmpkey != key)
+ delete tmpkey;
+ tmpkey = 0;
+#ifndef _WIN32_WCE
+ try {
+#endif
+ tmpkey = SWDYNAMIC_CAST(VerseKey, key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ if (!tmpkey)
+ tmpkey = new VerseKey(key);
+
+ if ((error = key->Error())) {
+ *key = lastgood;
+ break;
+ }
+ long index = tmpkey->Index();
+ findoffset(tmpkey->Testament(), index, &start, &size);
+ if ((((laststart != start) || (lastsize != size))||(!skipConsecutiveLinks)) && (start >= 0) && (size)) {
+ increment += (increment < 0) ? 1 : -1;
+ lastgood = *tmpkey;
+ }
+ }
+ error = (error) ? KEYERR_OUTOFBOUNDS : 0;
+
+ if (tmpkey != key)
+ delete tmpkey;
+
+ return *this;
+}
+
+SWModule &RawCom::setentry(const char *inbuf, long len) {
+ VerseKey *key = 0;
+ // see if we have a VerseKey * or decendant
+#ifndef _WIN32_WCE
+ try {
+#endif
+ key = SWDYNAMIC_CAST(VerseKey, this->key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ // if we don't have a VerseKey * decendant, create our own
+ if (!key)
+ key = new VerseKey(this->key);
+
+ settext(key->Testament(), key->Index(), inbuf, len);
+
+ if (this->key != key) // free our key if we created a VerseKey
+ delete key;
+
+ return *this;
+}
+
+SWModule &RawCom::operator <<(const char *inbuf) {
+ VerseKey *key = 0;
+ // see if we have a VerseKey * or decendant
+#ifndef _WIN32_WCE
+ try {
+#endif
+ key = SWDYNAMIC_CAST(VerseKey, this->key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ // if we don't have a VerseKey * decendant, create our own
+ if (!key)
+ key = new VerseKey(this->key);
+
+ settext(key->Testament(), key->Index(), inbuf);
+
+ if (this->key != key) // free our key if we created a VerseKey
+ delete key;
+
+ return *this;
+}
+
+
+SWModule &RawCom::operator <<(const SWKey *inkey) {
+ VerseKey *destkey = 0;
+ const VerseKey *srckey = 0;
+ // see if we have a VerseKey * or decendant
+#ifndef _WIN32_WCE
+ try {
+#endif
+ destkey = SWDYNAMIC_CAST(VerseKey, this->key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ // if we don't have a VerseKey * decendant, create our own
+ if (!destkey)
+ destkey = new VerseKey(this->key);
+
+ // see if we have a VerseKey * or decendant
+#ifndef _WIN32_WCE
+ try {
+#endif
+ srckey = SWDYNAMIC_CAST(VerseKey, inkey);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ // if we don't have a VerseKey * decendant, create our own
+ if (!srckey)
+ srckey = new VerseKey(inkey);
+
+ linkentry(destkey->Testament(), destkey->Index(), srckey->Index());
+
+ if (this->key != destkey) // free our key if we created a VerseKey
+ delete destkey;
+
+ if (inkey != srckey) // free our key if we created a VerseKey
+ delete srckey;
+
+ return *this;
+}
+
+
+/******************************************************************************
+ * RawCom::deleteEntry - deletes this entry
+ *
+ * RET: *this
+ */
+
+void RawCom::deleteEntry() {
+
+ VerseKey *key = 0;
+
+#ifndef _WIN32_WCE
+ try {
+#endif
+ key = SWDYNAMIC_CAST(VerseKey, this->key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ if (!key)
+ key = new VerseKey(this->key);
+
+ settext(key->Testament(), key->Index(), "");
+
+ if (key != this->key)
+ delete key;
+}
diff --git a/src/modules/comments/rawcom/rtfidx.cpp b/src/modules/comments/rawcom/rtfidx.cpp
new file mode 100644
index 0000000..38b38bc
--- /dev/null
+++ b/src/modules/comments/rawcom/rtfidx.cpp
@@ -0,0 +1,292 @@
+/*****************************************************************************
+ *
+ * This code wreaks but works (at least for MHC). Good luck!
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#ifndef __GNUC__
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#include <fcntl.h>
+#include <versekey.h>
+
+
+void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size);
+char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size);
+void openfiles(char *fname);
+void checkparams(int argc, char **argv);
+
+
+VerseKey key1, key2, key3;
+int fp, vfp, cfp, bfp;
+long chapoffset;
+short chapsize;
+char testmnt;
+
+
+main(int argc, char **argv)
+{
+ long pos, offset;
+ int num1, num2, rangemax, curbook = 0, curchap = 0, curverse = 0;
+ char buf[127], startflag = 0;
+ short size, tmp;
+
+ checkparams(argc, argv);
+
+ openfiles(argv[1]);
+
+ testmnt = key1.Testament();
+ pos = 0;
+ write(bfp, &pos, 4); /* Book offset for testament intros */
+ pos = 4;
+ write(cfp, &pos, 4); /* Chapter offset for testament intro */
+
+
+/* Right now just zero out intros until parsing correctly */
+ pos = 0;
+ size = 0;
+ write(vfp, &pos, 4); /* Module intro */
+ write(vfp, &size, 2);
+ write(vfp, &pos, 4); /* Testament intro */
+ write(vfp, &size, 2);
+
+ while(!findbreak(fp, &offset, &num1, &num2, &rangemax, &size)) {
+ if (num2) {
+ key2.Verse(1);
+ key2.Chapter(num1);
+ key2.Verse(num2);
+ }
+ else {
+ key2.Verse(1);
+ if (!startflag) {
+ startflag = 1;
+ }
+ else {
+ if (num1 <= key2.Chapter()) { // new book
+ key2.Chapter(1);
+ key2.Book(key2.Book()+1);
+ }
+ }
+ key2.Chapter(num1);
+ printf("Found Chapter Break: %d ('%s')\n", num1, (char *)key2);
+ chapoffset = offset;
+ chapsize = size;
+ continue;
+ }
+
+ key3 = key2;
+ key3 += (rangemax - key3.Verse());
+
+ writeidx(key1, key2, key3, offset, size);
+ }
+ close(vfp);
+ close(cfp);
+ close(bfp);
+ close(fp);
+}
+
+
+/**************************************************************************
+ * ENT: key1 - current location of index
+ * key2 - minimum keyval for which this offset is valid
+ * key3 - maximum keyval for which this offset is valid
+ */
+
+void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size)
+{
+ long pos;
+ short tmp;
+
+ for (; ((key1 <= key3) && (key1.Error() != KEYERR_OUTOFBOUNDS) && (key1.Testament() == testmnt)); key1+=1) {
+ if (key1.Verse() == 1) { // new chapter
+ if (key1.Chapter() == 1) { // new book
+ pos = lseek(cfp, 0, SEEK_CUR);
+ write(bfp, &pos, 4);
+ pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */
+ write(cfp, &pos, 4);
+ write(vfp, &chapoffset, 4); /* Book intro (vss) set to same as chap for now(it should be chap 1 which usually contains the book into anyway)*/
+ write(vfp, &chapsize, 2);
+ }
+ pos = lseek(vfp, 0, SEEK_CUR);
+ write(cfp, &pos, 4);
+ write(vfp, &chapoffset, 4); /* Chapter intro */
+ write(vfp, &chapsize, 2);
+ }
+ if (key1 >= key2) {
+ write(vfp, &offset, 4);
+ write(vfp, &size, 2);
+ }
+ else {
+ pos = 0;
+ tmp = 0;
+ write(vfp, &pos, 4);
+ write(vfp, &tmp, 2);
+ }
+ }
+}
+
+
+char startentry(char *buf)
+{
+ char loop;
+
+ if (buf[0] != 10)
+ return 0;
+ if (buf[1] != '#')
+ return 0;
+ if (!isdigit(buf[2]))
+ return 0;
+ for (loop = 3; loop < 7; loop++) {
+ if (buf[loop] == ' ')
+ break;
+ if ((!isdigit(buf[loop])) && (buf[loop] != ',') && (buf[loop] != '-'))
+ return 0;
+ }
+ return 1;
+}
+
+
+char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size)
+{
+ char buf[7];
+ char buf2[20];
+ char ch;
+ char loop;
+ long offset2;
+ int ch2, vs2, rm2;
+
+ memset(buf, ' ', 7);
+
+ while (1) {
+ if (startentry(buf)) {
+ memset(buf, ' ', 2);
+ for (loop = 2; loop < 7; loop++) {
+ if ((buf[loop] == '-') || (buf[loop] == ',') || (buf[loop] == ' ')) {
+ buf[loop] = 0;
+ *num2 = atoi(buf);
+ break;
+ }
+ }
+ for (ch = loop + 1; ch < 7; ch++) {
+ if (buf[ch] == ' ') {
+ break;
+ }
+ }
+ buf[ch] = 0;
+ *rangemax = atoi(&buf[loop+1]);
+ if (!*rangemax)
+ *rangemax = *num2;
+ *offset = lseek(fp, 0, SEEK_CUR) - 5;
+ if (size) {
+ if (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
+ *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
+ }
+ else {
+ if (vs2) {
+ *size = (offset2 - (*offset)) - 3;
+ }
+ else {
+ sprintf(buf2, "$-$-$- XX:%d", ch2);
+ *size = (offset2 - (*offset)) - ((strlen(buf2) + 4));
+ }
+ }
+ lseek(fp, *offset, SEEK_SET);
+ }
+ return 0;
+ }
+
+ if (!strncmp(buf, "$-$-$-", 6)) {
+ memset(buf2, 0, 7);
+ loop = 0;
+ while ((read(fp, &buf2[loop], 1) == 1) && (loop < 7)) {
+ if ((buf2[loop] == 10) || (buf2[loop] == 13)) {
+ buf2[loop] = 0;
+ break;
+ }
+ loop++;
+ }
+ while (read(fp, &ch, 1) == 1) {
+ if (ch == '*')
+ break;
+ }
+
+ *offset = lseek(fp, 0, SEEK_CUR) - 1;
+ *num2 = 0;
+ for (loop = strlen(buf2) - 1; loop; loop--) {
+ if (buf2[loop] == ':')
+ break;
+ }
+ *num1 = atoi(&buf2[loop+1]);
+ printf("Chapter marker: %s\n", buf2);
+ if (size) {
+ if (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
+ *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
+ }
+ else {
+ if (vs2) {
+ *size = (offset2 - (*offset)) - 3;
+ }
+ else {
+ sprintf(buf2, "$-$-$- XX:%d", ch2);
+ *size = (offset2 - (*offset)) - ((strlen(buf2) + 4));
+ }
+ }
+ lseek(fp, *offset, SEEK_SET);
+ }
+ return 0;
+ }
+
+
+ memmove(buf, &buf[1], 6);
+ if (read(fp, &buf[6], 1) != 1)
+ return 1;
+ }
+}
+
+
+void openfiles(char *fname)
+{
+ char buf[255];
+
+ if ((fp = open(fname, O_RDONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", fname);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.vss", fname);
+ if ((vfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.cps", fname);
+ if ((cfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.bks", fname);
+ if ((bfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+}
+
+
+void checkparams(int argc, char **argv)
+{
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s <file to process> [nt - for new testmt file]\n", argv[0]);
+ exit(1);
+ }
+ if (argc == 3)
+ key1 = key2 = key3 = "Matthew 1:1";
+ else key1 = key2 = key3 = "Genesis 1:1";
+}
diff --git a/src/modules/comments/rawcom/rwpidx.cpp b/src/modules/comments/rawcom/rwpidx.cpp
new file mode 100644
index 0000000..afcbd81
--- /dev/null
+++ b/src/modules/comments/rawcom/rwpidx.cpp
@@ -0,0 +1,266 @@
+/*****************************************************************************
+ *
+ * This code wreaks but works (at least for RWP). Good luck!
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#ifndef __GNUC__
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#include <fcntl.h>
+#include <versekey.h>
+
+
+void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size);
+char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size);
+void openfiles(char *fname);
+void checkparams(int argc, char **argv);
+
+
+VerseKey key1, key2, key3;
+int fp, vfp, cfp, bfp;
+long chapoffset;
+short chapsize;
+char testmnt;
+
+
+main(int argc, char **argv)
+{
+ long pos, offset;
+ int num1 = 0, num2 = 0, rangemax, curbook = 0, curchap = 0, curverse = 0;
+ char buf[127], startflag = 0;
+ short size, tmp;
+
+ checkparams(argc, argv);
+
+ openfiles(argv[1]);
+
+ testmnt = key1.Testament();
+ pos = 0;
+ write(bfp, &pos, 4); /* Book offset for testament intros */
+ pos = 4;
+ write(cfp, &pos, 4); /* Chapter offset for testament intro */
+
+
+/* Right now just zero out intros until parsing correctly */
+ pos = 0;
+ size = 0;
+ write(vfp, &pos, 4); /* Module intro */
+ write(vfp, &size, 2);
+ write(vfp, &pos, 4); /* Testament intro */
+ write(vfp, &size, 2);
+
+ while(!findbreak(fp, &offset, &num1, &num2, &rangemax, &size)) {
+ if (num2) {
+ key2.Verse(1);
+ key2.Chapter(num1);
+ key2.Verse(num2);
+ }
+ else {
+ key2.Verse(1);
+ if (!startflag) {
+ startflag = 1;
+ }
+ else {
+ if (num1 <= key2.Chapter()) { // new book
+ key2.Chapter(1);
+ key2.Book(key2.Book()+1);
+ }
+ }
+ key2.Chapter(num1);
+ printf("Found Chapter Break: %d ('%s')\n", num1, (const char *)key2);
+ chapoffset = offset;
+ chapsize = size;
+ continue;
+ }
+
+ key3 = key2;
+ key3 += (rangemax - key3.Verse());
+
+ printf("Found verse Break: ('%s')\n", (const char *)key2);
+ writeidx(key1, key2, key3, offset, size);
+ }
+ close(vfp);
+ close(cfp);
+ close(bfp);
+ close(fp);
+}
+
+
+/**************************************************************************
+ * ENT: key1 - current location of index
+ * key2 - minimum keyval for which this offset is valid
+ * key3 - maximum keyval for which this offset is valid
+ */
+
+void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size)
+{
+ long pos;
+ short tmp;
+
+ for (; ((key1 <= key3) && (key1.Error() != KEYERR_OUTOFBOUNDS) && (key1.Testament() == testmnt)); key1+=1) {
+ if (key1.Verse() == 1) { // new chapter
+ if (key1.Chapter() == 1) { // new book
+ pos = lseek(cfp, 0, SEEK_CUR);
+ write(bfp, &pos, 4);
+ pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */
+ write(cfp, &pos, 4);
+ write(vfp, &chapoffset, 4); /* Book intro (vss) set to same as chap for now(it should be chap 1 which usually contains the book into anyway)*/
+ write(vfp, &chapsize, 2);
+ }
+ pos = lseek(vfp, 0, SEEK_CUR);
+ write(cfp, &pos, 4);
+ write(vfp, &chapoffset, 4); /* Chapter intro */
+ write(vfp, &chapsize, 2);
+ }
+ if (key1 >= key2) {
+ write(vfp, &offset, 4);
+ write(vfp, &size, 2);
+ }
+ else {
+ pos = 0;
+ tmp = 0;
+ write(vfp, &pos, 4);
+ write(vfp, &tmp, 2);
+ }
+ }
+}
+
+
+char startentry(char *buf)
+{
+ char colon = 0;
+
+ if (buf[0] != 10)
+ return 0;
+ if (buf[1] != 10)
+ return 0;
+ if (!isdigit(buf[2]))
+ return 0;
+ if (!isdigit(buf[3])) {
+ if (buf[3]!= ':')
+ return 0;
+ else colon++;
+ }
+ if (!isdigit(buf[4])) {
+ if (buf[4]!= ':')
+ return 0;
+ else colon++;
+ }
+ if (colon != 1)
+ return 0;
+ return 1;
+}
+
+
+char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size)
+{
+ char buf[7];
+ char buf2[20];
+ char ch;
+ char loop;
+ long offset2;
+ int ch2, vs2, rm2;
+
+ memset(buf, ' ', 7);
+
+ while (1) {
+ if (startentry(buf)) {
+ buf[0] = ' ';
+ buf[1] = ' ';
+ sscanf(buf, "%d:%d", num1, num2);
+ *rangemax = *num2;
+ *offset = lseek(fp, 0, SEEK_CUR) - 5;
+ if (size) {
+ if (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
+ *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
+ }
+ else {
+ if (vs2) {
+ *size = (offset2 - (*offset)) - 2;
+ }
+ else {
+ *size = (offset2 - (*offset)) - 6;
+ }
+ }
+ lseek(fp, *offset, SEEK_SET);
+ }
+ return 0;
+ }
+
+ if (!strncmp(buf, "$-$-$-", 6)) {
+ *offset = lseek(fp, 0, SEEK_CUR) - 1;
+ *num2 = 0;
+ (*num1)++;
+ printf("Book marker: %s\n", buf2);
+ if (size) {
+ if (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
+ *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
+ }
+ else {
+ if (vs2) {
+ *size = (offset2 - (*offset)) - 2;
+ }
+ else {
+ *size = (offset2 - (*offset)) - 6;
+ }
+ }
+ lseek(fp, *offset, SEEK_SET);
+ }
+ return 0;
+ }
+
+
+ memmove(buf, &buf[1], 6);
+ if (read(fp, &buf[6], 1) != 1)
+ return 1;
+ }
+}
+
+
+void openfiles(char *fname)
+{
+ char buf[255];
+
+ if ((fp = open(fname, O_RDONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", fname);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.vss", fname);
+ if ((vfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.cps", fname);
+ if ((cfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.bks", fname);
+ if ((bfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+}
+
+
+void checkparams(int argc, char **argv)
+{
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s <file to process> [nt - for new testmt file]\n", argv[0]);
+ exit(1);
+ }
+ if (argc == 3)
+ key1 = key2 = key3 = "Matthew 1:1";
+ else key1 = key2 = key3 = "Genesis 1:1";
+}
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..53aadbe
--- /dev/null
+++ b/src/modules/comments/rawfiles/Makefile.am
@@ -0,0 +1,3 @@
+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..c8e9388
--- /dev/null
+++ b/src/modules/comments/rawfiles/rawfiles.cpp
@@ -0,0 +1,291 @@
+/******************************************************************************
+ * 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>
+
+#ifndef __GNUC__
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#include <string.h>
+#include <utilfuns.h>
+#include <rawverse.h>
+#include <rawfiles.h>
+#include <filemgr.h>
+
+#ifndef O_BINARY // O_BINARY is needed in Borland C++ 4.53
+#define O_BINARY 0 // If it hasn't been defined than we probably
+#endif // don't need it.
+
+
+ /******************************************************************************
+ * 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, O_RDWR), SWCom(iname, idesc, idisp, enc, dir, mark, ilang)
+{
+}
+
+
+/******************************************************************************
+ * RawFiles Destructor - Cleans up instance of RawFiles
+ */
+
+RawFiles::~RawFiles()
+{
+}
+
+
+/******************************************************************************
+ * RawFiles::operator char * - Returns the correct verse when char * cast
+ * is requested
+ *
+ * RET: string buffer with verse
+ */
+
+char *RawFiles::getRawEntry() {
+ FileDesc *datafile;
+ long start = 0;
+ unsigned short size = 0;
+ char *tmpbuf;
+ VerseKey *key = 0;
+
+#ifndef _WIN32_WCE
+ try {
+#endif
+ key = SWDYNAMIC_CAST(VerseKey, this->key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ if (!key)
+ key = new VerseKey(this->key);
+
+ findoffset(key->Testament(), key->Index(), &start, &size);
+
+ if (entrybuf)
+ delete [] entrybuf;
+
+ if (size) {
+ tmpbuf = new char [ (size + 2) + strlen(path) + 5 ];
+ sprintf(tmpbuf,"%s/",path);
+ gettext(key->Testament(), start, (size + 2), tmpbuf+strlen(tmpbuf));
+ datafile = FileMgr::systemFileMgr.open(tmpbuf, O_RDONLY|O_BINARY);
+ delete [] tmpbuf;
+ if (datafile->getFd() > 0) {
+ size = lseek(datafile->getFd(), 0, SEEK_END);
+ entrybuf = new char [ size * FILTERPAD ];
+ memset(entrybuf, 0, size * FILTERPAD);
+ lseek(datafile->getFd(), 0, SEEK_SET);
+ read(datafile->getFd(), entrybuf, size);
+ preptext(entrybuf);
+ }
+ else {
+ entrybuf = new char [2];
+ entrybuf[0] = 0;
+ entrybuf[1] = 0;
+ }
+ FileMgr::systemFileMgr.close(datafile);
+ }
+ else {
+ entrybuf = new char [2];
+ entrybuf[0] = 0;
+ entrybuf[1] = 0;
+ }
+
+ if (key != this->key)
+ delete key;
+
+ return entrybuf;
+}
+
+
+/******************************************************************************
+ * RawFiles::operator << (char *)- Update the modules current key entry with
+ * provided text
+ *
+ * RET: *this
+ */
+
+SWModule &RawFiles::operator <<(const char *inbuf) {
+ FileDesc *datafile;
+ long start;
+ unsigned short size;
+ char *tmpbuf;
+ VerseKey *key = 0;
+
+#ifndef _WIN32_WCE
+ try {
+#endif
+ key = SWDYNAMIC_CAST(VerseKey, this->key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ if (!key)
+ key = new VerseKey(this->key);
+
+ findoffset(key->Testament(), key->Index(), &start, &size);
+
+ if (size) {
+ tmpbuf = new char [ (size + 2) + strlen(path) + 1 ];
+ sprintf(tmpbuf, "%s/", path);
+ gettext(key->Testament(), start, (size + 2), tmpbuf+strlen(tmpbuf));
+ }
+ else {
+ tmpbuf = new char [ 16 + strlen(path) + 1 ];
+ sprintf(tmpbuf, "%s/%s", path, getnextfilename());
+ settext(key->Testament(), key->Index(), tmpbuf+strlen(path)+1);
+ }
+ datafile = FileMgr::systemFileMgr.open(tmpbuf, O_CREAT|O_WRONLY|O_BINARY|O_TRUNC);
+ delete [] tmpbuf;
+ if (datafile->getFd() > 0) {
+ write(datafile->getFd(), inbuf, strlen(inbuf));
+ }
+ FileMgr::systemFileMgr.close(datafile);
+
+ if (key != this->key)
+ delete key;
+
+ return *this;
+}
+
+
+/******************************************************************************
+ * RawFiles::operator << (SWKey *)- Link the modules current key entry with
+ * another module entry
+ *
+ * RET: *this
+ */
+
+SWModule &RawFiles::operator <<(const SWKey *inkey) {
+
+ long start;
+ unsigned short size;
+ char *tmpbuf;
+ const VerseKey *key = 0;
+
+#ifndef _WIN32_WCE
+ try {
+#endif
+ key = SWDYNAMIC_CAST(VerseKey, inkey);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ if (!key)
+ key = new VerseKey(this->key);
+
+ findoffset(key->Testament(), key->Index(), &start, &size);
+
+ if (size) {
+ tmpbuf = new char [ size + 2];
+ gettext(key->Testament(), start, size + 2, tmpbuf);
+
+ if (key != inkey)
+ delete key;
+ key = 0;
+
+#ifndef _WIN32_WCE
+ try {
+#endif
+ key = SWDYNAMIC_CAST(VerseKey, inkey);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ if (!key)
+ key = new VerseKey(this->key);
+ settext(key->Testament(), key->Index(), tmpbuf);
+ }
+
+ if (key != inkey)
+ delete key;
+
+ return *this;
+}
+
+
+/******************************************************************************
+ * RawFiles::deleteEntry - deletes this entry
+ *
+ * RET: *this
+ */
+
+void RawFiles::deleteEntry() {
+
+ VerseKey *key = 0;
+
+#ifndef _WIN32_WCE
+ try {
+#endif
+ key = SWDYNAMIC_CAST(VerseKey, this->key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ if (!key)
+ key = new VerseKey(this->key);
+
+ settext(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::systemFileMgr.open(incfile, O_RDONLY|O_BINARY);
+ if (read(datafile->getFd(), &number, 4) != 4)
+ number = 0;
+ number++;
+ FileMgr::systemFileMgr.close(datafile);
+
+ datafile = FileMgr::systemFileMgr.open(incfile, O_CREAT|O_WRONLY|O_BINARY|O_TRUNC);
+ write(datafile->getFd(), &number, 4);
+ FileMgr::systemFileMgr.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::systemFileMgr.open(incfile, O_CREAT|O_WRONLY|O_BINARY|O_TRUNC);
+ delete [] incfile;
+ write(datafile->getFd(), &zero, 4);
+ FileMgr::systemFileMgr.close(datafile);
+
+ return RawVerse::createModule (path);
+}
+
+
+
diff --git a/src/modules/comments/rawfiles/rawfilesgen.cpp b/src/modules/comments/rawfiles/rawfilesgen.cpp
new file mode 100644
index 0000000..f60c9e2
--- /dev/null
+++ b/src/modules/comments/rawfiles/rawfilesgen.cpp
@@ -0,0 +1,236 @@
+/*****************************************************************************
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#ifndef __GNUC__
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#include <fcntl.h>
+#include <versekey.h>
+
+#ifndef O_BINARY
+ #define O_BINARY 0
+#endif
+
+void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size);
+char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size);
+void openfiles();
+void checkparams(int argc, char **argv);
+void charsetconvert(char *data);
+
+
+VerseKey key1, key2, key3;
+int fp, vfp, cfp, bfp;
+long chapoffset;
+short chapsize;
+char testmnt;
+char startflag = 0;
+
+
+main(int argc, char **argv)
+{
+ long pos, offset;
+ int num1, num2, rangemax, curbook = 0, curchap = 0, curverse = 0;
+ char buf[127];
+ short size, tmp;
+ extern struct zonline online;
+
+ checkparams(argc, argv);
+
+ key1 = key2 = key3 = "Genesis 1:1";
+
+ openfiles();
+
+ num1 = key1.Chapter();
+ num2 = key1.Verse();
+
+ while(!findbreak(fp, &offset, &num1, &num2, &rangemax, &size)) {
+ if (!startflag) {
+ startflag = 1;
+ }
+ else {
+ if (num2 < key2.Verse()) { // new chapter
+ if (num1 <= key2.Chapter()) { // new book
+ key2.Verse(1);
+ key2.Chapter(1);
+ key2.Book(key2.Book()+1);
+ }
+ printf("Created Empty Entry: %d ('%s')\n", num1, (const char *)key2);
+ chapoffset = offset;
+ chapsize = size;
+// continue;
+ }
+ }
+ key2.Verse(1);
+ key2.Chapter(num1);
+ key2.Verse(num2);
+
+ key3 = key2;
+// key3 += (rangemax - key3.Verse());
+
+ writeidx(key1, key2, key3, offset, size);
+ }
+ close(vfp);
+ close(cfp);
+ close(bfp);
+ close(fp);
+}
+
+
+/**************************************************************************
+ * ENT: key1 - current location of index
+ * key2 - minimum keyval for which this offset is valid
+ * key3 - maximum keyval for which this offset is valid
+ */
+
+void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size)
+{
+ long pos;
+ short tmp;
+
+ if (key1.Verse() == 1) { // new chapter
+ if (key1.Chapter() == 1) { // new book
+ pos = lseek(cfp, 0, SEEK_CUR);
+ write(bfp, &pos, 4);
+ pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */
+ write(cfp, &pos, 4);
+ write(vfp, &chapoffset, 4); /* Book intro (vss) set to same as chap for now(it should be chap 1 which usually contains the book into anyway)*/
+ write(vfp, &chapsize, 2);
+ }
+ pos = lseek(vfp, 0, SEEK_CUR);
+ write(cfp, &pos, 4);
+ write(vfp, &chapoffset, 4); /* Chapter intro */
+ write(vfp, &chapsize, 2);
+ }
+ if (key1 >= key2) {
+ write(vfp, &offset, 4);
+ size = 0;
+ write(vfp, &size, 2);
+ }
+ else {
+ pos = 0;
+ tmp = 0;
+ write(vfp, &pos, 4);
+ write(vfp, &tmp, 2);
+ }
+ key1++;
+}
+
+
+static VerseKey inckey = "Genesis 1:1";
+
+char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size)
+{
+ char buf[7];
+ char buf2[20];
+ char ch;
+ char loop;
+ long offset2;
+ int ch2, vs2, rm2;
+ bool flag;
+ long chapstart = 0;
+ static int olbvnum = 0;
+ char data[16];
+
+ memset (data,0,16);
+
+ if (++olbvnum <= 31102) {
+
+ if (olbvnum == 23146) { // "Matthew 1:1"
+ close(vfp);
+ close(cfp);
+ close(bfp);
+ close(fp);
+ key1 = key2 = key3 = inckey = "Matthew 1:1";
+ openfiles();
+ startflag = 0;
+ }
+
+
+ *offset = lseek(fp, 0, SEEK_CUR);
+
+ if ((olbvnum!=1) && (olbvnum != 23146))
+ inckey++;
+
+ *num1 = inckey.Chapter();
+ *num2 = inckey.Verse();
+
+
+ write(fp, data, 16);
+
+ *size = lseek(fp, 0, SEEK_CUR) - *offset;
+ return 0;
+ }
+ return 1;
+}
+
+
+void openfiles()
+{
+ char buf[255];
+ char fname[5];
+ long pos;
+ short size;
+
+ testmnt = key1.Testament();
+
+ strcpy(fname, (testmnt==2) ? "nt" : "ot");
+ unlink(fname);
+ if ((fp = open(fname, O_CREAT|O_RDWR|O_BINARY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", fname);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.vss", fname);
+ unlink(buf);
+ if ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.cps", fname);
+ unlink(buf);
+ if ((cfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.bks", fname);
+ unlink(buf);
+ if ((bfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+
+ pos = 0;
+ write(bfp, &pos, 4); /* Book offset for testament intros */
+ pos = 4;
+ write(cfp, &pos, 4); /* Chapter offset for testament intro */
+
+
+/* Right now just zero out intros until parsing correctly */
+ pos = 0;
+ size = 0;
+ write(vfp, &pos, 4); /* Module intro */
+ write(vfp, &size, 2);
+ write(vfp, &pos, 4); /* Testament intro */
+ write(vfp, &size, 2);
+
+}
+
+
+void checkparams(int argc, char **argv)
+{
+ if (argc !=1) {
+ fprintf(stderr, "usage: %s\n", argv[0]);
+ exit(1);
+ }
+}
diff --git a/src/modules/comments/swcom.cpp b/src/modules/comments/swcom.cpp
new file mode 100644
index 0000000..1feb0cf
--- /dev/null
+++ b/src/modules/comments/swcom.cpp
@@ -0,0 +1,30 @@
+/******************************************************************************
+ * swcom.cpp - code for base class 'SWCom'- The basis for all commentary
+ * modules
+ */
+
+#include <swcom.h>
+
+
+/******************************************************************************
+ * 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, "Commentaries", enc, dir, mark, ilang)
+{
+ delete key;
+ key = CreateKey();
+}
+
+
+/******************************************************************************
+ * SWCom Destructor - Cleans up instance of SWCom
+ */
+
+SWCom::~SWCom()
+{
+}
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..ad1ef6a
--- /dev/null
+++ b/src/modules/comments/zcom/Makefile.am
@@ -0,0 +1,4 @@
+zcomdir = $(top_srcdir)/src/modules/comments/zcom
+
+libsword_la_SOURCES += $(zcomdir)/zcom.cpp
+
diff --git a/src/modules/comments/zcom/makeidx.c b/src/modules/comments/zcom/makeidx.c
new file mode 100644
index 0000000..311103e
--- /dev/null
+++ b/src/modules/comments/zcom/makeidx.c
@@ -0,0 +1,146 @@
+#include <stdio.h>
+#include <fcntl.h>
+
+
+char findbreak(int fp, int *offset, int *num1, int *num2, short *size);
+
+
+main(int argc, char **argv)
+{
+ int fp, vfp, cfp, bfp;
+ long pos;
+ short size, tmp;
+ int num1, num2, offset, curbook = 0, curchap = 0, curverse = 0;
+ char buf[127];
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s <file to process>\n", argv[0]);
+ exit(1);
+ }
+
+ if ((fp = open(argv[1], O_RDONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", argv[1]);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.vss", argv[1]);
+ if ((vfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.cps", argv[1]);
+ if ((cfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+
+ sprintf(buf, "%s.bks", argv[1]);
+ if ((bfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
+ fprintf(stderr, "Couldn't open file: %s\n", buf);
+ exit(1);
+ }
+
+ pos = 0;
+ write(bfp, &pos, 4); /* Book offset for testament intros */
+ pos = 4;
+ write(cfp, &pos, 4); /* Chapter offset for testament intro */
+
+
+/* Right now just zero out intros until parsing correctly */
+ pos = 0;
+ size = 0;
+ write(vfp, &pos, 4); /* Module intro */
+ write(vfp, &size, 2);
+ write(vfp, &pos, 4); /* Testament intro */
+ write(vfp, &size, 2);
+
+ while (!findbreak(fp, &offset, &num1, &num2, &size)) {
+
+ if (num2 == 1) { /* if we're at a new chapter */
+ if (num1 == 1) { /* if we're at a new book */
+ pos = lseek(cfp, 0, SEEK_CUR);
+ write(bfp, &pos, 4);
+ pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */
+ write(cfp, &pos, 4);
+ pos = 0;
+ tmp = 0;
+ write(vfp, &pos, 4); /* Book intro (vss) */
+ write(vfp, &tmp, 2);
+ curbook++;
+ curchap = 0;
+ }
+ pos = lseek(vfp, 0, SEEK_CUR);
+ write(cfp, &pos, 4);
+ curverse = 1;
+ pos = 0;
+ tmp = 0;
+ write(vfp, &pos, 4); /* Chapter intro */
+ write(vfp, &tmp, 2);
+ curchap++;
+ }
+ else curverse++;
+
+ printf("%2d:%3d:%3d found at offset: %7d\n", curbook, num1, num2, offset);
+
+ if (num1 != curchap) {
+ fprintf(stderr, "Error: Found chaptures out of sequence\n", buf);
+ break;
+ }
+ if (num2 != curverse) {
+ fprintf(stderr, "Error: Found verses out of sequence\n", buf);
+ break;
+ }
+ write(vfp, &offset, 4);
+ write(vfp, &size, 2);
+ }
+
+ close(vfp);
+ close(cfp);
+ close(bfp);
+ close(fp);
+}
+
+
+char findbreak(int fp, int *offset, int *num1, int *num2, short *size)
+{
+ char buf[7];
+ char buf2[7];
+ char loop;
+ int offset2, ch2, vs2;
+
+ memset(buf, ' ', 7);
+
+ while (1) {
+ if (buf[3] == ':') {
+ memcpy(buf2, buf, 7);
+ for (loop = 0; loop < 7; loop++) {
+ if (!isdigit(buf2[loop]))
+ buf2[loop] = ' ';
+ }
+ buf2[3] = 0;
+ *num1 = atoi(buf2);
+ *num2 = atoi(&buf2[4]);
+ if (*num1 && *num2) {
+ *offset = lseek(fp, 0, SEEK_CUR);
+ sprintf(buf2, "%d", *num2);
+ *offset -= 2 - strlen(buf2);
+ if (size) {
+ if (findbreak(fp, &offset2, &ch2, &vs2, 0)) {
+ *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
+ }
+ else {
+ sprintf(buf2, "%d:%d", ch2, vs2);
+ *size = (offset2 - (*offset)) - (strlen(buf2) + 2);
+ }
+ lseek(fp, *offset, SEEK_SET);
+ }
+ return 0;
+ }
+ }
+ memmove(buf, &buf[1], 6);
+ if (read(fp, &buf[6], 1) != 1)
+ return 1;
+ }
+}
+
diff --git a/src/modules/comments/zcom/rawtxt2z.cpp b/src/modules/comments/zcom/rawtxt2z.cpp
new file mode 100644
index 0000000..f8c18d0
--- /dev/null
+++ b/src/modules/comments/zcom/rawtxt2z.cpp
@@ -0,0 +1,83 @@
+#include <ctype.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#ifndef __GNUC__
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#include <swcomprs.h>
+
+
+main(int argc, char **argv)
+{
+ SWCompress *zobj;
+ int ifd, ofd, ixfd, oxfd;
+ long offset, loffset, lzoffset;
+ short size, lsize, lzsize;
+ char *tmpbuf;
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s <datafilename>\n", argv[0]);
+ exit(1);
+ }
+
+ zobj = new SWCompress();
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+ tmpbuf = new char [ strlen(argv[1]) + 9 ];
+ ifd = open(argv[1], O_RDONLY|O_BINARY);
+ sprintf(tmpbuf, "%s.vss", argv[1]);
+ ixfd = open(tmpbuf, O_RDONLY|O_BINARY);
+ sprintf(tmpbuf, "%s.zzz", argv[1]);
+ ofd = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT);
+ sprintf(tmpbuf, "%s.zzz.vss", argv[1]);
+ oxfd = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT);
+
+ delete [] tmpbuf;
+
+ printf("\n");
+
+ while (1) {
+ if (read(ixfd, &offset, 4) != 4)
+ break;
+ if (read(ixfd, &size, 2) != 2)
+ break;
+
+ if ((offset == loffset) && (size == lsize)) {
+ printf("using previous offset,size\n", size);
+ write(oxfd, &lzoffset, 4);
+ write(oxfd, &lzsize, 2);
+ }
+ else {
+ printf("%d -> ", size);
+ lsize = size;
+ loffset = offset;
+
+ if (size) {
+ tmpbuf = (char *) calloc(size + 1, 1);
+ lseek(ifd, offset, SEEK_SET);
+ read(ifd, tmpbuf, size);
+ zobj->Buf(tmpbuf);
+ zobj->zBuf(&size);
+ free(tmpbuf);
+ }
+ offset = lseek(ofd, 0, SEEK_END);
+ write(oxfd, &offset, 4);
+ if (size)
+ write(ofd, zobj->zBuf(&size), size);
+ lzoffset = offset;
+ write(oxfd, &size, 2);
+ lzsize = size;
+ printf("%d \n", size);
+ }
+ }
+ delete zobj;
+}
diff --git a/src/modules/comments/zcom/zcom.cpp b/src/modules/comments/zcom/zcom.cpp
new file mode 100644
index 0000000..c53fd1e
--- /dev/null
+++ b/src/modules/comments/zcom/zcom.cpp
@@ -0,0 +1,290 @@
+/******************************************************************************
+ * 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>
+
+#ifndef __GNUC__
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#include <string.h>
+#include <utilfuns.h>
+#include <zverse.h>
+#include <zcom.h>
+
+
+/******************************************************************************
+ * 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;
+}
+
+/******************************************************************************
+ * zCom::operator char * - Returns the correct verse when char * cast
+ * is requested
+ *
+ * RET: string buffer with verse
+ */
+char *zCom::getRawEntry() {
+ long start = 0;
+ unsigned short size = 0;
+ VerseKey *key = 0;
+
+#ifndef _WIN32_WCE
+ try {
+#endif
+ key = SWDYNAMIC_CAST(VerseKey, this->key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ // if we don't have a VerseKey * decendant, create our own
+ if (!key)
+ key = new VerseKey(this->key);
+
+ findoffset(key->Testament(), key->Index(), &start, &size);
+ entrySize = size; // support getEntrySize call
+
+ unsigned long newsize = (size + 2) * FILTERPAD;
+ if (newsize > entrybufallocsize) {
+ if (entrybuf)
+ delete [] entrybuf;
+ entrybuf = new char [ newsize ];
+ entrybufallocsize = newsize;
+ }
+ *entrybuf = 0;
+
+ swgettext(key->Testament(), start, (size + 2), entrybuf);
+
+ rawFilter(entrybuf, size, key);
+
+ if (!isUnicode())
+ preptext(entrybuf);
+
+ if (this->key != key) // free our key if we created a VerseKey
+ delete key;
+
+ 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;
+}
+
+SWModule &zCom::setentry(const char *inbuf, long len) {
+ VerseKey *key = 0;
+ // see if we have a VerseKey * or decendant
+#ifndef _WIN32_WCE
+ try {
+#endif
+ key = SWDYNAMIC_CAST(VerseKey, this->key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ // if we don't have a VerseKey * decendant, create our own
+ if (!key)
+ key = new VerseKey(this->key);
+
+
+ // see if we've jumped across blocks since last write
+ if (lastWriteKey) {
+ if (!sameBlock(lastWriteKey, key)) {
+ flushCache();
+ }
+ delete lastWriteKey;
+ }
+
+ settext(key->Testament(), key->Index(), inbuf, len);
+
+ lastWriteKey = (VerseKey *)key->clone(); // must delete
+
+ if (this->key != key) // free our key if we created a VerseKey
+ delete key;
+
+ return *this;
+}
+
+SWModule &zCom::operator <<(const char *inbuf) {
+ return setentry(inbuf, 0);
+}
+
+
+SWModule &zCom::operator <<(const SWKey *inkey) {
+ VerseKey *destkey = 0;
+ const VerseKey *srckey = 0;
+ // see if we have a VerseKey * or decendant
+#ifndef _WIN32_WCE
+ try {
+#endif
+ destkey = SWDYNAMIC_CAST(VerseKey, this->key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ // if we don't have a VerseKey * decendant, create our own
+ if (!destkey)
+ destkey = new VerseKey(this->key);
+
+ // see if we have a VerseKey * or decendant
+#ifndef _WIN32_WCE
+ try {
+#endif
+ srckey = (const VerseKey *) SWDYNAMIC_CAST(VerseKey, inkey);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {
+ }
+#endif
+ // if we don't have a VerseKey * decendant, create our own
+ if (!srckey)
+ srckey = new VerseKey(inkey);
+
+ linkentry(destkey->Testament(), destkey->Index(), srckey->Index());
+
+ if (this->key != destkey) // free our key if we created a VerseKey
+ delete destkey;
+
+ if (inkey != srckey) // free our key if we created a VerseKey
+ delete srckey;
+
+ return *this;
+}
+
+/******************************************************************************
+ * zCom::deleteEntry - deletes this entry
+ *
+ * RET: *this
+ */
+
+void zCom::deleteEntry() {
+
+ VerseKey *key = 0;
+
+#ifndef _WIN32_WCE
+ try {
+#endif
+ key = SWDYNAMIC_CAST(VerseKey, this->key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ if (!key)
+ key = new VerseKey(this->key);
+
+ settext(key->Testament(), key->Index(), "");
+
+ if (key != this->key)
+ delete key;
+}
+
+
+/******************************************************************************
+ * zCom::operator += - Increments module key a number of entries
+ *
+ * ENT: increment - Number of entries to jump forward
+ *
+ * RET: *this
+ */
+
+SWModule &zCom::operator +=(int increment) {
+ long start;
+ unsigned short size;
+ VerseKey *tmpkey = 0;
+
+#ifndef _WIN32_WCE
+ try {
+#endif
+ tmpkey = SWDYNAMIC_CAST(VerseKey, key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ if (!tmpkey)
+ tmpkey = new VerseKey(key);
+
+ findoffset(tmpkey->Testament(), tmpkey->Index(), &start, &size);
+
+ SWKey lastgood = *tmpkey;
+ while (increment) {
+ long laststart = start;
+ unsigned short lastsize = size;
+ SWKey lasttry = *tmpkey;
+ (increment > 0) ? (*key)++ : (*key)--;
+ if (tmpkey != key)
+ delete tmpkey;
+ tmpkey = 0;
+#ifndef _WIN32_WCE
+ try {
+#endif
+ tmpkey = SWDYNAMIC_CAST(VerseKey, key);
+#ifndef _WIN32_WCE
+ }
+ catch ( ... ) {}
+#endif
+ if (!tmpkey)
+ tmpkey = new VerseKey(key);
+
+ if ((error = key->Error())) {
+ *key = lastgood;
+ break;
+ }
+ long index = tmpkey->Index();
+ findoffset(tmpkey->Testament(), index, &start, &size);
+ if ((((laststart != start) || (lastsize != size))||(!skipConsecutiveLinks)) && (start >= 0) && (size)) {
+ increment += (increment < 0) ? 1 : -1;
+ lastgood = *tmpkey;
+ }
+ }
+ error = (error) ? KEYERR_OUTOFBOUNDS : 0;
+
+ if (tmpkey != key)
+ delete tmpkey;
+
+ return *this;
+}
+