diff options
author | danglassey <danglassey> | 2002-08-14 09:57:17 +0000 |
---|---|---|
committer | danglassey <danglassey> | 2002-08-14 09:57:17 +0000 |
commit | c9458897ebbb739d8db83c80e06512d8a612f743 (patch) | |
tree | f8c5381045887e34388cc6b26cfccc254bf766dc /src/modules/comments/rawcom | |
download | sword-sf-cvs-c9458897ebbb739d8db83c80e06512d8a612f743.tar.gz |
*** empty log message ***
Diffstat (limited to 'src/modules/comments/rawcom')
-rw-r--r-- | src/modules/comments/rawcom/Makefile | 5 | ||||
-rw-r--r-- | src/modules/comments/rawcom/Makefile.am | 4 | ||||
-rw-r--r-- | src/modules/comments/rawcom/mhcidx.cpp | 292 | ||||
-rw-r--r-- | src/modules/comments/rawcom/rawcom.cpp | 221 | ||||
-rw-r--r-- | src/modules/comments/rawcom/rtfidx.cpp | 292 | ||||
-rw-r--r-- | src/modules/comments/rawcom/rwpidx.cpp | 266 |
6 files changed, 1080 insertions, 0 deletions
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..f71b6ec --- /dev/null +++ b/src/modules/comments/rawcom/rawcom.cpp @@ -0,0 +1,221 @@ +/****************************************************************************** + * 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::getRawEntry() - 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; + + try { + key = SWDYNAMIC_CAST(VerseKey, this->key); + } + catch ( ... ) {} + 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; + + readtext(key->Testament(), start, (size + 2), entrybuf); + + rawFilter(entrybuf, size, key); + + if (!isUnicode()) + preptext(entrybuf); + + if (key != this->key) + delete key; + + return entrybuf; +} + + +/****************************************************************************** + * RawCom::increment - Increments module key a number of entries + * + * ENT: steps - Number of entries to jump forward + * + * RET: *this + */ + +void RawCom::increment(int steps) { + long start; + unsigned short size; + VerseKey *tmpkey = 0; + + try { + tmpkey = SWDYNAMIC_CAST(VerseKey, key); + } + catch ( ... ) {} + if (!tmpkey) + tmpkey = new VerseKey(key); + + findoffset(tmpkey->Testament(), tmpkey->Index(), &start, &size); + + SWKey lastgood = *tmpkey; + while (steps) { + long laststart = start; + unsigned short lastsize = size; + SWKey lasttry = *tmpkey; + (steps > 0) ? (*key)++ : (*key)--; + if (tmpkey != key) + delete tmpkey; + tmpkey = 0; + try { + tmpkey = SWDYNAMIC_CAST(VerseKey, key); + } + catch ( ... ) {} + 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)) // we're a different entry + && (start > 0) && (size)) // and we actually have a size + ||(!skipConsecutiveLinks)) { // or we don't want to skip consecutive links + steps += (steps < 0) ? 1 : -1; + lastgood = *tmpkey; + } + } + error = (error) ? KEYERR_OUTOFBOUNDS : 0; + + if (tmpkey != key) + delete tmpkey; +} + + +void RawCom::setEntry(const char *inbuf, long len) { + VerseKey *key = 0; + // see if we have a VerseKey * or decendant + try { + key = SWDYNAMIC_CAST(VerseKey, this->key); + } + catch ( ... ) {} + // 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; +} + + +void RawCom::linkEntry(const SWKey *inkey) { + VerseKey *destkey = 0; + const VerseKey *srckey = 0; + // see if we have a VerseKey * or decendant + try { + destkey = SWDYNAMIC_CAST(VerseKey, this->key); + } + catch ( ... ) {} + // 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 + try { + srckey = SWDYNAMIC_CAST(VerseKey, inkey); + } + catch ( ... ) {} + // 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; +} + + +/****************************************************************************** + * RawCom::deleteEntry - deletes this entry + * + * RET: *this + */ + +void RawCom::deleteEntry() { + + VerseKey *key = 0; + + try { + key = SWDYNAMIC_CAST(VerseKey, this->key); + } + catch ( ... ) {} + 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"; +} |