Debian Codegraph @

ide/rocqide/rocqide_WIN32.ml.in

raw
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 (* On win32, we add the directory of rocqide to the PATH at launch-time
12 (this used to be done in a .bat script). *)
13
14 let set_win32_path () =
15 Unix.putenv "PATH"
16 (Filename.dirname Sys.executable_name ^ ";" ^
17 (try Sys.getenv "PATH" with _ -> ""))
18
19 (* On win32, since rocqide is now console-free, we re-route stdout/stderr
20 to avoid Sys_error if someone writes to them. We write to a pipe which
21 is never read (by default) or to a temp log file (when in debug mode).
22 *)
23
24 let reroute_stdout_stderr () =
25 (* We anticipate a bit the argument parsing and look for -debug *)
26 let debug = List.mem "-debug" (Array.to_list Sys.argv) in
27 Minilib.debug := debug;
28 let out_descr =
29 if debug then
30 let (name,chan) = Filename.open_temp_file "rocqide_" ".log" in
31 Rocqide.logfile := Some name;
32 Unix.descr_of_out_channel chan
33 else
34 snd (Unix.pipe ())
35 in
36 Unix.set_close_on_exec out_descr;
37 Unix.dup2 out_descr Unix.stdout;
38 Unix.dup2 out_descr Unix.stderr
39
40 (* We also provide a specific interrupt function. *)
41
42 external win32_interrupt : int -> unit = "win32_interrupt"
43
44 let interrupter pid =
45 (* indicate which process to interrupt *)
46 let fd = open_out (Shared.get_interrupt_fname pid) in
47 close_out fd;
48 win32_interrupt pid
49
50 let () =
51 set_win32_path ();
52 RocqDriver.interrupter := interrupter;
53 reroute_stdout_stderr ();
54 try ignore (Unix.getenv "GTK_CSD") with Not_found -> Unix.putenv "GTK_CSD" "0"
55
56 let init () = ()