[sword-svn] r36 - in trunk: . misc

scribe at crosswire.org scribe at crosswire.org
Tue May 3 04:19:28 MST 2005


Author: scribe
Date: 2005-05-03 04:19:27 -0700 (Tue, 03 May 2005)
New Revision: 36

Added:
   trunk/misc/
   trunk/misc/gbfidx.cpp
   trunk/misc/jfbgen.cpp
   trunk/misc/kjvidx.cpp
   trunk/misc/makebnds.c
   trunk/misc/makeidx.c
   trunk/misc/mhcidx.cpp
   trunk/misc/nasb.cpp
   trunk/misc/no13.c
   trunk/misc/nuidx.cpp
   trunk/misc/ojbtxidx.c
   trunk/misc/rawfilesgen.cpp
   trunk/misc/rawldidx.c
   trunk/misc/rawtxidx.c
   trunk/misc/rtfidx.cpp
   trunk/misc/rwpidx.cpp
   trunk/misc/strongsidx.c
   trunk/misc/svetxidx.c
   trunk/misc/vntidx.cpp
Log:
Moved misc tools from sword repo, to here.


Added: trunk/misc/gbfidx.cpp
===================================================================
--- trunk/misc/gbfidx.cpp	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/gbfidx.cpp	2005-05-03 11:19:27 UTC (rev 36)
@@ -0,0 +1,661 @@
+/*****************************************************************************
+ *
+ *	This code reeks but works (sometimes).  Good luck!
+ * Modified for zText purposes
+ */
+
+//#include <stdio.h>
+#include <iostream>
+#include <fstream>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <assert.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, unsigned short *size);
+void openfiles(char *fname);
+void checkparams(int argc, char **argv);
+
+
+VerseKey key1, key2, key3;
+int fp=0, vfp=0, cfp=0, bfp=0;
+long chapoffset=0;
+unsigned short chapsize=0;
+long bookoffset=0;
+unsigned short booksize=0;
+long testoffset=0;
+unsigned short testsize=0;
+long verseoffset=0;
+unsigned short versesize=0;
+long nextoffset=0;
+char testmnt=0;
+int deadcount = 0;
+int chapmark=-4, bookmark=-1;
+ofstream cfile;
+
+
+int main(int argc, char **argv)
+{
+	long pos, offset;
+	int num1, num2, rangemax;//, curbook = 0, curchap = 0, curverse = 0;
+	//char buf[127],
+	char startflag = 0;
+	unsigned short size;//, tmp;
+
+	checkparams(argc, argv);
+
+	openfiles(argv[1]);
+	//key1 = "Matthew 1:1";
+	//key2 = "Matthew 1:1";
+	//key3 = "Matthew 1:1";
+
+	testmnt = key1.Testament();
+	cfile << "testament" << (int) testmnt << "\n";
+	num1 = key1.Chapter();
+	num2 = key1.Verse();
+	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);
+	cfile << "modintro pos{" << pos << "} size{" << size << "}\n";
+	write(vfp, &pos, 4);  // Testament intro
+	write(vfp, &size, 2);
+	cfile << "test intro pos{" << pos << "} size{" << size << "}\n";
+	*/
+	cout << "GBFIDX Running\n";
+	cout.flush();
+	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);
+				}
+				cfile << "Found Chapter Break: " << num1 << " ('" << (const char *)key2 << "')\n";
+				//chapoffset = offset;
+				//chapsize = 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);
+
+	return 1;
+}
+
+
+/**************************************************************************
+ * writeidx:	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;
+	unsigned short tmp;
+
+	for (; ((key1 <= key3) && (key1.Error() != KEYERR_OUTOFBOUNDS) && (key1.Testament() == testmnt)); key1+=1) {
+		if (chapmark>=2)
+		{
+			if (bookmark==2)
+			{
+				//booksize = booksize - chapsize + 7;
+				cfile << "versesize " << versesize << " booksize " << booksize << " chapsize " << chapsize << " size " << size << "\n";
+				//cfile.flush();
+				//assert(chapsize < size);
+				//if (chapsize > size)           // At start of Psalms gets chapsize rather than chapsize+size ???
+				//{
+				//	versesize = versesize - (booksize - (chapsize - size) + 7);
+				//}
+				//else
+				//{
+				versesize = versesize - (booksize - (chapsize) + 7);
+				//}
+					cfile << "Last verse in book\n";
+			}
+			//chapsize = chapsize - size;
+			cfile << "versesize " << versesize << " chapsize " << chapsize << " size " << size<< "\n";
+			cfile.flush();
+			//assert(chapsize > size);
+			//if (chapsize > size)           // At start of Psalms gets chapsize rather than chapsize+size ???
+			//{
+			//	versesize = versesize - (chapsize - size);
+			//}
+			//else
+			//{
+			versesize = versesize - (chapsize);
+			//}
+			cfile << "Last verse in chapter\n";
+		}
+		if (chapmark>=2 && bookmark!=1)
+		{
+			cfile << "prev verse pos{" << verseoffset << "} size{" << versesize << "} nextoffset{" << nextoffset << "}\n";
+			cfile.flush();
+			assert(verseoffset==nextoffset);
+			write(vfp, &verseoffset, 4);
+			write(vfp, &versesize, 2);
+			nextoffset = verseoffset+versesize;
+			bookmark = 0;
+			chapmark = 0;
+		}
+		if (key1.Verse() == 1) {	// new chapter
+			cfile << "size??? " << size << "\n";
+			cfile.flush();
+			//assert(chapsize > size || key1.Chapter()==1);
+			//assert(chapsize > size);
+			//if (chapsize > size)           // At start of books gets chapsize rather than chapsize+size
+			//{
+			//	chapsize = chapsize - size;
+			//}
+			if (key1.Chapter() == 1) {	// new book
+				booksize = booksize - chapsize + 7;
+				if (key1.Book() == 1)
+				{
+					pos = 0;
+					//tmp = testoffset;
+					tmp = 0;            	// better just remember that it goes up to the testament intro to avoid 64k limit
+												// AV exceeds that anyway!
+					write(vfp, &pos, 4);  /* Module intro */
+					write(vfp, &tmp, 2);
+					assert(nextoffset==0);
+					cfile << "modintro pos{" << pos << "} size{" << tmp << "}\n";
+					testsize = testsize - booksize - chapsize + 7;
+					if (testsize > 10000)
+					{
+						cerr << "Error: testament too big " << testsize << "\n";
+						exit(-1);
+					}
+					//assert(testoffset==nextoffset);
+					write(vfp, &testoffset, 4);  /* Testament intro (vss)  */
+					write(vfp, &testsize, 2);
+					nextoffset = testoffset+testsize;
+					cfile << "test intro pos{" << testoffset << "} size{" << testsize << "}\n";
+				}
+				pos = lseek(cfp, 0, SEEK_CUR);
+				write(bfp, &pos, 4);
+				pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */
+				write(cfp, &pos, 4);
+				if (booksize > 10000)
+				{
+					cerr << "Error: book too big " << booksize << "\n";
+					exit(-1);
+				}
+				assert(bookoffset==nextoffset);
+				write(vfp, &bookoffset, 4);  /* Book intro (vss)  */
+				write(vfp, &booksize, 2);
+				nextoffset = bookoffset+booksize;
+				cfile << "book intro pos{" << bookoffset << "} size{" << booksize << "}\n";
+				//offset += booksize;
+				//bookmark = false;
+			}
+			pos = lseek(vfp, 0, SEEK_CUR);
+			write(cfp, &pos, 4);
+			assert(chapsize < 10000);
+			write(vfp, &chapoffset, 4);  /* Chapter intro */
+			write(vfp, &chapsize, 2);
+			nextoffset = chapoffset+chapsize;
+			cfile << "chapter intro pos{" << chapoffset << "} size{" << chapsize << "}\n";
+			//offset += chapsize;
+			//size -= chapsize;
+			//chapmark = false;
+		}
+		if (key1 >= key2) {
+			if (size > 10000)
+			{
+				cerr << "Error: verse too big " << size << "\n";
+				exit(-1);
+			}
+			if (!chapmark && !bookmark)
+			{
+				write(vfp, &offset, 4);
+				write(vfp, &size, 2);
+				cfile << "verse pos{" << offset << "} size{" << size << "}\n";
+				cfile.flush();
+				assert(offset==nextoffset);
+				nextoffset = offset+size;
+				//cfile << "bookmark " << bookmark << " chapmark " << chapmark << "\n";
+			}
+			else
+			{
+				verseoffset = offset;
+				versesize = size;
+				cfile << "saving verse pos{" << offset << "} size{" << size << "}\n";
+				cfile << "bookmark " << bookmark << " chapmark " << chapmark << "\n";
+			}
+		}
+		else	{
+			pos = 0;
+			tmp = 0;
+			write(vfp, &pos, 4);
+			write(vfp, &tmp, 2);
+			cfile << "blank pos{" << pos << "} size{" << tmp << "}\n";
+		}
+	}
+}
+
+char startmod(char *buf)
+{
+	//char loop;
+
+	if (buf[0] != '<')
+		return 0;
+	if (buf[1] != 'H')
+		return 0;
+	if (buf[2] != '0')
+		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 starttest(char *buf)
+{
+	//char loop;
+
+	if (buf[0] != '<')
+		return 0;
+	if (buf[1] != 'B')
+		return 0;
+	if (testmnt==2)
+	{
+		if (buf[2] != 'N')
+			return 0;
+	}
+	else
+	{
+		if (buf[2] != 'O')
+			return 0;
+	}
+	//if (buf[3] != '>')
+	//	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 startbook(char *buf)
+{
+	//char loop;
+
+	if (buf[0] != '<')
+		return 0;
+	if (buf[1] != 'S')
+		return 0;
+	if (buf[2] != 'B')
+		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 startchap(char *buf)
+{
+	//char loop;
+
+	if (buf[0] != '<')
+		return 0;
+	if (buf[1] != 'S')
+		return 0;
+	if (buf[2] != 'C')
+		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 startentry(char *buf)
+{
+	//char loop;
+	//cfile << "{SV}";
+
+	if (buf[0] != '<')
+	{
+		//cfile << "{no<}";
+		return 0;
+	}
+	if (buf[1] != 'S')
+	{
+		//cfile << "\n{noS}\n";
+		return 0;
+	}
+	if (buf[2] != 'V')
+	{
+		//cfile << "\n{noV}\n";
+		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, unsigned short *size)
+{
+	char buf[8];
+	//char buf2[20];
+	//char ch;
+	char loop=0;
+	long offset2;
+	int ch2, vs2, rm2;
+	bool flag;
+	long versestart = 0;
+	long chapstart = 0;
+	long bookstart = 0;
+	long teststart = 0;
+
+	memset(buf, ' ', 8);
+
+	while (1) {
+		//cfile << "#" << buf << "#";
+		//if (lseek(fp, 0, SEEK_CUR) > 2000000)
+		//{
+		//	cfile << lseek(fp, 0, SEEK_CUR) << "\n";
+		//}
+		if (starttest(buf)) {
+			cfile << "\n{start of testament}\n";
+			//chapstart = lseek(fp, 0, SEEK_CUR) - 7;
+			teststart = lseek(fp, 0, SEEK_CUR) - 7;
+			testoffset = teststart;
+			memset(buf, ' ', 3);
+			flag = false;
+			for (loop = 3; loop < 6; loop++) {
+				if (buf[loop]!='>')
+					flag = true;
+				else {
+					buf[loop] = 0;
+					break;
+				}
+			}
+			ch2 = *num1;
+			vs2 = 1;
+			if (size) {
+				if (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
+					testsize = (unsigned short) (lseek(fp, 0, SEEK_END) - teststart-7);
+				}
+				else {
+					if (vs2) {
+						testsize = (offset2 - teststart - 7);
+					}
+				}
+				lseek(fp, teststart+7, SEEK_SET);
+				cfile << "\nGot testsize " << testsize << "\n";
+			}
+		}
+
+
+		if (startbook(buf)) {
+			cfile << "\n{start of book}\n";
+			bookmark++;
+			//chapstart = lseek(fp, 0, SEEK_CUR) - 7;
+			bookstart = lseek(fp, 0, SEEK_CUR) - 7;
+			bookoffset = bookstart;
+			memset(buf, ' ', 3);
+			flag = false;
+			for (loop = 3; loop < 6; loop++) {
+				if (buf[loop]!='>')
+					flag = true;
+				else {
+					buf[loop] = 0;
+					break;
+				}
+			}
+			if (size) {
+				ch2 = *num1;
+				vs2 = 1;
+				if (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
+					booksize = (unsigned short) (lseek(fp, 0, SEEK_END) - bookstart - 7);
+				}
+				else {
+					if (vs2) {
+						booksize = (offset2 - bookstart - 7);
+					}
+				}
+				lseek(fp, bookstart+7, SEEK_SET);
+				cfile << "\nGot booksize " << booksize << "\n";
+			}
+		}
+
+		if (startchap(buf)) {
+			cfile << "{start of chapter}";
+			chapmark++;
+			//chapstart = lseek(fp, 0, SEEK_CUR) - 7;
+			chapstart = lseek(fp, 0, SEEK_CUR) - 7;
+			chapoffset = chapstart;
+			memset(buf, ' ', 3);
+			flag = false;
+			for (loop = 3; loop < 6; loop++) {
+				if (isdigit(buf[loop]))
+					flag = true;
+				else {
+					buf[loop] = 0;
+					break;
+				}
+			}
+			if (flag)
+				*num1 = atoi(buf);
+			else	(*num1)++;
+
+			if (size) {
+				ch2 = *num1;
+				vs2 = 1;
+				lseek(fp, chapstart, SEEK_SET);
+				if (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
+					chapsize = (unsigned short) (lseek(fp, 0, SEEK_END) - chapstart);
+					cfile << "getting chapsizeend{" << chapsize << "} = " << lseek(fp, 0, SEEK_END) << " - " << chapstart << "\n";
+				}
+				else {
+					if (vs2) {
+						chapsize = (offset2 - chapstart);
+						cfile << "getting chapsize{" << chapsize << "} = " << offset2 << " - " << chapstart << "\n";
+					}
+				}
+				lseek(fp, chapstart + 7, SEEK_SET);
+				cfile << "\nGot chapsize " << chapsize << " loop{" << (int) loop << "}\n";
+			}
+			//return 0;
+
+		}
+		if (startentry(buf)) {
+			//cfile << "{start of verse}";
+			memset(buf, ' ', 3);
+			flag = false;
+			for (loop = 3; loop < 6; loop++) {
+				if (isdigit(buf[loop]))
+					flag = true;
+				else {
+					buf[loop] = 0;
+					break;
+				}
+			if (flag)
+				*num2 = atoi(buf);
+			else	(*num2)++;
+			}
+			loop++;
+			/*
+			if (size)
+			{
+				// *offset = lseek(fp, 0, SEEK_CUR) - (7 - loop);
+				 *offset = lseek(fp, 0, SEEK_CUR) - 7;
+			}
+			//else	*offset = (chapstart) ? chapstart : lseek(fp, 0, SEEK_CUR) - 7;
+			else	*offset = (chapstart) ? chapstart : lseek(fp, 0, SEEK_CUR) - 7;
+			*/
+			/*if (chapstart)
+			{
+				chapsize = *offset-chapstart;
+			}
+			else
+			{
+				chapsize = 0;
+			}*/
+			*offset = lseek(fp, 0, SEEK_CUR) - 7;
+			versestart = *offset;
+			if (size) {
+				ch2 = *num1;
+				vs2 = *num2;
+				if (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
+					*size = (unsigned short) (lseek(fp, 0, SEEK_END) - versestart);
+					cfile << "getting sizeend{" << *size << "} = " << lseek(fp, 0, SEEK_END) << " - " << versestart << "\n";
+				}
+				else {
+					if (vs2) {
+						*size = (offset2 - versestart);
+						cfile << "getting size{" << *size << "} = " << offset2 << " - " << versestart << "\n";
+					}
+				}
+				lseek(fp, *offset+1, SEEK_SET);
+			}
+			else
+			{
+				cfile << "got offset{" << *offset << "}\n";
+			}
+			return 0;
+		}
+		//cfile << "{ng}";
+		//deadcount++;
+		//if (deadcount==1000) exit(-1);
+		//if (!size)
+		//{
+		//	cfile << "not bound offset{" << *offset << "}\n";
+		//}
+		memmove(buf, &buf[1], 6);
+		if (read(fp, &buf[6], 1) != 1)
+			return 1;
+	}
+}
+
+
+void openfiles(char *fname)
+{
+#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.
+	char buf[255];
+
+	if ((fp = open(fname, O_RDONLY|O_BINARY)) == -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|O_BINARY|O_TRUNC)) == -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|O_BINARY|O_TRUNC)) == -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|O_BINARY|O_TRUNC)) == -1) {
+		fprintf(stderr, "Couldn't open file: %s\n", buf);
+		exit(1);
+	}
+	cfile.open("gbfidx.log", ios::out);
+	if (!cfile.is_open())
+	{
+		cerr << "Failed to open log file\n";
+		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 (!strcmp(argv[1], "nt"))
+		key1 = key2 = key3 = "Matthew 1:1";
+	else if (!strcmp(argv[1], "ot"))
+	{
+			key1 = key2 = key3 = "Genesis 1:1";
+	}
+	else
+	{
+		cerr << "File must be ot or nt\n";
+		exit(-1);
+	}
+}

