LZW viewer

Code to show the contents of an LZH file.

Contributor: SWAG SUPPORT TEAM

Program lzhview;

Uses
  Dos, Crt;

Const
  BSize = 4096; { I/O Buffer Size }

Type LZHHead = Record
                 HSize : Byte;
                 Fill1 : Byte;
                 Method : Array[1..5] of Char;
                 CompSize : LongInt;
                 UCompSize : LongInt;
                 Dos_DT : LongInt;
                 Fill2 : Word;
                 FileNameLen: Byte;
                 FileName : Array[1..12] of Char;
               end;

Var LZH1 : LZHHead;
    DT : DateTime;
    FSize,L,C : LongInt;
    F : File;
    BUFF : Array[1..BSize] of Byte;
    DATE : String[8]; { formatted date as YY/MM/DD }
    TIME : String[6]; { " time as HH:MM }
    RES : Word;
    DIR : DirStr;
    FNAME : NameStr;
    EXT : ExtStr;
    LZHString,
    SName : String;
    QUIT : Boolean;
    SW : Pointer;

Function upper(st:String):String;
Var i : Integer;
begin
  For i := 1 to length(st) do st[i] :=upcase(st[i]);
  upper := st;
end;

Function ord_to_str(i:LongInt;j:Byte):String;
Var c:String;
begin
  str(i,c);
  While length(c) 0 then
      begin
        Move (FileNameLen,SNAME,FileNameLen+1);
        UnPackTime (Dos_DT,DT);
        FSize := CompSize
      end
    else QUIT := True
end; { GET_LZH_ENTRY }

Procedure DO_LZH (FN : String);
Var fnstr, LZHMeth : String;
    fls,totu,totc : LongInt;
begin


  totu:=0; totc:=0; fls:=0;
  Assign (F,FN);
  {$I-} Reset (F,1); {$I+}
  if Ioresult<>0 then
    begin
      Writeln(upper(FN)+' not found');
      Exit;
    end;
  FSize := FileSize(F);
  C := 0;
  QUIT := False;
  Writeln('LZH File : '+upper(FN));
  Writeln;
  Writeln(' Filename OrigSize CompSize Method Date '
  +' Time');
  Writeln('------------ -------- -------- -------- --------'
  +' ------');
  Repeat
    GET_LZH_ENTRY;
    if not QUIT then
      begin
        FSplit (SNAME,DIR,FNAME,EXT);
        fnstr:=FNAME+EXT;
        While length(fnstr)<12 do insert(' ',fnstr,length(fnstr)+1);
        FDT(LZH1.Dos_DT);
        inc(totu,lzh1.ucompsize);
        inc(totc,lzh1.compsize);
        inc(fls,1);
        Case LZH1.Method[4] of {normally only 0,1 or 5}
          '0' : LZHMeth:='Stored ';
          '1' : LZHMeth:='Frozen 1';
          '2' : LZHMeth:='Frozen 2';
          '3' : LZHMeth:='Frozen 3';
          '4' : LZHMeth:='Frozen 4';
          '5' : LZHMeth:='Frozen 5';
        else LZHMeth:=' Unknown';
        end;
        LZHString:=Fnstr+' '+ord_to_str(LZH1.UCompsize,8)+' '+
                   ord_to_str(LZH1.Compsize,8)+' '+lzhmeth+' '
                   +DATE+' '+TIME;
        Writeln(LZHString);
      end;
    Inc (C,FSize+LZH1.HSize+2)
  Until QUIT;
  Close (F);
  Writeln('------------ -------- -------- -------- --------'
  +' -----');
  Writeln(ord_to_str(fls,5)+' Files '+ord_to_str(totu,8)+' '
  +ord_to_str(totc,8));
end; { DO_LZH }

begin
  ClrScr;
  do_lzh('whatever.lzh'); { <-- place Filename here }
end.

 

Share this article!

Follow us!

Find more helpful articles: