Debian Codegraph @

ide/rocqide/rocqide_main.ml

raw symbols SCIP
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 let _ = Rocqide.set_signal_handlers ()
12
13 (* We handle Gtk warning messages ourselves :
14 - on win32, we don't want them to end on a non-existing console
15 - we display critical messages via pop-ups *)
16
17 let catch_gtk_messages () =
18 let all_levels =
19 [`FLAG_RECURSION;`FLAG_FATAL;`ERROR;`CRITICAL;`WARNING;
20 `MESSAGE;`INFO;`DEBUG]
21 in
22 let log_level lvl =
23 let level_is tag = (lvl land Glib.Message.log_level tag) <> 0 in
24 if level_is `ERROR then `FATAL
25 else if level_is `CRITICAL then `ERROR
26 else if level_is `DEBUG then `DEBUG
27 else if level_is `WARNING then `WARNING
28 else if level_is `MESSAGE then `NOTICE
29 else `INFO
30 in
31 let handler ~level msg =
32 let header = "RocqIDE internal error: " in
33 match log_level level with
34 |`FATAL ->
35 let () = GToolbox.message_box ~title:"Error" (header ^ msg) in
36 Rocqide.crash_save 1
37 |`ERROR ->
38 if CDebug.(get_flag misc) then GToolbox.message_box ~title:"Error" (header ^ msg)
39 else Printf.eprintf "%s\n" (header ^ msg)
40 |`DEBUG -> Minilib.log msg
41 |level when Sys.os_type = "Win32" -> Minilib.log ~level msg
42 |_ -> Printf.eprintf "%s\n" msg
43 in
44 let catch domain =
45 ignore (Glib.Message.set_log_handler ~domain ~levels:all_levels handler)
46 in
47 List.iter catch ["GLib";"Gtk";"Gdk";"Pango"]
48
49 let () = catch_gtk_messages ()
50
51 let load_prefs () =
52 Preferences.load_pref ~warn:(fun ~delay -> Ideutils.flash_info ~delay)
53
54 let () =
55 Ideutils.push_info ("Ready"^ if Preferences.microPG#get then ", [μPG]" else "");
56 load_prefs ();
57 let argl = List.tl (Array.to_list Sys.argv) in
58 let argl = Rocqide.read_rocqide_args argl in
59 let files = RocqDriver.filter_rocq_opts argl in
60 let args = List.filter (fun x -> not (List.mem x files)) argl in
61 RocqDriver.check_connection args;
62 Rocqide.sup_args := args;
63 let w = Rocqide.main files in
64 Rocqide.set_signal_handlers ~parent:w ();
65 Rocqide_os_specific.init ();
66 Shared_os_specific.init ();
67 try
68 GMain.main ();
69 failwith "Gtk loop ended"
70 with e ->
71 Minilib.log ("RocqIDE unexpected error: " ^ Printexc.to_string e);
72 Rocqide.crash_save 127