Added: trunk/misc/jfbgen.cpp
===================================================================
--- trunk/misc/jfbgen.cpp	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/jfbgen.cpp	2005-05-03 11:19:27 UTC (rev 36)
@@ -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);
+	}
+}

Added: trunk/misc/kjvidx.cpp
===================================================================
--- trunk/misc/kjvidx.cpp	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/kjvidx.cpp	2005-05-03 11:19:27 UTC (rev 36)
@@ -0,0 +1,169 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <versekey.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];
+	VerseKey mykey;
+
+	if ((argc < 2) || (argc > 3)) {
+		fprintf(stderr, "usage: %s <file to process> [nt]\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);
+
+	mykey = (argc == 3) ? "Matthew 1:1" : "Genesis 1:1";
+
+	while (!findbreak(fp, &offset, &num1, &num2, &size)) {
+		num1 = mykey.Chapter();
+		num2 = mykey.Verse();
+		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");
+			break;
+		}
+		if (num2 != curverse) {
+			fprintf(stderr, "Error: Found verses out of sequence\n");
+			break;
+		}
+		write(vfp, &offset, 4);
+		write(vfp, &size, 2);
+		mykey++;
+	}
+	
+	close(vfp);
+	close(cfp);
+	close(bfp);
+	close(fp);
+}
+
+
+char findbreak(int fp, int *offset, int *num1, int *num2, short *size)
+{
+	char buf[17];
+	char buf2[7];
+	char loop;
+	char offadj, inquotes, sizeadj;
+	int offset2, ch2, vs2;
+	
+	memset(buf, ' ', 17);
+
+	while (1) {
+		offadj = -10;
+		inquotes = 0;
+		sizeadj = 0;
+  		if ((!memcmp(buf, "\\widctlpar {\\b\\f0\\cf2 ", 16)) && (!size)) {
+			offadj = -1;
+//			inquotes = 1;
+			sizeadj = -18;
+		}
+  		if (!memcmp(&buf[1], "\\f0\\fs16\\cf2\\up6", 15)) {
+			offadj = 0;
+			inquotes = 1;
+			sizeadj = (*buf == 10) ? -18:-17;
+		}
+  		if (!memcmp(buf, "\\fi200\\widctlpar", 16)) {
+			offadj = -1;
+//			inquotes = 1;
+			sizeadj = -18;
+		}
+		if (offadj > -10) {
+			*offset = lseek(fp, 0, SEEK_CUR) + offadj;
+			if (size) {
+				(*offset)++;
+				while (inquotes) {
+					while (read(fp, buf2, 1) == 1) {
+						if (*buf2 == '}')
+							break;
+						(*offset)++;
+					}
+					inquotes--;
+				}
+				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));
+				}
+				lseek(fp, *offset+17, SEEK_SET);
+			}
+			else (*offset) += sizeadj;
+			return 0;
+		}
+		memmove(buf, &buf[1], 16);
+		if (read(fp, &buf[16], 1) != 1)
+			return 1;
+	}
+}
+

