src/HOL/Tools/ATP/watcher.ML
author paulson
Tue May 24 10:23:24 2005 +0200 (2005-05-24)
changeset 16061 8a139c1557bf
parent 16039 dfe264950511
child 16089 9169bdf930f8
permissions -rw-r--r--
A new structure and reduced indentation
paulson@15789
     1
(*  Title:      Watcher.ML
paulson@15789
     2
    ID:         $Id$
paulson@15789
     3
    Author:     Claire Quigley
paulson@15789
     4
    Copyright   2004  University of Cambridge
quigley@15642
     5
 *)
quigley@15642
     6
quigley@15642
     7
 (***************************************************************************)
quigley@15642
     8
 (*  The watcher process starts a resolution process when it receives a     *)
quigley@15642
     9
(*  message from Isabelle                                                  *)
quigley@15642
    10
(*  Signals Isabelle, puts output of child into pipe to Isabelle,          *)
quigley@15642
    11
(*  and removes dead processes.  Also possible to kill all the resolution  *)
quigley@15642
    12
(*  processes currently running.                                           *)
quigley@15642
    13
(*  Hardwired version of where to pick up the tptp files for the moment    *)
quigley@15642
    14
(***************************************************************************)
quigley@15642
    15
quigley@15642
    16
(*use "Proof_Transfer";
quigley@15642
    17
use "VampireCommunication";
quigley@15642
    18
use "SpassCommunication";
quigley@15642
    19
use "modUnix";*)
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
quigley@15642
   141
                        if (String.isPrefix "\n"  (implode backList )) 
quigley@15642
   142
                        then 
quigley@15642
   143
                             (implode (rev ((tl backList))))
quigley@15642
   144
                        else
quigley@15642
   145
                           (cmdStr)
quigley@15642
   146
                    end
quigley@15642
   147
                            
quigley@15642
   148
(********************************************************************************)
quigley@15642
   149
(*  Send request to Watcher for a vampire to be called for filename in arg      *)
quigley@15642
   150
(********************************************************************************)
quigley@15642
   151
                    
quigley@15642
   152
fun callResProver (toWatcherStr,  arg) = (sendOutput (toWatcherStr, arg^"\n"); 
quigley@15642
   153
                                     TextIO.flushOut toWatcherStr
quigley@15642
   154
                                    
quigley@15642
   155
                                     )
quigley@15642
   156
quigley@15642
   157
(*****************************************************************************************)
quigley@15642
   158
(*  Send request to Watcher for multiple provers to be called for filenames in arg      *)
quigley@15642
   159
(*****************************************************************************************)
quigley@15642
   160
quigley@15782
   161
quigley@15782
   162
quigley@15642
   163
(* need to modify to send over hyps file too *)
quigley@15642
   164
fun callResProvers (toWatcherStr,  []) = (sendOutput (toWatcherStr, "End of calls\n"); 
quigley@15642
   165
                                     TextIO.flushOut toWatcherStr)
quigley@15782
   166
|   callResProvers (toWatcherStr,(prover,thmstring,goalstring, proverCmd,settings,clasimpfile, axfile, hypsfile,probfile)::args) =
paulson@16061
   167
      let val dfg_dir = File.tmp_path (Path.basic "dfg"); 
paulson@16061
   168
	 (*** need to check here if the directory exists and, if not, create it***)
paulson@16061
   169
	  val  outfile = TextIO.openAppend(File.sysify_path
paulson@16061
   170
				(File.tmp_path (Path.basic"thmstring_in_watcher")));                                                                         
paulson@16061
   171
	  val _ = TextIO.output (outfile, 
paulson@16061
   172
			(thmstring^"\n goals_watched"^(string_of_int(!goals_being_watched))^"\n"))
paulson@16061
   173
	  val _ =  TextIO.closeOut outfile
paulson@16061
   174
	 (*** want to cat clasimp ax hyps prob, then send the resulting file to tptp2x ***)
paulson@16061
   175
	 val probID = ReconOrderClauses.last(explode probfile)
paulson@16061
   176
	  val wholefile = File.tmp_path (Path.basic ("ax_prob_"^probID))
paulson@16061
   177
	  (*** only include problem and clasimp for the moment, not sure how to refer to ***)
paulson@16061
   178
	  (*** hyps/local axioms just now                                                ***)
