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

kjvidx.cpp

00001 #include <stdio.h>
00002 #include <fcntl.h>
00003 #include <versekey.h>
00004 
00005 
00006 char findbreak(int fp, int *offset, int *num1, int *num2, short *size);
00007 
00008 
00009 main(int argc, char **argv)
00010 {
00011         int fp, vfp, cfp, bfp;
00012         long pos;
00013         short size, tmp;
00014         int num1, num2, offset, curbook = 0, curchap = 0, curverse = 0;
00015         char buf[127];
00016         VerseKey mykey;
00017 
00018         if ((argc < 2) || (argc > 3)) {
00019                 fprintf(stderr, "usage: %s <file to process> [nt]\n", argv[0]);
00020                 exit(1);
00021         }
00022 
00023         if ((fp = open(argv[1], O_RDONLY)) == -1) {
00024                 fprintf(stderr, "Couldn't open file: %s\n", argv[1]);
00025                 exit(1);
00026         }
00027 
00028         sprintf(buf, "%s.vss", argv[1]);
00029         if ((vfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00030                 fprintf(stderr, "Couldn't open file: %s\n", buf);
00031                 exit(1);
00032         }
00033 
00034         sprintf(buf, "%s.cps", argv[1]);
00035         if ((cfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00036                 fprintf(stderr, "Couldn't open file: %s\n", buf);
00037                 exit(1);
00038         }
00039 
00040         sprintf(buf, "%s.bks", argv[1]);
00041         if ((bfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00042                 fprintf(stderr, "Couldn't open file: %s\n", buf);
00043                 exit(1);
00044         }
00045 
00046         pos  = 0;
00047         write(bfp, &pos, 4);  /* Book    offset for testament intros */
00048         pos = 4;
00049         write(cfp, &pos, 4);  /* Chapter offset for testament intro */
00050 
00051 
00052 /*      Right now just zero out intros until parsing correctly */
00053         pos = 0;
00054         size = 0;
00055         write(vfp, &pos, 4);  /* Module intro */
00056         write(vfp, &size, 2);
00057         write(vfp, &pos, 4);  /* Testament intro */
00058         write(vfp, &size, 2);
00059 
00060         mykey = (argc == 3) ? "Matthew 1:1" : "Genesis 1:1";
00061 
00062         while (!findbreak(fp, &offset, &num1, &num2, &size)) {
00063                 num1 = mykey.Chapter();
00064                 num2 = mykey.Verse();
00065                 if (num2 == 1) {                /* if we're at a new chapter */
00066                         if (num1 == 1) {        /* if we're at a new book */
00067                                 pos = lseek(cfp, 0, SEEK_CUR);
00068                                 write(bfp, &pos, 4);
00069                                 pos = lseek(vfp, 0, SEEK_CUR); /* Book intro (cps) */
00070                                 write(cfp, &pos, 4);
00071                                 pos  = 0;
00072                                 tmp = 0;
00073                                 write(vfp, &pos, 4);  /* Book intro (vss) */
00074                                 write(vfp, &tmp, 2);
00075                                 curbook++;
00076                                 curchap = 0;
00077                         }
00078                         pos = lseek(vfp, 0, SEEK_CUR);
00079                         write(cfp, &pos, 4);
00080                         curverse = 1;
00081                         pos  = 0;
00082                         tmp = 0;
00083                         write(vfp, &pos, 4);  /* Chapter intro */
00084                         write(vfp, &tmp, 2);
00085                         curchap++;
00086                 }
00087                 else curverse++;
00088         
00089                 printf("%2d:%3d:%3d found at offset: %7d\n", curbook, num1, num2, offset);
00090 
00091                 if (num1 != curchap) {
00092                         fprintf(stderr, "Error: Found chaptures out of sequence\n");
00093                         break;
00094                 }
00095                 if (num2 != curverse) {
00096                         fprintf(stderr, "Error: Found verses out of sequence\n");
00097                         break;
00098                 }
00099                 write(vfp, &offset, 4);
00100                 write(vfp, &size, 2);
00101                 mykey++;
00102         }
00103         
00104         close(vfp);
00105         close(cfp);
00106         close(bfp);
00107         close(fp);
00108 }
00109 
00110 
00111 char findbreak(int fp, int *offset, int *num1, int *num2, short *size)
00112 {
00113         char buf[17];
00114         char buf2[7];
00115         char loop;
00116         char offadj, inquotes, sizeadj;
00117         int offset2, ch2, vs2;
00118         
00119         memset(buf, ' ', 17);
00120 
00121         while (1) {
00122                 offadj = -10;
00123                 inquotes = 0;
00124                 sizeadj = 0;
00125                 if ((!memcmp(buf, "\\widctlpar {\\b\\f0\\cf2 ", 16)) && (!size)) {
00126                         offadj = -1;
00127 //                      inquotes = 1;
00128                         sizeadj = -18;
00129                 }
00130                 if (!memcmp(&buf[1], "\\f0\\fs16\\cf2\\up6", 15)) {
00131                         offadj = 0;
00132                         inquotes = 1;
00133                         sizeadj = (*buf == 10) ? -18:-17;
00134                 }
00135                 if (!memcmp(buf, "\\fi200\\widctlpar", 16)) {
00136                         offadj = -1;
00137 //                      inquotes = 1;
00138                         sizeadj = -18;
00139                 }
00140                 if (offadj > -10) {
00141                         *offset = lseek(fp, 0, SEEK_CUR) + offadj;
00142                         if (size) {
00143                                 (*offset)++;
00144                                 while (inquotes) {
00145                                         while (read(fp, buf2, 1) == 1) {
00146                                                 if (*buf2 == '}')
00147                                                         break;
00148                                                 (*offset)++;
00149                                         }
00150                                         inquotes--;
00151                                 }
00152                                 if (findbreak(fp, &offset2, &ch2, &vs2, 0)) {
00153                                         *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
00154                                 }
00155                                 else {
00156                                         sprintf(buf2, "%d:%d", ch2, vs2);
00157                                         *size = (offset2 - (*offset));
00158                                 }
00159                                 lseek(fp, *offset+17, SEEK_SET);
00160                         }
00161                         else (*offset) += sizeadj;
00162                         return 0;
00163                 }
00164                 memmove(buf, &buf[1], 16);
00165                 if (read(fp, &buf[16], 1) != 1)
00166                         return 1;
00167         }
00168 }
00169 

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