Added: trunk/misc/makebnds.c
===================================================================
--- trunk/misc/makebnds.c	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/makebnds.c	2005-05-03 11:19:27 UTC (rev 36)
@@ -0,0 +1,86 @@
+#include <stdio.h>
+#include <fcntl.h>
+
+
+char *bnames[] = {
+	"Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy",
+	"Joshua", "Judges", "Ruth", "I Samual", "II Samuel",
+	"I Kings", "II Kings", "I Chronicles", "II Chronicles", "Ezra",
+	"Nehemiah", "Esther", "Job", "Psalms", "Proverbs",
+	"Ecclesiastes", "Song of Solomon", "Isaiah", "Jeremiah", "Lamentations",
+	"Ezekiel", "Daniel", "Hosea", "Joel", "Amos",
+	"Obadiah", "Jonah", "Micah", "Nahum", "Habakkuk",
+	"Zephaniah", "Haggai", "Zechariah", "Malachi",
+	"Matthew", "Mark", "Luke", "John", "Acts",
+	"Romans", "I Corinthians", "II Corinthians", "Galatians", "Ephesians",
+	"Philippians", "Colossians", "I Thessalonians", "II Thessalonians", "I Timothy",
+	"II Timothy", "Titus", "Philemon", "Hebrews", "James",
+	"I Peter", "II Peter", "I John", "II John", "III John",
+	"Jude", "Revelation of John"};
+
+
+
+main(int argc, char **argv)
+{
+	int fp, vfp, cfp, bfp;
+	long pos;
+	int num1, num2, offset, offset2, chapmax, chapoff, chapoff2, curbook = 0, curchap = 0, curverse = 0;
+	char buf[127];
+
+	if (argc > 3) {
+		fprintf(stderr, "usage: %s <file to process> [NT?]\n", argv[0]);
+		exit(1);
+	}
+
+	if (argc > 2)
+		curbook = 39;
+	sprintf(buf, "%s.vss", argv[1]);
+	if ((vfp = open(buf, O_RDONLY)) == -1) {
+		fprintf(stderr, "Couldn't open file: %s\n", buf);
+		exit(1);
+	}
+
+	sprintf(buf, "%s.cps", argv[1]);
+	if ((cfp = open(buf, O_RDONLY)) == -1) {
+		fprintf(stderr, "Couldn't open file: %s\n", buf);
+		exit(1);
+	}
+
+	sprintf(buf, "%s.bks", argv[1]);
+	if ((bfp = open(buf, O_RDONLY)) == -1) {
+		fprintf(stderr, "Couldn't open file: %s\n", buf);
+		exit(1);
+	}
+
+	read(bfp, &offset2, sizeof(offset2));
+	read(cfp, &chapoff2, sizeof(chapoff2));
+	while (read(bfp, &offset, sizeof(offset)) == sizeof(offset)) {
+		chapmax = (offset - offset2) / sizeof(offset);
+		printf("\n\{\"%s\", %d}, \n// %s\n", bnames[curbook], chapmax, bnames[curbook]);
+		curbook++;
+		for (curchap = 0; curchap < chapmax; curchap++) {
+			read(cfp, &chapoff, sizeof(chapoff));
+			printf("%d, ", (chapoff - chapoff2) / sizeof(chapoff));
+			chapoff2 = chapoff;
+		}
+		offset2 = offset;
+	}
+	pos     =       lseek(cfp, 0, SEEK_CUR);
+	offset  = (int) lseek(cfp, 0, SEEK_END);
+	chapmax = (offset - offset2) / sizeof(offset);
+	printf("\n\{\"%s\", %d}, \n// %s\n", bnames[curbook], chapmax, bnames[curbook]);
+	curbook++;
+	lseek(cfp, pos, SEEK_SET);
+	for (curchap = 0; curchap < chapmax - 1; curchap++) {
+		read(cfp, &chapoff, sizeof(chapoff));
+		printf("%d, ", (chapoff - chapoff2) / sizeof(chapoff));
+		chapoff2 = chapoff;
+	}
+	chapoff = (int) lseek(vfp, 0, SEEK_END);
+	printf("%d, ", (chapoff - chapoff2) / sizeof(chapoff));
+	
+	close(vfp);
+	close(cfp);
+	close(bfp);
+	close(fp);
+}

