(* Archive support.  Needs an editor done.  Works pretty good, but *)
(* more needs to be added *)
unit archive;
interface
uses dos,crt,genstr,records,io;

function docompression(d:byte;af:STRING;fn:string):byte;
Function findcomp(fn:string):byte;

   var comps : array[1..3] of archrec;
       ctype : byte;

implementation

Function findcomp(fn:string):byte;


var f     : file;
    c     : array[1..2] of char;
    x     : byte;
begin
fillchar(comps,sizeof(comps),#0);
comps[1].name      :='ZIP'; { pkzip }
comps[1].id        :='PK';  { pkzip }
comps[1].compress  :='PKZIP.EXE -rpa -ex -m %AF %FN';
comps[1].uncompress:='PKUNZIP.EXE %AF %FN';
comps[1].test      :='PKUNZIP.EXE -t %AF';
comps[1].comment   :='PKZIP.EXE -z %AF <%CF';
comps[1].delete    :='PKZIP.EXE -d %AF %FN';
comps[1].errorlevel:=0;

comps[2].name      :='ARJ';
comps[2].id        :='`ê';
comps[2].compress  :='ARJ.EXE a -rp %AF %FN';
comps[2].uncompress:='ARJ.EXE x -y %AF %FN';
comps[2].test      :='ARJ.EXE t %AF';
comps[2].comment   :='ARJ.EXE %AF -z%CF';
comps[2].delete    :='ARJ.EXE d %AF %FN';
comps[2].errorlevel:=0;

comps[3].name      :='RAR';
comps[3].id        :='Ra';
comps[3].compress  :='RAR.EXE a -std -r %AF %FN';
comps[3].uncompress:='RAR.EXE x -std -y %AF %FN';
comps[3].test      :='RAR.EXE t -std %AF';
comps[3].comment   :='RAR.EXE c -z%CF %AF';
comps[3].delete    :='RAR.EXE d -std %AF %FN';
comps[3].errorlevel:=0;

assign(f,fn);
{$i-} reset(f,1); {$i+}
findcomp:=0;
if ioresult<>0 then exit;
blockread(f,c,sizeof(C));
close(f);
ctype:=0;
for x:=1 to 3 do if pos(c,comps[x].id)>0 then
                    ctype:=x;
END;

function docompression(d:byte;af:STRING;fn:string):byte;
    var
    x     : byte;
    cmd   : string;
    err   : byte;
    archp : string;

begin
archp:=config.arch_dir;
cmd:='';
case d of
1:begin
  killfile(fn);
  cmd:=archp+comps[ctype].compress;
  replaceit(cmd,'%FN',af);
  replaceit(cmd,'%AF',fn);
  err:=doExec(cmd);
  end;
2:begin
  cmd:=archp+comps[ctype].uncompress;
  replaceit(cmd,'%FN',af);
  replaceit(cmd,'%AF',fn);
  err:=doExec(cmd);
  end;
3:begin
  cmd:=archp+comps[ctype].TEST;
  replaceit(cmd,'%FN',af);
  replaceit(cmd,'%AF',fn);
  err:=doExec(cmd);
  end;
4:begin
  cmd:=archp+comps[ctype].comment;
  replaceit(cmd,'%AF',FN);
  replaceit(cmd,'%CF','COMMENT.TXT');
  err:=doExec(cmd);
  end;
5:begin;
  cmd:=archp+comps[ctype].delete;
  replaceit(cmd,'%AF',FN);
  replaceit(cmd,'%FN',AF);
  err:=doExec(cmd);
  end;
end;
docompression:=err;
end;

      begin
      end.