Skip to content

Commit ce34510

Browse files
committed
Format
1 parent e91c98f commit ce34510

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

bin/sgen.ml

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ let run_with_timeout input_file timeout =
2828
let pid = Unix.fork () in
2929
if pid = 0 then (
3030
(* Child process *)
31-
try run input_file; Stdlib.exit 0
31+
try
32+
run input_file;
33+
Stdlib.exit 0
3234
with e ->
3335
Stdlib.Printf.eprintf "Error: %s\n" (Exn.to_string e);
34-
Stdlib.exit 1
35-
) else (
36+
Stdlib.exit 1 )
37+
else
3638
(* Parent process *)
3739
let start_time = Unix.time () in
3840
let rec wait_with_timeout () =
@@ -41,10 +43,11 @@ let run_with_timeout input_file timeout =
4143
(* Timeout - kill child process *)
4244
Unix.kill pid Stdlib.Sys.sigkill;
4345
let _ = Unix.waitpid [] pid in
44-
Stdlib.Printf.eprintf "\n[Timeout: execution exceeded %.1fs - killed]\n%!" timeout;
45-
false
46-
) else (
47-
match Unix.waitpid [Unix.WNOHANG] pid with
46+
Stdlib.Printf.eprintf
47+
"\n[Timeout: execution exceeded %.1fs - killed]\n%!" timeout;
48+
false )
49+
else
50+
match Unix.waitpid [ Unix.WNOHANG ] pid with
4851
| 0, _ ->
4952
(* Still running *)
5053
Unix.sleepf 0.1;
@@ -60,19 +63,15 @@ let run_with_timeout input_file timeout =
6063
false
6164
| Unix.WSTOPPED signal ->
6265
Stdlib.Printf.eprintf "[Stopped by signal %d]\n%!" signal;
63-
false
64-
)
65-
)
66+
false )
6667
in
6768
wait_with_timeout ()
68-
)
6969

7070
let watch input_file timeout =
7171
let abs_path =
7272
if Stdlib.Filename.is_relative input_file then
7373
Stdlib.Filename.concat (Stdlib.Sys.getcwd ()) input_file
74-
else
75-
input_file
74+
else input_file
7675
in
7776

7877
Stdlib.Printf.printf "Watching %s (timeout: %.1fs)\n%!" abs_path timeout;
@@ -90,11 +89,9 @@ let watch input_file timeout =
9089
if Float.(current_mtime > last_mtime) then (
9190
Stdlib.Printf.printf "\n\n--- File changed, re-running ---\n%!";
9291
let _ = run_with_timeout input_file timeout in
93-
poll_loop current_mtime
94-
) else
95-
poll_loop last_mtime
96-
with
97-
| Unix.Unix_error _ ->
92+
poll_loop current_mtime )
93+
else poll_loop last_mtime
94+
with Unix.Unix_error _ ->
9895
Stdlib.Printf.eprintf "Error accessing file, retrying...\n%!";
9996
Unix.sleepf 1.0;
10097
poll_loop last_mtime
@@ -130,12 +127,14 @@ let preprocess_cmd =
130127

131128
let timeout_arg =
132129
let doc = "Timeout in seconds for each execution (default: 5.0)" in
133-
Arg.(value & opt float 5.0 & info ["t"; "timeout"] ~docv:"SECONDS" ~doc)
130+
Arg.(value & opt float 5.0 & info [ "t"; "timeout" ] ~docv:"SECONDS" ~doc)
134131

135132
let watch_cmd =
136133
let doc = "Watch and re-run the Stellogen program on file changes" in
137134
let term =
138-
Term.(const (fun input timeout -> wrap (fun i -> watch i timeout) input) $ input_file_arg $ timeout_arg |> term_result)
135+
Term.(
136+
const (fun input timeout -> wrap (fun i -> watch i timeout) input)
137+
$ input_file_arg $ timeout_arg |> term_result )
139138
in
140139
Cmd.v (Cmd.info "watch" ~doc) term
141140

0 commit comments

Comments
 (0)