Added: trunk/misc/makeidx.c
===================================================================
--- trunk/misc/makeidx.c	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/makeidx.c	2005-05-03 11:19:27 UTC (rev 36)
@@ -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;
+	}
+}
+

Added: trunk/misc/mhcidx.cpp
===================================================================
--- trunk/misc/mhcidx.cpp	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/mhcidx.cpp	2005-05-03 11:19:27 UTC (rev 36)
@@ -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";
+}

Added: trunk/misc/nasb.cpp
===================================================================
--- trunk/misc/nasb.cpp	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/nasb.cpp	2005-05-03 11:19:27 UTC (rev 36)
@@ -0,0 +1,107 @@
+
+
+#include <ctype.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#ifndef __GNUC__
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#include <swcomprs.h>
+
+class FileCompress: public SWCompress {
+	int ifd;
+	int ofd;
+	int ufd;
+	int zfd;
+public:
+	FileCompress(char *);
+	~FileCompress();
+	int GetChars(char *, int len);
+	int SendChars(char *, int len);
+	void Encode();
+	void Decode();
+};
+
+
+FileCompress::FileCompress(char *fname) 
+{
+	char buf[256];
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+	ufd  = open(fname, O_RDWR|O_CREAT|O_BINARY);
+
+	sprintf(buf, "%s.zzz", fname);
+	zfd = open(buf, O_RDWR|O_CREAT|O_BINARY);
+}
+
+	
+FileCompress::~FileCompress(char *fname) 
+{
+	close(ufd);
+	close(zfd);
+}
+
+
+int FileCompress::GetChars(char *buf, int len) 
+{
+	return read(ifd, buf, len);
+}
+
+
+int FileCompress::SendChars(char *buf, int len) 
+{
+	return write(ofd, buf, len);
+}
+
+
+void FileCompress::Encode() 
+{
+	ifd = ufd;
+	ofd = zfd;
+
+	SWCompress::Encode();
+}
+
+
+void FileCompress::Decode() 
+{
+	ifd = zfd;
+	ofd = ufd;
+
+	SWCompress::Decode();
+}
+
+
+main(int argc, char **argv)
+{
+	int decomp = 0;
+	SWCompress *fobj;
+	
+	if (argc != 2) {
+		fprintf(stderr, "usage: %s <filename|filename.zzz>\n", argv[0]);
+		exit(1);
+	}
+
+	if (strlen(argv[1]) > 4) {
+		if (!strcmp(&argv[1][strlen(argv[1])-4], ".zzz")) {
+			argv[1][strlen(argv[1])-4] = 0;
+			decomp = 1;
+		}
+	}
+			
+	fobj = new FileCompress(argv[1]);
+	
+	if (decomp)
+		fobj->Decode();
+	else fobj->Encode();
+
+	delete fobj;
+}

