home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / ARCHIVERS / lha208src.lzh / LHA / SRC / larc.c < prev    next >
Text File  |  1994-02-14  |  1KB  |  70 lines

  1. /***********************************************************
  2.     larc.c -- extract *.lzs
  3. ***********************************************************/
  4. #include <stdio.h>
  5. #include "slidehuf.h"
  6.  
  7. #define MAGIC0 18
  8. #define MAGIC5 19
  9.  
  10. static int flag, flagcnt, matchpos;
  11.  
  12. unsigned short decode_c_lzs()
  13. {
  14.     if (getbits(1)) {
  15.         return getbits(8);
  16.     } 
  17.     else {
  18.         matchpos = getbits(11);
  19.         return getbits(4) + 0x100;
  20.     }
  21. }
  22.  
  23. unsigned short decode_p_lzs()
  24. {
  25.     return (loc - matchpos - MAGIC0) & 0x7ff;
  26. }
  27.  
  28. void decode_start_lzs()
  29. {
  30.     init_getbits();
  31. }
  32.  
  33. unsigned short decode_c_lz5()
  34. {
  35.     int c;
  36.  
  37.     if (flagcnt == 0) {
  38.         flagcnt = 8;
  39.         flag = getc(infile);
  40.     }
  41.     flagcnt--;
  42.     c = getc(infile);
  43.     if ((flag & 1) == 0) {
  44.         matchpos = c;
  45.         c = getc(infile);
  46.         matchpos += (c & 0xf0) << 4;
  47.         c &= 0x0f;
  48.         c += 0x100;
  49.     }
  50.     flag >>= 1;
  51.     return c;
  52. }
  53.  
  54. unsigned short decode_p_lz5()
  55. {
  56.     return (loc - matchpos - MAGIC5) & 0xfff;
  57. }
  58.  
  59. void decode_start_lz5()
  60. {
  61.     int i;
  62.  
  63.     flagcnt = 0;
  64.     for (i = 0; i < 256; i++) memset(&text[i * 13 + 18], i, 13);
  65.     for (i = 0; i < 256; i++) text[256 * 13 + 18 + i] = i;
  66.     for (i = 0; i < 256; i++) text[256 * 13 + 256 + 18 + i] = 255 - i;
  67.     memset(&text[256 * 13 + 512 + 18], 0, 128);
  68.     memset(&text[256 * 13 + 512 + 128 + 18], ' ', 128 - 18);
  69. }
  70.