paulson@16061
   179
	  val whole_prob_file = Unix.execute("/bin/cat", [clasimpfile,(*,axfile, hypsfile,*)probfile,  ">", (File.sysify_path wholefile)])
paulson@16061
   180
	  val dfg_create =if File.exists dfg_dir 
paulson@16061
   181
			  then
paulson@16061
   182
			      ((warning("dfg dir exists"));())
paulson@16061
   183
			  else
paulson@16061
   184
				File.mkdir dfg_dir; 
paulson@16061
   185
	  
paulson@16061
   186
	  val dfg_path = File.sysify_path dfg_dir;
paulson@16061
   187
	  val exec_tptp2x = Unix.execute("/usr/groups/theory/tptp/TPTP-v3.0.1/TPTP2X/tptp2X",   ["-fdfg ",(File.sysify_path wholefile)," -d ",dfg_path])
paulson@16061
   188
	(*val _ = Posix.Process.wait ()*)
paulson@16061
   189
	(*val _ =Unix.reap exec_tptp2x*)
paulson@16061
   190
	  val newfile = dfg_path^"/ax_prob"^"_"^(probID)^".dfg"
paulson@16061
   191
 
paulson@16061
   192
       in   
paulson@16061
   193
	  goals_being_watched := (!goals_being_watched) + 1;
paulson@16061
   194
	  Posix.Process.sleep(Time.fromSeconds 1); 
paulson@16061
   195
	 (warning ("probfile is: "^probfile));
paulson@16061
   196
	  (warning("dfg file is: "^newfile));
paulson@16061
   197
	  (warning ("wholefile is: "^(File.sysify_path wholefile)));
paulson@16061
   198
	 sendOutput (toWatcherStr, (prover^"*"^thmstring^"*"^goalstring^"*"^proverCmd^"*"^settings^"*"^newfile^"\n"));
paulson@16061
   199
 (*sendOutput (toWatcherStr, (prover^"*"^thmstring^"*"^goalstring^"*"^proverCmd^"*"^settings^"*"^"/homes/clq20/IsabelleCVS/isabelle/HOL/Tools/ATP/dfg/mini_p1.dfg"^"\n"));*)
paulson@16061
   200
	  TextIO.flushOut toWatcherStr;
paulson@16061
   201
	  Unix.reap exec_tptp2x; 
paulson@16061
   202
	  
paulson@16061
   203
	  callResProvers (toWatcherStr,args)
paulson@16061
   204
 
paulson@16061
   205
      end
quigley@15782
   206
(*
quigley@15642
   207
fun callResProversStr (toWatcherStr,  []) =  "End of calls\n" 
quigley@15642
   208
                                     
quigley@15782
   209
|   callResProversStr (toWatcherStr,(prover,thmstring,goalstring, proverCmd,settings,clasimpfile, axfile, hypsfile, probfile)::args) =
quigley@15782
   210
                                            ((prover^"*"^thmstring^"*"^goalstring^"*"^proverCmd^"*"^settings^"*"^clasimpfile^"*"^axfile^"*"^hypsfile^"*"^probfile^"\n")
quigley@15642
   211
                                            
quigley@15782
   212
     *)                                      
quigley@15642
   213
 
quigley@15642
   214
(**************************************************************)
quigley@15642
   215
(* Send message to watcher to kill currently running vampires *)
quigley@15642
   216
(**************************************************************)
quigley@15642
   217
quigley@15642
   218
fun callSlayer (toWatcherStr) = (sendOutput (toWatcherStr, "Kill vampires\n"); 
quigley@15642
   219
                            TextIO.flushOut toWatcherStr)
quigley@15642
   220
quigley@15642
   221
quigley@15642
   222
quigley@15642
   223
(**************************************************************)
quigley@15642
   224
(* Remove \n token from a vampire goal filename and extract   *)
quigley@15642
   225
(* prover, proverCmd, settings and file from input string     *)
quigley@15642
   226
(**************************************************************)
quigley@15642
   227
quigley@15642
   228
quigley@15642
   229
 fun takeUntil ch [] res  = (res, [])
quigley@15642
   230
 |   takeUntil ch (x::xs) res = if   x = ch 
quigley@15642
   231
                                then
quigley@15642
   232
                                     (res, xs)
quigley@15642
   233
                                else
quigley@15642
   234
                                     takeUntil ch xs (res@[x])
quigley@15642
   235
quigley@15642
   236
 fun getSettings [] settings = settings
quigley@15642
   237
|    getSettings (xs) settings = let val (set, rest ) = takeUntil "%" xs []
quigley@15642
   238
                                 in
quigley@15642
   239
                                     getSettings rest (settings@[(implode set)])
quigley@15642
   240
                                 end
quigley@15642
   241
quigley@15642
   242
fun separateFields str = let val (prover, rest) = takeUntil "*" str []
quigley@15642
   243
                              val prover = implode prover
quigley@15642
   244
                              val (thmstring, rest) =  takeUntil "*" rest []
quigley@15642
   245
                              val thmstring = implode thmstring
quigley@15642
   246
                              val (goalstring, rest) =  takeUntil "*" rest []
quigley@15642
   247
                              val goalstring = implode goalstring
quigley@15642
   248
                              val (proverCmd, rest ) =  takeUntil "*" rest []
quigley@15642
   249
                              val proverCmd = implode proverCmd
quigley@15642
   250
                              
quigley@15642
   251
                              val (settings, rest) =  takeUntil "*" rest []
quigley@15642
   252
                              val settings = getSettings settings []
quigley@15642
   253
                              val (file, rest) =  takeUntil "*" rest []
quigley@15642
   254
                              val file = implode file
quigley@15658
   255
                              val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "sep_comms")));                                                                                    
