src/HOL/Tools/ATP/watcher.ML
author quigley
Thu Jun 02 15:54:11 2005 +0200 (2005-06-02)
changeset 16185 bb71c91e781e
parent 16156 2f6fc19aba1e
child 16260 4a1f36eafe17
permissions -rw-r--r--
Added time lime (60 secs) to Spass calls.
paulson@15789
     1
(*  Title:      Watcher.ML
quigley@16156
     2
paulson@15789
     3
    ID:         $Id$
paulson@15789
     4
    Author:     Claire Quigley
paulson@15789
     5
    Copyright   2004  University of Cambridge
quigley@15642
     6
 *)
quigley@15642
     7
quigley@15642
     8
 (***************************************************************************)
quigley@15642
     9
 (*  The watcher process starts a resolution process when it receives a     *)
quigley@15642
    10
(*  message from Isabelle                                                  *)
quigley@15642
    11
(*  Signals Isabelle, puts output of child into pipe to Isabelle,          *)
quigley@15642
    12
(*  and removes dead processes.  Also possible to kill all the resolution  *)
quigley@15642
    13
(*  processes currently running.                                           *)
quigley@15642
    14
(*  Hardwired version of where to pick up the tptp files for the moment    *)
quigley@15642
    15
(***************************************************************************)
quigley@15642
    16
quigley@15642
    17
(*use "Proof_Transfer";
quigley@15642
    18
use "VampireCommunication";
paulson@16089
    19
use "SpassCommunication";*)
quigley@15642
    20
(*use "/homes/clq20/Jia_Code/TransStartIsar";*)
quigley@15642
    21
quigley@15642
    22
quigley@15642
    23
structure Watcher: WATCHER =
quigley@15642
    24
  struct
quigley@15642
    25
quigley@15642
    26
val goals_being_watched = ref 0;
quigley@15642
    27
quigley@16039
    28
(*****************************************)
quigley@16039
    29
(*  The result of calling createWatcher  *)
quigley@16039
    30
(*****************************************)
quigley@15642
    31
quigley@16039
    32
datatype proc = PROC of {
quigley@16039
    33
        pid : Posix.Process.pid,
quigley@16039
    34
        instr : TextIO.instream,
quigley@16039
    35
        outstr : TextIO.outstream
quigley@16039
    36
      };
quigley@16039
    37
quigley@16039
    38
(*****************************************)
quigley@16039
    39
(*  The result of calling executeToList  *)
quigley@16039
    40
(*****************************************)
quigley@16039
    41
quigley@16039
    42
datatype cmdproc = CMDPROC of {
quigley@16039
    43
        prover: string,             (* Name of the resolution prover used, e.g. Vampire, SPASS *)
quigley@16039
    44
        cmd:  string,              (* The file containing the goal for res prover to prove *)     
quigley@16039
    45
        thmstring: string,         (* string representation of subgoal after negation, skolemization*) 
quigley@16039
    46
        goalstring: string,         (* string representation of subgoal*) 
quigley@16039
    47
        proc_handle : (TextIO.instream,TextIO.outstream) Unix.proc,
quigley@16039
    48
        instr : TextIO.instream,   (*  Input stream to child process *)
quigley@16039
    49
        outstr : TextIO.outstream  (*  Output stream from child process *)
quigley@16039
    50
      };
quigley@16039
    51
quigley@16039
    52
type signal = Posix.Signal.signal
quigley@16039
    53
datatype exit_status = datatype Posix.Process.exit_status
quigley@16039
    54
quigley@16039
    55
val fromStatus = Posix.Process.fromStatus
quigley@16039
    56
quigley@16039
    57
quigley@16039
    58
fun reap(pid, instr, outstr) =
quigley@16039
    59
        let
quigley@16039
    60
		val u = TextIO.closeIn instr;
quigley@16039
    61
	        val u = TextIO.closeOut outstr;
quigley@16039
    62
	
quigley@16039
    63
		val (_, status) =
quigley@16039
    64
			Posix.Process.waitpid(Posix.Process.W_CHILD pid, [])
quigley@16039
    65
	in
quigley@16039
    66
		status
quigley@16039
    67
	end
quigley@16039
    68
quigley@16039
    69
fun fdReader (name : string, fd : Posix.IO.file_desc) =
quigley@16039
    70
	  Posix.IO.mkTextReader {initBlkMode = true,name = name,fd = fd };
quigley@16039
    71
quigley@16039
    72
fun fdWriter (name, fd) =
quigley@16039
    73
          Posix.IO.mkTextWriter {
quigley@16039
    74
	      appendMode = false,
quigley@16039
    75
              initBlkMode = true,
quigley@16039
    76
              name = name,  
quigley@16039
    77
              chunkSize=4096,
quigley@16039
    78
              fd = fd
quigley@16039
    79
            };
quigley@16039
    80
quigley@16039
    81
fun openOutFD (name, fd) =
quigley@16039
    82
	  TextIO.mkOutstream (
quigley@16039
    83
	    TextIO.StreamIO.mkOutstream (
quigley@16039
    84
	      fdWriter (name, fd), IO.BLOCK_BUF));
quigley@16039
    85
quigley@16039
    86
fun openInFD (name, fd) =
quigley@16039
    87
	  TextIO.mkInstream (
quigley@16039
    88
	    TextIO.StreamIO.mkInstream (
quigley@16039
    89
	      fdReader (name, fd), ""));
quigley@16039
    90
quigley@16039
    91
quigley@16039
    92
quigley@16039
    93
quigley@16039
    94
quigley@16039
    95
fun killChild child_handle = Unix.reap child_handle 
quigley@16039
    96
quigley@16039
    97
fun childInfo (PROC{pid,instr,outstr }) = (pid,(instr,outstr));
quigley@16039
    98
quigley@16039
    99
fun cmdstreamsOf (CMDPROC{instr,outstr,...}) = (instr, outstr);
quigley@16039
   100
quigley@16039
   101
fun cmdInStream (CMDPROC{instr,outstr,...}) = (instr);
quigley@16039
   102
quigley@16039
   103
fun cmdchildInfo (CMDPROC{prover,cmd,thmstring,proc_handle,goalstring,instr,outstr}) = (prover,(cmd, (instr,outstr)));
quigley@16039
   104
quigley@16039
   105
fun cmdchildHandle (CMDPROC{prover,cmd,thmstring,goalstring,proc_handle,instr,outstr})  = proc_handle;
quigley@16039
   106
quigley@16039
   107
fun cmdProver (CMDPROC{prover,cmd,thmstring,goalstring,proc_handle,instr,outstr})  = (prover);
quigley@16039
   108
quigley@16039
   109