Added: trunk/misc/no13.c
===================================================================
--- trunk/misc/no13.c	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/no13.c	2005-05-03 11:19:27 UTC (rev 36)
@@ -0,0 +1,34 @@
+#include <fcntl.h>
+#include <stdio.h>
+
+main(int argc, char **argv)
+{
+	int fd, loop;
+	char ch;
+	char breakcnt = 0;
+
+	if (argc != 2) {
+		fprintf(stderr, "This program writes to stdout, so to be useful,\n\tit should be redirected (e.g no13 bla > bla.dat)\nusage: %s <filename>\n", argv[0]);
+		exit(1);
+	}
+	fd = open(argv[1], O_RDONLY);
+	while (read(fd, &ch, 1) == 1) {
+		if (ch == 0x0d) {	// CR
+			breakcnt++;
+			continue;
+		}
+		if (ch == 0x1a)	// Ctrl-Z
+			continue;
+
+		if (ch != 0x0a) {	// LF
+			if (breakcnt > 1) {
+				for (loop = breakcnt; loop > 0; loop--)
+					putchar(0x0d);
+				putchar(0x0a);
+			}
+			breakcnt=0;
+		}
+		putchar(ch);
+	}
+	close(fd);
+}

Added: trunk/misc/nuidx.cpp
===================================================================
--- trunk/misc/nuidx.cpp	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/nuidx.cpp	2005-05-03 11:19:27 UTC (rev 36)
@@ -0,0 +1,238 @@
+/*****************************************************************************
+ *
+ *	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();
+	num1 = key1.Chapter();
+	num2 = key1.Verse();
+	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)) {
+		writeidx(key1, key2, key3, offset, size);
+		key2++;
+		key3 = key2;
+	}
+	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 startchap(char *buf)
+{
+	char loop;
+
+	if (buf[0] != '<')
+		return 0;
+	if (buf[1] != 'S')
+		return 0;
+	if (buf[2] != 'C')
+		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 startentry(char *buf)
+{
+	char loop;
+
+	if (buf[0] != '<')
+		return 0;
+	if (buf[1] != 'S')
+		return 0;
+	if (buf[2] != 'V')
+		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;
+	bool flag;
+	long chapstart = 0; 
+	
+	memset(buf, ' ', 7);
+
+	while (1) {
+		if (startentry(buf)) {
+			if (size)
+				*offset = lseek(fp, 0, SEEK_CUR) - 3;
+			else	*offset = lseek(fp, 0, SEEK_CUR) - 7;
+			if (size) {
+				ch2 = *num1;
+				vs2 = *num2;
+				if (findbreak(fp, &offset2, &ch2, &vs2, &rm2, 0)) {
+					*size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
+				}
+				else {
+					*size = (offset2 - (*offset));
+				}
+				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";
+}

Added: trunk/misc/ojbtxidx.c
===================================================================
--- trunk/misc/ojbtxidx.c	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/ojbtxidx.c	2005-05-03 11:19:27 UTC (rev 36)
@@ -0,0 +1,166 @@
+#include <stdio.h>
+#include <fcntl.h>
+#ifndef __GNUC__
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+
+char findbreak(int fd, long *offset, int *num1, int *num2, short *size);
+
+
+main(int argc, char **argv)
+{
+	int fd, vfd, cfd, bfd;
+	long pos, offset;
+	short size, tmp;
+	int num1, num2, curbook = 0, curchap = 0, curverse = 0;
+	char buf[127];
+
+	if (argc != 2) {
+		fprintf(stderr, "usage: %s <file to process>\n", argv[0]);
+		exit(1);
+	}
+#ifndef O_BINARY		// O_BINARY is for Borland to be happy.  If we're in GNU, just define it to a NULL mask
+#define O_BINARY 0
+#endif
+	if ((fd = open(argv[1], O_RDONLY|O_BINARY)) == -1) {
+		fprintf(stderr, "Couldn't open file: %s\n", argv[1]);
+		exit(1);
+	}
+
+	sprintf(buf, "%s.vss", argv[1]);
+	if ((vfd = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+		fprintf(stderr, "Couldn't open file: %s\n", buf);
+		exit(1);
+	}
+
+	sprintf(buf, "%s.cps", argv[1]);
+	if ((cfd = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+		fprintf(stderr, "Couldn't open file: %s\n", buf);
+		exit(1);
+	}
+
+	sprintf(buf, "%s.bks", argv[1]);
+	if ((bfd = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+		fprintf(stderr, "Couldn't open file: %s\n", buf);
+		exit(1);
+	}
+
+	pos  = 0;
+	write(bfd, &pos, 4);  /* Book    offset for testament intros */
+	pos = 4;
+	write(cfd, &pos, 4);  /* Chapter offset for testament intro */
+
+
+/*	Right now just zero out intros until parsing correctly */
+	pos = 0;
+	size = 0;
+	write(vfd, &pos, 4);  /* Module intro */
+	write(vfd, &size, 2);
+	write(vfd, &pos, 4);  /* Testament intro */
+	write(vfd, &size, 2);
+
+	while (!findbreak(fd, &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(cfd, 0, SEEK_CUR);
+				write(bfd, &pos, 4);
+				pos = lseek(vfd, 0, SEEK_CUR); /* Book intro (cps) */
+				write(cfd, &pos, 4);
+				pos  = 0;
+				tmp = 0;
+				write(vfd, &pos, 4);  /* Book intro (vss) */
+				write(vfd, &tmp, 2);
+				curbook++;
+				curchap = 0;
+			}
+			pos = lseek(vfd, 0, SEEK_CUR);
+			write(cfd, &pos, 4);
+			curverse = 1;
+			pos  = 0;
+			tmp = 0;
+			write(vfd, &pos, 4);  /* Chapter intro */
+			write(vfd, &tmp, 2);
+			curchap++;
+		}
+		else curverse++;
+	
+		printf("%2d:%3d:%3d found at offset: %7ld\n", curbook, num1, num2, offset);
+
+		if (num1 != curchap) {
+			fprintf(stderr, "Error: Found chaptures out of sequence (%2d:%3d:%3d)\n", curbook, num1-1, num2);
+			curchap = num1;
+//			break;
+		}
+		if (num2 != curverse) {
+			fprintf(stderr, "Error: Found verses out of sequence (%2d:%3d:%3d)\n", curbook, num1, num2-1);
+//			break;
+			tmp = 0;
+			curverse = num2;
+			write(vfd, &offset, 4);
+			write(vfd, &tmp, 2);
+		}
+		write(vfd, &offset, 4);
+		write(vfd, &size, 2);
+	}
+	
+	close(vfd);
+	close(cfd);
+	close(bfd);
+	close(fd);
+	return 0;
+}
+
+
+char findbreak(int fd, long *offset, int *num1, int *num2, short *size)
+{
+	char buf[8];
+	char buf2[7];
+	char loop, len, star;
+
+	memset(buf, ' ', 7);
+	buf[7] = 0;
+
+	while (1) {
+
+		memmove(buf, &buf[1], 6);
+		if (read(fd, &buf[6], 1) != 1)
+			return 1;
+
+		if ((buf[0] == 10) && ((buf[2] == '*') || (buf[3] == '*') || (buf[4] == '*'))) { 
+			star = 0;
+			for (loop = 0; loop < 7; loop++) {
+				if (buf[loop] == '*')
+					star = 1;
+				if (isdigit(buf[loop])&&star)
+					break;
+				else buf[loop] = ' ';
+			}
+			if (loop < 7) {
+				sscanf(buf, "%d", num1);
+				continue;
+			}
+		}
+
+		if ((buf[0] == '|') && (isdigit(buf[1]))) {
+			sscanf(&buf[1], "%d", num2);
+			sprintf(buf, "%d", *num2);
+			(*offset)  = lseek(fd, 0, SEEK_CUR);
+			(*offset) -= (4-strlen(buf));
+
+			for (len = 1; len == 1; len = read(fd, &loop, 1)) {
+				if (loop == '|')
+					break;
+			}
+
+			*size = (short)(lseek(fd, 0, SEEK_CUR) - *offset) - 1;
+			lseek(fd, -1, SEEK_CUR);
+			break;
+		}
+	}
+	return 0;
+}
+

