home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / packer / lzw14 / compress.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-12  |  1.0 KB  |  44 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 <stdlib.h>
  10. #include "LZW4C.H"
  11. #include "RW_IO.H"
  12. #include "SAYERROR.H"
  13.  
  14. void main(int argc, char *argv[])
  15. {int RetCode;
  16.  float Ratio;
  17.  /* begin */
  18.  if(argc<3)
  19.     {printf("Usage: COMPRESS <infile> <outfile>\n");
  20.      exit(1);
  21.     }
  22.  if((RetCode=InitLZW(malloc,14))<0)
  23.     {SayError(RetCode);
  24.      exit(2);
  25.     }
  26.  /* open input file */
  27.  if(!ReaderOpen(argv[1])) exit(3);
  28.  /* open output file */
  29.  if(!WriterOpen(argv[2])) exit(4);
  30.  printf("Compressing %s ",argv[1]);
  31.  /* do the compression */
  32.  if((RetCode=Compress(Reader,Writer))<0)
  33.    {SayError(RetCode);
  34.     exit(3);
  35.    }
  36.  if(ReaderCount() > 0)
  37.    {Ratio = (float)(WriterCount())/(float)ReaderCount();
  38.     printf(" %0.2f\n",Ratio);
  39.    }
  40.  /* close files */
  41.  ReaderClose();
  42.  WriterClose();
  43.  TermLZW(free);
  44. }