home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 2: Collection B / 17Bit_Collection_B.iso / files / 2010.dms / in.adf / P-Compress / Object / crunch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-26  |  1.6 KB  |  68 lines

  1. #include "exec/types.h"
  2. #include "exec/memory.h"
  3. #include "libraries/dosextens.h"
  4. #include "libraries/dos.h"
  5. #include "stdio.h"
  6.  
  7. main(argc,argv)
  8. int    argc ;
  9. char   *argv[] ;
  10. {
  11.     struct FileHandle     *fi, *fo ;
  12.     int                   result, inlength ;
  13.     char                  header[4] ;
  14.     struct FileLock       *lock ;
  15.     struct FileInfoBlock  *block ; 
  16.  
  17.     if (argc < 3)
  18.      { puts (" Usage: Comp [input file] [output file]\n") ;
  19.        exit(NULL) ;
  20.      }
  21.    
  22.     lock = (struct FileLock *)Lock(argv[1], ACCESS_READ) ;
  23.     block =  (struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock), 0) ;
  24.     Examine (lock, block) ;  
  25.     inlength = block->fib_Size ;
  26.     UnLock (lock) ;
  27.     FreeMem (block, sizeof(struct FileInfoBlock)) ;
  28.   
  29.     if ((fi = (struct FileHandle *)Open(argv[1], MODE_OLDFILE)) == 0)
  30.       {
  31.         puts ("Can't open input file\n") ;
  32.         exit (NULL) ; 
  33.       }
  34.     
  35.     Read(fi, header, 4) ;
  36.     if ((header[0] == 'P') && (header[1] == 'R') && (header[2] == 'E')) ;
  37.     else      Seek (fi, -4, 0) ;
  38.         
  39.     Read(fi, header, 2) ;
  40.       
  41.     if ((header[0] == 'L') && (header[1] == 'H'))
  42.       {
  43.         puts ("File already compressed\n");
  44.         Close (fi) ;
  45.         exit(NULL) ;
  46.       }
  47.  
  48.     if ((fo = (struct FileHandle *)Open(argv[2], MODE_NEWFILE)) == 0)
  49.       {
  50.         puts ("Can't open output file\n") ;
  51.         Close (fi) ;
  52.         exit (NULL) ;
  53.       }
  54.  
  55.     result = compress (fi, fo) ;
  56.  
  57.     Close (fi) ;
  58.     Close (fo) ;
  59.     if      (result == 1)  puts ("Decompression failed\n") ;
  60.     else if (result == 2)  puts ("Out of memory\n") ;
  61.     exit(NULL) ;
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68.