quigley@15642
   256
                              val _ = TextIO.output (outfile,(prover^thmstring^goalstring^proverCmd^file) )
quigley@15642
   257
                              val _ =  TextIO.closeOut outfile
quigley@15642
   258
                              
quigley@15642
   259
                          in
quigley@15642
   260
                             (prover,thmstring,goalstring, proverCmd, settings, file)
quigley@15642
   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) = 
quigley@15642
   284
                                       let val thisLine = TextIO.inputLine fromParentStr 
quigley@15642
   285
                                       in
quigley@15642
   286
                                          (if (thisLine = "End of calls\n") 
quigley@15642
   287
                                           then 
quigley@15642
   288
                                              (cmdList)
quigley@15642
   289
                                           else if (thisLine = "Kill children\n") 
quigley@15642
   290
                                                then 
quigley@15642
   291
                                                    (   TextIO.output (toParentStr,thisLine ); 
quigley@15642
   292
                                                        TextIO.flushOut toParentStr;
quigley@15642
   293
                                                      (("","","","Kill children",[],"")::cmdList)
quigley@15642
   294
                                                     )
quigley@15642
   295
                                              else (let val thisCmd = getCmd (thisLine) (* thisCmd = (prover,thmstring,proverCmd, settings, file)*)
quigley@15642
   296
                                                    in
quigley@15642
   297
                                                      (*TextIO.output (toParentStr, thisCmd); 
quigley@15642
   298
                                                        TextIO.flushOut toParentStr;*)
quigley@15642
   299
                                                        getCmds (toParentStr,fromParentStr, (thisCmd::cmdList))
quigley@15642
   300
                                                    end
quigley@15642
   301
                                                    )
quigley@15642
   302
                                            )
quigley@15642
   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)
paulson@16061
   390
				 val pdl = OS.IO.poll ([pd'], SOME (Time.fromMilliseconds 100)) 
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)
paulson@16061
   416
				 val pdl = OS.IO.poll ([pd'], SOME (Time.fromMilliseconds 100)) 
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@16061
   455
			val _ = (warning ("subgoals forked to checkChildren: "^prems_string));
paulson@16061
   456
			val goalstring = cmdGoal childProc
paulson@16061
   457
									       
paulson@16061
   458
			val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "child_comms")));  
paulson@16061
   459
			val _ = TextIO.output (outfile,(prover^thmstring^goalstring^childCmd) )
paulson@16061
   460
			val _ =  TextIO.closeOut outfile
paulson@16061
   461
		    in 
paulson@16061
   462
		      if (isSome childIncoming) 
paulson@16061
   463
		      then 
paulson@16061
   464
			  (* check here for prover label on child*)
paulson@16061
   465
			   
paulson@16061
   466
			  let val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "child_incoming")));  
paulson@16061
   467
			val _ = TextIO.output (outfile,(("subgoals forked to checkChildren: "^prems_string)^prover^thmstring^goalstring^childCmd) )
paulson@16061
   468
			val _ =  TextIO.closeOut outfile
