{$m 5000,4000,4000}
uses dos,crt,newexec;

type crec=record
     name       : string[15];
     id         : string[2];
     compress   : String[50];
     uncompress : String[50];
     test       : String[50];
     comment    : String[50];
     delete     : String[50];
     listChar   : Char;
     errorLevel : Byte;
   end;

    var comps : array[1..3] of crec;

procedure killfile(s:string);
var f:file;
begin
WRITELn('deleteing file ',s);
assign(f,s);
{$i-} reset(f,1); {$i+}
if ioresult<>0 then exit;
erase(f);
end;

procedure replaceit(var c:string;code:string;wi:string);
  var x:integer;
  begin
  x:=pos(code,c);
  if x>0 then begin
              delete(c,x,3);
              insert(wi,c,x);
              end;
  end;

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 -do %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'; { pkzip }
comps[2].id        :='`ê';  { pkzip }
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;

assign(f,fn);
{$i-} reset(f,1); {$i+}
findcomp:=0;
if ioresult<>0 then exit;
blockread(f,c,sizeof(C));
for x:=1 to 3 do if pos(c,comps[x].id)>0 then
                    begin
                    writeln(comps[x].name,' Detected!');
                    findcomp:=x;
                    end;
for x:=1 to 80 do write('Ä');
END;

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

begin
case d of
1:begin
  killfile(fn);
  cmd:=archp+comps[1].compress;
  replaceit(cmd,'%FN',af);
  replaceit(cmd,'%AF',fn);
  err:=doExec(cmd);
  end;
2:begin
  cmd:=archp+comps[1].uncompress;
  replaceit(cmd,'%FN',af);
  replaceit(cmd,'%AF',fn);
  err:=doExec(cmd);
  end;
3:begin
  writeln('testing');
  cmd:=archp+comps[1].TEST;
  replaceit(cmd,'%FN',af);
  replaceit(cmd,'%AF',fn);
  err:=doExec(cmd);
  end;
4:begin
  writeln('commenting');
  cmd:=archp+comps[1].comment;
  replaceit(cmd,'%AF',FN);
  replaceit(cmd,'%CF','<COMMENT.TXT');
  Exec(GetEnv('COMSPEC'), '/C '+cmd);
  end;
5:begin;
  writeln('deleteing');
  cmd:=archp+comps[1].delete;
  replaceit(cmd,'%AF',FN);
  replaceit(cmd,'%FN',AF);
  err:=doExec(cmd);
  end;
end;
end;

      begin
      textattr:=7;
      clrscr;
      findcomp('1.arj');
      findcomp(2,'c:\lucid\arch\temp\','1.ARJ');
      findcomp(1,'c:\lucid\arch\temp\*.*','1.ARJ');
      findcomp(3,'','1.ARJ');
      findcomp(4,'','c:\lucid\arch\1.ARJ');
      findcomp(5,'comment.txt','c:\lucid\arch\1.ARJ');
      end.