home *** CD-ROM | disk | FTP | other *** search
/ Palm Utilities / Palm_Utilities_CD-ROM_2001_2001.iso / files / utils misc / Boxer 0.18 / Boxer018.exe / boxer / LinBoxer / unbox.c < prev   
Encoding:
C/C++ Source or Header  |  2000-06-29  |  1010 b   |  52 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #include <netinet/in.h>
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8.   char bbuf[5000];
  9.   unsigned long xlong;
  10.   unsigned short xshort;
  11.   long bbuflen;
  12.   int i;
  13.   FILE *outfd, *infd;
  14.   int argp;
  15.  
  16.   if (argc < 2) {
  17.     fprintf(stderr, "Usage: %s prcfile\n", argv[0]);
  18.     exit(1);
  19.   }
  20.  
  21.   for (argp = 1; argp < argc; argp++) {
  22.     strcpy(bbuf, argv[argp]);
  23.  
  24.     infd = fopen(bbuf, "r");
  25.  
  26.     if (!strcmp(&bbuf[strlen(bbuf) - 4], ".pdb"))
  27.       bbuf[strlen(bbuf) - 4] = 0;
  28.     else
  29.       strcat(bbuf, ".out");
  30.  
  31.     outfd = fopen(bbuf, "w");
  32.  
  33.     fseek(infd, 76, SEEK_SET);
  34.     fread(&xshort, 1, 2, infd);
  35.     fread(&xlong, 1, 4, infd);
  36.  
  37.     xshort = htons(xshort);
  38.     xlong = htonl(xlong);
  39.     fseek(infd, xlong, SEEK_SET);
  40.  
  41.     for (i = 0; i < xshort; i++) {
  42.       bbuflen = fread(bbuf, 1, 4104, infd);
  43.       if (bbuflen < 8 || strncmp(bbuf, "DBLK", 4))
  44.         exit(-2);
  45.       fwrite(&bbuf[8], 1, bbuflen - 8, outfd);
  46.     }
  47.     fclose(outfd);
  48.     fclose(infd);
  49.   }
  50.   return 0;
  51. }
  52.