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
.
8 structure Instream
: INSTREAM
=
13 structure String = ZString
16 Trace
.trace ("Instream.input", layout
, String.layout
) input
18 fun outputAll (ins
: t
, out
: Out
.t
): unit
=
23 | s
=> (Out
.output (out
, s
); loop ())
29 Trace
.trace ("Instream.inputLine", layout
, Option
.layout
String.layout
) inputLine
31 fun 'a
withClose (ins
: t
, f
: t
-> 'a
): 'a
=
32 Exn
.finally (fn () => f ins
, fn () => close ins
)
34 fun 'a
withIn (f
: string, g
: t
-> 'a
): 'a
=
35 withClose (openIn f
handle IO
.Io _
=>
36 Error
.bug (concat
["Instream.withIn: cannot open ", f
]), g
)
38 fun withNull f
= withIn ("/dev/zero", f
)
40 fun lines ins
= rev (foldLines (ins
, [], op ::))
44 structure In
= Instream