home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_11_12 / engbert / decomp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-11  |  1.2 KB  |  54 lines

  1. /*                        DECOMP.C
  2. **
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <conio.h>
  8. #include <ctype.h>
  9. #include "config.h"
  10. #include "proto.h"
  11.  
  12. signed int bit;  /*global shared with BITS.C */
  13.  
  14. int decompress() {
  15.  
  16. unsigned int long length;
  17. unsigned int character;
  18. unsigned int byte_count;
  19. unsigned int character_count;
  20. extern signed int user_byte;
  21.  
  22.     byte_count = 0;
  23.     character_count = 0;
  24.     init_bits();
  25.     init_list();
  26.  
  27.     fread(&length,sizeof(length),1,stdin);
  28.  
  29.     user_byte = getc(stdin);
  30.     /* ignore any EOF return value here! */
  31.     putc(user_byte,stdout);
  32.     update_list(&byte_count, &character_count);
  33.  
  34.     length--;  /*for the first byte read above*/
  35.     bit = read_bit();
  36.     /* bit is global !!! , first bit set here,
  37.     ** rest in decode_byte()! */
  38.  
  39.     while ( bit != EOF && length){
  40.         /* if bit == EOF, the file was tampered with */
  41.         decode_byte(0, character_count+1, byte_count+1);
  42.           /* decode_byte() sets global user_byte*/
  43.         update_list(&byte_count, &character_count);
  44.  
  45.         putc (user_byte,stdout);
  46.         length--;
  47.     } /*while */
  48.     fflush(stdout);
  49.     fprintf(stderr,"byte_count is %u\n",byte_count);
  50.     if (ferror(stdout)) return WRITE_ERR;
  51.     else return 0;
  52. } /*decompress()*/
  53.  
  54.