home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / btoc_v12.lha / BtoCDir / ExplodeStuff / Decrunch30.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-27  |  1.6 KB  |  73 lines

  1. /************************************************/
  2. /*                        */
  3. /* Like GCC/Decrunch_MIT.s - SAS_C/Decrunch30.s    */
  4. /* but all work is in C                */
  5. /* See Docs/Decrunch30.doc for complete docs    */
  6. /* about this function                */
  7. /* See Docs/SAS_C/SAS_C_interface for an    */
  8. /* example program using this function        */
  9. /*                        */
  10. /* Copyright © 1992-1994 by Stefano Reksten    */                            */
  11. /*                        */
  12. /************************************************/
  13.  
  14. #include <exec/types.h>
  15.  
  16. #define BTOC_MSG    ( (ULONG)'B'<<24L | (ULONG)'T'<<16L | 'O'<<8 | 'C' )
  17.  
  18. BOOL Decrunch30( register UBYTE *dest_ptr, register UBYTE *source_ptr )
  19. {
  20. register ULONG  data_size, decrunched = 0;
  21. register UBYTE  most_used, byte_counter, current_byte,
  22.         max_counter, skip_counter, skip_byte;
  23.  
  24. if ( *(ULONG *)source_ptr++ != BTOC_MSG )
  25.     return( FALSE );
  26.  
  27. data_size = *(ULONG *)source_ptr++;
  28. most_used = *source_ptr++;
  29. max_counter = *source_ptr++;
  30.  
  31. while ( decrunched < data_size )
  32.     {
  33.     if ( *source_ptr != most_used )
  34.         {
  35.         *dest_ptr++ = *source_ptr++;
  36.         decrunched++;
  37.         }
  38.     else
  39.         {
  40.         source_ptr++;
  41.         byte_counter = *source_ptr++;
  42.         if ( byte_counter == max_counter )
  43.             {
  44.             *dest_ptr++ = most_used;
  45.  
  46.             skip_byte = *source_ptr++;
  47.             skip_counter=7;
  48.             do    {
  49.                 if ( skip_byte & 1<<skip_counter )
  50.                     *dest_ptr++ = *source_ptr++;
  51.                 else    *dest_ptr++ = most_used;
  52.                 skip_counter--;
  53.                 } while ( skip_counter >= 0 );
  54.             decrunched += 9;
  55.             }
  56.         else
  57.             {
  58.             if ( byte_counter > max_counter )
  59.                 {
  60.                 byte_counter -= max_counter;
  61.                 current_byte = *source_ptr++;
  62.                 }
  63.             else    current_byte = most_used;
  64.  
  65.             decrunched += byte_counter;
  66.             while ( byte_counter-- )
  67.                 *dest_ptr++ = current_byte;
  68.             }
  69.         }
  70.     }
  71. return( TRUE );
  72. }
  73.