paulson@16061
   469
		      val childDone = (case prover of
paulson@16061
   470
	    (* "vampire" => startVampireTransfer(childInput, toParentStr, parentID, childCmd)                                               |*)"spass" => (checkSpassProofFound(childInput, toParentStr, parentID,thmstring,goalstring, childCmd, thm, sg_num,clause_arr, num_of_clauses)     ) )
paulson@16061
   471
			   in
paulson@16061
   472
			    if childDone      (**********************************************)
paulson@16061
   473
			    then              (* child has found a proof and transferred it *)
paulson@16061
   474
					      (**********************************************)
quigley@15642
   475
paulson@16061
   476
			       (**********************************************)
paulson@16061
   477
			       (* Remove this child and go on to check others*)
paulson@16061
   478
			       (**********************************************)
paulson@16061
   479
			       ( Unix.reap child_handle;
paulson@16061
   480
				 checkChildren(otherChildren, toParentStr))
paulson@16061
   481
			    else 
paulson@16061
   482
			       (**********************************************)
paulson@16061
   483
			       (* Keep this child and go on to check others  *)
paulson@16061
   484
			       (**********************************************)
quigley@15642
   485
paulson@16061
   486
				 (childProc::(checkChildren (otherChildren, toParentStr)))
paulson@16061
   487
			 end
paulson@16061
   488
		       else
paulson@16061
   489
			   let val  outfile = TextIO.openAppend(File.sysify_path(File.tmp_path (Path.basic "child_incoming")));  
paulson@16061
   490
			val _ = TextIO.output (outfile,"No child output " )
paulson@16061
   491
			val _ =  TextIO.closeOut outfile
paulson@16061
   492
			 in
paulson@16061
   493
			    (childProc::(checkChildren (otherChildren, toParentStr)))
paulson@16061
   494
			 end
paulson@16061
   495
		    end
quigley@15642
   496
paulson@16061
   497
	     
paulson@16061
   498
	  (********************************************************************)                  
paulson@16061
   499
	  (* call resolution processes                                        *)
paulson@16061
   500
	  (* settings should be a list of strings                             *)
paulson@16061
   501
	  (* e.g. ["-t 300", "-m 100000"]                                     *)
paulson@16061
   502
	  (* takes list of (string, string, string list, string)list proclist *)
paulson@16061
   503
	  (********************************************************************)
quigley@15642
   504
quigley@16039
   505
paulson@16061
   506
(*** add subgoal id num to this *)
paulson@16061
   507
	     fun execCmds  [] procList = procList
paulson@16061
   508
	     |   execCmds  ((prover, thmstring,goalstring,proverCmd,settings,file)::cmds) procList  = 
paulson@16061
   509
					       if (prover = "spass") 
paulson@16061
   510
					       then 
paulson@16061
   511
						   let val childhandle:(TextIO.instream,TextIO.outstream) Unix.proc  = (Unix.execute(proverCmd, (["-FullRed=0"]@settings@[file])))
paulson@16061
   512
						       val (instr, outstr)=Unix.streamsOf childhandle
paulson@16061
   513
						       val newProcList =    (((CMDPROC{
paulson@16061
   514
									    prover = prover,
paulson@16061
   515
									    cmd = file,
paulson@16061
   516
									    thmstring = thmstring,
paulson@16061
   517
									    goalstring = goalstring,
paulson@16061
   518
									    proc_handle = childhandle,
paulson@16061
   519
									    instr = instr,
paulson@16061
   520
									    outstr = outstr })::procList))
paulson@16061
   521
							val  outfile = TextIO.openAppend(File.sysify_path(File.tmp_path (Path.basic "exec_child")));  
paulson@16061
   522
					  val _ = TextIO.output (outfile,"executing command for goal:"^goalstring^proverCmd^(concat settings)^file )
paulson@16061
   523
					  val _ =  TextIO.closeOut outfile
paulson@16061
   524
						   in
paulson@16061
   525
						      execCmds cmds newProcList
paulson@16061
   526
						   end
paulson@16061
   527
					       else 
paulson@16061
   528
						   let val childhandle:(TextIO.instream,TextIO.outstream) Unix.proc  = (Unix.execute(proverCmd, (["-FullRed=0"]@settings@[file])))
paulson@16061
   529
						       val (instr, outstr)=Unix.streamsOf childhandle
