home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / OLS / Os2 / LHA2P205 / LHA2P205.LZH / lha2-2.05pre / source.lzh / src / larc.c < prev    next >
C/C++ Source or Header  |  1994-10-23  |  2KB  |  99 lines

  1. /*
  2.  * larc.c --- extract *.lzs
  3.  *   Copyright (C) 1988-1992, Haruyasu YOSHIZAKI
  4.  *
  5.  * $Log$
  6.  */
  7.  
  8.  
  9. #include <sys/types.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <limits.h>
  13. #include "typedef.h"
  14. #include "slidehuf.h"
  15. #include "intrface.h"
  16.  
  17.  
  18. #define MAGIC0 18
  19. #define MAGIC5 19
  20.  
  21.  
  22. static int flag, flagcnt, matchpos;
  23.  
  24.  
  25. ushort
  26. decode_c_lzs(void)
  27. {
  28.   if(getbits(1))
  29.     return getbits(8);
  30.   else
  31.     {
  32.       matchpos = getbits(11);
  33.       return getbits(4) + 0x100;
  34.     }
  35. }
  36.  
  37.  
  38. ushort
  39. decode_p_lzs(void)
  40. {
  41.   return (ushort)(loc - matchpos - MAGIC0) & 0x7ff;
  42. }
  43.  
  44.  
  45. void
  46. decode_start_lzs(void)
  47. {
  48.   init_getbits();
  49. }
  50.  
  51.  
  52. ushort
  53. decode_c_lz5(void)
  54. {
  55.   int c;
  56.  
  57.   if(flagcnt == 0)
  58.     {
  59.       flagcnt = 8;
  60.       flag = getc(infile);
  61.     }
  62.   flagcnt--;
  63.   c = getc(infile);
  64.   if(((uint)flag & 1) == 0)
  65.     {
  66.       matchpos = c;
  67.       c = getc(infile);
  68.       matchpos += ((uint)c & 0xf0) << 4;
  69.       c = (uint)c & 0x0f;
  70.       c += 0x100;
  71.     }
  72.   flag = (uint)flag >> 1;
  73.   return (ushort)c;
  74. }
  75.  
  76.  
  77. ushort
  78. decode_p_lz5(void)
  79. {
  80.   return (ushort)(loc - matchpos - MAGIC5) & 0xfff;
  81. }
  82.  
  83.  
  84. void
  85. decode_start_lz5(void)
  86. {
  87.   int i;
  88.  
  89.   flagcnt = 0;
  90.   for(i = 0; i < 256; i++)
  91.     memset(&text[i * 13 + 18], i, 13);
  92.   for(i = 0; i < 256; i++)
  93.     text[256 * 13 + 18 + i] = i;
  94.   for(i = 0; i < 256; i++)
  95.     text[256 * 13 + 256 + 18 + i] = 255 - i;
  96.   memset(&text[256 * 13 + 512 + 18], 0, 128);
  97.   memset(&text[256 * 13 + 512 + 128 + 18], ' ', 128 - 18);
  98. }
  99.