summaryrefslogtreecommitdiff
path: root/src/util.ml
diff options
context:
space:
mode:
authorJon French2018-12-28 15:12:00 +0000
committerJon French2018-12-28 15:12:00 +0000
commitb59fba68e535f39b6285ec7f4f693107b6e34148 (patch)
tree3135513ac4b23f96b41f3d521990f1ce91206c99 /src/util.ml
parent9f6a95882e1d3d057bcb83d098ba1b63925a4d1f (diff)
parent2c887e7d01331d3165120695594eac7a2650ec03 (diff)
Merge branch 'sail2' into rmem_interpreter
Diffstat (limited to 'src/util.ml')
-rw-r--r--src/util.ml19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/util.ml b/src/util.ml
index e0366fe7..5e5654d1 100644
--- a/src/util.ml
+++ b/src/util.ml
@@ -232,6 +232,15 @@ let rec option_these = function
| None :: xs -> option_these xs
| [] -> []
+let rec option_all = function
+ | [] -> Some []
+ | None :: _ -> None
+ | Some x :: xs ->
+ begin match option_all xs with
+ | None -> None
+ | Some xs -> Some (x :: xs)
+ end
+
let changed2 f g x h y =
match (g x, h y) with
| (None,None) -> None
@@ -439,6 +448,14 @@ let zencode_string str = "z" ^ List.fold_left (fun s1 s2 -> s1 ^ s2) "" (List.ma
let zencode_upper_string str = "Z" ^ List.fold_left (fun s1 s2 -> s1 ^ s2) "" (List.map zchar (string_to_list str))
+(** Encode string for use as a filename. We can't use zencode directly
+ because some operating systems make the mistake of being
+ case-insensitive. *)
+let file_encode_string str =
+ let zstr = zencode_string str in
+ let md5 = Digest.to_hex (Digest.string zstr) in
+ String.lowercase_ascii zstr ^ String.lowercase_ascii md5
+
let warn str =
if !opt_warnings then
prerr_endline (("Warning" |> yellow |> clear) ^ ": " ^ str)
@@ -446,3 +463,5 @@ let warn str =
let log_line str line msg =
"\n[" ^ (str ^ ":" ^ string_of_int line |> blue |> clear) ^ "] " ^ msg
+
+let header str n = "\n" ^ str ^ "\n" ^ String.make (String.length str - 9 * n) '='