home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 428_02 / examples / uncomp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-13  |  1.2 KB  |  53 lines

  1. /*
  2. ** UNCOMP.C: Uncompresses a file that was compressed with
  3. ** COMPRESS.C.
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <compress.h>
  9.  
  10. BYTE inbuff[BUFSIZ + 200];
  11. BYTE outbuff[BUFSIZ];
  12.  
  13. void main(int argc,char *argv[])
  14. {
  15.    FILE *istream,*ostream;
  16.    WORD complen,uncomplen;
  17.    NODE *rootnode;
  18.  
  19.    /* check arguments */
  20.    if(argc != 3 || !stricmp(argv[1],argv[2])) {
  21.       printf("Usage:\tUNCOMP <infile> <outfile>\n");
  22.       return;
  23.    }
  24.  
  25.    /* open files */
  26.    istream = fopen(argv[1],"rb");
  27.    ostream = fopen(argv[2],"wt");
  28.    if(istream == NULL || ostream == NULL) {
  29.       printf("File error\n");
  30.       return;
  31.    }
  32.  
  33.    /* read and uncompress code tree */
  34.    complen = getw(istream);
  35.    fread(inbuff,sizeof(BYTE),complen,istream);
  36.    rootnode = readtree(inbuff);
  37.    if(rootnode == NULL) {
  38.       printf("Out of memory\n");
  39.       return;
  40.    }
  41.  
  42.    /* uncompress data and write to file */
  43.    while((uncomplen = getw(istream)) != 0) {
  44.       complen = getw(istream);
  45.       fread(inbuff,sizeof(BYTE),complen,istream);
  46.       uncompress(inbuff,uncomplen,outbuff,rootnode);
  47.       fwrite(outbuff,sizeof(BYTE),uncomplen,ostream);
  48.    }
  49.  
  50.    fclose(istream);
  51.    fclose(ostream);
  52. }
  53.