paulson@16061
   530
						       val newProcList =    (((CMDPROC{
paulson@16061
   531
									    prover = prover,
paulson@16061
   532
									    cmd = file,
paulson@16061
   533
									    thmstring = thmstring,
paulson@16061
   534
									    goalstring = goalstring,
paulson@16061
   535
									    proc_handle = childhandle,
paulson@16061
   536
									    instr = instr,
paulson@16061
   537
									    outstr = outstr })::procList))
paulson@16061
   538
						   in
paulson@16061
   539
						      execCmds cmds newProcList
paulson@16061
   540
						   end
quigley@15642
   541
quigley@15642
   542
quigley@16039
   543
paulson@16061
   544
	  (****************************************)                  
paulson@16061
   545
	  (* call resolution processes remotely   *)
paulson@16061
   546
	  (* settings should be a list of strings *)
paulson@16061
   547
	  (* e.g. ["-t 300", "-m 100000"]         *)
paulson@16061
   548
	  (****************************************)
paulson@16061
   549
paulson@16061
   550
	   (*  fun execRemoteCmds  [] procList = procList
paulson@16061
   551
	     |   execRemoteCmds ((prover, thmstring,goalstring,proverCmd ,settings,file)::cmds) procList  =  
paulson@16061
   552
				       let val  newProcList =  mySshExecuteToList ("/usr/bin/ssh",([prover,thmstring,goalstring,"-t", "shep"]@[proverCmd]@settings@[file]), procList)
paulson@16061
   553
					   in
paulson@16061
   554
						execRemoteCmds  cmds newProcList
paulson@16061
   555
					   end
quigley@16039
   556
*)
quigley@15642
   557
paulson@16061
   558
	     fun printList (outStr, []) = ()
paulson@16061
   559
	     |   printList (outStr, (x::xs)) = (TextIO.output (outStr, x);TextIO.flushOut outStr; printList (outStr,xs))                  
quigley@15642
   560
quigley@15642
   561
paulson@16061
   562
	  (**********************************************)                  
paulson@16061
   563
	  (* Watcher Loop                               *)
paulson@16061
   564
	  (**********************************************)
paulson@16061
   565
quigley@15642
   566
quigley@15642
   567
quigley@15642
   568
paulson@16061
   569
	      fun keepWatching (toParentStr, fromParentStr,procList) = 
paulson@16061
   570
		    let    fun loop (procList) =  
