src/Pure/ML-Systems/smlnj.ML
author wenzelm
Thu, 15 Nov 2001 18:20:13 +0100
changeset 12207 4dff931b852f
parent 12108 b6f10dcde803
child 12581 dceea9dbdedd
permissions -rw-r--r--
added Induct/Binary_Trees.thy, Induct/Tree_Forest (converted from former ex/TF.ML ex/TF.thy ex/Term.ML ex/Term.thy);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/ML-Systems/smlnj.ML
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
     3
    Author:     Carsten Clasohm and Markus Wenzel, TU Muenchen
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
     4
5708
fb09ab6a447f dropped support for SML/NJ 109.x;
wenzelm
parents: 5090
diff changeset
     5
Compatibility file for Standard ML of New Jersey 110 or later.
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
     6
*)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
     7
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
     8
(** ML system related **)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
     9
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    10
(* restore old-style character / string functions *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    11
10725
ea048ad15283 better definitions of SML90 features
paulson
parents: 7890
diff changeset
    12
val ord     = SML90.ord;
ea048ad15283 better definitions of SML90 features
paulson
parents: 7890
diff changeset
    13
val chr     = SML90.chr;
ea048ad15283 better definitions of SML90 features
paulson
parents: 7890
diff changeset
    14
val explode = SML90.explode;
ea048ad15283 better definitions of SML90 features
paulson
parents: 7890
diff changeset
    15
val implode = SML90.implode;
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    16
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    17
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    18
(* New Jersey ML parameters *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    19
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    20
val _ =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    21
 (Compiler.Control.Print.printLength := 1000;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    22
  Compiler.Control.Print.printDepth := 350;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    23
  Compiler.Control.Print.stringDepth := 250;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    24
  Compiler.Control.Print.signatures := 2);
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    25
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    26
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    27
(* Poly/ML emulation *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    28
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    29
fun quit () = exit 0;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    30
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    31
(*limit the printing depth -- divided by 2 for comparibility with Poly/ML*)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    32
fun print_depth n =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    33
 (Compiler.Control.Print.printDepth := n div 2;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    34
  Compiler.Control.Print.printLength := n);
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    35
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    36
5816
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
    37
(* compiler-independent timing functions *)
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    38
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    39
(*Note start point for timing*)
5816
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
    40
fun startTiming() =
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    41
  let val CPUtimer = Timer.startCPUTimer();
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    42
      val time = Timer.checkCPUTimer(CPUtimer)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    43
  in  (CPUtimer,time)  end;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    44
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    45
(*Finish timing and return string*)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    46
fun endTiming (CPUtimer, {gc,sys,usr}) =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    47
  let open Time  (*...for Time.toString, Time.+ and Time.- *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    48
      val {gc=gc2,sys=sys2,usr=usr2} = Timer.checkCPUTimer(CPUtimer)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    49
  in  "User " ^ toString (usr2-usr) ^
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    50
      "  GC " ^ toString (gc2-gc) ^
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    51
      "  All "^ toString (sys2-sys + usr2-usr + gc2-gc) ^
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    52
      " secs"
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    53
      handle Time => ""
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    54
  end;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    55
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    56
4977
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    57
(* prompts *)
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    58
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    59
fun ml_prompts p1 p2 =
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    60
  (Compiler.Control.primaryPrompt := p1; Compiler.Control.secondaryPrompt := p2);
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    61
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    62
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    63
(* toplevel pretty printing (see also Pure/install_pp.ML) *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    64
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    65
fun make_pp path pprint =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    66
  let
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    67
    open Compiler.PrettyPrint;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    68
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    69
    fun pp pps obj =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    70
      pprint obj
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    71
        (add_string pps, begin_block pps INCONSISTENT,
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    72
          fn wd => add_break pps (wd, 0), fn () => add_newline pps,
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    73
          fn () => end_block pps);
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    74
  in
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    75
    (path, pp)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    76
  end;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    77
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    78
fun install_pp (path, pp) = Compiler.PPTable.install_pp path pp;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    79
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    80
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    81
(* ML command execution *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    82
10914
aded4ba99b88 use_text etc.: proper output of error messages;
wenzelm
parents: 10725
diff changeset
    83
fun use_text (print, err) verbose txt =
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    84
  let
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    85
    val ref out_orig = Compiler.Control.Print.out;
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    86
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    87
    val out_buffer = ref ([]: string list);
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    88
    val out = {say = (fn s => out_buffer := s :: ! out_buffer), flush = (fn () => ())};
10914
aded4ba99b88 use_text etc.: proper output of error messages;
wenzelm
parents: 10725
diff changeset
    89
    fun output () =
7890
0aa16bc2abdb use_text: remove last char from output;
wenzelm
parents: 7855
diff changeset
    90
      let val str = implode (rev (! out_buffer))
10914
aded4ba99b88 use_text etc.: proper output of error messages;
wenzelm
parents: 10725
diff changeset
    91
      in String.substring (str, 0, Int.max (0, size str - 1)) end;
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    92
  in
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    93
    Compiler.Control.Print.out := out;
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    94
    Compiler.Interact.useStream (TextIO.openString txt) handle exn =>
10914
aded4ba99b88 use_text etc.: proper output of error messages;
wenzelm
parents: 10725
diff changeset
    95
      (Compiler.Control.Print.out := out_orig; err (output ()); raise exn);
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    96
    Compiler.Control.Print.out := out_orig;
10914
aded4ba99b88 use_text etc.: proper output of error messages;
wenzelm
parents: 10725
diff changeset
    97
    if verbose then print (output ()) else ()
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    98
  end;
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    99
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   100
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   101
5816
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   102
(** interrupts **)
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   103
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   104
local
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   105
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   106
datatype 'a result =
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   107
  Result of 'a |
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   108
  Exn of exn;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   109
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   110
fun capture f x = Result (f x) handle exn => Exn exn;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   111
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   112
fun release (Result x) = x
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   113
  | release (Exn exn) = raise exn;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   114
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   115
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   116
val sig_int = Signals.sigINT;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   117
val sig_int_mask = Signals.MASK [Signals.sigINT];
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   118
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   119
fun interruptible () =
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   120
  (case Signals.masked () of
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   121
    Signals.MASKALL => false
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   122
  | Signals.MASK sigs => List.all (fn s => s <> sig_int) sigs);
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   123
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   124
val mask_signals = Signals.maskSignals;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   125
val unmask_signals = Signals.unmaskSignals;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   126
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   127
fun change_mask ok change unchange f x =
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   128
  if ok () then f x
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   129
  else
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   130
    let
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   131
      val _ = change sig_int_mask;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   132
      val result = capture f x;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   133
      val _ = unchange sig_int_mask;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   134
    in release result end;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   135
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   136
in
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   137
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   138
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   139
(* mask / unmask interrupt *)
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   140
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   141
fun mask_interrupt f = change_mask (not o interruptible) mask_signals unmask_signals f;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   142
fun unmask_interrupt f = change_mask interruptible unmask_signals mask_signals f;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   143
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   144
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   145
(* exhibit interrupt (via exception) *)
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   146
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   147
exception Interrupt;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   148
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   149
fun exhibit_interrupt f x =
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   150
  let
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   151
    val orig_handler = Signals.inqHandler sig_int;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   152
    fun reset_handler () = (Signals.setHandler (sig_int, orig_handler); ());
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   153
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   154
    val interrupted = ref false;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   155
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   156
    fun set_handler cont =
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   157
      Signals.setHandler (sig_int, Signals.HANDLER (fn _ => (interrupted := true; cont)));
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   158
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   159
    fun proceed cont =
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   160
      let
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   161
        val _ = set_handler cont;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   162
        val result = unmask_interrupt (capture f) x;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   163
        val _ = reset_handler ();
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   164
      in release result end;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   165
  in
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   166
    SMLofNJ.Cont.callcc proceed;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   167
    reset_handler ();
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   168
    if ! interrupted then raise Interrupt else ()
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   169
   end;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   170
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   171
end;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   172
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   173
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   174
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   175
(** OS related **)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   176
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   177
(* system command execution *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   178
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   179
(*execute Unix command which doesn't take any input from stdin and
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   180
  sends its output to stdout; could be done more easily by Unix.execute,
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   181
  but that function doesn't use the PATH*)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   182
fun execute command =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   183
  let
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   184
    val tmp_name = OS.FileSys.tmpName ();
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   185
    val is = (OS.Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name);
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   186
    val result = TextIO.inputAll is;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   187
  in
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   188
    TextIO.closeIn is;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   189
    OS.FileSys.remove tmp_name;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   190
    result
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   191
  end;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   192
7855
092a6435afad system;
wenzelm
parents: 6227
diff changeset
   193
(*plain version; with return code*)
092a6435afad system;
wenzelm
parents: 6227
diff changeset
   194
val system = OS.Process.system: string -> int; 
092a6435afad system;
wenzelm
parents: 6227
diff changeset
   195
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   196
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   197
(* file handling *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   198
6227
3198f547f8af fixed file_info;
wenzelm
parents: 5816
diff changeset
   199
(*get time of last modification*)
3198f547f8af fixed file_info;
wenzelm
parents: 5816
diff changeset
   200
fun file_info name = Time.toString (OS.FileSys.modTime name) handle _ => "";
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   201
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   202
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   203
(* getenv *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   204
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   205
fun getenv var =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   206
  (case OS.Process.getEnv var of
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   207
    NONE => ""
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   208
  | SOME txt => txt);