Added: trunk/misc/rawfilesgen.cpp
===================================================================
--- trunk/misc/rawfilesgen.cpp	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/rawfilesgen.cpp	2005-05-03 11:19:27 UTC (rev 36)
@@ -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);
+	}
+}

Added: trunk/misc/rawldidx.c
===================================================================
--- trunk/misc/rawldidx.c	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/rawldidx.c	2005-05-03 11:19:27 UTC (rev 36)
@@ -0,0 +1,96 @@
+/*****************************************************************************
+ * Bible dictionary index utility
+ */
+
+
+#ifndef __GNUC__
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+char findbreak(int fd, long *offset, short *size)
+{
+	char buf[3];
+	char rc = 1;
+	long offset2;
+
+	memset(buf, 0, sizeof(buf));
+
+	while (read(fd, &buf[sizeof(buf)-1], 1) == 1) {
+		if ((buf[0] == 10) && (buf[1] == '$') && (buf[2] == '$')) {
+			while (read(fd, buf, 1) == 1) {
+				if (*buf == 10) {
+					if (read(fd, buf, 1) == 1) {
+						*offset = lseek(fd, 0, SEEK_CUR);
+						rc = 0;
+						if (size) {
+							if (!findbreak(fd, &offset2, 0))
+								*size = offset2 - *offset - 13;
+							else *size = lseek(fd, 0, SEEK_END) - *offset;
+							lseek(fd, *offset, SEEK_SET);
+						}
+						break;
+					}
+				}
+			}
+			break;
+		}
+		memmove(buf, &buf[1], sizeof(buf)-1);
+	}
+	return rc;
+}
+
+
+void main(int argc, char **argv)
+{
+	int   fd, ifd;
+	long  offset;
+	short size;
+	char  *buf;
+
+	if (argc < 2) {
+		fprintf(stderr, "usage: %s <file to process (no .dat)>\n", argv[0]);
+		exit(1);
+	}
+
+	buf = (char *) calloc(strlen(argv[1]) + 5, 1);
+
+#ifndef O_BINARY		// O_BINARY is for Borland to be happy.  If we're in GNU, just define it to a NULL mask
+#define O_BINARY 0
+#endif
+	sprintf(buf, "%s.dat", argv[1]);
+	fd = open(buf, O_RDONLY|O_BINARY);
+
+	sprintf(buf, "%s.idx", argv[1]);
+	ifd = open(buf, O_CREAT|O_WRONLY|O_BINARY);
+
+	offset = 0;				/* write offset for intro */
+	write(ifd, &offset, 4);
+	findbreak(fd, &offset, 0);
+	lseek(fd, 0L, SEEK_SET);
+	size = offset - 12;
+	write(ifd, &size, 2);
+
+	buf[3] = 0;				/* delimit string for read below */
+
+	while(!findbreak(fd, &offset, &size)) {
+		write(ifd, &offset, 4);
+		write(ifd, &size, 2);
+		read(fd, buf, 3);
+		printf("Found: %s...(%ld:%d)\n", buf, offset, size);
+	}
+
+	free(buf);
+
+	close(ifd);
+	close(fd);
+}

