From 95ebd2d6acfa744c5e93287cc6385f4f1359376e Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Sun, 30 Oct 2022 03:42:11 +1300 Subject: wallgen and wallsolve working, visualwall partially done, license added --- src/util.ml | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/util.ml (limited to 'src/util.ml') diff --git a/src/util.ml b/src/util.ml new file mode 100644 index 0000000..93f2c93 --- /dev/null +++ b/src/util.ml @@ -0,0 +1,57 @@ + + +(* Programmed by Jedidiah Barber *) +(* Licensed under the Sunset License v1.0 *) + + +exception Not_an_integer of string + + + +let ( @@ ) f g x = f (g x) + +let ( |> ) f x = f x + + + +let call_with_open_input_file ~filename ~func = + let ic = open_in filename in + let res = + try func ic + with exn -> close_in ic; raise exn in + close_in ic; + res + + + +let call_with_open_output_file ~filename ~func = + let oc = open_out filename in + let res = + try func oc + with exn -> close_out oc; raise exn in + close_out oc; + res + + + +let read_integer_list args = + let convert x = + try Z.of_string x + with Invalid_argument _ -> + raise (Not_an_integer x) in + let blank_is_zero x = + if x = "" then "0" else x in + (Array.map convert) @@ + Array.of_list @@ + (List.map (blank_is_zero @@ String.trim)) @@ + (String.split_on_char ',') |> args + + + +let read_sequence_file filename = + let reader handle = + let line = input_line handle in + read_integer_list line + in call_with_open_input_file ~filename:filename ~func:reader + + -- cgit