1 (* Copyright (C
) 1999-2006 Henry Cejtin
, Matthew Fluet
, Suresh
2 * Jagannathan
, and Stephen Weeks
.
4 * MLton is released under a BSD
-style license
.
5 * See the file MLton
-LICENSE for details
.
11 structure TextIO = Pervasive
.TextIO
14 (*val output
= fn (out
, s
) => (output (out
, s
); flushOut out
) *)
21 fun outputc stream
string = output (stream
, string)
24 fun newline s
= output (s
, "\n")
26 fun outputl (s
, x
) = (output (s
, x
); newline s
)
28 fun print s
= output (standard
, s
)
30 fun outputNothing _
= ()
32 fun set (o1
: t
, o2
:t
): unit
=
33 TextIO.setOutstream (o1
, TextIO.getOutstream o2
)
35 fun fluidLet (s1
, s2
, thunk
) =
37 val old
= TextIO.getOutstream s1
40 Exn0
.finally (thunk
, fn () => TextIO.setOutstream (s1
, old
))
43 fun withClose (out
: t
, f
: t
-> 'a
): 'a
=
44 Exn0
.finally (fn () => f out
, fn () => close out
)
47 fun 'a
withh (f
, p
: t
-> 'a
, openn
): 'a
=
49 val out
= openn f
handle IO
.Io _
=> Error
.bug ("OutStream0.withh: cannot open " ^ f
)
54 fun 'a
withOut (f
, p
: t
-> 'a
): 'a
= withh (f
, p
, openOut
)
55 fun withAppend (f
, p
) = withh (f
, p
, openAppend
)
58 fun 'a
withNull (f
: t
-> 'a
): 'a
= withOut ("/dev/null", f
)
60 fun ignore (out
: t
, f
: unit
-> 'a
): 'a
=
61 withNull (fn out
' => fluidLet (out
, out
', f
))