home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / packery / xpkilzr / source / eilzr.c < prev    next >
C/C++ Source or Header  |  1977-12-31  |  2KB  |  109 lines

  1.  
  2.  
  3. /**-----------------------------------------------------------------------
  4.   *   Bloque de includes, por fin me ocupan menos de una pagina de
  5.   * impresisn, lo que hay que hacer para tener todos los prototipos..
  6.   *
  7.   **/
  8.  
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12.  
  13. #define NO_SUB_PRAGMAS
  14. #include <libraries/xpksub.h>
  15.  
  16. #include "ilzr.h"
  17.  
  18. /**-----------------------------------------------------------------------
  19.   *   Prototipos para todas estas paridas necesarias para compilar.
  20.   *
  21.   **/
  22.  
  23. long __saveds __asm XpksUnpackChunk( REG __a0 XPARAMS* xpar )
  24. {
  25.     /*  variables para input - output   */
  26.   
  27. register  CHARS       *inpb       = xpar->InBuf;
  28. register  CHARS       *outb       = xpar->OutBuf;
  29. register  CHARS       *bumpcode;
  30. register  CHARS       *outbstart  = xpar->OutBuf;
  31. register  signed char  shift      = 0;
  32.           UBYTE        bitcount;
  33. register  signed long  outbsize;
  34.           ULONG        matchpos;
  35.           ULONG        matchlen;      
  36.           
  37.  
  38.   outbsize = *((unsigned short *)inpb);
  39.   inpb    += 2;     /* short leido */
  40.  
  41.   bitcount = INIT_BIT_BUMP;
  42.   bumpcode = &outb[ 1<<INIT_BIT_BUMP ]; 
  43.   
  44.   if( outbsize > xpar->OutBufLen )
  45.     return( XPKERR_SMALLBUF );
  46.   
  47.   xpar->OutBufLen = outbsize; 
  48.     
  49.   while( outbsize > 0 )
  50.     {
  51.     if( *inpb & (0x80>>shift) )
  52.       {
  53.       if( (++shift) > 7 )
  54.         {
  55.         shift=0;
  56.         inpb++;
  57.         }
  58.           
  59.       *outb = ( ((ULONG *)inpb)[0] )>>(24-shift);
  60.       outb++;
  61.       inpb++;
  62.       outbsize--;
  63.       }
  64.     else
  65.       {
  66.       if( ++shift > 7 )
  67.         {
  68.         shift=0;
  69.         inpb++;
  70.         }
  71.       
  72.       if( bumpcode <  outb )
  73.         {
  74.         bitcount++;
  75.         bumpcode = &outbstart[ 1<<bitcount ];
  76.         }
  77.  
  78.       matchpos = (( ((ULONG *)inpb)[0] ) >> ( 32 - bitcount - shift ) ) & ((1<<bitcount)-1);
  79.       
  80.       shift   = shift + bitcount - 8;    /* ALWAYS bitccount >= 8 */
  81.       inpb++;
  82.       if( shift > 7 )
  83.         {
  84.         shift-=8;
  85.         inpb++;
  86.         }
  87.       
  88.       matchlen = (( ((ULONG *)inpb)[0] ) >> ( 32 - BITS_LOOKAHEAD - shift ) ) & ((1<<BITS_LOOKAHEAD)-1);
  89.       
  90.       shift   += BITS_LOOKAHEAD;
  91.       if( shift > 7 )
  92.         {
  93.         shift-=8;
  94.         inpb++;
  95.         }
  96.         
  97.       matchlen += MIN_MATCH;
  98.  
  99.       memcpy( outb , &outbstart[ matchpos ] , (size_t)matchlen );
  100.       outb     += matchlen;
  101.  
  102.       outbsize -= matchlen;
  103.       }
  104.     }
  105.   return( 0 );
  106. }
  107.  
  108. /************************** End of ILZR.C *************************/
  109.