#!/usr/bin/perl -w
use strict "subs";

$proof_filename = "/tmp/hol_light_proof";
$goals_servername = "hol_light_goals";
$command_filename = "/tmp/hol_light_step_command";
$pid_filename = "/tmp/hol_light_step_pid";

$command = shift;

undef $/;
$p = <>;
open(F,">$proof_filename");
print F $p;
close(F);
if (-e $pid_filename) {
  open(F,">$command_filename");
  print F $command;
  close(F);
  open(F,"<$pid_filename");
  $pid = <F>;
  chop($pid);
  kill 1, $pid;
  while (-e $command_filename) { select(undef,undef,undef,0.01); }
} else {
  print "###>  HOL server not running\n";
}
open(F,"<$proof_filename");
print <F>;
close(F);
close(STDERR);
system("vim --servername $goals_servername --remote-send '".'<esc>:set noruler<cr>:e!<cr>Gf h<C-L>'."'") if fork;