Added: trunk/misc/rawtxidx.c
===================================================================
--- trunk/misc/rawtxidx.c	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/rawtxidx.c	2005-05-03 11:19:27 UTC (rev 36)
@@ -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;
+	}
+}
+

Added: trunk/misc/rtfidx.cpp
===================================================================
--- trunk/misc/rtfidx.cpp	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/rtfidx.cpp	2005-05-03 11:19:27 UTC (rev 36)
@@ -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";
+}

Added: trunk/misc/rwpidx.cpp
===================================================================
--- trunk/misc/rwpidx.cpp	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/rwpidx.cpp	2005-05-03 11:19:27 UTC (rev 36)
@@ -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";
+}

Added: trunk/misc/strongsidx.c
===================================================================
--- trunk/misc/strongsidx.c	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/strongsidx.c	2005-05-03 11:19:27 UTC (rev 36)
@@ -0,0 +1,90 @@
+/*****************************************************************************
+ * Bible dictionary index utility
+ */
+
+
+#ifndef __GNUC__
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+char findbreak(int fd, long *offset, short *size)
+{
+	char buf[3];
+	char rc = 1;
+	long offset2;
+
+	memset(buf, 0, sizeof(buf));
+
+	while (read(fd, &buf[sizeof(buf)-1], 1) == 1) {
+		if ((buf[0] == 10) && (isdigit(buf[1])) && (isdigit(buf[2]))) {
+			if (read(fd, buf, 1) == 1) {
+				*offset = lseek(fd, 0, SEEK_CUR) - 3;
+				rc = 0;
+				if (size) {
+					if (!findbreak(fd, &offset2, 0))
+						*size = offset2 - *offset;
+					else *size = lseek(fd, 0, SEEK_END) - *offset;
+					lseek(fd, *offset, SEEK_SET);
+				}
+				break;
+			}
+			break;
+		}
+		memmove(buf, &buf[1], sizeof(buf)-1);
+	}
+	return rc;
+}
+
+
+void main(int argc, char **argv)
+{
+	int   fd, ifd;
+	long  offset;
+	short size;
+	char  *buf;
+	char  entbuf[6];
+
+	if (argc < 2) {
+		fprintf(stderr, "usage: %s <file to process (no .dat)>\n", argv[0]);
+		exit(1);
+	}
+
+	buf = (char *) calloc(strlen(argv[1]) + 5, 1);
+
+	sprintf(buf, "%s.dat", argv[1]);
+	fd = open(buf, O_RDONLY);
+
+	sprintf(buf, "%s.idx", argv[1]);
+	ifd = open(buf, O_CREAT|O_WRONLY);
+
+	offset = 0;				/* write offset for intro */
+	write(ifd, &offset, 4);
+	findbreak(fd, &offset, 0);
+	lseek(fd, 0L, SEEK_SET);
+	size = offset - 12;
+	write(ifd, &size, 2);
+
+	entbuf[5] = 0;				/* delimit string for read below */
+
+	while(!findbreak(fd, &offset, &size)) {
+		write(ifd, &offset, 4);
+		write(ifd, &size, 2);
+		read(fd, entbuf, 5);
+		printf("Found: %s...(%ld:%d)\n", entbuf, offset, size);
+	}
+
+	free(buf);
+
+	close(ifd);
+	close(fd);
+}

