Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

jfbgen.cpp

00001 /*****************************************************************************
00002  *
00003  */
00004 
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007 #include <string.h>
00008 #include <ctype.h>
00009 
00010 #ifndef __GNUC__
00011 #include <io.h>
00012 #else
00013 #include <unistd.h>
00014 #endif
00015 
00016 #include <fcntl.h>
00017 #include <versekey.h>
00018 
00019 #ifndef O_BINARY
00020         #define O_BINARY 0
00021 #endif
00022 
00023 void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size);
00024 char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size);
00025 void openfiles();
00026 void checkparams(int argc, char **argv);
00027 void charsetconvert(char *data);
00028 
00029 
00030 VerseKey key1, key2, key3;
00031 int fp, vfp, cfp, bfp;
00032 long chapoffset;
00033 short chapsize;
00034 char testmnt;
00035 char startflag = 0;
00036 
00037 
00038 main(int argc, char **argv)
00039 {
00040         long pos, offset;
00041         int num1, num2, rangemax, curbook = 0, curchap = 0, curverse = 0;
00042         char buf[127];
00043         short size, tmp;
00044         extern struct zonline online;
00045 
00046         checkparams(argc, argv);
00047 
00048         key1 = key2 = key3 = "Genesis 1:1";
00049 
00050         openfiles();
00051 
00052         num1    = key1.Chapter();
00053         num2    = key1.Verse();
00054 
00055         while(!findbreak(fp, &offset, &num1, &num2, &rangemax, &size)) {
00056                 if (!startflag) {
00057                         startflag = 1;
00058                 }
00059                 else {
00060                         if (num2 < key2.Verse()) {            // new chapter
00061                                 if (num1 <= key2.Chapter()) { // new book
00062                                         key2.Verse(1);
00063                                         key2.Chapter(1);
00064                                         key2.Book(key2.Book()+1);
00065                                 }
00066                                 printf("Found Chapter Break: %d ('%s')\n", num1, (const char *)key2);
00067                                 chapoffset = offset;
00068                                 chapsize = size;
00069 //                              continue;
00070                         }
00071                 }
00072                 key2.Verse(1);
00073                 key2.Chapter(num1);
00074                 key2.Verse(num2);
00075 
00076                 key3 = key2;
00077 //              key3 += (rangemax - key3.Verse());
00078 
00079                 writeidx(key1, key2, key3, offset, size);
00080         }
00081         close(vfp);
00082         close(cfp);
00083         close(bfp);
00084         close(fp);
00085 }
00086 
00087 
00088 /**************************************************************************
00089  * ENT: key1    - current location of index
00090  *      key2    - minimum keyval for which this offset is valid
00091  *      key3    - maximum keyval for which this offset is valid
00092  */
00093 
00094 void writeidx(VerseKey &key1, VerseKey &key2, VerseKey &key3, long offset, short size)
00095 {
00096         long pos;
00097         short tmp;
00098 
00099                 if (key1.Verse() == 1) {        // new chapter
00100                         if (key1.Chapter() == 1) {      // new book
00101                                 pos = lseek(cfp, 0, SEEK_CUR);
00102                                 write(bfp, &pos, 4);
00103                                 pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */
00104                                 write(cfp, &pos, 4);
00105                                 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)*/
00106                                 write(vfp, &chapsize, 2);
00107                         }
00108                         pos = lseek(vfp, 0, SEEK_CUR);
00109                         write(cfp, &pos, 4);
00110                         write(vfp, &chapoffset, 4);  /* Chapter intro */
00111                         write(vfp, &chapsize, 2);
00112                 }
00113                 if (key1 >= key2) {
00114                         write(vfp, &offset, 4);
00115                         write(vfp, &size, 2);
00116                 }
00117                 else    {
00118                         pos = 0;
00119                         tmp = 0;
00120                         write(vfp, &pos, 4);
00121                         write(vfp, &tmp, 2);
00122                 }
00123                 key1++;
00124 }
00125 
00126 
00127 static VerseKey inckey = "Genesis 1:1";
00128 
00129 char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size)
00130 {
00131         char buf[7];
00132         char buf2[20];
00133         char ch;
00134         char loop;
00135         long offset2;
00136         int ch2, vs2, rm2;
00137         bool flag;
00138         long chapstart = 0; 
00139         static int olbvnum = 0;
00140         char data[256];
00141         char *bookabrev[66] = {"Ge", "Ex", "Le", "Nu", "De", "Jos", "Jud", "Ru",
00142                 "1Sa", "2Sa", "1Ki", "2Ki", "1Ch", "2Ch", "Ezr", "Ne", "Es",
00143                 "Job", "Ps", "Pr", "Ec", "So", "Isa", "Jer", "La", "Eze", "Da",
00144                 "Ho", "Joe", "Am", "Ob", "Jon", "Mic", "Na", "Heb", "Zep",
00145                 "Hag", "Zec", "Mal",
00146                 "Mt", "Mr", "Lu", "Joh", "Ac", "Ro", "1Co", "2Co", "Ga",
00147                 "Eph", "Php", "Col", "1Th", "2Th", "1Ti", "2Ti", "Tit", "Phm",
00148                 "Heb", "Jas", "1Pe", "2Pe", "1Jo", "2Jo", "3Jo", "Jude", "Re" };
00149 
00150         if (++olbvnum <= 31102) {
00151 
00152                 if (olbvnum == 23146) { // "Matthew 1:1"        
00153                         close(vfp);
00154                         close(cfp);
00155                         close(bfp);
00156                         close(fp);
00157                         key1 = key2 = key3 = inckey = "Matthew 1:1";
00158                         openfiles();
00159                         startflag = 0;
00160                 }
00161 
00162 
00163                 *offset = lseek(fp, 0, SEEK_CUR);
00164 
00165                 if ((olbvnum!=1) && (olbvnum != 23146))
00166                         inckey++;
00167                         
00168                 *num1 = inckey.Chapter();
00169                 *num2 = inckey.Verse();
00170         
00171                 sprintf(data, "JFB%.2d.htm#%s%d_%d", inckey.Book() + ((inckey.Testament()>1)?39:0), bookabrev[inckey.Book() + ((inckey.Testament()>1)?39:0)-1], inckey.Chapter(), inckey.Verse());
00172                 write(fp, data, strlen(data));
00173 
00174                 *size = lseek(fp, 0, SEEK_CUR) - *offset;
00175                 write(fp, "\n", 1);
00176                 return 0;
00177         }
00178         return 1;
00179 }
00180 
00181 
00182 void openfiles()
00183 {
00184         char buf[255];
00185         char fname[5];
00186         long pos;
00187         short size;
00188         
00189         testmnt = key1.Testament();
00190 
00191         strcpy(fname, (testmnt==2) ? "nt" : "ot");
00192         unlink(fname);
00193         if ((fp = open(fname, O_CREAT|O_RDWR|O_BINARY)) == -1) {
00194                 fprintf(stderr, "Couldn't open file: %s\n", fname);
00195                 exit(1);
00196         }
00197 
00198         sprintf(buf, "%s.vss", fname);
00199         unlink(buf);
00200         if ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
00201                 fprintf(stderr, "Couldn't open file: %s\n", buf);
00202                 exit(1);
00203         }
00204 
00205         sprintf(buf, "%s.cps", fname);
00206         unlink(buf);
00207         if ((cfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
00208                 fprintf(stderr, "Couldn't open file: %s\n", buf);
00209                 exit(1);
00210         }
00211 
00212         sprintf(buf, "%s.bks", fname);
00213         unlink(buf);
00214         if ((bfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
00215                 fprintf(stderr, "Couldn't open file: %s\n", buf);
00216                 exit(1);
00217         }
00218 
00219         pos  = 0;
00220         write(bfp, &pos, 4);  /* Book    offset for testament intros */
00221         pos = 4;
00222         write(cfp, &pos, 4);  /* Chapter offset for testament intro */
00223 
00224 
00225 /*      Right now just zero out intros until parsing correctly */
00226         pos = 0;
00227         size = 0;
00228         write(vfp, &pos, 4);  /* Module intro */
00229         write(vfp, &size, 2);
00230         write(vfp, &pos, 4);  /* Testament intro */
00231         write(vfp, &size, 2);
00232 
00233 }
00234 
00235 
00236 void checkparams(int argc, char **argv)
00237 {
00238         if (argc !=1) {
00239                 fprintf(stderr, "usage: %s\n", argv[0]);
00240                 exit(1);
00241         }
00242 }

Generated on Thu Jun 20 22:12:59 2002 for The Sword Project by doxygen1.2.15