summaryrefslogtreecommitdiff
path: root/src/util.ml
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2022-10-30 03:42:11 +1300
committerJedidiah Barber <contact@jedbarber.id.au>2022-10-30 03:42:11 +1300
commit95ebd2d6acfa744c5e93287cc6385f4f1359376e (patch)
tree87cea8951f3ef00b9ad53679c7fe70c208b0ec62 /src/util.ml
parent3f290e0d6c3ef1435253095de2cf53016855840e (diff)
wallgen and wallsolve working, visualwall partially done, license added
Diffstat (limited to 'src/util.ml')
-rw-r--r--src/util.ml57
1 files changed, 57 insertions, 0 deletions
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
+
+