paulson@16061
   571
			   (
paulson@16061
   572
			   let val cmdsFromIsa = pollParentInput ()
paulson@16061
   573
			       fun killchildHandler (n:int)  = (TextIO.output(toParentStr, "Killing child proof processes!\n");
paulson@16061
   574
					    TextIO.flushOut toParentStr;
paulson@16061
   575
					     killChildren (map (cmdchildHandle) procList);
paulson@16061
   576
					      ())
paulson@16061
   577
			       
paulson@16061
   578
			   in 
paulson@16061
   579
			      (*Signal.signal (Posix.Signal.usr2, Signal.SIG_HANDLE killchildHandler);*)
paulson@16061
   580
										 (**********************************)
paulson@16061
   581
			      if (isSome cmdsFromIsa) then                       (*  deal with input from Isabelle *)
paulson@16061
   582
				   (                                             (**********************************)                             
paulson@16061
   583
				    if (getProofCmd(hd(valOf cmdsFromIsa)) = "Kill children" )
paulson@16061
   584
				    then 
paulson@16061
   585
				      (
paulson@16061
   586
					let val child_handles = map cmdchildHandle procList 
paulson@16061
   587
					in
paulson@16061
   588
					   killChildren child_handles;
paulson@16061
   589
					   (*Posix.Process.kill(Posix.Process.K_PROC (Posix.ProcEnv.getppid()), Posix.Signal.usr2);*)                                                              loop ([])
paulson@16061
   590
					end
paulson@16061
   591
					   
paulson@16061
   592
				       )
paulson@16061
   593
				    else
paulson@16061
   594
				      ( 
paulson@16061
   595
					if ((length procList)<10)    (********************)
paulson@16061
   596
					then                        (* Execute locally  *)
paulson@16061
   597
					   (                        (********************)
paulson@16061
   598
					    let 
paulson@16061
   599
					      val newProcList = execCmds (valOf cmdsFromIsa) procList
paulson@16061
   600
					      val parentID = Posix.ProcEnv.getppid()
paulson@16061
   601
					      val newProcList' =checkChildren (newProcList, toParentStr) 
paulson@16061
   602
					    in
paulson@16061
   603
					      (*Posix.Process.sleep (Time.fromSeconds 1);*)
paulson@16061
   604
					      loop (newProcList') 
paulson@16061
   605
					    end
paulson@16061
   606
					    )
paulson@16061
   607
					else                         (*********************************)
paulson@16061
   608
								     (* Execute remotely              *)
paulson@16061
   609
								     (* (actually not remote for now )*)
paulson@16061
   610
					    (                        (*********************************)
paulson@16061
   611
					    let 
paulson@16061
   612
					      val newProcList = execCmds (valOf cmdsFromIsa) procList
paulson@16061
   613
					      val parentID = Posix.ProcEnv.getppid()
paulson@16061
   614
					      val newProcList' =checkChildren (newProcList, toParentStr) 
paulson@16061
   615
					    in
paulson@16061
   616
					      (*Posix.Process.sleep (Time.fromSeconds 1);*)
paulson@16061
   617
					      loop (newProcList') 
paulson@16061
   618
					    end
paulson@16061
   619
					    )
quigley@15642
   620
quigley@15642
   621
quigley@15642
   622
paulson@16061
   623
					)
paulson@16061
   624
				     )                                              (******************************)
paulson@16061
   625
			      else                                                  (* No new input from Isabelle *)
paulson@16061
   626
										    (******************************)
paulson@16061
   627
				  (    let val newProcList = checkChildren ((procList), toParentStr)
paulson@16061
   628
				       in
paulson@16061
   629
					 Posix.Process.sleep (Time.fromSeconds 1);
paulson@16061
   630
					 loop (newProcList)
paulson@16061
   631
				       end
paulson@16061
   632
				   
paulson@16061
   633
				   )
paulson@16061
   634
			    end)
paulson@16061
   635
		    in  
paulson@16061
   636
			loop (procList)
paulson@16061
   637
		    end
paulson@16061
   638
		
paulson@16061
   639
    
paulson@16061
   640
		in
paulson@16061
   641
		 (***************************)
paulson@16061
   642
		 (*** Sort out pipes ********)
paulson@16061
   643
		 (***************************)
quigley@15642
   644
paulson@16061
   645
		  Posix.IO.close (#outfd p1);
paulson@16061
   646
		  Posix.IO.close (#infd p2);
paulson@16061
   647
		  Posix.IO.dup2{old = oldchildin, new = fromParent};
paulson@16061
   648
		  Posix.IO.close oldchildin;
paulson@16061
   649
		  Posix.IO.dup2{old = oldchildout, new = toParent};
paulson@16061
   650
		  Posix.IO.close oldchildout;
quigley@15642
   651
paulson@16061
   652
		  (***************************)
paulson@16061
   653
		  (* start the watcher loop  *)
paulson@16061
   654
		  (***************************)
paulson@16061
   655
		  keepWatching (toParentStr, fromParentStr, procList);
quigley@15642
   656
quigley@15642
   657
paulson@16061
   658
		  (****************************************************************************)
paulson@16061
   659
		  (* fake return value - actually want the watcher to loop until killed       *)
paulson@16061
   660
		  (****************************************************************************)
paulson@16061
   661
		  Posix.Process.wordToPid 0w0
paulson@16061
   662
		  
paulson@16061
   663
		end);
paulson@16061
   664
	  (* end case *)
quigley@15642
   665
quigley@15642
   666
paulson@16061
   667
    val _ = TextIO.flushOut TextIO.stdOut
quigley@15642
   668
paulson@16061
   669
    (*******************************)
paulson@16061
   670
    (***  set watcher going ********)
paulson@16061
   671
    (*******************************)
quigley@15642
   672
paulson@16061
   673
    val procList = []
paulson@16061
   674
    val pid = startWatcher (procList)
paulson@16061
   675
    (**************************************************)
paulson@16061
   676
    (* communication streams to watcher               *)
paulson@16061
   677
    (**************************************************)
quigley@15642
   678
paulson@16061
   679
    val instr = openInFD ("_exec_in", #infd p2)
paulson@16061
   680
    val outstr = openOutFD ("_exec_out", #outfd p1)
paulson@16061
   681
    
paulson@16061
   682
    in
paulson@16061
   683
     (*******************************)
paulson@16061
   684
     (* close the child-side fds    *)
paulson@16061
   685
     (*******************************)
paulson@16061
   686
      Posix.IO.close (#outfd p2);
paulson@16061
   687
      Posix.IO.close (#infd p1);
paulson@16061
   688
      (* set the fds close on exec *)
paulson@16061
   689
      Posix.IO.setfd (#infd p2, Posix.IO.FD.flags [Posix.IO.FD.cloexec]);
paulson@16061
   690
      Posix.IO.setfd (#outfd p1, Posix.IO.FD.flags [Posix.IO.FD.cloexec]);
paulson@16061
   691
       
paulson@16061
   692
     (*******************************)
paulson@16061
   693
     (* return value                *)
paulson@16061
   694
     (*******************************)
paulson@16061
   695
      PROC{pid = pid,
paulson@16061
   696
	instr = instr,
paulson@16061
   697
	outstr = outstr
paulson@16061
   698
      }
paulson@16061
   699
   end;
quigley@15642
   700
quigley@15642
   701
quigley@15642
   702
quigley@15642
   703
(**********************************************************)
quigley@15642
   704
(* Start a watcher and set up signal handlers             *)
quigley@15642
   705
(**********************************************************)
quigley@16039
   706
quigley@16039
   707
fun killWatcher pid= Posix.Process.kill(Posix.Process.K_PROC pid, Posix.Signal.kill);
quigley@16039
   708
quigley@16039
   709
fun reapWatcher(pid, instr, outstr) =
quigley@16039
   710
        let
quigley@16039
   711
		val u = TextIO.closeIn instr;
quigley@16039
   712
	        val u = TextIO.closeOut outstr;
quigley@16039
   713
	
quigley@16039
   714
		val (_, status) =
quigley@16039
   715
			Posix.Process.waitpid(Posix.Process.W_CHILD pid, [])
quigley@16039
   716
	in
quigley@16039
   717
		status
quigley@16039
   718
	end
quigley@15642
   719
quigley@15919
   720
fun createWatcher (thm,clause_arr, ( num_of_clauses:int)) = let val mychild = childInfo (setupWatcher(thm,clause_arr,  num_of_clauses))
quigley@15642
   721
			   val streams =snd mychild
quigley@15642
   722
                           val childin = fst streams
quigley@15642
   723
                           val childout = snd streams
quigley@15642
   724
                           val childpid = fst mychild
quigley@15782
   725
                           val sign = sign_of_thm thm
quigley@15782
   726
                           val prems = prems_of thm
quigley@15782
   727
                           val prems_string =  Meson.concat_with_and (map (Sign.string_of_term sign) prems) 
quigley@15782
   728
                           val _ = (warning ("subgoals forked to createWatcher: "^prems_string));
paulson@15702
   729
                           fun vampire_proofHandler (n) =
quigley@15642
   730
                           (Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
quigley@15782
   731
                           getVampInput childin; Pretty.writeln(Pretty.str  (oct_char "361"));() )               
quigley@15642
   732
                          
quigley@15642
   733
paulson@15702
   734
fun spass_proofHandler (n) = (
quigley@15658
   735
                                 let  val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_signal1")));
quigley@15642
   736
                                      val _ = TextIO.output (outfile, ("In signal handler now\n"))
quigley@15642
   737
                                      val _ =  TextIO.closeOut outfile
quigley@15642
   738
                                      val (reconstr, thmstring, goalstring) = getSpassInput childin
quigley@15658
   739
                                      val  outfile = TextIO.openAppend(File.sysify_path(File.tmp_path (Path.basic "foo_signal")));
quigley@15642
   740
quigley@15642
   741
                                      val _ = TextIO.output (outfile, ("In signal handler  "^reconstr^thmstring^goalstring^"goals_being_watched is: "^(string_of_int (!goals_being_watched))))
quigley@15642
   742
                                      val _ =  TextIO.closeOut outfile
quigley@15642
   743
                                      in          (* if a proof has been found and sent back as a reconstruction proof *)
quigley@15642
   744
                                                  if ( (substring (reconstr, 0,1))= "[")
quigley@15642
   745
                                                  then 
quigley@15642
   746
quigley@15642
   747
                                                            (
quigley@15642
   748
                                                                 Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
paulson@15684
   749
                                                                 Recon_Transfer.apply_res_thm reconstr goalstring;
quigley@15642
   750
                                                                 Pretty.writeln(Pretty.str  (oct_char "361"));
quigley@15642
   751
                                                                 
quigley@15642
   752
                                                                 goals_being_watched := ((!goals_being_watched) - 1);
quigley@15642
   753
                                                         
quigley@15642
   754
                                                                 if ((!goals_being_watched) = 0)
quigley@15642
   755
                                                                 then 
quigley@15658
   756
                                                                    (let val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_reap_found")));
quigley@15642
   757
                                                                         val _ = TextIO.output (outfile, ("Reaping a watcher, goals watched is: "^(string_of_int (!goals_being_watched))^"\n"))
quigley@15642
   758
                                                                         val _ =  TextIO.closeOut outfile
quigley@15642
   759
                                                                     in
quigley@16039
   760
                                                                         reapWatcher (childpid,childin, childout); ()
quigley@15642
   761
                                                                     end)
quigley@15642
   762
                                                                 else
quigley@15642
   763
                                                                    ()
quigley@15642
   764
                                                            )
quigley@15642
   765
                                                    (* if there's no proof, but a message from Spass *)
quigley@15642
   766
                                                    else if ((substring (reconstr, 0,5))= "SPASS")
quigley@15642
   767
                                                         then
quigley@15642
   768
                                                                 (
quigley@15642
   769
                                                                     goals_being_watched := (!goals_being_watched) -1;
quigley@15642
   770
                                                                     Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
quigley@15642
   771
                                                                      Pretty.writeln(Pretty.str (goalstring^reconstr));
quigley@15642
   772
                                                                      Pretty.writeln(Pretty.str  (oct_char "361"));
quigley@15642
   773
                                                                      if (!goals_being_watched = 0)
quigley@15642
   774
                                                                      then 
quigley@15658
   775
                                                                          (let val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_reap_comp")));
quigley@15642
   776
                                                                               val _ = TextIO.output (outfile, ("Reaping a watcher, goals watched is: "^(string_of_int (!goals_being_watched))^"\n"))
quigley@15642
   777
                                                                               val _ =  TextIO.closeOut outfile
quigley@15642
   778
                                                                           in
quigley@16039
   779
                                                                              reapWatcher (childpid,childin, childout); ()
quigley@15642
   780
                                                                           end )
quigley@15642
   781
                                                                      else
quigley@15642
   782
                                                                         ()
quigley@15642
   783
                                                                )
quigley@15642
   784
                                                          (* if proof translation failed *)
quigley@15642
   785
                                                          else if ((substring (reconstr, 0,5)) = "Proof")
quigley@15642
   786
                                                               then 
quigley@15642
   787
                                                                   (
quigley@15642
   788
                                                                     goals_being_watched := (!goals_being_watched) -1;
quigley@15642
   789
                                                                     Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
quigley@15642
   790
                                                                      Pretty.writeln(Pretty.str (goalstring^reconstr));
quigley@15642
   791
                                                                      Pretty.writeln(Pretty.str  (oct_char "361"));
quigley@15642
   792
                                                                      if (!goals_being_watched = 0)
quigley@15642
   793
                                                                      then 
quigley@15658
   794
                                                                          (let val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_reap_comp")));
quigley@15642
   795
                                                                               val _ = TextIO.output (outfile, ("Reaping a watcher, goals watched is: "^(string_of_int (!goals_being_watched))^"\n"))
quigley@15642
   796
                                                                               val _ =  TextIO.closeOut outfile
quigley@15642
   797
                                                                           in
quigley@16039
   798
                                                                              reapWatcher (childpid,childin, childout); ()
quigley@15642
   799
                                                                           end )
quigley@15642
   800
                                                                      else
quigley@15642
   801
                                                                         ()
quigley@15642
   802
                                                                )
quigley@15642
   803
quigley@15642
   804
quigley@15642
   805
                                                                else  (* add something here ?*)
quigley@15642
   806
                                                                   ()
quigley@15642
   807
                                                             
quigley@15642
   808
                                       end)
quigley@15642
   809
quigley@15642
   810
quigley@15642
   811
                        
quigley@15782
   812
                       in IsaSignal.signal (IsaSignal.usr1, IsaSignal.SIG_HANDLE vampire_proofHandler);
paulson@15702
   813
                          IsaSignal.signal (IsaSignal.usr2, IsaSignal.SIG_HANDLE spass_proofHandler);
quigley@15642
   814
                          (childin, childout, childpid)
quigley@15642
   815
quigley@15642
   816
                       end
quigley@15642
   817
quigley@15642
   818
quigley@15642
   819
quigley@15642
   820
quigley@15642
   821
quigley@15642
   822
end (* structure Watcher *)