Added: trunk/misc/svetxidx.c
===================================================================
--- trunk/misc/svetxidx.c	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/svetxidx.c	2005-05-03 11:19:27 UTC (rev 36)
@@ -0,0 +1,153 @@
+#include <stdio.h>
+#include <fcntl.h>
+#ifndef __GNUC__
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
+
+char findbreak(int fd, long *offset, int *num1, int *num2, short *size);
+
+
+main(int argc, char **argv)
+{
+	int fd, vfd, cfd, bfd;
+	long pos, offset;
+	short size, tmp;
+	int num1, num2, curbook = 0, curchap = 0, curverse = 0;
+	char buf[127];
+
+	if (argc != 2) {
+		fprintf(stderr, "usage: %s <file to process>\n", argv[0]);
+		exit(1);
+	}
+#ifndef O_BINARY		// O_BINARY is for Borland to be happy.  If we're in GNU, just define it to a NULL mask
+#define O_BINARY 0
+#endif
+	if ((fd = open(argv[1], O_RDONLY|O_BINARY)) == -1) {
+		fprintf(stderr, "Couldn't open file: %s\n", argv[1]);
+		exit(1);
+	}
+
+	sprintf(buf, "%s.vss", argv[1]);
+	if ((vfd = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+		fprintf(stderr, "Couldn't open file: %s\n", buf);
+		exit(1);
+	}
+
+	sprintf(buf, "%s.cps", argv[1]);
+	if ((cfd = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+		fprintf(stderr, "Couldn't open file: %s\n", buf);
+		exit(1);
+	}
+
+	sprintf(buf, "%s.bks", argv[1]);
+	if ((bfd = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+		fprintf(stderr, "Couldn't open file: %s\n", buf);
+		exit(1);
+	}
+
+	pos  = 0;
+	write(bfd, &pos, 4);  /* Book    offset for testament intros */
+	pos = 4;
+	write(cfd, &pos, 4);  /* Chapter offset for testament intro */
+
+
+/*	Right now just zero out intros until parsing correctly */
+	pos = 0;
+	size = 0;
+	write(vfd, &pos, 4);  /* Module intro */
+	write(vfd, &size, 2);
+	write(vfd, &pos, 4);  /* Testament intro */
+	write(vfd, &size, 2);
+
+	while (!findbreak(fd, &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(cfd, 0, SEEK_CUR);
+				write(bfd, &pos, 4);
+				pos = lseek(vfd, 0, SEEK_CUR); /* Book intro (cps) */
+				write(cfd, &pos, 4);
+				pos  = 0;
+				tmp = 0;
+				write(vfd, &pos, 4);  /* Book intro (vss) */
+				write(vfd, &tmp, 2);
+				curbook++;
+				curchap = 0;
+			}
+			pos = lseek(vfd, 0, SEEK_CUR);
+			write(cfd, &pos, 4);
+			curverse = 1;
+			pos  = 0;
+			tmp = 0;
+			write(vfd, &pos, 4);  /* Chapter intro */
+			write(vfd, &tmp, 2);
+			curchap++;
+		}
+		else curverse++;
+	
+		printf("%2d:%3d:%3d found at offset: %7ld\n", curbook, num1, num2, offset);
+
+		if (num1 != curchap) {
+			fprintf(stderr, "Error: Found chaptures out of sequence (%2d:%3d:%3d)\n", curbook, num1-1, num2);
+			curchap = num1;
+//			break;
+		}
+		if (num2 != curverse) {
+			fprintf(stderr, "Error: Found verses out of sequence (%2d:%3d:%3d)\n", curbook, num1, num2-1);
+//			break;
+			tmp = 0;
+			curverse = num2;
+			write(vfd, &offset, 4);
+			write(vfd, &tmp, 2);
+		}
+		write(vfd, &offset, 4);
+		write(vfd, &size, 2);
+	}
+	
+	close(vfd);
+	close(cfd);
+	close(bfd);
+	close(fd);
+}
+
+
+char findbreak(int fd, long *offset, int *num1, int *num2, short *size)
+{
+	char buf[8];
+	char buf2[7];
+	char loop, len;
+
+	memset(buf, ' ', 7);
+	buf[7] = 0;
+
+	while (1) {
+
+		memmove(buf, &buf[1], 6);
+		if (read(fd, &buf[6], 1) != 1)
+			return 1;
+
+		if ((buf[0] == 10) && (isdigit(buf[1]))) {
+			sscanf(buf, "%d %s", num2, buf2);
+			if (!strncmp(buf2, "KAP", 3)) {
+				*num1 = *num2;
+				continue;
+			}
+			sprintf(buf, "%d", *num2);
+			(*offset)  = lseek(fd, 0, SEEK_CUR);
+			(*offset) -= (5-strlen(buf));
+			for (len = 1; len == 1; len = read(fd, &loop, 1)) {
+				if ((loop == 10) || (loop == 13))
+					break;
+			}
+
+			*size = (short)(lseek(fd, 0, SEEK_CUR) - *offset) - 1;
+			lseek(fd, -1, SEEK_CUR);
+			break;
+		}
+	}
+	return 0;
+}
+

Added: trunk/misc/vntidx.cpp
===================================================================
--- trunk/misc/vntidx.cpp	2005-04-13 20:05:33 UTC (rev 35)
+++ trunk/misc/vntidx.cpp	2005-05-03 11:19:27 UTC (rev 36)
@@ -0,0 +1,185 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <versekey.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];
+	VerseKey mykey;
+
+	if ((argc < 2) || (argc > 3)) {
+		fprintf(stderr, "usage: %s <file to process> [nt]\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);
+
+	mykey = (argc == 3) ? "Matthew 1:1" : "Genesis 1:1";
+
+	while (!findbreak(fp, &offset, &num1, &num2, &size)) {
+		num1 = mykey.Chapter();
+		num2 = mykey.Verse();
+		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");
+			break;
+		}
+		if (num2 != curverse) {
+			fprintf(stderr, "Error: Found verses out of sequence\n");
+			break;
+		}
+		write(vfp, &offset, 4);
+		write(vfp, &size, 2);
+		mykey++;
+	}
+	
+	close(vfp);
+	close(cfp);
+	close(bfp);
+	close(fp);
+}
+
+
+char findbreak(int fp, int *offset, int *num1, int *num2, short *size)
+{
+	char buf[17];
+	char buf2[7];
+	char buf3[7];
+	char loop;
+	char offadj, inquotes, sizeadj;
+	int offset2, ch2, vs2;
+	
+	strcpy (buf3, "\\par  ");
+	buf3[5] = 10;
+	memset(buf, ' ', 17);
+
+	while (1) {
+		offadj = -100;
+		inquotes = 0;
+		sizeadj = 0;
+  		if (!memcmp(buf, "\\par FIN DEL NUEVO TESTAMENTO", 16)) {
+			offadj = -11;
+//			inquotes = 1;
+			sizeadj = -7;
+		}
+		
+  		if ((!memcmp(buf, buf3, 6)) && (!size)) {
+			offadj = -11;
+//			inquotes = 1;
+			sizeadj = -7;
+		}
+  		if (!memcmp(buf, "\\par  ", 6)) {
+			if (isdigit(buf[6])) {
+				for (loop = 7; loop < 10; loop++) {
+					if (!isdigit(buf[loop]))
+						break;
+				}
+				offadj = -(11 - (loop - 6));
+	//			inquotes = 1;
+				sizeadj = -7;
+			}
+		}
+/*
+  		if (!memcmp(buf, "\\fi200\\widctlpar", 16)) {
+			offadj = -1;
+//			inquotes = 1;
+			sizeadj = -18;
+		}
+*/
+		if (offadj > -100) {
+			*offset = lseek(fp, 0, SEEK_CUR) + offadj;
+			if (size) {
+				(*offset)++;
+				while (inquotes) {
+					while (read(fp, buf2, 1) == 1) {
+						if (*buf2 == '}')
+							break;
+						(*offset)++;
+					}
+					inquotes--;
+				}
+				if (findbreak(fp, &offset2, &ch2, &vs2, 0)) {
+					*size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
+				}
+				else {
+					*size = (offset2 - (*offset));
+				}
+				lseek(fp, *offset-sizeadj, SEEK_SET);
+			}
+			else (*offset) += sizeadj;
+			return 0;
+		}
+		memmove(buf, &buf[1], 16);
+		if (read(fp, &buf[16], 1) != 1)
+			return 1;
+	}
+}
+



More information about the sword-cvs mailing list