home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Amiga / Workbench / Archivers / PPCxDMS.lha / PPCxDMS / source.lha / src / u_quick.c < prev    next >
C/C++ Source or Header  |  1998-02-28  |  995b  |  57 lines

  1.  
  2. /*
  3.  *     xDMS  v1.1  -  Portable DMS archive unpacker  -  Public Domain
  4.  *     Written by     Andre R. de la Rocha  <adlroc@usa.net>
  5.  *
  6.  *
  7.  */
  8.  
  9.  
  10. #include <string.h>
  11.  
  12. #include "cdata.h"
  13. #include "u_quick.h"
  14. #include "getbits.h"
  15.  
  16.  
  17. #define QBITMASK 0xff
  18.  
  19.  
  20. static USHORT quick_text_loc;
  21.  
  22.  
  23.  
  24. void Init_QUICK(void){
  25.     quick_text_loc = 251;
  26.     memset(text,0,252);
  27. }
  28.  
  29.  
  30.  
  31. USHORT Unpack_QUICK(UCHAR *in, UCHAR *out, UCHAR flags, USHORT origsize){
  32.     USHORT i, j;
  33.     UCHAR *outend;
  34.  
  35.     initbitbuf(in);
  36.  
  37.     outend = out+origsize;
  38.     while (out < outend) {
  39.         if (GETBITS(1)!=0) {
  40.             DROPBITS(1);
  41.             *out++ = text[quick_text_loc++ & QBITMASK] = (UCHAR)GETBITS(8);  DROPBITS(8);
  42.         } else {
  43.             DROPBITS(1);
  44.             j = (USHORT) (GETBITS(2)+2);  DROPBITS(2);
  45.             i = (USHORT) (quick_text_loc - GETBITS(8) - 1);  DROPBITS(8);
  46.             while(j--) {
  47.                 *out++ = text[quick_text_loc++ & QBITMASK] = text[i++ & QBITMASK];
  48.             }
  49.         }
  50.     }
  51.     quick_text_loc = (USHORT)((quick_text_loc+5) & QBITMASK);
  52.     if (!(flags & 1)) Init_QUICK();
  53.  
  54.     return 0;
  55. }
  56.  
  57.