diff options
Diffstat (limited to 'src/modules/comments/rawfiles')
-rw-r--r-- | src/modules/comments/rawfiles/Makefile | 5 | ||||
-rw-r--r-- | src/modules/comments/rawfiles/Makefile.am | 3 | ||||
-rw-r--r-- | src/modules/comments/rawfiles/rawfiles.cpp | 291 | ||||
-rw-r--r-- | src/modules/comments/rawfiles/rawfilesgen.cpp | 236 |
4 files changed, 535 insertions, 0 deletions
diff --git a/src/modules/comments/rawfiles/Makefile b/src/modules/comments/rawfiles/Makefile new file mode 100644 index 0000000..35d6648 --- /dev/null +++ b/src/modules/comments/rawfiles/Makefile @@ -0,0 +1,5 @@ + +root := ../../../.. + +all: + make -C ${root} diff --git a/src/modules/comments/rawfiles/Makefile.am b/src/modules/comments/rawfiles/Makefile.am new file mode 100644 index 0000000..53aadbe --- /dev/null +++ b/src/modules/comments/rawfiles/Makefile.am @@ -0,0 +1,3 @@ +rawfilesdir = $(top_srcdir)/src/modules/comments/rawfiles + +libsword_la_SOURCES += $(rawfilesdir)/rawfiles.cpp diff --git a/src/modules/comments/rawfiles/rawfiles.cpp b/src/modules/comments/rawfiles/rawfiles.cpp new file mode 100644 index 0000000..c8e9388 --- /dev/null +++ b/src/modules/comments/rawfiles/rawfiles.cpp @@ -0,0 +1,291 @@ +/****************************************************************************** + * rawfiles.cpp - code for class 'RawFiles'- a module that produces HTML HREFs + * pointing to actual text desired. Uses standard + * files: ot and nt using indexs ??.bks ??.cps ??.vss + */ + + +#include <ctype.h> +#include <stdio.h> +#include <fcntl.h> + +#ifndef __GNUC__ +#include <io.h> +#else +#include <unistd.h> +#endif + +#include <string.h> +#include <utilfuns.h> +#include <rawverse.h> +#include <rawfiles.h> +#include <filemgr.h> + +#ifndef O_BINARY // O_BINARY is needed in Borland C++ 4.53 +#define O_BINARY 0 // If it hasn't been defined than we probably +#endif // don't need it. + + + /****************************************************************************** + * RawFiles Constructor - Initializes data for instance of RawFiles + * + * ENT: iname - Internal name for module + * idesc - Name to display to user for module + * idisp - Display object to use for displaying + */ + +RawFiles::RawFiles(const char *ipath, const char *iname, const char *idesc, SWDisplay *idisp, SWTextEncoding enc, SWTextDirection dir, SWTextMarkup mark, const char* ilang) : RawVerse(ipath, O_RDWR), SWCom(iname, idesc, idisp, enc, dir, mark, ilang) +{ +} + + +/****************************************************************************** + * RawFiles Destructor - Cleans up instance of RawFiles + */ + +RawFiles::~RawFiles() +{ +} + + +/****************************************************************************** + * RawFiles::operator char * - Returns the correct verse when char * cast + * is requested + * + * RET: string buffer with verse + */ + +char *RawFiles::getRawEntry() { + FileDesc *datafile; + long start = 0; + unsigned short size = 0; + char *tmpbuf; + VerseKey *key = 0; + +#ifndef _WIN32_WCE + try { +#endif + key = SWDYNAMIC_CAST(VerseKey, this->key); +#ifndef _WIN32_WCE + } + catch ( ... ) {} +#endif + if (!key) + key = new VerseKey(this->key); + + findoffset(key->Testament(), key->Index(), &start, &size); + + if (entrybuf) + delete [] entrybuf; + + if (size) { + tmpbuf = new char [ (size + 2) + strlen(path) + 5 ]; + sprintf(tmpbuf,"%s/",path); + gettext(key->Testament(), start, (size + 2), tmpbuf+strlen(tmpbuf)); + datafile = FileMgr::systemFileMgr.open(tmpbuf, O_RDONLY|O_BINARY); + delete [] tmpbuf; + if (datafile->getFd() > 0) { + size = lseek(datafile->getFd(), 0, SEEK_END); + entrybuf = new char [ size * FILTERPAD ]; + memset(entrybuf, 0, size * FILTERPAD); + lseek(datafile->getFd(), 0, SEEK_SET); + read(datafile->getFd(), entrybuf, size); + preptext(entrybuf); + } + else { + entrybuf = new char [2]; + entrybuf[0] = 0; + entrybuf[1] = 0; + } + FileMgr::systemFileMgr.close(datafile); + } + else { + entrybuf = new char [2]; + entrybuf[0] = 0; + entrybuf[1] = 0; + } + + if (key != this->key) + delete key; + + return entrybuf; +} + + +/****************************************************************************** + * RawFiles::operator << (char *)- Update the modules current key entry with + * provided text + * + * RET: *this + */ + +SWModule &RawFiles::operator <<(const char *inbuf) { + FileDesc *datafile; + long start; + unsigned short size; + char *tmpbuf; + VerseKey *key = 0; + +#ifndef _WIN32_WCE + try { +#endif + key = SWDYNAMIC_CAST(VerseKey, this->key); +#ifndef _WIN32_WCE + } + catch ( ... ) {} +#endif + if (!key) + key = new VerseKey(this->key); + + findoffset(key->Testament(), key->Index(), &start, &size); + + if (size) { + tmpbuf = new char [ (size + 2) + strlen(path) + 1 ]; + sprintf(tmpbuf, "%s/", path); + gettext(key->Testament(), start, (size + 2), tmpbuf+strlen(tmpbuf)); + } + else { + tmpbuf = new char [ 16 + strlen(path) + 1 ]; + sprintf(tmpbuf, "%s/%s", path, getnextfilename()); + settext(key->Testament(), key->Index(), tmpbuf+strlen(path)+1); + } + datafile = FileMgr::systemFileMgr.open(tmpbuf, O_CREAT|O_WRONLY|O_BINARY|O_TRUNC); + delete [] tmpbuf; + if (datafile->getFd() > 0) { + write(datafile->getFd(), inbuf, strlen(inbuf)); + } + FileMgr::systemFileMgr.close(datafile); + + if (key != this->key) + delete key; + + return *this; +} + + +/****************************************************************************** + * RawFiles::operator << (SWKey *)- Link the modules current key entry with + * another module entry + * + * RET: *this + */ + +SWModule &RawFiles::operator <<(const SWKey *inkey) { + + long start; + unsigned short size; + char *tmpbuf; + const VerseKey *key = 0; + +#ifndef _WIN32_WCE + try { +#endif + key = SWDYNAMIC_CAST(VerseKey, inkey); +#ifndef _WIN32_WCE + } + catch ( ... ) {} +#endif + if (!key) + key = new VerseKey(this->key); + + findoffset(key->Testament(), key->Index(), &start, &size); + + if (size) { + tmpbuf = new char [ size + 2]; + gettext(key->Testament(), start, size + 2, tmpbuf); + + if (key != inkey) + delete key; + key = 0; + +#ifndef _WIN32_WCE + try { +#endif + key = SWDYNAMIC_CAST(VerseKey, inkey); +#ifndef _WIN32_WCE + } + catch ( ... ) {} +#endif + if (!key) + key = new VerseKey(this->key); + settext(key->Testament(), key->Index(), tmpbuf); + } + + if (key != inkey) + delete key; + + return *this; +} + + +/****************************************************************************** + * RawFiles::deleteEntry - deletes this entry + * + * RET: *this + */ + +void RawFiles::deleteEntry() { + + VerseKey *key = 0; + +#ifndef _WIN32_WCE + try { +#endif + key = SWDYNAMIC_CAST(VerseKey, this->key); +#ifndef _WIN32_WCE + } + catch ( ... ) {} +#endif + if (!key) + key = new VerseKey(this->key); + + settext(key->Testament(), key->Index(), ""); + + if (key != this->key) + delete key; +} + + +/****************************************************************************** + * RawFiles::getnextfilename - generates a valid filename in which to store + * an entry + * + * RET: filename + */ + +char *RawFiles::getnextfilename() { + static char incfile[255]; + long number; + FileDesc *datafile; + + sprintf(incfile, "%s/incfile", path); + datafile = FileMgr::systemFileMgr.open(incfile, O_RDONLY|O_BINARY); + if (read(datafile->getFd(), &number, 4) != 4) + number = 0; + number++; + FileMgr::systemFileMgr.close(datafile); + + datafile = FileMgr::systemFileMgr.open(incfile, O_CREAT|O_WRONLY|O_BINARY|O_TRUNC); + write(datafile->getFd(), &number, 4); + FileMgr::systemFileMgr.close(datafile); + sprintf(incfile, "%.7ld", number-1); + return incfile; +} + + +char RawFiles::createModule (const char *path) { + char *incfile = new char [ strlen (path) + 16 ]; + static long zero = 0; + FileDesc *datafile; + + sprintf(incfile, "%s/incfile", path); + datafile = FileMgr::systemFileMgr.open(incfile, O_CREAT|O_WRONLY|O_BINARY|O_TRUNC); + delete [] incfile; + write(datafile->getFd(), &zero, 4); + FileMgr::systemFileMgr.close(datafile); + + return RawVerse::createModule (path); +} + + + diff --git a/src/modules/comments/rawfiles/rawfilesgen.cpp b/src/modules/comments/rawfiles/rawfilesgen.cpp new file mode 100644 index 0000000..f60c9e2 --- /dev/null +++ b/src/modules/comments/rawfiles/rawfilesgen.cpp @@ -0,0 +1,236 @@ +/***************************************************************************** + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> + +#ifndef __GNUC__ +#include <io.h> +#else +#include <unistd.h> +#endif + +#include <fcntl.h> +#include <versekey.h> + +#ifndef O_BINARY + #define O_BINARY 0 +#endif + +void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size); +char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size); +void openfiles(); +void checkparams(int argc, char **argv); +void charsetconvert(char *data); + + +VerseKey key1, key2, key3; +int fp, vfp, cfp, bfp; +long chapoffset; +short chapsize; +char testmnt; +char startflag = 0; + + +main(int argc, char **argv) +{ + long pos, offset; + int num1, num2, rangemax, curbook = 0, curchap = 0, curverse = 0; + char buf[127]; + short size, tmp; + extern struct zonline online; + + checkparams(argc, argv); + + key1 = key2 = key3 = "Genesis 1:1"; + + openfiles(); + + num1 = key1.Chapter(); + num2 = key1.Verse(); + + while(!findbreak(fp, &offset, &num1, &num2, &rangemax, &size)) { + if (!startflag) { + startflag = 1; + } + else { + if (num2 < key2.Verse()) { // new chapter + if (num1 <= key2.Chapter()) { // new book + key2.Verse(1); + key2.Chapter(1); + key2.Book(key2.Book()+1); + } + printf("Created Empty Entry: %d ('%s')\n", num1, (const char *)key2); + chapoffset = offset; + chapsize = size; +// continue; + } + } + key2.Verse(1); + key2.Chapter(num1); + key2.Verse(num2); + + key3 = key2; +// key3 += (rangemax - key3.Verse()); + + writeidx(key1, key2, key3, offset, size); + } + close(vfp); + close(cfp); + close(bfp); + close(fp); +} + + +/************************************************************************** + * ENT: key1 - current location of index + * key2 - minimum keyval for which this offset is valid + * key3 - maximum keyval for which this offset is valid + */ + +void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size) +{ + long pos; + short tmp; + + if (key1.Verse() == 1) { // new chapter + if (key1.Chapter() == 1) { // new book + pos = lseek(cfp, 0, SEEK_CUR); + write(bfp, &pos, 4); + pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */ + write(cfp, &pos, 4); + write(vfp, &chapoffset, 4); /* Book intro (vss) set to same as chap for now(it should be chap 1 which usually contains the book into anyway)*/ + write(vfp, &chapsize, 2); + } + pos = lseek(vfp, 0, SEEK_CUR); + write(cfp, &pos, 4); + write(vfp, &chapoffset, 4); /* Chapter intro */ + write(vfp, &chapsize, 2); + } + if (key1 >= key2) { + write(vfp, &offset, 4); + size = 0; + write(vfp, &size, 2); + } + else { + pos = 0; + tmp = 0; + write(vfp, &pos, 4); + write(vfp, &tmp, 2); + } + key1++; +} + + +static VerseKey inckey = "Genesis 1:1"; + +char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size) +{ + char buf[7]; + char buf2[20]; + char ch; + char loop; + long offset2; + int ch2, vs2, rm2; + bool flag; + long chapstart = 0; + static int olbvnum = 0; + char data[16]; + + memset (data,0,16); + + if (++olbvnum <= 31102) { + + if (olbvnum == 23146) { // "Matthew 1:1" + close(vfp); + close(cfp); + close(bfp); + close(fp); + key1 = key2 = key3 = inckey = "Matthew 1:1"; + openfiles(); + startflag = 0; + } + + + *offset = lseek(fp, 0, SEEK_CUR); + + if ((olbvnum!=1) && (olbvnum != 23146)) + inckey++; + + *num1 = inckey.Chapter(); + *num2 = inckey.Verse(); + + + write(fp, data, 16); + + *size = lseek(fp, 0, SEEK_CUR) - *offset; + return 0; + } + return 1; +} + + +void openfiles() +{ + char buf[255]; + char fname[5]; + long pos; + short size; + + testmnt = key1.Testament(); + + strcpy(fname, (testmnt==2) ? "nt" : "ot"); + unlink(fname); + if ((fp = open(fname, O_CREAT|O_RDWR|O_BINARY)) == -1) { + fprintf(stderr, "Couldn't open file: %s\n", fname); + exit(1); + } + + sprintf(buf, "%s.vss", fname); + unlink(buf); + if ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) { + fprintf(stderr, "Couldn't open file: %s\n", buf); + exit(1); + } + + sprintf(buf, "%s.cps", fname); + unlink(buf); + if ((cfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) { + fprintf(stderr, "Couldn't open file: %s\n", buf); + exit(1); + } + + sprintf(buf, "%s.bks", fname); + unlink(buf); + if ((bfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) { + fprintf(stderr, "Couldn't open file: %s\n", buf); + exit(1); + } + + pos = 0; + write(bfp, &pos, 4); /* Book offset for testament intros */ + pos = 4; + write(cfp, &pos, 4); /* Chapter offset for testament intro */ + + +/* Right now just zero out intros until parsing correctly */ + pos = 0; + size = 0; + write(vfp, &pos, 4); /* Module intro */ + write(vfp, &size, 2); + write(vfp, &pos, 4); /* Testament intro */ + write(vfp, &size, 2); + +} + + +void checkparams(int argc, char **argv) +{ + if (argc !=1) { + fprintf(stderr, "usage: %s\n", argv[0]); + exit(1); + } +} |