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

vntidx.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 buf3[7];
00116         char loop;
00117         char offadj, inquotes, sizeadj;
00118         int offset2, ch2, vs2;
00119         
00120         strcpy (buf3, "\\par  ");
00121         buf3[5] = 10;
00122         memset(buf, ' ', 17);
00123 
00124         while (1) {
00125                 offadj = -100;
00126                 inquotes = 0;
00127                 sizeadj = 0;
00128                 if (!memcmp(buf, "\\par FIN DEL NUEVO TESTAMENTO", 16)) {
00129                         offadj = -11;
00130 //                      inquotes = 1;
00131                         sizeadj = -7;
00132                 }
00133                 
00134                 if ((!memcmp(buf, buf3, 6)) && (!size)) {
00135                         offadj = -11;
00136 //                      inquotes = 1;
00137                         sizeadj = -7;
00138                 }
00139                 if (!memcmp(buf, "\\par  ", 6)) {
00140                         if (isdigit(buf[6])) {
00141                                 for (loop = 7; loop < 10; loop++) {
00142                                         if (!isdigit(buf[loop]))
00143                                                 break;
00144                                 }
00145                                 offadj = -(11 - (loop - 6));
00146         //                      inquotes = 1;
00147                                 sizeadj = -7;
00148                         }
00149                 }
00150 /*
00151                 if (!memcmp(buf, "\\fi200\\widctlpar", 16)) {
00152                         offadj = -1;
00153 //                      inquotes = 1;
00154                         sizeadj = -18;
00155                 }
00156 */
00157                 if (offadj > -100) {
00158                         *offset = lseek(fp, 0, SEEK_CUR) + offadj;
00159                         if (size) {
00160                                 (*offset)++;
00161                                 while (inquotes) {
00162                                         while (read(fp, buf2, 1) == 1) {
00163                                                 if (*buf2 == '}')
00164                                                         break;
00165                                                 (*offset)++;
00166                                         }
00167                                         inquotes--;
00168                                 }
00169                                 if (findbreak(fp, &offset2, &ch2, &vs2, 0)) {
00170                                         *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
00171                                 }
00172                                 else {
00173                                         *size = (offset2 - (*offset));
00174                                 }
00175                                 lseek(fp, *offset-sizeadj, SEEK_SET);
00176                         }
00177                         else (*offset) += sizeadj;
00178                         return 0;
00179                 }
00180                 memmove(buf, &buf[1], 16);
00181                 if (read(fp, &buf[16], 1) != 1)
00182                         return 1;
00183         }
00184 }
00185 

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