home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / LZW4C12.ZIP / COMPRESS.C < prev    next >
Text File  |  1992-11-08  |  1KB  |  49 lines

  1. /*
  2. **  COMPRESS.C      Copyright (C) 1992 by MarshallSoft Computing, Inc.
  3. **
  4. **  Compresses specified file. Use EXPAND to un-compress file.
  5. **  Usage is:  COMPRESS <input_file> <output_file>
  6. */
  7.  
  8. #include <stdio.h>
  9. #include "LZW4C.H"
  10. #include "RW_IO.H"
  11.  
  12. extern char *malloc();
  13. extern int free();
  14.  
  15. void SayError(int);
  16.  
  17. void main(argc,argv)
  18. int argc;
  19. char *argv[];
  20. {int RetCode;
  21.  float Ratio;
  22.  /* begin */
  23.  if(argc<3)
  24.     {printf("Usage: COMPRESS <infile> <outfile>\n");
  25.      exit(1);
  26.     }
  27.  if((RetCode=InitLZW(malloc))<0)
  28.     {SayError(RetCode);
  29.      exit(2);
  30.     }
  31.  /* open input file */
  32.  if(!ReaderOpen(argv[1])) exit(3);
  33.  /* open output file */
  34.  if(!WriterOpen(argv[2])) exit(4);
  35.  printf("Compressing %s ",argv[1]);
  36.  /* do the compression */
  37.  if((RetCode=Compress(Reader,Writer))<0)
  38.    {SayError(RetCode);
  39.     exit(3);
  40.    }
  41.  if(ReaderCount() > 0)
  42.    {Ratio = (float)(WriterCount())/(float)ReaderCount();
  43.     printf(" %0.2f\n",Ratio);
  44.    }
  45.  /* close files */
  46.  ReaderClose();
  47.  WriterClose();
  48.  TermLZW(free);
  49. }