Huffman Compression Engine
LHA/LZH is a freeware compression utility and associated file format

Delphi & Pascal (česká wiki)
Přejít na: navigace, hledání
Kategórie: KMP (Programy mladých programátorů)

Program: Lzh.pas
Soubor exe: Lzh.exe
Potřebné: Lzhasm.objLz.pasLzo.pasTestlzo.pasTplzh.docLzh.zip

Huffman Compression Engine
LHA/LZH is a freeware compression utility and associated file format. It was created in 1988 by Haruyasu Yoshizaki (Yoshizaki Haruyasu?), and originally named LHarc. A complete rewrite of LHarc, tentatively named LHx, was eventually released as LH. It was then renamed to LHA to avoid conflicting with the then-new MS-DOS 5.0 LH ("load high") command. According to early documentation, LHA is pronounced like La.
LHA/LZH on wikipedia
{ LZH.PAS                                                              }
{ Base unit for all Huffman engine components.                         }
{ see: http://en.wikipedia.org/wiki/LHA_(file_format)#Canonical_LZH    }
{                                                                      }
{ LHA/LZH is a freeware compression utility and associated file format.}
{ It was created in 1988 by Haruyasu Yoshizaki (Yoshizaki Haruyasu?),  }
{ and originally named LHarc. A complete rewrite of LHarc, tentatively }
{ named LHx, was eventually released as LH. It was then renamed to LHA }
{ to avoid conflicting with the then-new MS-DOS 5.0 LH ("load high")   }
{ command. According to early documentation, LHA is pronounced like La.}
{                                                                      }
{   LZH.PAS based on:                                                  }
{                                                                      }
{   LZHUF.C English version 1.0 based on Japanese version 29-NOV-1988  }
{   Haruhiko OKUMURA:   LZSS coded                                     }
{   Haruyasu YOSHIZAKI: Adaptive Huffman Coding coded                  }
{   Kenji RIKITAKE:     Edited and translated to English               }
{   Peter Sawatzki,                                                    }
{   Wayne Sullivan:     Converted to Turbo Pascal 5.0                  }
{   Joe Jared:          Assembler and Atari Port (12/16/92.. ??/??/??) }
{   Andres Cvitkovich:  object-oriented interface   (TP5.5+)           }
{                                                                      }
{ Datum: 31.07.1993                              http://www.trsek.com  }
 
{$A+,i-,v-,s-,f+,r-,O+}
 
Unit LZH;
Interface
uses memory;
Const
 
     EngineVer = '0.26';
     {These constants are hard coded into LZHASM.OBJ}
     N         = $1000             ; {Size of string buffer}
     F         = 60               ; {60 Size of look-ahead buffer}
type
  IObuf = array[0..$2800-1] of byte;
 
  LZHRec = Record       {Segment:0 aligned}
         WorkSpace1     : Array [0..N+F-1] of byte;
         count          : LongInt;
         textsize       : LongInt;
         codesize       : LongInt;
         inptr,inend,outptr,outend    : Word;
         Ebytes         : Longint;
         inbuf,outbuf        : IObuf;
         {Buffersize and position are critical}
         WorkSpace           : Array [0..$73ff] of byte;
         {LZHASM work space} {Some space reserved}
         End;
 
 
(*
 LZHERROR   : WORD  ;
 LZHMessage : String; { English response from
 LZHVERSION : WORD  ; { Hibyte major, lobyte minor}
 
*)
 
var
	LZHERROR    : Word; {for future use}
   	{$F+}
   	WriteFromBuffer, ReadToBuffer: Procedure;
	LZHMem: ^LZHRec;
	LZHMemSeg       : WORD;
   	{$F+}
   	procedure Encode ;
   	procedure Decode;
 
   Procedure InitLZH;
   Procedure DInitLZH;
Implementation
{$F+}
 {$L LZHASM}
procedure Decode; External;
procedure Encode; External;
 
{ .model Small,Pascal}
{$R-}
Procedure InitLZH;
{
 
If need be, call this routine before any other allocations, or...
Segment align all allocations.  This routine is setup to keep memory
allocations segment aligned, and to be backwards compatible with all
versions of Turbo Pascal.
 
}
Begin
   lzhmem := memallocseg (Sizeof(LZhmem^));
   LZHMemSeg := Seg(LZhmem^);
   LZhmem^.Inend := 0;  { This is to insure that Read is called.      }
   LZhmem^.outend := 0; { If you don't fill the input, the engine will}
End;
 
Procedure DInitLZH;
Begin
     FreeMem (LZHMem,(Sizeof(LZhmem^)AND $FFF0) +16);
End;
 
end.