home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
LZHSRC97
/
LZHVIEW.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1989-12-18
|
4KB
|
188 lines
program lzhview;
uses
dos,crt;
type
{data structure for the fileheader}
fileheadertype = record
Headsize,Headchk:byte;
HeadID:packed array[1..5] of char;
Packsize,Origsize,Filetime:longint;
Attr:word;
filename:pathstr;
end;
var
fh:fileheadertype;
fha:array[1..sizeof(fileheadertype)] of byte absolute fh;
crc:word; {crc value}
crcbuf:array[1..2] of byte absolute crc;
crc_table:array[0..255] of word;
infile:file;
{ this routine initialize the CRC_table }
procedure make_crc_table;
var
i,index,ax:word;
carry:boolean;
begin
index:=0;
repeat
ax:=index;
for i:=1 to 8 do
begin
carry:=odd(ax);
ax:=ax shr 1;
if carry then ax:=ax xor $A001;
end;
crc_table[index]:=ax;
inc(index);
until index>255;
end;
{use this to calculate the CRC value of the original file}
{call this function afer reading every byte from the file}
procedure calccrc(data:byte);
var
index:integer;
begin
crcbuf[1]:=crcbuf[1] xor data;
index:=crcbuf[1];
crc:=crc shr 8;
crc:=crc xor crc_table[index];
end;
function mksum:byte; {calculate check sum for file header }
var
i:integer;
b:byte;
begin
b:=0;
for i:=3 to fh.headsize+2 do
b:=b+fha[i];
mksum:=b;
end;
{format of LZH file }
{
[fileheader]
[CRC] <--crc value(2 bytes)
[compressed data] <--- first file
[fileheader]
[CRC]
[compressed data] <--- second file
.
.
.
[fileheader] <--- last file
[CRC]
[compressed data]
0 <--- a zero indicates end of LZH archive
fileheader:
Headsize = size of file header in bytes
Headchk = check sum of fileheader, obtained using mksum
HeadID = 5 characters,
either '-lh0- (file is not compressed, simply stored)
or '-lh1-' (file is compressed)
Packsize = compressed size of file
Origsize = original size of file
Filetime = time/date of file;
Attr = attribue of file;
filename = the filename,a string in PASCAL;
For the source for the compression routine, see the file
LZHSRC10.LZH, a C source file implementing the LZH routine, but does
not include information on fileheader and CRC-value.
Use the function make_crc_table to set up the crc table before
every compression. and use the calcCRC(byte) to work out the crc value.
Unfortunately, the source code is in C, you may have to convert this
program to C as well.
Using Turbo C, is faster than Turbo Pascal in execution speed, after
applying the various optimizations.
I have also converted the LZH routine to PASCAL, unfortunately, I have
misplaced it somewhere. I can get upload it to you when I found it.
Note: A routine in pure Turbo Pascal is about 4 times as slow as
LHarc. There is also the source code for LHarc if you're interested.
It's written in assembler and interfaced to C.
}
procedure viewlzh;
label
done;
var
l1,l2,oldfilepos:longint;
count:integer;
numread,i:word;
s1:string[50];
s2:string[20];
begin
assign(infile,paramstr(1));
reset(infile,1);
gotoxy(3,wherey);
writeln('Filename Original Packsize Ratio');
oldfilepos:=0;
count:=1;
repeat
seek(infile,oldfilepos);
blockread(infile,fha,sizeof(fileheadertype),numread);
oldfilepos:=oldfilepos+fh.headsize+2+fh.packsize;
i:=mksum;
if fh.headsize<>0 then
begin
if i<>fh.headchk then
begin
writeln('Checksum error in file');
goto done;
end;
gotoxy(3,wherey);
write(fh.filename);
gotoxy(15,wherey);
write(fh.origsize:10);
write(fh.packsize:10);
l1:=fh.packsize;
l2:=fh.origsize;
if l2>2147400 then
begin
l2:=l2 div 1000;
end
else l1:=l1*1000;
l1:=l1 div l2;
writeln(l1 div 10:4,'.',l1 mod 10:1,'%');
end;
until (fh.headsize=0);
done:
close(infile);
end;
begin
viewlzh;
end.