fun cmdThm (CMDPROC{prover,cmd,thmstring,goalstring,proc_handle,instr,outstr})  = (thmstring);
quigley@16039
   110
quigley@16039
   111
fun cmdGoal (CMDPROC{prover,cmd,thmstring,goalstring,proc_handle,instr,outstr})  = (goalstring);
quigley@15642
   112
quigley@15642
   113
fun sendOutput (outstr,str) = (TextIO.outputSubstr (outstr, (Substring.all str));TextIO.flushOut outstr);
quigley@15642
   114
quigley@15642
   115
(********************************************************************************************)
quigley@15642
   116
(*  takes a list of arguments and sends them individually to the watcher process by pipe    *)
quigley@15642
   117
(********************************************************************************************)
quigley@15642
   118
quigley@15642
   119
fun outputArgs (toWatcherStr, []) = ()
quigley@15642
   120
|   outputArgs (toWatcherStr, (x::xs)) = (TextIO.output (toWatcherStr, x); 
quigley@15642
   121
                                          TextIO.flushOut toWatcherStr;
quigley@15642
   122
                                         outputArgs (toWatcherStr, xs))
quigley@15642
   123
quigley@15642
   124
(********************************************************************************)
quigley@15642
   125
(*    gets individual args from instream and concatenates them into a list      *)
quigley@15642
   126
(********************************************************************************)
quigley@15642
   127
quigley@15642
   128
fun getArgs (fromParentStr, toParentStr,ys) =  let 
quigley@15642
   129
                                       val thisLine = TextIO.input fromParentStr
quigley@15642
   130
                                    in
quigley@15642
   131
                                        ((ys@[thisLine]))
quigley@15642
   132
                                    end
quigley@15642
   133
quigley@15642
   134
(********************************************************************************)
quigley@15642
   135
(*  Remove the \n character from the end of each filename                       *)
quigley@15642
   136
(********************************************************************************)
quigley@15642
   137
quigley@15642
   138
fun getCmd cmdStr = let val backList = ((rev(explode cmdStr))) 
quigley@15642
   139
                    in
quigley@15642
   140
                        if (String.isPrefix "\n"  (implode backList )) 
paulson@16089
   141
                        then (implode (rev ((tl backList))))
paulson@16089
   142
                        else cmdStr
quigley@15642
   143
                    end
quigley@15642
   144
                            
quigley@15642
   145
(********************************************************************************)
quigley@15642
   146
(*  Send request to Watcher for a vampire to be called for filename in arg      *)
quigley@15642
   147
(********************************************************************************)
quigley@15642
   148
                    
quigley@15642
   149
fun callResProver (toWatcherStr,  arg) = (sendOutput (toWatcherStr, arg^"\n"); 
paulson@16089
   150
                                     TextIO.flushOut toWatcherStr)
quigley@15642
   151
quigley@15642
   152
(*****************************************************************************************)
quigley@15642
   153
(*  Send request to Watcher for multiple provers to be called for filenames in arg      *)
quigley@15642
   154
(*****************************************************************************************)
quigley@15642
   155
quigley@15642
   156
(* need to modify to send over hyps file too *)
paulson@16100
   157
fun callResProvers (toWatcherStr,  []) =
paulson@16100
   158
      (sendOutput (toWatcherStr, "End of calls\n"); 
paulson@16100
   159
       TextIO.flushOut toWatcherStr)
quigley@15782
   160
|   callResProvers (toWatcherStr,(prover,thmstring,goalstring, proverCmd,settings,clasimpfile, axfile, hypsfile,probfile)::args) =
paulson@16061
   161
      let val dfg_dir = File.tmp_path (Path.basic "dfg"); 
paulson@16061
   162
	 (*** need to check here if the directory exists and, if not, create it***)
paulson@16100
   163
	  val _ = File.append (File.tmp_path (Path.basic"thmstring_in_watcher"))                                                                     
paulson@16100
   164
	              (thmstring^"\n goals_watched"^(string_of_int(!goals_being_watched))^"\n")
paulson@16061
   165
	 (*** want to cat clasimp ax hyps prob, then send the resulting file to tptp2x ***)
quigley@16156
   166
	 val probID = ReconOrderClauses.last(explode probfile)
paulson@16061
   167
	  val wholefile = File.tmp_path (Path.basic ("ax_prob_"^probID))
paulson@16061
   168
	  (*** only include problem and clasimp for the moment, not sure how to refer to ***)
quigley@16156
   169
quigley@16156
   170
	  (*** hyps/local axioms just now (*,axfile, hypsfile,*)                                               ***)
quigley@16156
   171
	  val whole_prob_file = system ("/bin/cat " ^ clasimpfile ^" "^ probfile ^ " > " ^ (File.sysify_path wholefile))
quigley@16156
   172
paulson@16089
   173
	  val dfg_create = if File.exists dfg_dir 
paulson@16089
   174
			   then warning("dfg dir exists")
paulson@16089
   175
			   else File.mkdir dfg_dir; 
paulson@16061
   176
	  
paulson@16061
   177
	  val dfg_path = File.sysify_path dfg_dir;
quigley@16185
   178
	 (* val exec_tptp2x = 
quigley@16156
   179
	        Unix.execute(getenv "TPTP2X_HOME" ^ "/tptp2X",  
quigley@16185
   180
	                     ["-fdfg", "-d " ^ dfg_path, File.sysify_path wholefile]) *)
quigley@16185
   181
        val tptp_home = getenv "TPTP2X_HOME" ^ "/tptp2X"
quigley@16185
   182
       
quigley@16185
   183
        val systemcall = system (tptp_home^" -fdfg -d " ^ dfg_path^" "^( File.sysify_path wholefile))
quigley@16185
   184
        val _ =  warning("systemcall is "^ (string_of_int systemcall))
paulson@16061
   185
	(*val _ = Posix.Process.wait ()*)
paulson@16061
   186
	(*val _ =Unix.reap exec_tptp2x*)
paulson@16061
   187
	  val newfile = dfg_path^"/ax_prob"^"_"^(probID)^".dfg"
paulson@16061
   188
 
paulson@16061
   189
       in   
paulson@16061
   190
	  goals_being_watched := (!goals_being_watched) + 1;
quigley@16156
   191
	  Posix.Process.sleep(Time.fromSeconds 1); 
paulson@16089
   192
	  (warning ("probfile is: "^probfile));
paulson@16061
   193
	  (warning("dfg file is: "^newfile));
paulson@16061
   194
	  (warning ("wholefile is: "^(File.sysify_path wholefile)));
paulson@16089
   195
	  sendOutput (toWatcherStr,
paulson@16089
   196
	       prover ^ "*" ^ thmstring ^ "*" ^ goalstring ^ "*" ^ proverCmd ^ 
paulson@16089
   197
	       "*" ^ settings ^ "*" ^ newfile ^ "\n");
