1 (* Copyright (C) 2004, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
32 (** {2 Initialization} *)
35 Helm_registry.load_from "matita.conf.xml"; (* read conf *)
37 MetadataTypes.ownerize_tables (Helm_registry.get "matita.owner");
38 MatitaDb.clean_owner_environment ();
39 MatitaDb.create_owner_environment ();
40 GtkMain.Rc.add_default_file BuildTimeConf.gtkrc; (* loads gtk rc files *)
41 ignore (GMain.Main.init ())
43 let gui = MatitaGui.instance ()
44 let disambiguator = MatitaDisambiguator.instance ()
45 let _ = (* set disambiguator callbacks *)
46 disambiguator#setChooseUris (interactive_user_uri_choice ~gui);
47 disambiguator#setChooseInterp (interactive_interp_choice ~gui)
49 let _ = (* environment trust *)
50 CicEnvironment.set_trust
51 (let trust = Helm_registry.get_bool "matita.environment_trust" in
54 let currentProof = MatitaProof.instance ()
56 let sequent_viewer = MatitaMathView.sequent_viewer_instance ()
57 let sequents_viewer = MatitaMathView.sequents_viewer_instance ()
58 let _ = (* attach observers to proof status *)
59 let browser_observer _ _ = MatitaMathView.refresh_all_browsers () in
60 let sequents_observer _ (((_, metasenv, _, _), goal_opt), ()) =
61 sequents_viewer#reset;
65 sequents_viewer#load_sequents metasenv;
66 sequents_viewer#goto_sequent goal)
68 currentProof#addObserver sequents_observer;
69 currentProof#addObserver browser_observer;
70 currentProof#connect `Quit (fun () ->
71 (* quit program, asking for confirmation if needed *)
72 if not (currentProof#onGoing ()) ||
73 (ask_confirmation ~gui
74 ~msg:("Proof in progress, are you sure you want to quit?") ())
78 currentProof#connect `Abort (fun () -> sequents_viewer#reset; false)
81 let mathViewer = MatitaMathView.mathViewer () in
82 MatitaInterpreter.interpreter ~console:gui#console ~mathViewer ()
83 let script = MatitaScript.script ~interpreter
85 let href_callback uri =
86 let term = CicAst.Uri (uri, None) in
87 ignore (interpreter#evalAst (TacticAst.Command (TacticAst.Check term)))
89 sequent_viewer#set_href_callback (Some href_callback)
91 let console_callback s =
92 let module A = TacticAst in
93 let rec strip_locations = function
94 | A.LocatedTactical (loc, tac) -> strip_locations tac
97 let needed_by_script ast =
98 match strip_locations ast with
101 (A.Inductive _ | A.Theorem _ | A.Coercion _ | A.Qed _ | A.Proof) ->
105 let ast = disambiguator#parserr#parseTactical (Stream.of_string s) in
106 debug_print (sprintf "evaluating '%s'" s);
107 if needed_by_script ast then
110 interpreter#evalAst ast
112 let console_callback s =
113 match gui#console#wrap_exn (fun () -> console_callback s) with
114 | None -> (false, false)
115 | Some outcome -> outcome
117 (** {2 GUI callbacks} *)
120 gui#setQuitCallback currentProof#quit;
121 gui#setPhraseCallback console_callback;
122 gui#main#debugMenu#misc#hide ();
123 ignore (gui#main#newProofMenuItem#connect#activate (fun _ ->
124 gui#console#clear ();
125 gui#console#show ~msg:"theorem " ()));
126 ignore (gui#main#openMenuItem#connect#activate (fun _ ->
127 match gui#chooseFile () with
129 | Some f when is_proof_script f ->
130 ignore (gui#console#wrap_exn (fun () -> script#loadFrom f))
132 gui#console#echo_error (sprintf
133 "Don't know what to do with file: %s\nUnrecognized file format."
135 ignore (gui#main#newCicBrowserMenuItem#connect#activate (fun _ ->
136 ignore (MatitaMathView.cicBrowser ())));
137 let module A = TacticAst in
138 let hole = CicAst.UserInput in
140 let ast = A.Tactic ast in
141 ignore (script#advance (TacticAstPp.pp_tactical ast))
143 let tac_w_term ast _ =
144 (* gui#console#clear (); *)
145 gui#console#show ~msg:(TacticAstPp.pp_tactic ast) ();
146 gui#main#mainWin#present ()
148 let tbar = gui#toolbar in
149 connect_button tbar#introsButton (tac (A.Intros (None, [])));
150 connect_button tbar#applyButton (tac_w_term (A.Apply hole));
151 connect_button tbar#exactButton (tac_w_term (A.Exact hole));
152 connect_button tbar#elimButton (tac_w_term (A.Elim (hole, None)));
153 connect_button tbar#elimTypeButton (tac_w_term (A.ElimType hole));
154 connect_button tbar#splitButton (tac A.Split);
155 connect_button tbar#leftButton (tac A.Left);
156 connect_button tbar#rightButton (tac A.Right);
157 connect_button tbar#existsButton (tac A.Exists);
158 connect_button tbar#reflexivityButton (tac A.Reflexivity);
159 connect_button tbar#symmetryButton (tac A.Symmetry);
160 connect_button tbar#transitivityButton (tac_w_term (A.Transitivity hole));
161 connect_button tbar#assumptionButton (tac A.Assumption);
162 connect_button tbar#cutButton (tac_w_term (A.Cut hole));
163 connect_button tbar#autoButton (tac A.Auto)
168 if BuildTimeConf.debug then begin
169 gui#main#debugMenu#misc#show ();
170 let addDebugItem ~label callback =
172 GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label ()
174 ignore (item#connect#activate callback)
176 addDebugItem "dump environment to \"env.dump\"" (fun _ ->
177 let oc = open_out "env.dump" in
178 CicEnvironment.dump_to_channel oc;
180 addDebugItem "print selected terms" (fun () ->
183 (fun t -> incr i; debug_print (sprintf "%d: %s" !i (CicPp.ppterm t)))
184 sequent_viewer#get_selected_terms);
185 addDebugItem "dump getter settings" (fun _ ->
186 prerr_endline (Http_getter_env.env_to_string ()));
187 addDebugItem "getter: update" Http_getter.update;
188 addDebugItem "getter: getalluris" (fun _ ->
189 List.iter prerr_endline (Http_getter.getalluris ()));
195 (try script#loadFrom Sys.argv.(1) with Invalid_argument _ -> ());
196 if Filename.basename Sys.argv.(0) = "cicbrowser" then begin (* cicbrowser *)
197 Helm_registry.set "matita.mode" "cicbrowser";
198 let browser = MatitaMathView.cicBrowser () in
200 browser#loadUri Sys.argv.(1)
201 with Invalid_argument _ -> ()
202 end else begin (* matita *)
203 Helm_registry.set "matita.mode" "matita";
204 gui#main#mainWin#show ();
205 gui#toolbar#toolBarWin#show ();