From 82c9d8a327130d9b8e47526f9583f51d862ec96f Mon Sep 17 00:00:00 2001 From: Chris Little Date: Sat, 22 Jun 2013 09:21:20 +0000 Subject: moved this ancient, unmaintained, and unneeded converter from the sword SVN root git-svn-id: https://www.crosswire.org/svn/sword-tools/trunk@425 07627401-56e2-0310-80f4-f8cd0041bdcd --- misc/olb/Convert.bpr | 116 +++++++++++ misc/olb/Convert.cpp | 44 ++++ misc/olb/Doinit.c | 149 ++++++++++++++ misc/olb/Getstrng.c | 43 ++++ misc/olb/Getvrsn.c | 67 +++++++ misc/olb/Mainfrm.cpp | 327 ++++++++++++++++++++++++++++++ misc/olb/Mainfrm.dfm | Bin 0 -> 897 bytes misc/olb/Mainfrm.h | 69 +++++++ misc/olb/Online.c | 114 +++++++++++ misc/olb/addstrongs.cpp | 118 +++++++++++ misc/olb/dumpav.cpp | 46 +++++ misc/olb/olb.bpg | 26 +++ misc/olb/olb2sword.bpr | 112 +++++++++++ misc/olb/olb2sword.cpp | 312 +++++++++++++++++++++++++++++ misc/olb/online.ide | Bin 0 -> 40902 bytes misc/olb/online.prj | 1 + misc/olb/prn2sword.bpr | 123 ++++++++++++ misc/olb/prn2sword.cpp | 49 +++++ misc/olb/prn2swordfrm.cpp | 501 ++++++++++++++++++++++++++++++++++++++++++++++ misc/olb/prn2swordfrm.dfm | Bin 0 -> 2540 bytes misc/olb/prn2swordfrm.h | 54 +++++ 21 files changed, 2271 insertions(+) create mode 100644 misc/olb/Convert.bpr create mode 100644 misc/olb/Convert.cpp create mode 100644 misc/olb/Doinit.c create mode 100644 misc/olb/Getstrng.c create mode 100644 misc/olb/Getvrsn.c create mode 100644 misc/olb/Mainfrm.cpp create mode 100644 misc/olb/Mainfrm.dfm create mode 100644 misc/olb/Mainfrm.h create mode 100644 misc/olb/Online.c create mode 100644 misc/olb/addstrongs.cpp create mode 100644 misc/olb/dumpav.cpp create mode 100644 misc/olb/olb.bpg create mode 100644 misc/olb/olb2sword.bpr create mode 100644 misc/olb/olb2sword.cpp create mode 100644 misc/olb/online.ide create mode 100644 misc/olb/online.prj create mode 100644 misc/olb/prn2sword.bpr create mode 100644 misc/olb/prn2sword.cpp create mode 100644 misc/olb/prn2swordfrm.cpp create mode 100644 misc/olb/prn2swordfrm.dfm create mode 100644 misc/olb/prn2swordfrm.h diff --git a/misc/olb/Convert.bpr b/misc/olb/Convert.bpr new file mode 100644 index 0000000..ff704fb --- /dev/null +++ b/misc/olb/Convert.bpr @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +[Version Info] +IncludeVerInfo=0 +AutoIncBuild=0 +MajorVer=1 +MinorVer=0 +Release=0 +Build=0 +Debug=0 +PreRelease=0 +Special=0 +Private=0 +DLL=0 +Locale=1033 +CodePage=1252 + +[Version Info Keys] +CompanyName= +FileDescription= +FileVersion=1.0.0.0 +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion=1.0.0.0 +Comments= + +[HistoryLists\hlIncludePath] +Count=2 +Item0=..\src\utilfuns;..\src\keys;$(BCB)\include;$(BCB)\include\vcl;../include +Item1=$(BCB)\include;$(BCB)\include\vcl;../include + +[HistoryLists\hlLibraryPath] +Count=2 +Item0=..\src\utilfuns;..\src\keys;$(BCB)\lib\obj;$(BCB)\lib +Item1=$(BCB)\lib\obj;$(BCB)\lib + +[HistoryLists\hlDebugSourcePath] +Count=1 +Item0=$(BCB)\source\vcl + +[HistoryLists\hlConditionals] +Count=1 +Item0=_RTLDLL;USEPACKAGES + +[Debugging] +DebugSourceDirs=$(BCB)\source\vcl + +[Parameters] +RunParams= +HostApplication= +RemoteHost= +RemotePath= +RemoteDebug=0 + +[Compiler] +ShowInfoMsgs=0 +LinkDebugVcl=0 +LinkCGLIB=0 + +[Language] +ActiveLang= +ProjectLang= +RootDir= + + \ No newline at end of file diff --git a/misc/olb/Convert.cpp b/misc/olb/Convert.cpp new file mode 100644 index 0000000..9400324 --- /dev/null +++ b/misc/olb/Convert.cpp @@ -0,0 +1,44 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +//--------------------------------------------------------------------------- +#include +#pragma hdrstop +USERES("Convert.res"); +USEFORM("Mainfrm.cpp", Form1); +USEUNIT("all.c"); +USEUNIT("..\src\keys\versekey.cpp"); +USEUNIT("..\src\keys\strkey.cpp"); +USEUNIT("..\src\keys\swkey.cpp"); +USEUNIT("..\src\keys\listkey.cpp"); +USEUNIT("..\src\utilfuns\utilstr.cpp"); +//--------------------------------------------------------------------------- +WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) +{ + try + { + Application->Initialize(); + Application->CreateForm(__classid(TForm1), &Form1); + Application->Run(); + } + catch (Exception &exception) + { + Application->ShowException(&exception); + } + return 0; +} +//--------------------------------------------------------------------------- diff --git a/misc/olb/Doinit.c b/misc/olb/Doinit.c new file mode 100644 index 0000000..29a06ca --- /dev/null +++ b/misc/olb/Doinit.c @@ -0,0 +1,149 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +#include +struct zonline online; +struct zversion version; +struct zref ref; +struct zstdindex stdindex; +struct ztrace trace; +/* + Initialises the System + + Inputs: + pointer to path for files + e.g. c:\bible\scholar +*/ +void DOINIT(CHAR *olbpath) +{ + static CHAR *titles[10] = + {"\\id.dat", "\\text.dat", "\\textndx.dat", "\\tokens.dat", + "\\version.dat", "\\xref.dat", "\\xrefndx.dat", "\\xrefndxs.dat", + "\\cxref\\cxref.dat", "\\cxref\\cxrefndx.dat"}; + + CHAR path[64]; + static long int zero ={0}; + + struct + { + CHAR key; + CHAR size[2]; + INT indexsize; + int token_blksize; + } record; + + int i; + int j; + + /* + Open Files + */ + + trace.level = -1; + X("Doinit"); + for (i = 0; i < 8; i++) + { + STRCPY(path, olbpath, 64, "Doinit-1"); + STRCAT(path, titles[i], 64,"Doinit-2"); + call OPEN(i, path); + online.lrecl[i] = 0; + } + + /* + Initialise Version Structure + */ + call READ(fp_version, sizeof(version), &version.version_id); + call CLOSE(fp_version); + call DUMPLINE("VERSION.DAT", 16, &version.version_id); + /* convert PLI strings to C-Weed format */ +/* + for (i = 0; i < 128; i++) + call PLITOC(&(version.hot_words[i][0]), 9); +*/ + for (i = 0; i < 66; i++) + call PLITOC(&(version.books[i][0]), 15); + + /* + setup access to TEXT.DAT file + */ + call DREAD(fp_textndx, 3, &record.key, zero); + call DUMPLINE("TEXTNDX.DAT", 3, &record.key); + + online.textndxsz = record.size[0]; + if (record.key == 0) then + online.lrecl[fp_textndx] = 3; + else + online.lrecl[fp_textndx] = record.size[0]; + + /* + setup access to XREF.DAT file + */ + call DREAD(fp_xrefndx, 7, &record.key, zero); + call DUMPLINE("XREFNDX.DAT", 7, &record.key); + online.lrecl[fp_xrefndx] = record.size[0] + record.size[1]; + online.xrefndxsz[0] = record.size[0]; + online.xrefndxsz[1] = record.size[1]; + if (record.key == 2) then + { + online.indexsize = record.indexsize; + online.tokenblksize = record.token_blksize * 2; + online.tokenarea = &online.tokenwork[0]; + } + else + online.tokenblksize = 0; + /* + setup access to XREFNDXS.DAT file + */ + call DREAD(fp_xrefndxs, 3, &record.key, zero); + call DUMPLINE("XREFNDXS.DAT", 3, &record.key); + if (record.key == 0) then + online.lrecl[fp_xrefndxs] = 3; + else + online.lrecl[fp_xrefndxs] = record.size[0]; + + online.version_mark = 3; + /* + Setup Version ID for multiple versions + */ + call VERINIT(); + + /* + Setup Cross Reference Files + */ + for (i = 8; i < 10; i++) + { + STRCPY(path, olbpath, 64, "Doinit-3"); + j = strlen(path); + while(path[j] != '\\') + j--; + path[j] = 0; + STRCAT(path, titles[i], 64, "Doinit-4"); + call OPEN(i, path); + online.lrecl[i] = 0; + } + /* + setup access to CXREF.DAT file + */ + call DREAD(fp_cxrefndx, 3, &record.key, zero); + call DUMPLINE("CXREFNDX.DAT", 3, &record.key); + if (record.key == 0) then + online.lrecl[fp_cxrefndx] = 3; + else + online.lrecl[fp_cxrefndx] = record.size[0]; + trace.traceflag = 1; + Y(); +} diff --git a/misc/olb/Getstrng.c b/misc/olb/Getstrng.c new file mode 100644 index 0000000..4e87fd4 --- /dev/null +++ b/misc/olb/Getstrng.c @@ -0,0 +1,43 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +#include + +void GETSTRNG(strongs_no, verse_list, otflg) + + /* get verses for a given strongs no */ + +int strongs_no; /* strongs number to fetch verse list for */ +INT verse_list[MAX_LIST]; /* resultant verse list */ +CHAR otflg; /* Old Testament Number flag */ +{ + extern struct zversion version; + int entry_size; + long int seek_posn; + + X("Getstrng"); + if (strongs_no > 8849 || strongs_no < 0) then + ERROR("Getstrng - Invalid Strong's Number"); + + entry_size = READNDX(strongs_no, fp_xrefndxs, &seek_posn); + call LISTLOAD(fp_xref, entry_size, verse_list, seek_posn); + if (otflg == 0) then + call LISTRANG(verse_list, version.nt_ver, version.total_ver); + else + call LISTRANG(verse_list, 1, version.nt_ver - 1); + Y(); +} diff --git a/misc/olb/Getvrsn.c b/misc/olb/Getvrsn.c new file mode 100644 index 0000000..d447642 --- /dev/null +++ b/misc/olb/Getvrsn.c @@ -0,0 +1,67 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +#include + +/* + Get version id for display + + If triple verse A_B_C then + + Inputs: + 1 - returns "A" + 2 - returns "B" + 3 - returns "A_B" + 4 - returns "C" + 5 - returns "A_C" + 6 - returns "B_C" + 7 - returns "A_B_C" +*/ + +CHAR *GETVRSN(int version) +{ + extern struct zonline online; + static CHAR versionid[16]; + + X("Getvrsn"); + if (version < 1 || version > 7) then + call ERROR("Version Id Invalid"); + versionid[0] = 0; + if (version & 1) then + { + strcat(versionid, "_"); + STRCAT(versionid, &online.versions[0][0], 16, "Getrsn-1"); + } + if (version & 2) then + { + if (online.versions[1][0] != 0) then + { + strcat(versionid, "_"); + STRCAT(versionid, &online.versions[1][0], 16, "Getrsn-2"); + } + } + if (version & 4) then + { + if (online.versions[2][0] != 0) then + { + strcat(versionid, "_"); + STRCAT(versionid, &online.versions[2][0], 16, "Getrsn-3"); + } + } + Y(); + return(&versionid[1]); +} diff --git a/misc/olb/Mainfrm.cpp b/misc/olb/Mainfrm.cpp new file mode 100644 index 0000000..0a542db --- /dev/null +++ b/misc/olb/Mainfrm.cpp @@ -0,0 +1,327 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +//--------------------------------------------------------------------------- +#include +#pragma hdrstop + +#include "Mainfrm.h" +//--------------------------------------------------------------------------- +#pragma package(smart_init) +#pragma resource "*.dfm" + + + extern "C" { +#include "online.h" +} + +#include +#include +#include +#include + +#ifndef __GNUC__ +#include +#include +#else +#include +#endif + +#include +#include + + + + + +TForm1 *Form1; +//--------------------------------------------------------------------------- +__fastcall TForm1::TForm1(TComponent* Owner) + : TForm(Owner) +{ + +} +//--------------------------------------------------------------------------- + +int TForm1::ProcessOLB(char *filepath) +{ + 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); + startflag = 0; + + inckey = key1 = key2 = key3 = "Genesis 1:1"; + olbvnum = 0; + + openfiles(); + + num1 = key1.Chapter(); + num2 = key1.Verse(); + + DOINIT(filepath); /* initialize OLB system */ + + 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); + DOEND(); // close OLB system +} + + +/************************************************************************** + * 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 TForm1::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++; +} + + + +char TForm1::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; + short versedata[MAX_VERSE]; + char data[MAX_DATA]; + + + 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(); + + // output verse from olb +// printf("%s\n", (const char *)inckey); + GETEXT(olbvnum, versedata, 1, 1, 1, 1); + BLDVERSE(versedata, data); + charsetconvert(data); + write(fp, data, strlen(data)); + + *size = lseek(fp, 0, SEEK_CUR) - *offset; + write(fp, "\n", 1); + return 0; + } + return 1; +} + +void TForm1::charsetconvert(char *data) +{ + for (;*data; data++) { +// printf("%c %d", *data, *data); + switch((unsigned char)*data) { + case 129: *data = 252; break; + case 130: *data = 233; break; + case 131: *data = 226; break; + case 133: *data = 224; break; + case 135: *data = 231; break; + case 136: *data = 234; break; + case 137: *data = 235; break; + case 138: *data = 232; break; + case 139: *data = 239; break; + case 140: *data = 238; break; + case 144: *data = 201; break; + case 147: *data = 244; break; + case 150: *data = 251; break; + case 151: *data = 249; break; + case 160: *data = 225; break; + case 161: *data = 237; break; + case 162: *data = 243; break; + case 163: *data = 250; break; + case 164: *data = 241; break; + case 168: *data = 191; break; + case 173: *data = 161; break; + default: + if ((unsigned char)*data > 126) + fprintf(stderr, "Suspicious character: %c (%d); %s\n", *data, (unsigned char )*data, (const char *)inckey); + break; + } + } +} + + +void TForm1::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, S_IREAD|S_IWRITE)) == -1) { + sprintf(buf, "Couldn't open file: %s\n", fname); + MessageBox(this->Handle, buf, "openfiles()", MB_OK); + exit(1); + } + + sprintf(buf, "%s.vss", fname); + unlink(buf); + if ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE)) == -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, S_IREAD|S_IWRITE)) == -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, S_IREAD|S_IWRITE)) == -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 TForm1::checkparams(int argc, char **argv) +{ + if (argc < 2) { + fprintf(stderr, "usage: %s \n", argv[0]); + exit(1); + } +} +void __fastcall TForm1::FSButtonClick(TObject *Sender) +{ + FSDialog->FileName = "Text.dat"; + char *fname; + + if (FSDialog->Execute()) { + fname = new char [ strlen(FSDialog->FileName.c_str()) + 1 ]; + strcpy(fname, FSDialog->FileName.c_str()); + for (int i = strlen(fname) - 1; i; i--) { + if ((fname[i] != '\\') && (fname[i] != '/')) + fname[i] = 0; + else break; + } + FilePathEdit->Text = fname; + delete [] fname; + try { + RichEdit1->Lines->LoadFromFile(FilePathEdit->Text + "Copyrite.dat"); + } + catch (...) {} + } +} +//--------------------------------------------------------------------------- +void __fastcall TForm1::Button1Click(TObject *Sender) +{ + ProcessOLB(FilePathEdit->Text.c_str()); +} +//--------------------------------------------------------------------------- diff --git a/misc/olb/Mainfrm.dfm b/misc/olb/Mainfrm.dfm new file mode 100644 index 0000000..a92c4b8 Binary files /dev/null and b/misc/olb/Mainfrm.dfm differ diff --git a/misc/olb/Mainfrm.h b/misc/olb/Mainfrm.h new file mode 100644 index 0000000..ef8dcf6 --- /dev/null +++ b/misc/olb/Mainfrm.h @@ -0,0 +1,69 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +//--------------------------------------------------------------------------- +#ifndef MainfrmH +#define MainfrmH +//--------------------------------------------------------------------------- +#include +#include +#include +#include +#include +#include +#include +#include +//--------------------------------------------------------------------------- +class TForm1 : public TForm +{ +__published: // IDE-managed Components + TOpenDialog *FSDialog; + TPanel *Panel1; + TPanel *Panel2; + TButton *Button1; + TLabel *Label1; + TEdit *FilePathEdit; + TButton *FSButton; + TRichEdit *RichEdit1; + void __fastcall FSButtonClick(TObject *Sender); + void __fastcall Button1Click(TObject *Sender); +private: // User declarations + +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); +int ProcessOLB(char *filepath); + + +VerseKey key1, key2, key3; +int fp, vfp, cfp, bfp; +long chapoffset; +short chapsize; +char testmnt; +char startflag; +VerseKey inckey; +int olbvnum; + +public: // User declarations + __fastcall TForm1(TComponent* Owner); +}; +//--------------------------------------------------------------------------- +extern PACKAGE TForm1 *Form1; +//--------------------------------------------------------------------------- +#endif diff --git a/misc/olb/Online.c b/misc/olb/Online.c new file mode 100644 index 0000000..59653e8 --- /dev/null +++ b/misc/olb/Online.c @@ -0,0 +1,114 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +#include "online.dcl" + +/* + Online Bible Database Access Routines +*/ + +INT versedata[MAX_VERSE]; +INT verse_list[MAX_LIST]; +CHAR data[MAX_DATA]; + +void main(argc, argv) +int argc; +CHAR *argv[]; +{ + CHAR found, passage[64], *p; + int i, j; + INT word; +short verse_list[MAX_LIST]; + extern struct zonline online; + + if (argc > 1) + call DOINIT(argv[1]); /* initialise system */ + else + call DOINIT("g:\\bible\\av"); /* initialise system */ + + /* get text for Ge 1:1 & Rev 22:21 */ + + for (i = 1; i < 8; i++) + puts(GETVRSN(i)); + + verse_list[0] = 10; + for (i=1; i <= 8; i++) + verse_list[i] = i; + verse_list[9] = 31101; + verse_list[10] = 31102; + for (i = 1; i <= 10; i++) + puts(VRSTOREF(verse_list[i], 0)); + call DUMPVRS(verse_list, versedata, data); + + word = MAPWORD("Aaron", &found); /* map a word into an absolute number */ + call PUTLIST("Aaron=", word); + if (found == 0) then + puts("*Not Found"); + else + puts("*Found"); + call GETWORD(word, verse_list); /* get list of verses for a word */ + call DUMPVRS(verse_list, versedata, (CHAR *) data); + + /* first word in index */ + word = MAPWORD("a", &found); /* map a word into an absolute number */ + call PUTLIST("a=", word); + if (found == 0) then + puts("*Not Found"); + else + puts("*Found"); + call GETWORD(word, verse_list); /* get list of verses for a word */ + call DUMPVRS(verse_list, versedata, (CHAR *) data); + call GETSTRNG(1, verse_list, 0); /* get list of verses for Strong's */ + call DUMPVRS(verse_list, versedata, (CHAR *) data); + + /* last word in index */ + word = MAPWORD("Zuzims", &found); /* map a word into an absolute number */ + call PUTLIST("Zuzims=", word); + if (found == 0) then + puts("*Not Found"); + else + puts("*Found"); + + call GETWORD(word, verse_list); /* get list of verses for a word */ + call DUMPVRS(verse_list, versedata, (CHAR *) data); + + printf("\nCross References for Ge 1:1\n"); + call GETCXREF(1, verse_list); /* get cross-references for a verse */ + verse_list[1] = verse_list[66]; + verse_list[2] = verse_list[67]; + call DUMPVRS(verse_list, versedata, (CHAR *) data); + + for (i = 1; i <= 31102; i++) /* verify conversion routines work */ + { + if ((i % 1000) == 0) then + puts(DECIMAL(i)); + p = VRSTOREF(i, 0); + if (*p < '9' && *(p+1) == ' ') then + { /* fix book names like 1 Timothy -> 1Timothy */ + *(p+1) = *p; + *p = ' '; + } + j = REFTOVRS(p); + if (j != i) then + { + printf("i=%d, j=%d, ref=%s\n", i, j, p); + call ERROR("VRSTOREF - Error"); + } + } + + DOEND(); +} diff --git a/misc/olb/addstrongs.cpp b/misc/olb/addstrongs.cpp new file mode 100644 index 0000000..78d6a92 --- /dev/null +++ b/misc/olb/addstrongs.cpp @@ -0,0 +1,118 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +#include "online.dcl" +#include +#include +#include + +/* + Online Bible Database Access Routines +*/ + +INT versedata[MAX_VERSE]; +CHAR data[MAX_DATA]; + +void main(argc, argv) +int argc; +CHAR *argv[]; +{ + int fd; + CHAR found, passage[64], *p; + int i, j; + INT word; +short verse_list[MAX_LIST]; + extern struct zonline online; + + if (argc > 1) + call DOINIT(argv[1]); /* initialise system */ + else + call DOINIT("g:\\bible\\av"); /* initialise system */ + fd = open("../modules/texts/rawtext/kjv/ot", O_RDONLY, S_IREAD|S_IWRITE); + + /* get text for Ge 1:1 & Rev 22:21 */ + + for (i = 1; i < 8; i++) + puts(GETVRSN(i)); + + verse_list[0] = 10; + for (i=1; i <= 8; i++) + verse_list[i] = i; + verse_list[9] = 31101; + verse_list[10] = 31102; + for (i = 1; i <= 10; i++) + puts(VRSTOREF(verse_list[i], 0)); + call DUMPVRS(verse_list, versedata, data); + + word = MAPWORD("Aaron", &found); /* map a word into an absolute number */ + call PUTLIST("Aaron=", word); + if (found == 0) then + puts("*Not Found"); + else + puts("*Found"); + call GETWORD(word, verse_list); /* get list of verses for a word */ + call DUMPVRS(verse_list, versedata, (CHAR *) data); + + /* first word in index */ + word = MAPWORD("a", &found); /* map a word into an absolute number */ + call PUTLIST("a=", word); + if (found == 0) then + puts("*Not Found"); + else + puts("*Found"); + call GETWORD(word, verse_list); /* get list of verses for a word */ + call DUMPVRS(verse_list, versedata, (CHAR *) data); + call GETSTRNG(1, verse_list, 0); /* get list of verses for Strong's */ + call DUMPVRS(verse_list, versedata, (CHAR *) data); + + /* last word in index */ + word = MAPWORD("Zuzims", &found); /* map a word into an absolute number */ + call PUTLIST("Zuzims=", word); + if (found == 0) then + puts("*Not Found"); + else + puts("*Found"); + + call GETWORD(word, verse_list); /* get list of verses for a word */ + call DUMPVRS(verse_list, versedata, (CHAR *) data); + + printf("\nCross References for Ge 1:1\n"); + call GETCXREF(1, verse_list); /* get cross-references for a verse */ + verse_list[1] = verse_list[66]; + verse_list[2] = verse_list[67]; + call DUMPVRS(verse_list, versedata, (CHAR *) data); + + for (i = 1; i <= 31102; i++) /* verify conversion routines work */ + { + if ((i % 1000) == 0) then + puts(DECIMAL(i)); + p = VRSTOREF(i, 0); + if (*p < '9' && *(p+1) == ' ') then + { /* fix book names like 1 Timothy -> 1Timothy */ + *(p+1) = *p; + *p = ' '; + } + j = REFTOVRS(p); + if (j != i) then + { + printf("i=%d, j=%d, ref=%s\n", i, j, p); + call ERROR("VRSTOREF - Error"); + } + } + + DOEND(); +} diff --git a/misc/olb/dumpav.cpp b/misc/olb/dumpav.cpp new file mode 100644 index 0000000..5a07e6a --- /dev/null +++ b/misc/olb/dumpav.cpp @@ -0,0 +1,46 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +extern "C" { +#include "online.dcl" +} + +void main(int argc, char **argv) +{ + CHAR found, passage[64], *p; + int i, j; + INT word; + short verse_list[MAX_LIST]; + short versedata[MAX_VERSE]; + char data[MAX_DATA]; + extern struct zonline online; + int versenum = 0; + + + if (argc > 1) + call DOINIT(argv[1]); /* initialise system */ + else call DOINIT("g:\\bible\\av"); /* initialise system */ + + for (versenum = 23146; versenum <= 23147 /*31102*/; versenum++) { + call GETEXT(versenum, versedata, 1, 1, 1, 1); + call BLDVERSE(versedata, data); + printf("%s\n", VRSTOREF(versenum, 1)); +// printf("%s\n", data); + } + + DOEND(); +} diff --git a/misc/olb/olb.bpg b/misc/olb/olb.bpg new file mode 100644 index 0000000..d6cb8be --- /dev/null +++ b/misc/olb/olb.bpg @@ -0,0 +1,26 @@ +#------------------------------------------------------------------------------ +VERSION = BWS.01 +#------------------------------------------------------------------------------ +!ifndef ROOT +ROOT = $(MAKEDIR)\.. +!endif +#------------------------------------------------------------------------------ +MAKE = $(ROOT)\bin\make.exe -$(MAKEFLAGS) -f$** +DCC = $(ROOT)\bin\dcc32.exe $** +BRCC = $(ROOT)\bin\brcc32.exe $** +#------------------------------------------------------------------------------ +PROJECTS = Convert.exe olb2sword.exe prn2sword.exe +#------------------------------------------------------------------------------ +default: $(PROJECTS) +#------------------------------------------------------------------------------ + +Convert.exe: Convert.bpr + $(MAKE) + +olb2sword.exe: olb2sword.bpr + $(MAKE) + +prn2sword.exe: prn2sword.bpr + $(MAKE) + + diff --git a/misc/olb/olb2sword.bpr b/misc/olb/olb2sword.bpr new file mode 100644 index 0000000..f3b9c4a --- /dev/null +++ b/misc/olb/olb2sword.bpr @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +[Version Info] +IncludeVerInfo=0 +AutoIncBuild=0 +MajorVer=1 +MinorVer=0 +Release=0 +Build=0 +Debug=0 +PreRelease=0 +Special=0 +Private=0 +DLL=0 +Locale=1033 +CodePage=1252 + +[Version Info Keys] +CompanyName= +FileDescription=Executable (Console) +FileVersion=1.0.0.0 +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion=1.0.0.0 +Comments= + +[HistoryLists\hlIncludePath] +Count=2 +Item0=..\src\utilfuns;..\src\keys;$(BCB)\include;..\include +Item1=$(BCB)\include;../include + +[HistoryLists\hlLibraryPath] +Count=2 +Item0=..\src\utilfuns;..\src\keys;$(BCB)\lib +Item1=$(BCB)\lib + +[HistoryLists\hlRunParameters] +Count=2 +Item0=c:\bible\weyItem1=c:\bible\wey[Debugging] +Item1= + +[Debugging] +DebugSourceDirs= + +[Parameters] +RunParams=c:\bible\weyHostApplication= +HostApplication= +RemoteHost= +RemotePath= +RemoteDebug=0 + +[Compiler] +ShowInfoMsgs=0 +LinkDebugVcl=1 +LinkCGLIB=0 + +[Language] +ActiveLang= +ProjectLang= +RootDir= + + \ No newline at end of file diff --git a/misc/olb/olb2sword.cpp b/misc/olb/olb2sword.cpp new file mode 100644 index 0000000..925a13b --- /dev/null +++ b/misc/olb/olb2sword.cpp @@ -0,0 +1,312 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + + +#pragma hdrstop +#include + + +//--------------------------------------------------------------------------- +#pragma argsused +/***************************************************************************** + * + */ + + extern "C" { +#include "online.h" +} + +#include +#include +#include +#include + +#ifndef __GNUC__ +#include +#else +#include +#endif + +#include +#include + + +USEUNIT("..\src\keys\listkey.cpp"); +USEUNIT("..\src\keys\strkey.cpp"); +USEUNIT("..\src\keys\swkey.cpp"); +USEUNIT("..\src\keys\versekey.cpp"); +USEUNIT("..\src\utilfuns\utilstr.cpp"); +USEUNIT("all.c"); +//--------------------------------------------------------------------------- +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; +VerseKey inckey; + + +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); + + inckey = key1 = key2 = key3 = "Genesis 1:1"; + + openfiles(); + + num1 = key1.Chapter(); + num2 = key1.Verse(); + + DOINIT(argv[1]); /* initialize OLB system */ + + 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); + DOEND(); // close OLB system +} + + +/************************************************************************** + * 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++; +} + + + +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; + short versedata[MAX_VERSE]; + char data[MAX_DATA]; + int len; + + + 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(); + + // output verse from olb +// printf("%s\n", (const char *)inckey); + GETEXT(olbvnum, versedata, 1, 1, 1, 1); + BLDVERSE(versedata, data); + charsetconvert(data); + len = strlen(data); + if (len) + write(fp, data, strlen(data)); + + *size = lseek(fp, 0, SEEK_CUR) - *offset; + write(fp, "\n", 1); + return 0; + } + return 1; +} + +void charsetconvert(char *data) +{ + for (;*data; data++) { +// printf("%c %d", *data, *data); + switch((unsigned char)*data) { + case 129: *data = 252; break; + case 130: *data = 233; break; + case 131: *data = 226; break; + case 133: *data = 224; break; + case 135: *data = 231; break; + case 136: *data = 234; break; + case 137: *data = 235; break; + case 138: *data = 232; break; + case 139: *data = 239; break; + case 140: *data = 238; break; + case 144: *data = 201; break; + case 147: *data = 244; break; + case 150: *data = 251; break; + case 151: *data = 249; break; + case 160: *data = 225; break; + case 161: *data = 237; break; + case 162: *data = 243; break; + case 163: *data = 250; break; + case 164: *data = 241; break; + case 168: *data = 191; break; + case 173: *data = 161; break; + default: + if ((unsigned char)*data > 126) + fprintf(stderr, "Suspicious character: %c (%d); %s\n", *data, (unsigned char )*data, (const char *)inckey); + break; + } + } +} + + +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, S_IREAD|S_IWRITE)) == -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, S_IREAD|S_IWRITE)) == -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, S_IREAD|S_IWRITE)) == -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, S_IREAD|S_IWRITE)) == -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 < 2) { + fprintf(stderr, "usage: %s \n", argv[0]); + exit(1); + } +} diff --git a/misc/olb/online.ide b/misc/olb/online.ide new file mode 100644 index 0000000..efc10f0 Binary files /dev/null and b/misc/olb/online.ide differ diff --git a/misc/olb/online.prj b/misc/olb/online.prj new file mode 100644 index 0000000..17be6ae --- /dev/null +++ b/misc/olb/online.prj @@ -0,0 +1 @@ +Turbo C Project File \ No newline at end of file diff --git a/misc/olb/prn2sword.bpr b/misc/olb/prn2sword.bpr new file mode 100644 index 0000000..624da7f --- /dev/null +++ b/misc/olb/prn2sword.bpr @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +[Version Info] +IncludeVerInfo=0 +AutoIncBuild=0 +MajorVer=1 +MinorVer=0 +Release=0 +Build=0 +Debug=0 +PreRelease=0 +Special=0 +Private=0 +DLL=0 +Locale=1033 +CodePage=1252 + +[Version Info Keys] +CompanyName= +FileDescription= +FileVersion=1.0.0.0 +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion=1.0.0.0 +Comments= + +[HistoryLists\hlIncludePath] +Count=3 +Item0=..\src\mgr;..\src\utilfuns;..\src\keys;$(BCB)\include;$(BCB)\include\vcl;..\include +Item1=..\src\utilfuns;..\src\keys;$(BCB)\include;$(BCB)\include\vcl;..\include +Item2=$(BCB)\include;$(BCB)\include\vcl;../include + +[HistoryLists\hlLibraryPath] +Count=3 +Item0=..\src\mgr;..\src\utilfuns;..\src\keys;$(BCB)\Projects\Lib;$(BCB)\lib\obj;$(BCB)\lib +Item1=..\src\utilfuns;..\src\keys;$(BCB)\Projects\Lib;$(BCB)\lib\obj;$(BCB)\lib +Item2=$(BCB)\Projects\Lib;$(BCB)\lib\obj;$(BCB)\lib + +[HistoryLists\hlDebugSourcePath] +Count=1 +Item0=$(BCB)\source\vcl + +[Debugging] +DebugSourceDirs=$(BCB)\source\vcl + +[Parameters] +RunParams= +HostApplication= +RemoteHost= +RemotePath= +RemoteDebug=0 + +[Compiler] +ShowInfoMsgs=0 +LinkDebugVcl=0 +LinkCGLIB=0 + +[CORBA] +AddServerUnit=1 +AddClientUnit=1 +PrecompiledHeaders=1 + +[Language] +ActiveLang= +ProjectLang= +RootDir= + + \ No newline at end of file diff --git a/misc/olb/prn2sword.cpp b/misc/olb/prn2sword.cpp new file mode 100644 index 0000000..f5cf442 --- /dev/null +++ b/misc/olb/prn2sword.cpp @@ -0,0 +1,49 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +//--------------------------------------------------------------------------- +#include +#pragma hdrstop +USERES("prn2sword.res"); +USEFORM("prn2swordfrm.cpp", Form2); +USEUNIT("..\src\keys\versekey.cpp"); +USEUNIT("..\src\keys\strkey.cpp"); +USEUNIT("..\src\keys\swkey.cpp"); +USEUNIT("..\src\keys\listkey.cpp"); +USEUNIT("..\src\utilfuns\utilstr.cpp"); +USEUNIT("..\src\mgr\localemgr.cpp"); +USEUNIT("..\src\mgr\swlocale.cpp"); +USEUNIT("..\src\mgr\swconfig.cpp"); +USEUNIT("..\src\mgr\swmgr.cpp"); +USEUNIT("..\src\mgr\filemgr.cpp"); +USEUNIT("..\src\utilfuns\roman.c"); +//--------------------------------------------------------------------------- +WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) +{ + try + { + Application->Initialize(); + Application->CreateForm(__classid(TForm2), &Form2); + Application->Run(); + } + catch (Exception &exception) + { + Application->ShowException(&exception); + } + return 0; +} +//--------------------------------------------------------------------------- diff --git a/misc/olb/prn2swordfrm.cpp b/misc/olb/prn2swordfrm.cpp new file mode 100644 index 0000000..a6ea129 --- /dev/null +++ b/misc/olb/prn2swordfrm.cpp @@ -0,0 +1,501 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +//--------------------------------------------------------------------------- +#include +#pragma hdrstop + +#include "prn2swordfrm.h" +#include +#include +#include +#include +#include + +//--------------------------------------------------------------------------- +#pragma package(smart_init) +#pragma resource "*.dfm" +TForm2 *Form2; +const MAXVLEN = 8192; +//--------------------------------------------------------------------------- +__fastcall TForm2::TForm2(TComponent* Owner) + : TForm(Owner) +{ +} +//--------------------------------------------------------------------------- +void __fastcall TForm2::FSButtonClick(TObject *Sender) +{ + FSDialog->FileName = "*.rtf"; + char *fname; + + if (FSDialog->Execute()) { + FilePathEdit->Text = FSDialog->FileName; + } +} +//--------------------------------------------------------------------------- + + +void TForm2::ProcessFile(char *fileName) +{ + unsigned long pos = 0L; + unsigned short size = 0, tmp; + int verseNum, curbook = 0, curchap = 0, curverse = 0, curTestament = 1; + char buf[127]; + VerseKey mykey; + char verseBuf[MAXVLEN]; + bool fail = false; + char end = 0; + + + if ((fp = open(fileName, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE)) == -1) { + sprintf(buf, "Couldn't open file: %s\n", fileName); + MessageBox(this->Handle, buf, "ProcessFile", MB_OK); + return; + } + + openFiles("ot"); + + mykey = "Genesis 1:1"; + + getVerse(fp, &verseNum, verseBuf, 1); + do { + end = getVerse(fp, &verseNum, verseBuf, mykey.Testament()); + if (mykey.Verse() == 1) { /* if we're at a new chapter */ + if (mykey.Chapter() == 1) { /* if we're at a new book */ + if (mykey.Testament() != curTestament) { // we've made it to new testament + curTestament = mykey.Testament(); + close(vfp); // verse + close(cfp); // chapter + close(bfp); // book + close(dfp); // data + openFiles("nt"); + } + Memo1->Text = ""; + pos = lseek(cfp, 0, SEEK_CUR); + write(bfp, &pos, 4); + pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */ + write(cfp, &pos, 4); + pos = 0L; + 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 = 0L; + tmp = 0; + write(vfp, &pos, 4); /* Chapter intro */ + write(vfp, &tmp, 2); + curchap++; + } + else curverse++; + + if (mykey.Chapter() != curchap) { + sprintf(buf, "Error: Found chaptures out of sequence"); + Memo1->Lines->Append(buf); + fail = true; + break; + } + if ((mykey.Verse() != curverse) || (curverse != verseNum)) { + Memo1->Lines->Append("Error: Found verses out of sequence"); + sprintf(buf, "Expected %d (%s), but got %d\n\n", curverse, (const char *)mykey, verseNum); + Memo1->Lines->Append(buf); + Memo1->Lines->Append(" Currently SWORD only supports KJV verse numbering and book ordering."); + Memo1->Lines->Append(" Try combining extra verses with the last valid verse just before, including it in footnote markers (eg. (24) verse text. (25) verse text)"); + Memo1->Lines->Append(" This way, even though they will display in SWORD along with the previous verse, all data will be displayed."); + Memo1->Lines->Append(" Where verses are missing, add a blank entry."); + Memo1->Lines->Append(" Then try rerunning"); + fail = true; + break; + } + + pos = lseek(dfp, 0, SEEK_CUR); + write(vfp, &pos, 4); + size = strlen(verseBuf); + write(vfp, &size, 2); + sprintf(buf, "%2d:%3d:%3d (%s) found at offset: %7ld; size: %d", curbook, mykey.Chapter(), mykey.Verse(), (const char *)mykey, pos, size); + Memo1->Lines->Append(buf); + if ((size < 0) || (size > 1000)) { + Memo1->Lines->Append("WARNING: Strange Size."); + } + write(dfp, verseBuf, size); + mykey++; + } while (!end); + + close(vfp); // verse + close(cfp); // chapter + close(bfp); // book + close(dfp); // data + close(fp); // source + if (!fail) + Memo1->Lines->Append("SUCCESS!!!!!!!"); +} + + +char TForm2::getVerse(int fp, int *verseNum, char *verseBuf, char testament) +{ + char buf[21]; + char retVal = 0; + *verseNum=-1; + char *finalBuf = verseBuf; + int paridx; + const char *parchar = "\\par"; + + memset(buf, 0, 21); + + while (1) { + + if (!memcmp(buf, "\\f1 \\b0 \\fs22 \\f", 17)) { + if (isdigit(buf[18])) { + lseek(fp, -1, SEEK_CUR); + break; + } + else if (isdigit(buf[17])) { + lseek(fp, -2, SEEK_CUR); + break; + } + } + if (!memcmp(buf, "\\f1 \\b0 \\fs22 ", 14)) { + lseek(fp, -7, SEEK_CUR); + break; + } + if (!memcmp(buf, "\\li0\\fi0 \\par \\u", 16)) { + lseek(fp, -4, SEEK_CUR); + while(read(fp, buf, 1) == 1) { + if (*buf == 10) + break; + } + memset(buf, 0, 21); + } + memmove(buf, &buf[1], 20); + if (*buf) { + *verseBuf++ = *buf; + if (*verseNum == -1) { + if (isdigit(*buf)) { + sscanf(buf, "%d", verseNum); + } + } + } + if (read(fp, &buf[20], 1) != 1) { + retVal = 1; + for (int i = 1; i < 12; i++) + *verseBuf++ = buf[i]; + break; + } + } + *--verseBuf = 0; + paridx = 3; + // trim trailing junk + do { + verseBuf--; + if (paridx > -1) { + if (*verseBuf == parchar[paridx]) { + *verseBuf = 0; + paridx--; + continue; + } + if (paridx < 3) { + for (;paridx < 4;paridx++) + *verseBuf++ = parchar[paridx]; + break; + } + } + if ((*verseBuf != ' ') && (*verseBuf != 10) && (*verseBuf != 13) && (*verseBuf != '\\')) + break; + *verseBuf = 0; + } while (verseBuf > finalBuf); + *++verseBuf = 0; + + // check for Paragraph marker on next verse + for (int i = 7; i < 48; i++) { + if (buf[i] == '¶') { + *verseBuf++ = '<'; + *verseBuf++ = 'C'; + *verseBuf++ = 'M'; + *verseBuf++ = '>'; + *verseBuf++ = 0; + break; + } + } + + filterVerse(finalBuf, (testament == 2)?'G':'H'); + + return retVal; +} + + + + + + + +// lang - 'G' | 'H' +void TForm2::filterVerse(char *text, char lang) +{ + char *to, *from, token[MAXVLEN], tokpos = 0; + bool intoken = false; + bool intoken2 = false; + bool deref = false; + bool lastspace = false; + int len; + int maxlen = MAXVLEN - 1; + + + len = strlen(text) + 1; // shift string to right of buffer + if (len < maxlen) { + memmove(&text[maxlen - len], text, len); + from = &text[maxlen - len]; + } + else from = text; // ------------------------------- + + while (*from) { + if ((*from != ' ') && (!isdigit(*from)) && (*from != 10) && (*from !=13)) + break; + from++; + } + + for (to = text; *from; from++) { + if ((*from == '\\') && (!deref)) { + deref = true; + continue; + } + if (*from == '<') { + if (!isdigit(from[1])) { // Not a strongs number + if ((from[1] != 'C') || (from[2] != 'M') || (from[3] != '>')) { + *to++ = '<'; + *to++ = 'F'; + *to++ = 'O'; + *to++ = '>'; + continue; + } + } + } + if (*from == '>') { + if (!isdigit(from[-1])) { // Not a strongs number + if ((from[-2] != 'C') || (from[-1] != 'M') || (from[-3] != '<')) { + *to++ = '<'; + *to++ = 'F'; + *to++ = 'o'; + *to++ = '>'; + continue; + } + } + } + if (deref) { + deref = false; + if (*from == '{') { + *to++ = '<'; + *to++ = 'R'; + *to++ = 'F'; + *to++ = '>'; + continue; + } + + if (*from == '}') { + *to++ = '<'; + *to++ = 'R'; + *to++ = 'f'; + *to++ = '>'; + if (from[1] == '\\' && from[2] == 'i' && from[3] == '0') { + from += 3; + if (from[1] == ' ') { + if (lastspace) + from++; + } + } + continue; + } + if (*from == 'i') { + if (from[1] == '1') { + if (from[2] == ' ' && from[3] == '\\' && from[4] == '{') { + from++; + if (lastspace) + from++; + continue; + } + *to++ = '<'; + *to++ = 'F'; + *to++ = 'I'; + *to++ = '>'; + from++; + if (from[1] == ' ') { + if (lastspace) + from++; + } + continue; + } + if (from[1] == '0') { + *to++ = '<'; + *to++ = 'F'; + *to++ = 'i'; + *to++ = '>'; + from++; + if (from[1] == ' ') { + if (lastspace) + from++; + } + if ((from[1] == ' ') && (from[2] == ' ')){ // dorky, but OLB places 2 spaces after italics off + from++; + } + continue; + } + } + if (*from == 'f' && from[1] == 's') { + from++; + while (isdigit(from[1])) { + from++; + } + if (from[1] == ' ') { + if (lastspace) + from++; + } + continue; + } + *to++ = '\\'; + *to++ = *from; + lastspace = (*from == ' '); + continue; + } + + if (*from == '<') { + if (isdigit(from[1])) { + intoken = true; + tokpos = 0; + memset(token, 0, 20); + continue; + } + } + if (*from == '(') { + if (isdigit(from[1])) { + intoken2 = true; + tokpos = 0; + memset(token, 0, 20); + continue; + } + } + if ((*from == '>') && (intoken)) { + intoken = false; + if (*(to - 1) == ' ') + to--; + *to++ = '<'; + *to++ = 'W'; + *to++ = lang; + for (int i = 0; i < strlen(token); i++) + *to++ = token[i]; + *to++ = '>'; + continue; + } + if ((*from == ')') && (intoken2)) { + intoken2 = false; + if (*(to - 1) == ' ') + to--; + *to++ = '<'; + *to++ = 'W'; + *to++ = 'T'; + *to++ = lang; + for (int i = 0; i < strlen(token); i++) + *to++ = token[i]; + *to++ = '>'; + continue; + } + + if ((*from == 13) || (*from == 10)) { + continue; + } + + if (*from == '¶') { + if (from[1] == ' ') { + from++; + } + continue; + } + + if (intoken || intoken2) + token[tokpos++] = *from; + else + *to++ = *from; + lastspace = (*from == ' '); + } + *to-- = 0; + *++to = '\n'; + *++to = 0; +} + + +void TForm2::openFiles(char *fileName) +{ + char buf[128]; + long pos; + short size; + + unlink(fileName); + if ((dfp = open(fileName, O_CREAT|O_WRONLY, S_IREAD|S_IWRITE)) == -1) { + sprintf(buf, "Couldn't open file: %s\n", fileName); + MessageBox(this->Handle, buf, "ProcessFile", MB_OK); + return; + } + + sprintf(buf, "%s.vss", fileName); + unlink(buf); + if ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE)) == -1) { + sprintf(buf, "Couldn't open file: %s\n", buf); + MessageBox(this->Handle, buf, "ProcessFile", MB_OK); + return; + } + + sprintf(buf, "%s.cps", fileName); + unlink(buf); + if ((cfp = open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE)) == -1) { + sprintf(buf, "Couldn't open file: %s\n", buf); + MessageBox(this->Handle, buf, "ProcessFile", MB_OK); + return; + } + + sprintf(buf, "%s.bks", fileName); + unlink(buf); + if ((bfp = open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE)) == -1) { + sprintf(buf, "Couldn't open file: %s\n", buf); + MessageBox(this->Handle, buf, "ProcessFile", MB_OK); + return; + } + 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 __fastcall TForm2::Button1Click(TObject *Sender) +{ + ProcessFile(FilePathEdit->Text.c_str()); +} +//--------------------------------------------------------------------------- + + diff --git a/misc/olb/prn2swordfrm.dfm b/misc/olb/prn2swordfrm.dfm new file mode 100644 index 0000000..0bc45fc Binary files /dev/null and b/misc/olb/prn2swordfrm.dfm differ diff --git a/misc/olb/prn2swordfrm.h b/misc/olb/prn2swordfrm.h new file mode 100644 index 0000000..162d224 --- /dev/null +++ b/misc/olb/prn2swordfrm.h @@ -0,0 +1,54 @@ +/* + * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org) + * CrossWire Bible Society + * P. O. Box 2528 + * Tempe, AZ 85280-2528 + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +//--------------------------------------------------------------------------- +#ifndef prn2swordfrmH +#define prn2swordfrmH +//--------------------------------------------------------------------------- +#include +#include +#include +#include +#include +#include +//--------------------------------------------------------------------------- +class TForm2 : public TForm +{ +__published: // IDE-managed Components + TPanel *Panel1; + TLabel *Label1; + TEdit *FilePathEdit; + TButton *FSButton; + TPanel *Panel2; + TButton *Button1; + TMemo *Memo1; + TOpenDialog *FSDialog; + void __fastcall FSButtonClick(TObject *Sender); + void __fastcall Button1Click(TObject *Sender); +private: // User declarations + int fp, vfp, cfp, bfp, dfp; + void openFiles(char *fileName); + void filterVerse(char *finalBuf, char lang); +public: // User declarations + __fastcall TForm2(TComponent* Owner); + void ProcessFile(char *fileName); + char getVerse(int fp, int *verseNum, char *verseBuf, char testament); +}; +//--------------------------------------------------------------------------- +extern PACKAGE TForm2 *Form2; +//--------------------------------------------------------------------------- +#endif -- cgit