home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / t / tplzh025.zip / LZH.PAS < prev    next >
Pascal/Delphi Source File  |  1993-02-08  |  3KB  |  118 lines

  1. {$A+,i-,v-,s-,f+,r-,O+}
  2. {
  3.  
  4.    LZH.PAS - base unit for all Huffman engine components
  5.  
  6.    LZH.PAS based on:
  7.  
  8.    LZHUF.C English version 1.0 based on Japanese version 29-NOV-1988
  9.    Haruhiko OKUMURA:   LZSS coded
  10.    Haruyasu YOSHIZAKI: Adaptive Huffman Coding coded
  11.    Kenji RIKITAKE:     Edited and translated to English
  12.    Peter Sawatzki,
  13.    Wayne Sullivan:     Converted to Turbo Pascal 5.0
  14.    Joe Jared:          Assembler (12/16/92.. ??/??/??)
  15.    Andres Cvitkovich:  object-oriented interface   (TP5.5+)
  16.  
  17.    <Your name here>: Other language interface.
  18. }
  19.  
  20. Unit LZH;
  21. Interface
  22. Const
  23.      EngineVer = '0.25';
  24.      {These constants are hard coded into LZHASM.OBJ}
  25.      N         = $1000             ; {Size of string buffer}
  26.      F         = 60               ; {60 Size of look-ahead buffer}
  27. type
  28.   IObuf = array[0..$2800-1] of byte;
  29.  
  30.   LZHRec = Record       {Segment:0 aligned}
  31.          WorkSpace1     : Array [0..N+F-1] of byte;
  32.          count          : LongInt;
  33.          textsize       : LongInt;
  34.          codesize       : LongInt;
  35.          inptr,inend,outptr,outend    : Word;
  36.          Ebytes         : Longint;
  37.          inbuf,outbuf        : IObuf;
  38.          {Buffersize and position are critical}
  39.          WorkSpace           : Array [0..$73ff] of byte;
  40.          {LZHASM work space} {Some space reserved}
  41.          End;
  42.  
  43.  
  44.  
  45.  {LZH_CUSTOM  : WORD  ; {Customized settings        
  46.  LZHERROR   : WORD  ; {
  47.  LZHMessage : String; { English response from
  48.  LZHVERSION : WORD  ; { Hibyte major, lobyte minor}
  49.  
  50.     
  51.  
  52. var
  53.    LZHERROR    : Word; {for future use}
  54.    StupidAlloc  : Boolean;
  55.    StupidPtr    : Pointer;
  56.    {$F+}
  57.    WriteFromBuffer,
  58.    ReadToBuffer: Procedure;
  59.    LZHMem: ^LZHRec;
  60.    LZHMemSeg       : WORD;
  61.    {$F+}                            
  62.    procedure Encode ;
  63.    procedure Decode;
  64.  
  65.    Procedure InitLZH;
  66.    Procedure DInitLZH;
  67. Implementation
  68. {$F+}
  69. procedure Decode; External;
  70. procedure Encode; External;
  71.  
  72.  {$L LZHASM}
  73. { .model Small,Pascal}
  74. {$R-}
  75. Procedure InitLZH;
  76. {
  77.  
  78. If need be, call this routine before any other allocations, or...
  79. Segment align all allocations.  This routine is setup to keep memory
  80. allocations segment aligned, and to be backwards compatible with all
  81. versions of Turbo Pascal.
  82.  
  83. }
  84. Begin
  85.      
  86.      StupidAlloc := True;
  87.      GetMem (StupidPtr,8);
  88.      If Ofs(StupidPtr^) = 0 Then Begin
  89.         Freemem(StupidPtr,8);
  90.         StupidAlloc := False;
  91.         End;
  92.  
  93.  
  94.      GetMem (LZHMem,(Sizeof(LZhmem^)AND $FFF0) +16);
  95.      LZHMemSeg := Seg(LZhmem^);
  96.      LZhmem^.Inend := 0;  { This is to insure that Read is called.      }
  97.      LZhmem^.outend := 0; { If you don't fill the input, the engine will}
  98.      {If you wonder why it locks up at any point, this is probably the cause}
  99.      {If you changed this source, it's probably your fault.}
  100.  
  101.      {$IFDEF DEBUGLZH}
  102.      Writeln (Seg(LZhmem^),':', ofs(LZhmem^));
  103.      Writeln (Sizeof(LZhmem^));
  104.      halt;
  105.      {$ENDIF}
  106.  
  107.  
  108.  
  109. End;
  110. Procedure DInitLZH;
  111. Begin
  112.      FreeMem (LZHMem,(Sizeof(LZhmem^)AND $FFF0) +16);
  113.      if StupidAlloc then Freemem(StupidPtr,8);
  114.  
  115. End;
  116.  
  117. end.
  118.