/* dump some files from a jpl edr tape after it has gone through jplfixto bat */ #include #include void dump_() { static unsigned char buf[16384]; static int count; int i, j, kinput, koutput; static unsigned char size[2]; int tmp, eof; int i1,i2,i3; FILE * fp; kinput = 1; koutput = 1; fp = fopen ("output_dump.txt", "w+"); /* read in first file with fread */ count = fread(buf, 1, 8192, stdin); /*buf - This is the pointer to a block of memory with a minimum size of size*nmemb bytes. size - This is the size in bytes of each element to be read. nmemb - This is the number of elements, each one with a size of size bytes. stream - This is the pointer to a FILE object that specifies an input stream. */ fprintf(fp, "; count is %d", count); fprintf(fp, "; buf[0] is %x ", buf[0]); fprintf(fp, "; buf[1] is %x, buf[2] is %x " , buf[1], buf[2]); fprintf(fp, "; buf[3] is %x, buf[4] is %x " , buf[3], buf[4]); fprintf(fp, "; buf[5] is %x, buf[6] is %x \n" , buf[5], buf[6]); kinput = kinput + 1; if (count < 0) { fprintf(stderr, "Cannot read input\n"); exit(1); } /* the below sequence of three hex numbers means we are at the beginning of a PLS record */ if ((buf[0] != 0xd4) || (buf[1] != 0xd1) || (buf[2] != 0xe2)) { fprintf(stderr, "Not a PLS data file\n"); exit(1); } eof = 0; while (count > 0) { for (i = 3; i < count; i++) { if ((buf[i] == 0xd4) && (i + 2 < count) && (buf[i + 1] == 0xd1) && (buf[i + 2] == 0xe2)) break; } /* we break when we see we have the beginning of a file and we have not yet gotten to * the end of the current buf file */ size[0] = i % 256; size[1] = i / 256; fprintf(fp, " break i is %d", i); fprintf(fp, " size[0] is %d", size[0]); fprintf(fp, " size[1] is %d \n", size[1]); /* print out file with fwrite i1 = fwrite( &i, 4, 1, stdout); i2 = fwrite(buf, 1, i, stdout); i3 = fwrite( &i, 4, 1, stdout); */ fprintf(fp, "FILES OUT %d i %o i1 %d i2 %d i3 %d \n",koutput,i,i1,i2,i3); koutput = koutput + 1; /* &1 - This is the pointer to the array of elements to be written. size - This is the size in bytes of each element to be written. nmemb - This is the number of elements, each one with a size of size bytes. stream - This is the pointer to a FILE object that specifies an output stream. */ for (j = 0; i < count; j++, i++) buf[j] = buf[i]; count = j; if (!eof && (count < 8192)) { tmp = fread(buf + count, 1, 8192, stdin); fprintf(fp, "files in %d",kinput); fprintf(fp, "; count is %d", count); fprintf(fp, "; buf[0] is %x ", buf[0]); fprintf(fp, "; buf[1] is %x, buf[2] is %x \n" , buf[1], buf[2]); kinput = kinput+1; if (tmp < 0) { fprintf(stderr, "Error reading input file\n"); exit(1); } else if (tmp == 0) { eof = 1; } else { count += tmp; } } } i = 0; /* i1 = fwrite( &i, 4, 1, stdout); i1 = fwrite( &i, 4, 1, stdout); i1 = fwrite( &i, 4, 1, stdout); i1 = fwrite( &i, 4, 1, stdout); */ fclose(fp); return; }