home *** CD-ROM | disk | FTP | other *** search
/ Mega Demo / MegaDemoCDRom1.cdr / os2 / archive / booz.exe / IO.C < prev    next >
C/C++ Source or Header  |  1991-07-11  |  1KB  |  60 lines

  1. /*$Source: /usr/home/dhesi/booz/RCS/io.c,v $*/
  2. /*$Id: io.c,v 1.8 91/07/08 12:06:55 dhesi Exp $*/
  3. /***********************************************************
  4. Input/output for lzh decoding.
  5.  
  6. Adapted from "ar" archiver written by Haruhiko Okumura.
  7. ***********************************************************/
  8. #include "booz.h"
  9. #include "zoo.h"
  10. #include "ar.h"
  11. #include "lzh.h"
  12.  
  13. extern FILE *arcfile;
  14. t_uint16 bitbuf;
  15.  
  16. static uint  subbitbuf;
  17. static int   bitcount;
  18.  
  19. int fillbuf(n)  /* Shift bitbuf n bits left, read n bits */
  20. int n;
  21. {
  22.     bitbuf <<= n;
  23.     while (n > bitcount) {
  24.         bitbuf |= subbitbuf << (n -= bitcount);
  25.         if (feof(arcfile))
  26.             subbitbuf = 0;
  27.         else
  28.             subbitbuf = (uchar) getc(arcfile);
  29.         bitcount = CHAR_BIT;
  30.     }
  31.     bitbuf |= subbitbuf >> (bitcount -= n);
  32. }
  33.  
  34. uint getbits(n)
  35. int n;
  36. {
  37.     uint x;
  38.  
  39.     x = bitbuf >> (BITBUFSIZ - n);  fillbuf(n);
  40.     return x;
  41. }
  42.  
  43. int fwrite_crc(p, n, f)
  44. uchar *p;
  45. int n;
  46. FILE *f;
  47. {
  48.     if (f != NULL) {
  49.         if (fwrite((char *) p, 1, n, f) < n) 
  50.             prterror('f', "disk full", (char *)0, (char *)0);
  51.     }
  52.     addbfcrc((char *) p, (unsigned) n);
  53. }
  54.  
  55. int init_getbits()
  56. {
  57.     bitbuf = 0;  subbitbuf = 0;  bitcount = 0;
  58.     fillbuf(BITBUFSIZ);
  59. }
  60.