src/Pure/Tools/isabelle_process.ML
author wenzelm
Sun, 30 Dec 2007 23:07:27 +0100
changeset 25748 55a458a31e37
parent 25631 9036ccd685b4
child 25810 bac99880fa99
permissions -rw-r--r--
added PROMPT message;

(*  Title:      Pure/Tools/isabelle_process.ML
    ID:         $Id$
    Author:     Makarius

Isabelle process wrapper -- interaction via external program.

General format of process output:

  (a) unmarked stdout/stderr, no line structure (output should be
  processed immediately as it arrives)

  (b) echo of my pid on stdout, appears *relatively* early after
  startup on a separate line, e.g. "\nPID=4711\n"

  (c) properly marked-up messages, e.g. for writeln channel
  "\002A" ^ text ^ "\002.\n" where the body text may consist of several
  lines (output should be processed in one piece).
*)

signature ISABELLE_PROCESS =
sig
  val test_markupN: string
  val test_markup: Markup.T -> output * output
  val isabelle_processN: string
  val init: unit -> unit
end;

structure IsabelleProcess: ISABELLE_PROCESS =
struct

(* test_markup *)

val test_markupN = "test_markup";

fun test_markup (name, props) =
 (enclose "<" ">" (space_implode " " (name :: map XML.attribute props)),
  enclose "</" ">" name);

val _ = Markup.add_mode test_markupN test_markup;


(* channels *)

val isabelle_processN = "isabelle_process";

local

fun special c = chr 2 ^ c;
val special_end = special ".";

fun output c m s =
  Output.writeln_default (special c ^ Markup.enclose m s ^ special_end);

in

fun setup_channels () =
 (Output.writeln_fn  := output "A" Markup.writeln;
  Output.priority_fn := output "B" Markup.priority;
  Output.tracing_fn  := output "C" Markup.tracing;
  Output.warning_fn  := output "D" Markup.warning;
  Output.error_fn    := output "E" Markup.error;
  Output.debug_fn    := output "F" Markup.debug);

val _ = Markup.add_mode isabelle_processN (fn (name, _) =>
  if name = Markup.promptN then (special "G", special_end ^ "\n")
  else ("", ""));

end;


(* init *)

fun init () =
 (Output.writeln_default ("\nPID=" ^ string_of_pid (Posix.ProcEnv.getpid ()));
  setup_channels ();
  change print_mode (update (op =) isabelle_processN);
  Isar.secure_main ());

end;