uses stdio;

 (* Скопировать файл f1 в файл f2
  * при помощи стандартных процедур ввода/вывода
  *)
function copyfile(const f1, f2:pchar):integer;
var
  inf, outf:pfile;
  c:longint;
begin
  inf := fopen (f1, 'r');
  if inf = nil then
  begin
    copyfile:=-1;
    exit;
  end;
  outf := fopen (f2, 'w');
  if outf = nil then
  begin
    fclose (inf);
    copyfile:=-2;
    exit;
  end;
  c := getc (inf);
  while c <> EOF do
  begin
    putc (c, outf);
    c := getc (inf);
  end;
  fclose (inf);
  fclose (outf);
  copyfile:=0;
end;


begin
  if argc < 3 then
    halt (1);
  if copyfile (argv[1], argv[2])<>0 then
  begin
    perror ('copyfile');
    halt (1);
  end;
end.