paulson@16061
   198
 (*sendOutput (toWatcherStr, (prover^"*"^thmstring^"*"^goalstring^"*"^proverCmd^"*"^settings^"*"^"/homes/clq20/IsabelleCVS/isabelle/HOL/Tools/ATP/dfg/mini_p1.dfg"^"\n"));*)
paulson@16061
   199
	  TextIO.flushOut toWatcherStr;
quigley@16185
   200
	  (*Unix.reap exec_tptp2x;*)
paulson@16089
   201
	  if File.exists
paulson@16089
   202
	        (Path.append dfg_dir (Path.basic ("ax_prob"^"_" ^ probID ^ ".dfg")))
paulson@16089
   203
	  then callResProvers (toWatcherStr, args)
quigley@16156
   204
	  else error ("tptp2X failed: " ^ getenv "TPTP2X_HOME" ^ "/tptp2X" ^
quigley@16156
   205
	              " -fdfg " ^ File.sysify_path wholefile ^ " -d " ^ dfg_path)
paulson@16061
   206
      end
quigley@15782
   207
(*
quigley@15642
   208
fun callResProversStr (toWatcherStr,  []) =  "End of calls\n" 
quigley@15642
   209
                                     
quigley@15782
   210
|   callResProversStr (toWatcherStr,(prover,thmstring,goalstring, proverCmd,settings,clasimpfile, axfile, hypsfile, probfile)::args) =
quigley@15782
   211
                                            ((prover^"*"^thmstring^"*"^goalstring^"*"^proverCmd^"*"^settings^"*"^clasimpfile^"*"^axfile^"*"^hypsfile^"*"^probfile^"\n")
quigley@15642
   212
                                            
quigley@15782
   213
     *)                                      
quigley@15642
   214
 
quigley@15642
   215
(**************************************************************)
quigley@15642
   216
(* Send message to watcher to kill currently running vampires *)
quigley@15642
   217
(**************************************************************)
quigley@15642
   218
quigley@15642
   219
fun callSlayer (toWatcherStr) = (sendOutput (toWatcherStr, "Kill vampires\n"); 
quigley@15642
   220
                            TextIO.flushOut toWatcherStr)
quigley@15642
   221
quigley@15642
   222
quigley@15642
   223
quigley@15642
   224
(**************************************************************)
quigley@15642
   225
(* Remove \n token from a vampire goal filename and extract   *)
quigley@15642
   226
(* prover, proverCmd, settings and file from input string     *)
quigley@15642
   227
(**************************************************************)
quigley@15642
   228
quigley@15642
   229
quigley@15642
   230
 fun takeUntil ch [] res  = (res, [])
quigley@15642
   231
 |   takeUntil ch (x::xs) res = if   x = ch 
quigley@15642
   232
                                then
quigley@15642
   233
                                     (res, xs)
quigley@15642
   234
                                else
quigley@15642
   235
                                     takeUntil ch xs (res@[x])
quigley@15642
   236
quigley@15642
   237
 fun getSettings [] settings = settings
quigley@15642
   238
|    getSettings (xs) settings = let val (set, rest ) = takeUntil "%" xs []
quigley@15642
   239
                                 in
quigley@15642
   240
                                     getSettings rest (settings@[(implode set)])
quigley@15642
   241
                                 end
quigley@15642
   242
paulson@16100
   243
fun separateFields str =
paulson@16100
   244
  let val (prover, rest) = takeUntil "*" str []
paulson@16100
   245
      val prover = implode prover
paulson@16100
   246
      val (thmstring, rest) =  takeUntil "*" rest []
paulson@16100
   247
      val thmstring = implode thmstring
paulson@16100
   248
      val (goalstring, rest) =  takeUntil "*" rest []
paulson@16100
   249
      val goalstring = implode goalstring
paulson@16100
   250
      val (proverCmd, rest ) =  takeUntil "*" rest []
paulson@16100
   251
      val proverCmd = implode proverCmd
paulson@16100
   252
      
paulson@16100
   253
      val (settings, rest) =  takeUntil "*" rest []
paulson@16100
   254
      val settings = getSettings settings []
paulson@16100
   255
      val (file, rest) =  takeUntil "*" rest []
paulson@16100
   256
      val file = implode file
paulson@16100
   257
      val _ = File.write (File.tmp_path (Path.basic "sep_comms"))
paulson@16100
   258
                (prover^thmstring^goalstring^proverCmd^file) 
paulson@16100
   259
  in
paulson@16100
   260
     (prover,thmstring,goalstring, proverCmd, settings, file)
paulson@16100
   261
  end
quigley@15642
   262
quigley@15642
   263
 
quigley@15642
   264
quigley@15642
   265
 fun getCmd cmdStr = let val backList = ((rev(explode cmdStr))) 
quigley@15642
   266
                     in
quigley@15642
   267
quigley@15642
   268
                         if (String.isPrefix "\n"  (implode backList )) 
quigley@15642
   269
                         then 
quigley@15642
   270
                             separateFields ((rev ((tl backList))))
quigley@15642
   271
                         else
quigley@15642
   272
                           (separateFields (explode cmdStr))
quigley@15642
   273
                     end
quigley@15642
   274
                      
quigley@15642
   275
quigley@15642
   276
fun getProofCmd (a,b,c,d,e,f) = d
quigley@15642
   277
quigley@15642
   278
quigley@15642
   279
(**************************************************************)
quigley@15642
   280
(* Get commands from Isabelle                                 *)
quigley@15642
   281
(**************************************************************)
quigley@15642
   282
quigley@15642
   283
fun getCmds (toParentStr,fromParentStr, cmdList) = 
paulson@16100
   284
       let val thisLine = TextIO.inputLine fromParentStr 
paulson@16100
   285
       in
paulson@16100
   286
	  (if (thisLine = "End of calls\n") 
paulson@16100
   287
	   then 
paulson@16100
   288
	      (cmdList)
paulson@16100
   289
	   else if (thisLine = "Kill children\n") 
paulson@16100
   290
		then 
paulson@16100
   291
		    (   TextIO.output (toParentStr,thisLine ); 
paulson@16100
   292
			TextIO.flushOut toParentStr;
paulson@16100
   293
		      (("","","","Kill children",[],"")::cmdList)
paulson@16100
   294
		     )
paulson@16100
   295
	      else (let val thisCmd = getCmd (thisLine) (* thisCmd = (prover,thmstring,proverCmd, settings, file)*)
paulson@16100
   296
		    in
paulson@16100
   297
		      (*TextIO.output (toParentStr, thisCmd); 
paulson@16100
   298
			TextIO.flushOut toParentStr;*)
paulson@16100
   299
			getCmds (toParentStr,fromParentStr, (thisCmd::cmdList))
paulson@16100
   300
		    end
paulson@16100
   301
		    )
paulson@16100
   302
	    )
paulson@16100
   303
	end
quigley@15642
   304
                                    
quigley@15642
   305
                                    
quigley@15642
   306
(**************************************************************)
quigley@15642
   307
(*  Get Io-descriptor for polling of an input stream          *)
quigley@15642
   308
(**************************************************************)
quigley@15642
   309
quigley@15642
   310
quigley@15642
   311
fun getInIoDesc someInstr = 
quigley@15642
   312
    let val (rd, buf) = TextIO.StreamIO.getReader(TextIO.getInstream someInstr)
paulson@15702
   313
        val _ = TextIO.output (TextIO.stdOut, buf)
quigley@15642
   314
        val ioDesc = 
quigley@15642
   315
	    case rd
quigley@15642
   316
	      of TextPrimIO.RD{ioDesc = SOME iod, ...} =>SOME iod
quigley@15642
   317
	       | _ => NONE
quigley@15642
   318
     in (* since getting the reader will have terminated the stream, we need
quigley@15642
   319
	 * to build a new stream. *)
quigley@15642
   320
	TextIO.setInstream(someInstr, TextIO.StreamIO.mkInstream(rd, buf));
quigley@15642
   321
	ioDesc
quigley@15642
   322
    end
quigley@15642
   323
quigley@15642
   324
quigley@15642
   325
(*************************************)
quigley@15642
   326
(*  Set up a Watcher Process         *)
quigley@15642
   327
(*************************************)
quigley@15642
   328
quigley@15642
   329
quigley@15642
   330
paulson@16061
   331
fun setupWatcher (thm,clause_arr, num_of_clauses) = 
paulson@16061
   332
  let
paulson@16061
   333
    (** pipes for communication between parent and watcher **)
paulson@16061
   334
    val p1 = Posix.IO.pipe ()
paulson@16061
   335
    val p2 = Posix.IO.pipe ()
paulson@16061
   336
    fun closep () = (
paulson@16061
   337
	  Posix.IO.close (#outfd p1); 
paulson@16061
   338
	  Posix.IO.close (#infd p1);
paulson@16061
   339
	  Posix.IO.close (#outfd p2); 
paulson@16061
   340
	  Posix.IO.close (#infd p2)
paulson@16061
   341
	)
paulson@16061
   342
    (***********************************************************)
paulson@16061
   343
    (****** fork a watcher process and get it set up and going *)
paulson@16061
   344
    (***********************************************************)
paulson@16061
   345
    fun startWatcher (procList) =
paulson@16061
   346
	     (case  Posix.Process.fork() (***************************************)
paulson@16061
   347
	   of SOME pid =>  pid           (* parent - i.e. main Isabelle process *)
paulson@16061
   348
					 (***************************************)
paulson@16061
   349
paulson@16061
   350
					   (*************************)
paulson@16061
   351
	    | NONE => let                  (* child - i.e. watcher  *)
paulson@16061
   352
		val oldchildin = #infd p1  (*************************)
paulson@16061
   353
		val fromParent = Posix.FileSys.wordToFD 0w0
paulson@16061
   354
		val oldchildout = #outfd p2
paulson@16061
   355
		val toParent = Posix.FileSys.wordToFD 0w1
paulson@16061
   356
		val fromParentIOD = Posix.FileSys.fdToIOD fromParent
paulson@16061
   357
		val fromParentStr = openInFD ("_exec_in_parent", fromParent)
paulson@16061
   358
		val toParentStr = openOutFD ("_exec_out_parent", toParent)
paulson@16061
   359
		val sign = sign_of_thm thm
paulson@16061
   360
		val prems = prems_of thm
paulson@16061
   361
		val prems_string =  Meson.concat_with_and (map (Sign.string_of_term sign) prems) 
paulson@16061
   362
		val _ = (warning ("subgoals forked to startWatcher: "^prems_string));
paulson@16061
   363
	       (* tracing *)
paulson@16061
   364
	      (*val tenth_ax = fst( Array.sub(clause_arr, 1))  
paulson@16061
   365
		val tenth_ax_thms = memo_find_clause (tenth_ax, clause_tab)
paulson@16061
   366
		val clause_str = Meson.concat_with_and (map string_of_thm tenth_ax_thms)
paulson@16061
   367
		val _ = (warning ("tenth axiom in array in watcher is: "^tenth_ax))         
paulson@16061
   368
		val _ = (warning ("tenth axiom in table in watcher is: "^clause_str))         
paulson@16061
   369
		val _ = (warning ("num_of_clauses in watcher is: "^(string_of_int (num_of_clauses))) )       
paulson@16061
   370
			 *)
paulson@16061
   371
		(*val goalstr = string_of_thm (the_goal)
paulson@16061
   372
		 val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "goal_in_watcher")));  
paulson@16061
   373
		val _ = TextIO.output (outfile,goalstr )
paulson@16061
   374
		val _ =  TextIO.closeOut outfile*)
paulson@16061
   375
		fun killChildren [] = ()
paulson@16061
   376
	     |      killChildren  (child_handle::children) = (killChild child_handle; killChildren children)
quigley@15642
   377
paulson@16061
   378
	       
paulson@16061
   379
     
paulson@16061
   380
	      (*************************************************************)
paulson@16061
   381
	      (* take an instream and poll its underlying reader for input *)
paulson@16061
   382
	      (*************************************************************)
quigley@15642
   383
paulson@16061
   384
	      fun pollParentInput () = 
paulson@16061
   385
		     
paulson@16061
   386
			 let val pd = OS.IO.pollDesc (fromParentIOD)
paulson@16061
   387
			 in 
paulson@16061
   388
			 if (isSome pd ) then 
paulson@16061
   389
			     let val pd' = OS.IO.pollIn (valOf pd)
quigley@16156
   390
				 val pdl = OS.IO.poll ([pd'], SOME (Time.fromMilliseconds 2000)) 
paulson@16061
   391
			     in
paulson@16061
   392
				if null pdl 
paulson@16061
   393
				then
paulson@16061
   394
				   NONE
paulson@16061
   395
				else if (OS.IO.isIn (hd pdl)) 
paulson@16061
   396
				     then
paulson@16061
   397
					(SOME ( getCmds (toParentStr, fromParentStr, [])))
paulson@16061
   398
				     else
paulson@16061
   399
					 NONE
paulson@16061
   400
			     end
paulson@16061
   401
			   else
paulson@16061
   402
			       NONE
paulson@16061
   403
			   end
paulson@16061
   404
		      
paulson@16061
   405
	     
quigley@15642
   406
paulson@16061
   407
	       fun pollChildInput (fromStr) = 
paulson@16061
   408
		     let val iod = getInIoDesc fromStr
paulson@16061
   409
		     in 
paulson@16061
   410
		     if isSome iod 
paulson@16061
   411
		     then 
paulson@16061
   412
			 let val pd = OS.IO.pollDesc (valOf iod)
paulson@16061
   413
			 in 
paulson@16061
   414
			 if (isSome pd ) then 
paulson@16061
   415
			     let val pd' = OS.IO.pollIn (valOf pd)
quigley@16156
   416
				 val pdl = OS.IO.poll ([pd'], SOME (Time.fromMilliseconds 2000)) 
paulson@16061
   417
			     in
paulson@16061
   418
				if null pdl 
paulson@16061
   419
				then
paulson@16061
   420
				   NONE
paulson@16061
   421
				else if (OS.IO.isIn (hd pdl)) 
paulson@16061
   422
				     then
paulson@16061
   423
					 SOME (getCmd (TextIO.inputLine fromStr))
paulson@16061
   424
				     else
paulson@16061
   425
					 NONE
paulson@16061
   426
			     end
paulson@16061
   427
			   else
paulson@16061
   428
			       NONE
paulson@16061
   429
			   end
paulson@16061
   430
		       else 
paulson@16061
   431
			   NONE
paulson@16061
   432
		      end
quigley@15642
   433
quigley@15642
   434
paulson@16061
   435
	     (****************************************************************************)
paulson@16061
   436
	     (* Check all vampire processes currently running for output                 *)
paulson@16061
   437
	     (****************************************************************************) 
paulson@16061
   438
							(*********************************)
paulson@16061
   439
	      fun checkChildren ([], toParentStr) = []  (*** no children to check ********)
paulson@16061
   440
							(*********************************)
paulson@16061
   441
	      |   checkChildren ((childProc::otherChildren), toParentStr) = 
paulson@16061
   442
		    let val (childInput,childOutput) =  cmdstreamsOf childProc
paulson@16061
   443
			val child_handle= cmdchildHandle childProc
paulson@16061
   444
			(* childCmd is the .dfg file that the problem is in *)
paulson@16061
   445
			val childCmd = fst(snd (cmdchildInfo childProc))
paulson@16061
   446
			(* now get the number of the subgoal from the filename *)
paulson@16061
   447
			val sg_num = int_of_string(ReconOrderClauses.get_nth 5 (rev(explode childCmd)))
paulson@16061
   448
			val childIncoming = pollChildInput childInput
paulson@16061
   449
			val parentID = Posix.ProcEnv.getppid()
paulson@16061
   450
			val prover = cmdProver childProc
paulson@16061
   451
			val thmstring = cmdThm childProc
paulson@16061
   452
			val sign = sign_of_thm thm
paulson@16061
   453
			val prems = prems_of thm
paulson@16061
   454
			val prems_string =  Meson.concat_with_and (map (Sign.string_of_term sign) prems) 
paulson@16100
   455
			val _ = warning("subgoals forked to checkChildren: "^prems_string)
paulson@16100
   456
			val goalstring = cmdGoal childProc							
paulson@16100
   457
			val _ = File.write (File.tmp_path (Path.basic "child_comms")) 
paulson@16100
   458
			           (prover^thmstring^goalstring^childCmd)
paulson@16061
   459
		    in 
paulson@16061
   460
		      if (isSome childIncoming) 
paulson@16061
   461
		      then 
paulson@16061
   462
			  (* check here for prover label on child*)
paulson@16100
   463
			  let val _ = File.write (File.tmp_path (Path.basic "child_incoming"))  ("subgoals forked to checkChildren: "^prems_string^prover^thmstring^goalstring^childCmd) 
paulson@16061
   464
		      val childDone = (case prover of
quigley@16156
   465
	    (* "vampire" => startVampireTransfer(childInput, toParentStr, parentID, childCmd)                                               |*)"spass" => (SpassComm.checkSpassProofFound(childInput, toParentStr, parentID,thmstring,goalstring, childCmd, thm, sg_num,clause_arr, num_of_clauses)     ) )
paulson@16061
   466
			   in
paulson@16061
   467
			    if childDone      (**********************************************)
paulson@16061
   468
			    then              (* child has found a proof and transferred it *)
paulson@16061
   469
					      (**********************************************)
quigley@15642
   470
paulson@16061
   471
			       (**********************************************)
paulson@16061
   472
			       (* Remove this child and go on to check others*)
paulson@16061
   473
			       (**********************************************)
paulson@16061
   474
			       ( Unix.reap child_handle;
paulson@16061
   475
				 checkChildren(otherChildren, toParentStr))
paulson@16061
   476
			    else 
paulson@16061
   477
			       (**********************************************)
paulson@16061
   478
			       (* Keep this child and go on to check others  *)
paulson@16061
   479
			       (**********************************************)
quigley@15642
   480
paulson@16061
   481
				 (childProc::(checkChildren (otherChildren, toParentStr)))
paulson@16061
   482
			 end
paulson@16061
   483
		       else
paulson@16100
   484
			 (File.append (File.tmp_path (Path.basic "child_incoming")) "No child output ";
paulson@16100
   485
			  childProc::(checkChildren (otherChildren, toParentStr)))
paulson@16061
   486
		    end
quigley@15642
   487
paulson@16061
   488
	     
paulson@16061
   489
	  (********************************************************************)                  
paulson@16061
   490
	  (* call resolution processes                                        *)
paulson@16061
   491
	  (* settings should be a list of strings                             *)
paulson@16061
   492
	  (* e.g. ["-t 300", "-m 100000"]                                     *)
paulson@16061
   493
	  (* takes list of (string, string, string list, string)list proclist *)
paulson@16061
   494
	  (********************************************************************)
quigley@15642
   495
quigley@16039
   496
paulson@16061
   497
(*** add subgoal id num to this *)
paulson@16061
   498
	     fun execCmds  [] procList = procList
paulson@16061
   499
	     |   execCmds  ((prover, thmstring,goalstring,proverCmd,settings,file)::cmds) procList  = 
paulson@16100
   500
		   if (prover = "spass") 
paulson@16100
   501
		   then 
paulson@16100
   502
		       let val childhandle:(TextIO.instream,TextIO.outstream) Unix.proc  = (Unix.execute(proverCmd, (["-FullRed=0"]@settings@[file])))
paulson@16100
   503
			   val (instr, outstr)=Unix.streamsOf childhandle
paulson@16100
   504
			   val newProcList =    (((CMDPROC{
paulson@16100
   505
						prover = prover,
paulson@16100
   506
						cmd = file,
paulson@16100
   507
						thmstring = thmstring,
paulson@16100
   508
						goalstring = goalstring,
paulson@16100
   509
						proc_handle = childhandle,
paulson@16100
   510
						instr = instr,
paulson@16100
   511
						outstr = outstr })::procList))
paulson@16100
   512
			    val _ = File.append (File.tmp_path (Path.basic "exec_child"))  ("executing command for goal:"^goalstring^proverCmd^(concat settings)^file)
paulson@16100
   513
		       in
paulson@16100
   514
			  execCmds cmds newProcList
paulson@16100
   515
		       end
paulson@16100
   516
		   else 
paulson@16100
   517
		       let val childhandle:(TextIO.instream,TextIO.outstream) Unix.proc  = (Unix.execute(proverCmd, (["-FullRed=0"]@settings@[file])))
paulson@16100
   518
			   val (instr, outstr)=Unix.streamsOf childhandle
paulson@16100
   519
			   val newProcList =    (((CMDPROC{
paulson@16100
   520
						prover = prover,
paulson@16100
   521
						cmd = file,
paulson@16100
   522
						thmstring = thmstring,
paulson@16100
   523
						goalstring = goalstring,
paulson@16100
   524
						proc_handle = childhandle,
paulson@16100
   525
						instr = instr,
paulson@16100
   526
						outstr = outstr })::procList))
paulson@16100
   527
		       in
paulson@16100
   528
			  execCmds cmds newProcList
paulson@16100
   529
		       end
quigley@15642
   530
quigley@15642
   531
quigley@16039
   532
paulson@16061
   533
	  (****************************************)                  
paulson@16061
   534
	  (* call resolution processes remotely   *)
paulson@16061
   535
	  (* settings should be a list of strings *)
paulson@16061
   536
	  (* e.g. ["-t 300", "-m 100000"]         *)
paulson@16061
   537
	  (****************************************)
paulson@16061
   538
paulson@16061
   539
	   (*  fun execRemoteCmds  [] procList = procList
paulson@16061
   540
	     |   execRemoteCmds ((prover, thmstring,goalstring,proverCmd ,settings,file)::cmds) procList  =  
paulson@16061
   541
				       let val  newProcList =  mySshExecuteToList ("/usr/bin/ssh",([prover,thmstring,goalstring,"-t", "shep"]@[proverCmd]@settings@[file]), procList)
paulson@16061
   542
					   in
paulson@16061
   543
						execRemoteCmds  cmds newProcList
paulson@16061
   544
					   end
quigley@16039
   545
*)
quigley@15642
   546
paulson@16061
   547
	     fun printList (outStr, []) = ()
paulson@16061
   548
	     |   printList (outStr, (x::xs)) = (TextIO.output (outStr, x);TextIO.flushOut outStr; printList (outStr,xs))                  
quigley@15642
   549
quigley@15642
   550
paulson@16061
   551
	  (**********************************************)                  
paulson@16061
   552
	  (* Watcher Loop                               *)
paulson@16061
   553
	  (**********************************************)
paulson@16061
   554
quigley@15642
   555
quigley@15642
   556
quigley@15642
   557
paulson@16061
   558
	      fun keepWatching (toParentStr, fromParentStr,procList) = 
paulson@16061
   559
		    let    fun loop (procList) =  
paulson@16061
   560
			   (
paulson@16061
   561
			   let val cmdsFromIsa = pollParentInput ()
paulson@16061
   562
			       fun killchildHandler (n:int)  = (TextIO.output(toParentStr, "Killing child proof processes!\n");
paulson@16061
   563
					    TextIO.flushOut toParentStr;
paulson@16061
   564
					     killChildren (map (cmdchildHandle) procList);
paulson@16061
   565
					      ())
paulson@16061
   566
			       
paulson@16061
   567
			   in 
paulson@16061
   568
			      (*Signal.signal (Posix.Signal.usr2, Signal.SIG_HANDLE killchildHandler);*)
paulson@16061
   569
										 (**********************************)
paulson@16061
   570
			      if (isSome cmdsFromIsa) then                       (*  deal with input from Isabelle *)
paulson@16061
   571
				   (                                             (**********************************)                             
paulson@16061
   572
				    if (getProofCmd(hd(valOf cmdsFromIsa)) = "Kill children" )
paulson@16061
   573
				    then 
paulson@16061
   574
				      (
paulson@16061
   575
					let val child_handles = map cmdchildHandle procList 
paulson@16061
   576
					in
paulson@16061
   577
					   killChildren child_handles;
paulson@16061
   578
					   (*Posix.Process.kill(Posix.Process.K_PROC (Posix.ProcEnv.getppid()), Posix.Signal.usr2);*)                                                              loop ([])
paulson@16061
   579
					end
paulson@16061
   580
					   
paulson@16061
   581
				       )
paulson@16061
   582
				    else
paulson@16061
   583
				      ( 
paulson@16061
   584
					if ((length procList)<10)    (********************)
paulson@16061
   585
					then                        (* Execute locally  *)
paulson@16061
   586
					   (                        (********************)
paulson@16061
   587
					    let 
paulson@16061
   588
					      val newProcList = execCmds (valOf cmdsFromIsa) procList
paulson@16061
   589
					      val parentID = Posix.ProcEnv.getppid()
paulson@16061
   590
					      val newProcList' =checkChildren (newProcList, toParentStr) 
paulson@16061
   591
					    in
paulson@16061
   592
					      (*Posix.Process.sleep (Time.fromSeconds 1);*)
paulson@16061
   593
					      loop (newProcList') 
paulson@16061
   594
					    end
paulson@16061
   595
					    )
paulson@16061
   596
					else                         (*********************************)
paulson@16061
   597
								     (* Execute remotely              *)
paulson@16061
   598
								     (* (actually not remote for now )*)
paulson@16061
   599
					    (                        (*********************************)
paulson@16061
   600
					    let 
paulson@16061
   601
					      val newProcList = execCmds (valOf cmdsFromIsa) procList
paulson@16061
   602
					      val parentID = Posix.ProcEnv.getppid()
paulson@16061
   603
					      val newProcList' =checkChildren (newProcList, toParentStr) 
paulson@16061
   604
					    in
paulson@16061
   605
					      (*Posix.Process.sleep (Time.fromSeconds 1);*)
paulson@16061
   606
					      loop (newProcList') 
paulson@16061
   607
					    end
paulson@16061
   608
					    )
quigley@15642
   609
quigley@15642
   610
quigley@15642
   611
paulson@16061
   612
					)
paulson@16061
   613
				     )                                              (******************************)
paulson@16061
   614
			      else                                                  (* No new input from Isabelle *)
paulson@16061
   615
										    (******************************)
paulson@16061
   616
				  (    let val newProcList = checkChildren ((procList), toParentStr)
paulson@16061
   617
				       in
paulson@16061
   618
					 Posix.Process.sleep (Time.fromSeconds 1);
paulson@16061
   619
					 loop (newProcList)
paulson@16061
   620
				       end
paulson@16061
   621
				   
paulson@16061
   622
				   )
paulson@16061
   623
			    end)
paulson@16061
   624
		    in  
paulson@16061
   625
			loop (procList)
paulson@16061
   626
		    end
paulson@16061
   627
		
paulson@16061
   628
    
paulson@16061
   629
		in
paulson@16061
   630
		 (***************************)
paulson@16061
   631
		 (*** Sort out pipes ********)
paulson@16061
   632
		 (***************************)
quigley@15642
   633
paulson@16061
   634
		  Posix.IO.close (#outfd p1);
paulson@16061
   635
		  Posix.IO.close (#infd p2);
paulson@16061
   636
		  Posix.IO.dup2{old = oldchildin, new = fromParent};
paulson@16061
   637
		  Posix.IO.close oldchildin;
paulson@16061
   638
		  Posix.IO.dup2{old = oldchildout, new = toParent};
paulson@16061
   639
		  Posix.IO.close oldchildout;
quigley@15642
   640
paulson@16061
   641
		  (***************************)
paulson@16061
   642
		  (* start the watcher loop  *)
paulson@16061
   643
		  (***************************)
paulson@16061
   644
		  keepWatching (toParentStr, fromParentStr, procList);
quigley@15642
   645
quigley@15642
   646
paulson@16061
   647
		  (****************************************************************************)
paulson@16061
   648
		  (* fake return value - actually want the watcher to loop until killed       *)
paulson@16061
   649
		  (****************************************************************************)
paulson@16061
   650
		  Posix.Process.wordToPid 0w0
paulson@16061
   651
		  
paulson@16061
   652
		end);
paulson@16061
   653
	  (* end case *)
quigley@15642
   654
quigley@15642
   655
paulson@16061
   656
    val _ = TextIO.flushOut TextIO.stdOut
quigley@15642
   657
paulson@16061
   658
    (*******************************)
paulson@16061
   659
    (***  set watcher going ********)
paulson@16061
   660
    (*******************************)
quigley@15642
   661
paulson@16061
   662
    val procList = []
paulson@16061
   663
    val pid = startWatcher (procList)
paulson@16061
   664
    (**************************************************)
paulson@16061
   665
    (* communication streams to watcher               *)
paulson@16061
   666
    (**************************************************)
quigley@15642
   667
paulson@16061
   668
    val instr = openInFD ("_exec_in", #infd p2)
paulson@16061
   669
    val outstr = openOutFD ("_exec_out", #outfd p1)
paulson@16061
   670
    
paulson@16061
   671
    in
paulson@16061
   672
     (*******************************)
paulson@16061
   673
     (* close the child-side fds    *)
paulson@16061
   674
     (*******************************)
paulson@16061
   675
      Posix.IO.close (#outfd p2);
paulson@16061
   676
      Posix.IO.close (#infd p1);
paulson@16061
   677
      (* set the fds close on exec *)
paulson@16061
   678
      Posix.IO.setfd (#infd p2, Posix.IO.FD.flags [Posix.IO.FD.cloexec]);
paulson@16061
   679
      Posix.IO.setfd (#outfd p1, Posix.IO.FD.flags [Posix.IO.FD.cloexec]);
paulson@16061
   680
       
paulson@16061
   681
     (*******************************)
paulson@16061
   682
     (* return value                *)
paulson@16061
   683
     (*******************************)
paulson@16061
   684
      PROC{pid = pid,
paulson@16061
   685
	instr = instr,
paulson@16061
   686
	outstr = outstr
paulson@16061
   687
      }
paulson@16061
   688
   end;
quigley@15642
   689
quigley@15642
   690
quigley@15642
   691
quigley@15642
   692
(**********************************************************)
quigley@15642
   693
(* Start a watcher and set up signal handlers             *)
quigley@15642
   694
(**********************************************************)
quigley@16039
   695
quigley@16039
   696
fun killWatcher pid= Posix.Process.kill(Posix.Process.K_PROC pid, Posix.Signal.kill);
quigley@16039
   697
quigley@16039
   698
fun reapWatcher(pid, instr, outstr) =
quigley@16039
   699
        let
quigley@16039
   700
		val u = TextIO.closeIn instr;
quigley@16039
   701
	        val u = TextIO.closeOut outstr;
quigley@16039
   702
	
quigley@16039
   703
		val (_, status) =
quigley@16039
   704
			Posix.Process.waitpid(Posix.Process.W_CHILD pid, [])
quigley@16039
   705
	in
quigley@16039
   706
		status
quigley@16039
   707
	end
quigley@15642
   708
quigley@16156
   709
quigley@16156
   710
fun createWatcher (thm,clause_arr, ( num_of_clauses:int)) = let val mychild = childInfo (setupWatcher(thm,clause_arr,  num_of_clauses))
quigley@16156
   711
			   val streams =snd mychild
quigley@16156
   712
                           val childin = fst streams
quigley@16156
   713
                           val childout = snd streams
quigley@16156
   714
                           val childpid = fst mychild
quigley@16156
   715
                           val sign = sign_of_thm thm
quigley@16156
   716
                           val prems = prems_of thm
quigley@16156
   717
                           val prems_string =  Meson.concat_with_and (map (Sign.string_of_term sign) prems) 
quigley@16156
   718
                           val _ = (warning ("subgoals forked to createWatcher: "^prems_string));
quigley@16156
   719
                           fun vampire_proofHandler (n) =
quigley@16156
   720
                           (Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
quigley@16156
   721
                           getVampInput childin; Pretty.writeln(Pretty.str  (oct_char "361"));() )               
quigley@16156
   722
                          
quigley@16156
   723
quigley@16156
   724
fun spass_proofHandler (n) = (
quigley@16156
   725
                                 let  val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_signal1")));
quigley@16156
   726
                                      val _ = TextIO.output (outfile, ("In signal handler now\n"))
quigley@16156
   727
                                      val _ =  TextIO.closeOut outfile
quigley@16156
   728
                                      val (reconstr, thmstring, goalstring) = SpassComm.getSpassInput childin
quigley@16156
   729
                                      val  outfile = TextIO.openAppend(File.sysify_path(File.tmp_path (Path.basic "foo_signal")));
quigley@16156
   730
quigley@16156
   731
                                      val _ = TextIO.output (outfile, ("In signal handler  "^reconstr^thmstring^goalstring^"goals_being_watched is: "^(string_of_int (!goals_being_watched))))
quigley@16156
   732
                                      val _ =  TextIO.closeOut outfile
quigley@16156
   733
                                      in          (* if a proof has been found and sent back as a reconstruction proof *)
quigley@16156
   734
                                                  if ( (substring (reconstr, 0,1))= "[")
quigley@16156
   735
                                                  then 
quigley@15642
   736
quigley@16156
   737
                                                            (
quigley@16156
   738
                                                                 Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
quigley@16156
   739
                                                                 Recon_Transfer.apply_res_thm reconstr goalstring;
quigley@16156
   740
                                                                 Pretty.writeln(Pretty.str  (oct_char "361"));
quigley@16156
   741
                                                                 
quigley@16156
   742
                                                                 goals_being_watched := ((!goals_being_watched) - 1);
quigley@16156
   743
                                                         
quigley@16156
   744
                                                                 if ((!goals_being_watched) = 0)
quigley@16156
   745
                                                                 then 
quigley@16156
   746
                                                                    (let val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_reap_found")));
quigley@16156
   747
                                                                         val _ = TextIO.output (outfile, ("Reaping a watcher, goals watched is: "^(string_of_int (!goals_being_watched))^"\n"))
quigley@16156
   748
                                                                         val _ =  TextIO.closeOut outfile
quigley@16156
   749
                                                                     in
quigley@16156
   750
                                                                         killWatcher (childpid); reapWatcher (childpid,childin, childout); ()
quigley@16156
   751
                                                                     end)
quigley@16156
   752
                                                                 else
quigley@16156
   753
                                                                    ()
quigley@16156
   754
                                                            )
quigley@16156
   755
                                                    (* if there's no proof, but a message from Spass *)
quigley@16156
   756
                                                    else if ((substring (reconstr, 0,5))= "SPASS")
quigley@16156
   757
                                                         then
quigley@16156
   758
                                                                 (
quigley@16156
   759
                                                                     goals_being_watched := (!goals_being_watched) -1;
quigley@16156
   760
                                                                     Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
quigley@16156
   761
                                                                      Pretty.writeln(Pretty.str (goalstring^reconstr));
quigley@16156
   762
                                                                      Pretty.writeln(Pretty.str  (oct_char "361"));
quigley@16156
   763
                                                                      if (!goals_being_watched = 0)
quigley@16156
   764
                                                                      then 
quigley@16156
   765
                                                                          (let val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_reap_comp")));
quigley@16156
   766
                                                                               val _ = TextIO.output (outfile, ("Reaping a watcher, goals watched is: "^(string_of_int (!goals_being_watched))^"\n"))
quigley@16156
   767
                                                                               val _ =  TextIO.closeOut outfile
quigley@16156
   768
                                                                           in
quigley@16156
   769
                                                                              killWatcher (childpid); reapWatcher (childpid,childin, childout); ()
quigley@16156
   770
                                                                           end )
quigley@16156
   771
                                                                      else
quigley@16156
   772
                                                                         ()
quigley@16156
   773
                                                                ) 
quigley@16156
   774
						   (* print out a list of rules used from clasimpset*)
quigley@16156
   775
                                                    else if ((substring (reconstr, 0,5))= "Rules")
quigley@16156
   776
                                                         then
quigley@16156
   777
                                                                 (
quigley@16156
   778
                                                                     goals_being_watched := (!goals_being_watched) -1;
quigley@16156
   779
                                                                     Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
quigley@16156
   780
                                                                      Pretty.writeln(Pretty.str (goalstring^reconstr));
quigley@16156
   781
                                                                      Pretty.writeln(Pretty.str  (oct_char "361"));
quigley@16156
   782
                                                                      if (!goals_being_watched = 0)
quigley@16156
   783
                                                                      then 
quigley@16156
   784
                                                                          (let val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_reap_comp")));
quigley@16156
   785
                                                                               val _ = TextIO.output (outfile, ("Reaping a watcher, goals watched is: "^(string_of_int (!goals_being_watched))^"\n"))
quigley@16156
   786
                                                                               val _ =  TextIO.closeOut outfile
quigley@16156
   787
                                                                           in
quigley@16156
   788
                                                                              killWatcher (childpid);  reapWatcher (childpid,childin, childout);()
quigley@16156
   789
                                                                           end )
quigley@16156
   790
                                                                      else
quigley@16156
   791
                                                                         ()
quigley@16156
   792
                                                                )
quigley@16156
   793
							
quigley@16156
   794
                                                          (* if proof translation failed *)
quigley@16156
   795
                                                          else if ((substring (reconstr, 0,5)) = "Proof")
quigley@16156
   796
                                                               then 
quigley@16156
   797
                                                                   (
quigley@16156
   798
                                                                     goals_being_watched := (!goals_being_watched) -1;
quigley@16156
   799
                                                                     Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
quigley@16156
   800
                                                                      Pretty.writeln(Pretty.str (goalstring^reconstr));
quigley@16156
   801
                                                                      Pretty.writeln(Pretty.str  (oct_char "361"));
quigley@16156
   802
                                                                      if (!goals_being_watched = 0)
quigley@16156
   803
                                                                      then 
quigley@16156
   804
                                                                          (let val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_reap_comp")));
quigley@16156
   805
                                                                               val _ = TextIO.output (outfile, ("Reaping a watcher, goals watched is: "^(string_of_int (!goals_being_watched))^"\n"))
quigley@16156
   806
                                                                               val _ =  TextIO.closeOut outfile
quigley@16156
   807
                                                                           in
quigley@16156
   808
                                                                              killWatcher (childpid); reapWatcher (childpid,childin, childout); ()
quigley@16156
   809
                                                                           end )
quigley@16156
   810
                                                                      else
quigley@16156
   811
                                                                         ()
quigley@16156
   812
                                                                )
quigley@15642
   813
quigley@15642
   814
quigley@16156
   815
                                                                else  (* add something here ?*)
quigley@16156
   816
                                                                   ()
quigley@16156
   817
                                                             
quigley@16156
   818
                                       end)
quigley@16156
   819
quigley@16156
   820
quigley@16156
   821
                        
quigley@16156
   822
                       in IsaSignal.signal (IsaSignal.usr1, IsaSignal.SIG_HANDLE vampire_proofHandler);
quigley@16156
   823
                          IsaSignal.signal (IsaSignal.usr2, IsaSignal.SIG_HANDLE spass_proofHandler);
quigley@16156
   824
                          (childin, childout, childpid)
quigley@16156
   825
quigley@15642
   826
paulson@16100
   827
  end
quigley@15642
   828
quigley@15642
   829
quigley@15642
   830
quigley@15642
   831
quigley@15642
   832
quigley@15642
   833
end (* structure Watcher *)