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

rawfilesgen.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("Created Empty Entry: %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                         size = 0;
00116                         write(vfp, &size, 2);
00117                 }
00118                 else    {
00119                         pos = 0;
00120                         tmp = 0;
00121                         write(vfp, &pos, 4);
00122                         write(vfp, &tmp, 2);
00123                 }
00124                 key1++;
00125 }
00126 
00127 
00128 static VerseKey inckey = "Genesis 1:1";
00129 
00130 char findbreak(int fp, long *offset, int *num1, int *num2, int *rangemax, short *size)
00131 {
00132         char buf[7];
00133         char buf2[20];
00134         char ch;
00135         char loop;
00136         long offset2;
00137         int ch2, vs2, rm2;
00138         bool flag;
00139         long chapstart = 0; 
00140         static int olbvnum = 0;
00141         char data[16];
00142 
00143         memset (data,0,16);
00144 
00145         if (++olbvnum <= 31102) {
00146 
00147                 if (olbvnum == 23146) { // "Matthew 1:1"        
00148                         close(vfp);
00149                         close(cfp);
00150                         close(bfp);
00151                         close(fp);
00152                         key1 = key2 = key3 = inckey = "Matthew 1:1";
00153                         openfiles();
00154                         startflag = 0;
00155                 }
00156 
00157 
00158                 *offset = lseek(fp, 0, SEEK_CUR);
00159 
00160                 if ((olbvnum!=1) && (olbvnum != 23146))
00161                         inckey++;
00162                         
00163                 *num1 = inckey.Chapter();
00164                 *num2 = inckey.Verse();
00165         
00166                 
00167                 write(fp, data, 16);
00168 
00169                 *size = lseek(fp, 0, SEEK_CUR) - *offset;
00170                 return 0;
00171         }
00172         return 1;
00173 }
00174 
00175 
00176 void openfiles()
00177 {
00178         char buf[255];
00179         char fname[5];
00180         long pos;
00181         short size;
00182         
00183         testmnt = key1.Testament();
00184 
00185         strcpy(fname, (testmnt==2) ? "nt" : "ot");
00186         unlink(fname);
00187         if ((fp = open(fname, O_CREAT|O_RDWR|O_BINARY)) == -1) {
00188                 fprintf(stderr, "Couldn't open file: %s\n", fname);
00189                 exit(1);
00190         }
00191 
00192         sprintf(buf, "%s.vss", fname);
00193         unlink(buf);
00194         if ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
00195                 fprintf(stderr, "Couldn't open file: %s\n", buf);
00196                 exit(1);
00197         }
00198 
00199         sprintf(buf, "%s.cps", fname);
00200         unlink(buf);
00201         if ((cfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
00202                 fprintf(stderr, "Couldn't open file: %s\n", buf);
00203                 exit(1);
00204         }
00205 
00206         sprintf(buf, "%s.bks", fname);
00207         unlink(buf);
00208         if ((bfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
00209                 fprintf(stderr, "Couldn't open file: %s\n", buf);
00210                 exit(1);
00211         }
00212 
00213         pos  = 0;
00214         write(bfp, &pos, 4);  /* Book    offset for testament intros */
00215         pos = 4;
00216         write(cfp, &pos, 4);  /* Chapter offset for testament intro */
00217 
00218 
00219 /*      Right now just zero out intros until parsing correctly */
00220         pos = 0;
00221         size = 0;
00222         write(vfp, &pos, 4);  /* Module intro */
00223         write(vfp, &size, 2);
00224         write(vfp, &pos, 4);  /* Testament intro */
00225         write(vfp, &size, 2);
00226 
00227 }
00228 
00229 
00230 void checkparams(int argc, char **argv)
00231 {
00232         if (argc !=1) {
00233                 fprintf(stderr, "usage: %s\n", argv[0]);
00234                 exit(1);
00235         }
00236 }

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