src/Pure/System/command_line.ML
author wenzelm
Wed Jul 17 17:16:51 2013 +0200 (2013-07-17 ago)
changeset 52686 f4871fe80410
parent 51312 0ce544fbb509
child 54387 890e983cb07b
permissions -rw-r--r--
more robust exn_messages_ids;
more robust failure of exn_messages_ids;
wenzelm@48681
     1
(*  Title:      Pure/System/command_line.ML
wenzelm@48681
     2
    Author:     Makarius
wenzelm@48681
     3
wenzelm@48681
     4
Support for Isabelle/ML command line tools.
wenzelm@48681
     5
*)
wenzelm@48681
     6
wenzelm@48681
     7
signature COMMAND_LINE =
wenzelm@48681
     8
sig
wenzelm@48731
     9
  val tool: (unit -> int) -> unit
wenzelm@51312
    10
  val tool0: (unit -> unit) -> unit
wenzelm@48681
    11
end;
wenzelm@48681
    12
wenzelm@48681
    13
structure Command_Line: COMMAND_LINE =
wenzelm@48681
    14
struct
wenzelm@48681
    15
wenzelm@48681
    16
fun tool body =
wenzelm@48681
    17
  uninterruptible (fn restore_attributes => fn () =>
wenzelm@48681
    18
    let val rc =
wenzelm@48681
    19
      restore_attributes body () handle exn =>
wenzelm@52686
    20
        let
wenzelm@52686
    21
          val _ =
wenzelm@52686
    22
            Output.error_msg (ML_Compiler.exn_message exn)
wenzelm@52686
    23
              handle _ => Output.error_msg "Exception raised, but failed to print details!";
wenzelm@52686
    24
        in if Exn.is_interrupt exn then 130 else 1 end;
wenzelm@48731
    25
    in if rc = 0 then () else exit rc end) ();
wenzelm@48681
    26
wenzelm@51312
    27
fun tool0 body = tool (fn () => (body (); 0));
wenzelm@51312
    28
wenzelm@48681
    29
end;
wenzelm@48681
    30