1 (* Copyright (C
) 1999-2005 Henry Cejtin
, Matthew Fluet
, Suresh
2 * Jagannathan
, and Stephen Weeks
.
3 * Copyright (C
) 1997-2000 NEC Research Institute
.
5 * MLton is released under a BSD
-style license
.
6 * See the file MLton
-LICENSE for details
.
9 structure System
: SYSTEM
=
11 fun insertBackslashes (ss
: string list
,
13 indent
: int): string list
=
15 val indentation
= String.make (indent
, #
" ")
16 fun loop (ss
, pos
, line
, lines
) =
17 (* pos
+ 2 < width (so the backslash can be inserted
) *)
19 [] => rev (concat (rev line
) :: lines
)
26 | _
=> (pos
+ n
+ 1, s
:: " " :: line
)
28 loop (ss
, indent
+ n
, [s
, indentation
],
29 concat (rev (" \\" :: line
)) :: lines
)
34 [] => rev (concat (rev line
') :: lines
)
37 then loop (ss
, pos
, line
', lines
)
41 in loop (ss
, 0, [], [])
44 fun system (com
: string, args
: string list
): unit
=
46 (* Many terminal emulators
do the line folding one character early
,
47 * so we use
79 instead
of 80 columns
.
51 val s
= concat (List.separate (com
:: args
, " "))
56 message (Top
, fn () =>
58 (List.map (insertBackslashes
65 Process
.wait (MLton
.Process
.spawnp
{file
= com
, args
= com
:: args
})
66 handle e
=> Error
.bug (concat
["call to system failed with ",
67 Exn
.toString e
, ":\n", s
])