src/Pure/ML-Systems/smlnj.ML
author wenzelm
Sat, 11 Jun 2005 23:17:28 +0200
changeset 16374 f4b7cf8975af
parent 16266 7a6616be8712
child 16502 5a56e59526a5
permissions -rw-r--r--
some cygwin support;
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
12874
368966ceafe5 ML-Systems/smlnj-compiler.ML compatibility tweak;
wenzelm
parents: 12581
diff changeset
     8
(case #version_id (Compiler.version) of
368966ceafe5 ML-Systems/smlnj-compiler.ML compatibility tweak;
wenzelm
parents: 12581
diff changeset
     9
  [110, x] => if x >= 35 then use "ML-Systems/smlnj-compiler.ML" else ()
368966ceafe5 ML-Systems/smlnj-compiler.ML compatibility tweak;
wenzelm
parents: 12581
diff changeset
    10
| _ => ());
368966ceafe5 ML-Systems/smlnj-compiler.ML compatibility tweak;
wenzelm
parents: 12581
diff changeset
    11
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    12
(** ML system related **)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    13
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    14
(* restore old-style character / string functions *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    15
10725
ea048ad15283 better definitions of SML90 features
paulson
parents: 7890
diff changeset
    16
val ord     = SML90.ord;
ea048ad15283 better definitions of SML90 features
paulson
parents: 7890
diff changeset
    17
val chr     = SML90.chr;
ea048ad15283 better definitions of SML90 features
paulson
parents: 7890
diff changeset
    18
val explode = SML90.explode;
ea048ad15283 better definitions of SML90 features
paulson
parents: 7890
diff changeset
    19
val implode = SML90.implode;
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    20
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    21
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    22
(* New Jersey ML parameters *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    23
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    24
val _ =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    25
 (Compiler.Control.Print.printLength := 1000;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    26
  Compiler.Control.Print.printDepth := 350;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    27
  Compiler.Control.Print.stringDepth := 250;
12581
dceea9dbdedd Redundant patterns no longer cause errors.
berghofe
parents: 12108
diff changeset
    28
  Compiler.Control.Print.signatures := 2;
dceea9dbdedd Redundant patterns no longer cause errors.
berghofe
parents: 12108
diff changeset
    29
  Compiler.Control.MC.matchRedundantError := false);
4403
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
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    32
(* Poly/ML emulation *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    33
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    34
fun quit () = exit 0;
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
(*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
    37
fun print_depth n =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    38
 (Compiler.Control.Print.printDepth := n div 2;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    39
  Compiler.Control.Print.printLength := n);
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    40
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    41
5816
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
    42
(* compiler-independent timing functions *)
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    43
14519
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12990
diff changeset
    44
(case #version_id (Compiler.version) of
14656
765badface6a changed SML/NJ v 45 to 44
paulson
parents: 14520
diff changeset
    45
  [110, x] => if x >= 44
14519
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12990
diff changeset
    46
	      then use "ML-Systems/cpu-timer-basis.ML"
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12990
diff changeset
    47
	      else use "ML-Systems/cpu-timer-gc.ML"
14520
af9d7fcf873e Whoops. Those default cases can be tricky.
skalberg
parents: 14519
diff changeset
    48
| _ => use "ML-Systems/cpu-timer-gc.ML");
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    49
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    50
4977
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    51
(* prompts *)
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    52
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    53
fun ml_prompts p1 p2 =
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    54
  (Compiler.Control.primaryPrompt := p1; Compiler.Control.secondaryPrompt := p2);
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    55
6cec2c0ffdbf added ml_prompts;
wenzelm
parents: 4428
diff changeset
    56
14519
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12990
diff changeset
    57
(case #version_id (Compiler.version) of
14656
765badface6a changed SML/NJ v 45 to 44
paulson
parents: 14520
diff changeset
    58
  [110, x] => if x >= 44
14519
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12990
diff changeset
    59
	      then use "ML-Systems/smlnj-basis-compat.ML"
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12990
diff changeset
    60
	      else ()
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12990
diff changeset
    61
| _ => ());
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12990
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
14519
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12990
diff changeset
    65
(case #version_id (Compiler.version) of
14656
765badface6a changed SML/NJ v 45 to 44
paulson
parents: 14520
diff changeset
    66
  [110, x] => if x >= 44
14519
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12990
diff changeset
    67
	      then use "ML-Systems/smlnj-pp-new.ML"
4ca3608fdf4f Added support for the newer versions of SML/NJ, which break several of the
skalberg
parents: 12990
diff changeset
    68
	      else use "ML-Systems/smlnj-pp-old.ML"
14520
af9d7fcf873e Whoops. Those default cases can be tricky.
skalberg
parents: 14519
diff changeset
    69
| _ => use "ML-Systems/smlnj-pp-old.ML");
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    70
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    71
fun install_pp (path, pp) = Compiler.PPTable.install_pp path pp;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    72
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    73
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    74
(* ML command execution *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    75
10914
aded4ba99b88 use_text etc.: proper output of error messages;
wenzelm
parents: 10725
diff changeset
    76
fun use_text (print, err) verbose txt =
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    77
  let
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    78
    val ref out_orig = Compiler.Control.Print.out;
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    79
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    80
    val out_buffer = ref ([]: string list);
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    81
    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
    82
    fun output () =
7890
0aa16bc2abdb use_text: remove last char from output;
wenzelm
parents: 7855
diff changeset
    83
      let val str = implode (rev (! out_buffer))
10914
aded4ba99b88 use_text etc.: proper output of error messages;
wenzelm
parents: 10725
diff changeset
    84
      in String.substring (str, 0, Int.max (0, size str - 1)) end;
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    85
  in
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    86
    Compiler.Control.Print.out := out;
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    87
    Compiler.Interact.useStream (TextIO.openString txt) handle exn =>
10914
aded4ba99b88 use_text etc.: proper output of error messages;
wenzelm
parents: 10725
diff changeset
    88
      (Compiler.Control.Print.out := out_orig; err (output ()); raise exn);
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    89
    Compiler.Control.Print.out := out_orig;
10914
aded4ba99b88 use_text etc.: proper output of error messages;
wenzelm
parents: 10725
diff changeset
    90
    if verbose then print (output ()) else ()
5090
75ac9b451ae0 use_text: verbose flag;
wenzelm
parents: 5038
diff changeset
    91
  end;
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    92
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    93
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
    94
5816
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
    95
(** interrupts **)
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
    96
12990
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
    97
exception Interrupt;
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
    98
5816
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
    99
local
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   100
12990
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   101
fun capture f x = ((f x): unit; NONE) handle exn => SOME exn;
5816
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   102
12990
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   103
fun release NONE = ()
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   104
  | release (SOME exn) = raise exn;
5816
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   105
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   106
in
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   107
12990
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   108
fun ignore_interrupt f x =
5816
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   109
  let
12990
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   110
    val old_handler = Signals.setHandler (Signals.sigINT, Signals.IGNORE);
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   111
    val result = capture f x;
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   112
    val _ = Signals.setHandler (Signals.sigINT, old_handler);
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   113
  in release result end;
5816
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   114
12990
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   115
fun raise_interrupt f x =
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   116
  let
5816
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   117
    val interrupted = ref false;
12990
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   118
    val result = ref NONE;
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   119
    val old_handler = Signals.inqHandler Signals.sigINT;
5816
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   120
  in
12990
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   121
    SMLofNJ.Cont.callcc (fn cont =>
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   122
      (Signals.setHandler (Signals.sigINT, Signals.HANDLER (fn _ => (interrupted := true; cont)));
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   123
      result := capture f x));
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   124
    Signals.setHandler (Signals.sigINT, old_handler);
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   125
    if ! interrupted then raise Interrupt else release (! result)
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   126
  end;
5816
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   127
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   128
end;
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   129
15702
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   130
(** Signal handling: emulation of the Poly/ML Signal structure. Note that types 
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   131
    Posix.Signal.signal and Signals.signal differ **)
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   132
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   133
structure IsaSignal =
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   134
struct
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   135
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   136
datatype sig_handle = SIG_DFL | SIG_IGN | SIG_HANDLE of Signals.signal -> unit;
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   137
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   138
(*From the SML/NJ documentation:
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   139
"HANDLER(f) installs a handler for a signal. When signal is delivered to the process, the execution state of the current thread will be bundled up as a continuation k, then f(signal,n,k) will be called. The number n is the number of times signal has been signalled since the last time f was invoked for it."*)
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   140
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   141
fun toAction SIG_DFL = Signals.DEFAULT
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   142
  | toAction SIG_IGN = Signals.IGNORE
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   143
  | toAction (SIG_HANDLE iu) = 
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   144
      Signals.HANDLER (fn (signo,_,cont) => (iu signo; cont));
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   145
  
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   146
(*The types are correct, but I'm not sure about the semantics!*)
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   147
fun fromAction Signals.DEFAULT = SIG_DFL
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   148
  | fromAction Signals.IGNORE = SIG_IGN
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   149
  | fromAction (Signals.HANDLER f) = 
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   150
      SIG_HANDLE (fn signo => SMLofNJ.Cont.callcc (fn k => (f (signo,0,k); ())));
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   151
    
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   152
(*Poly/ML version has type  int * sig_handle -> sig_handle*)
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   153
fun signal (signo, sh) = fromAction (Signals.setHandler (signo, toAction sh));
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   154
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   155
val usr1 = UnixSignals.sigUSR1
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   156
val usr2 = UnixSignals.sigUSR2
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   157
2677db44c795 new signalling primmitives for sml/nj compatibility
paulson
parents: 14981
diff changeset
   158
end;
5816
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   159
6f3cb53502fa smart interrupt handler;
wenzelm
parents: 5708
diff changeset
   160
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   161
(** OS related **)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   162
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   163
(* system command execution *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   164
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   165
(*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
   166
  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
   167
  but that function doesn't use the PATH*)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   168
fun execute command =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   169
  let
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   170
    val tmp_name = OS.FileSys.tmpName ();
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   171
    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
   172
    val result = TextIO.inputAll is;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   173
  in
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   174
    TextIO.closeIn is;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   175
    OS.FileSys.remove tmp_name;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   176
    result
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   177
  end;
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   178
7855
092a6435afad system;
wenzelm
parents: 6227
diff changeset
   179
(*plain version; with return code*)
12990
c11adf2b1c1e renamed mask_interrupt to ignore_interrupt;
wenzelm
parents: 12874
diff changeset
   180
val system = OS.Process.system: string -> int;
7855
092a6435afad system;
wenzelm
parents: 6227
diff changeset
   181
4403
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   182
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   183
(* getenv *)
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   184
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   185
fun getenv var =
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   186
  (case OS.Process.getEnv var of
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   187
    NONE => ""
1914f727f93f Compatibility file for Standard ML of New Jersey.
wenzelm
parents:
diff changeset
   188
  | SOME txt => txt);