forked from CakeML/regression
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilLib.sml
53 lines (44 loc) · 1.52 KB
/
utilLib.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(*
Small library of useful code.
*)
structure utilLib = struct
fun equal x y = x = y
fun find f (x::xs) = if f x then x else find f xs
| find _ _ = raise Match
fun assoc k [] = raise Match
| assoc k ((k',v)::ls) = if k = k' then v else assoc k ls
val until_space =
Substring.string o Substring.takel (not o Char.isSpace) o Substring.full
fun month_from_int 1 = Date.Jan
| month_from_int 2 = Date.Feb
| month_from_int 3 = Date.Mar
| month_from_int 4 = Date.Apr
| month_from_int 5 = Date.May
| month_from_int 6 = Date.Jun
| month_from_int 7 = Date.Jul
| month_from_int 8 = Date.Aug
| month_from_int 9 = Date.Sep
| month_from_int 10 = Date.Oct
| month_from_int 11 = Date.Nov
| month_from_int 12 = Date.Dec
| month_from_int _ = raise Match
fun file_to_string f =
let val inp = TextIO.openIn f in TextIO.inputAll inp before TextIO.closeIn inp end
val curl_path = "/usr/bin/curl"
local
open Unix
in
fun system_output die (cmd,args) =
let
val proc = execute (cmd,args)
handle e as OS.SysErr _ =>
(die[cmd," failed to execute on ",String.concatWith" "args,"\n",exnMessage e];
raise e) (* re-raise because SML does not support first-class polymorphism *)
val output = TextIO.inputAll (textInstreamOf proc)
val status = reap proc
in
if OS.Process.isSuccess status then output
else die[cmd," failed on ",String.concatWith" "args]
end
end
end