1 (* Copyright (C) 2004-2005, 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/
33 (** {2 Initialization} *)
36 MatitaInit.add_cmdline_spec
37 ["-tptppath",Arg.String
38 (fun s -> Helm_registry.set_string "matita.tptppath" s),
39 "Where to find the Axioms/ and Problems/ directory"];
40 MatitaInit.initialize_all ()
43 (* let _ = Saturation.init () (* ALB to link paramodulation *) *)
45 (** {2 GUI callbacks} *)
47 let gui = MatitaGui.instance ()
52 ~source_view:gui#sourceView
53 ~mathviewer:(MatitaMathView.mathViewer ())
54 ~urichooser:(fun uris ->
56 MatitaGui.interactive_uri_choice ~selection_mode:`SINGLE
57 ~title:"Matita: URI chooser"
58 ~msg:"Select the URI" ~hide_uri_entry:true
59 ~hide_try:true ~ok_label:"_Apply" ~ok_action:`SELECT
60 ~copy_cb:(fun s -> gui#sourceView#buffer#insert ("\n"^s^"\n"))
62 with MatitaTypes.Cancel -> [])
65 (fun ~title ~message ->
66 MatitaGtkMisc.ask_confirmation ~title ~message
67 ~parent:gui#main#toplevel ())
70 Predefined_virtuals.load_predefined_virtuals ();
71 Predefined_virtuals.load_predefined_classes ();
72 gui#sourceView#source_buffer#begin_not_undoable_action ();
75 gui#sourceView#source_buffer#end_not_undoable_action ();
80 let cic_math_view = MatitaMathView.cicMathView_instance () in
81 let sequents_viewer = MatitaMathView.sequentsViewer_instance () in
82 sequents_viewer#load_logo;
83 cic_math_view#set_href_callback
87 `Uri (UriManager.uri_of_string uri)
89 UriManager.IllFormedUri _ ->
90 `NRef (NReference.reference_of_string uri)
92 (MatitaMathView.cicBrowser ())#load uri));
93 let browser_observer _ = MatitaMathView.refresh_all_browsers () in
94 let sequents_observer grafite_status =
95 sequents_viewer#reset;
96 match grafite_status#proof_status with
97 | Incomplete_proof ({ stack = stack } as incomplete_proof) ->
98 sequents_viewer#load_sequents grafite_status incomplete_proof;
100 script#setGoal (Some (Continuationals.Stack.find_goal stack));
102 match script#goal with
106 sequents_viewer#goto_sequent grafite_status goal
107 with Failure _ -> script#setGoal None);
108 | Proof proof -> sequents_viewer#load_logo_with_qed
110 (match grafite_status#ng_mode with
112 sequents_viewer#nload_sequents grafite_status;
115 (Some (Continuationals.Stack.find_goal grafite_status#stack));
117 match script#goal with
121 sequents_viewer#goto_sequent grafite_status goal
122 with Failure _ -> script#setGoal None);
123 | `CommandMode -> sequents_viewer#load_logo
125 | Intermediate _ -> assert false (* only the engine may be in this state *)
127 script#addObserver sequents_observer;
128 script#addObserver browser_observer
132 if BuildTimeConf.debug ||
133 Helm_registry.get_bool "matita.debug_menu"
135 gui#main#debugMenu#misc#show ();
136 let addDebugItem ~label callback =
138 GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label () in
139 ignore (item#connect#activate callback) in
140 let addDebugSeparator () =
141 ignore (GMenu.separator_item ~packing:gui#main#debugMenu_menu#append ())
143 addDebugItem "dump aliases" (fun _ ->
144 let status = script#grafite_status in
145 LexiconEngine.dump_aliases HLog.debug "" status);
147 addDebugItem "dump interpretations" (fun _ ->
148 let status = script#lexicon_status in
150 List.filter (function LexiconAst.Interpretation _ -> true | _ -> false)
152 HLog.debug (String.concat "\n"
154 (fun x l -> (LexiconAstPp.pp_command x)::l)
155 (filter status.LexiconEngine.lexicon_content_rev) [])));
157 addDebugItem "print metasenv goals and stack to stderr"
159 prerr_endline ("metasenv goals: " ^ String.concat " "
160 (List.map (fun (g, _, _) -> string_of_int g)
161 (MatitaScript.current ())#proofMetasenv));
162 prerr_endline ("stack: " ^ Continuationals.Stack.pp
163 (GrafiteTypes.get_stack (MatitaScript.current ())#grafite_status)));
164 addDebugItem "Print current proof term"
169 (MatitaScript.current ())#grafite_status#proof_status
171 | GrafiteTypes.No_proof -> (Cic.Implicit None)
172 | Incomplete_proof i ->
173 let _,_,_subst,p,_, _ = i.GrafiteTypes.proof in
175 | Proof p -> let _,_,_subst,p,_, _ = p in Lazy.force p
176 | Intermediate _ -> assert false)));
177 addDebugItem "Print current proof (natural language) to stderr"
180 (ApplyTransformation.txt_of_cic_object 120 []
181 ~map_unicode_to_tex:(Helm_registry.get_bool
182 "matita.paste_unicode_as_tex")
184 (MatitaScript.current ())#grafite_status#proof_status
186 | GrafiteTypes.No_proof -> assert false
187 | Incomplete_proof i ->
188 let _,m,_subst,p,ty, attrs = i.GrafiteTypes.proof in
189 Cic.CurrentProof ("current (incomplete) proof",m,Lazy.force p,ty,[],attrs)
190 | Proof (_,m,_subst,p,ty, attrs) ->
191 Cic.CurrentProof ("current proof",m,Lazy.force p,ty,[],attrs)
192 | Intermediate _ -> assert false)));
193 addDebugSeparator ();
194 addDebugItem "disable high level pretty printer"
195 (fun _ -> CicMetaSubst.use_low_level_ppterm_in_context := true);
196 addDebugItem "enable high level pretty printer"
197 (fun _ -> CicMetaSubst.use_low_level_ppterm_in_context := false);
198 addDebugSeparator ();
199 addDebugItem "enable multiple disambiguation passes (default)"
200 (fun _ -> MultiPassDisambiguator.only_one_pass := false);
201 addDebugItem "enable only one disambiguation pass"
202 (fun _ -> MultiPassDisambiguator.only_one_pass := true);
203 addDebugItem "always show all disambiguation errors"
204 (fun _ -> MatitaGui.all_disambiguation_passes := true);
205 addDebugItem "prune disambiguation errors"
206 (fun _ -> MatitaGui.all_disambiguation_passes := false);
207 addDebugSeparator ();
208 addDebugItem "enable refiner/unification logging"
209 (fun _ -> NCicRefiner.debug := true; NCicUnification.debug := true;);
210 addDebugItem "disable refiner/unification logging"
211 (fun _ -> NCicRefiner.debug := false; NCicUnification.debug := false;);
212 addDebugSeparator ();
213 addDebugItem "enable reduction logging"
214 (fun _ -> NCicReduction.debug := true);
215 addDebugItem "disable reduction logging"
216 (fun _ -> NCicReduction.debug := false);
217 addDebugSeparator ();
218 addDebugItem "Expand virtuals"
219 (fun _ -> (MatitaScript.current ())#expandAllVirtuals);
226 at_exit (fun () -> print_endline "\nThanks for using Matita!\n");
227 Sys.catch_break true;
228 let args = Helm_registry.get_list Helm_registry.string "matita.args" in
229 (try gui#loadScript (List.hd args) with Failure _ -> ());
230 gui#main#mainWin#show ();
234 Sys.set_signal Sys.sigint
237 prerr_endline "Still cleaning the library: don't be impatient!"));
238 prerr_endline "Matita is cleaning up. Please wait.";
240 (MatitaScript.current ())#grafite_status#baseuri
242 LibraryClean.clean_baseuris [baseuri]
244 (* vim:set foldmethod=marker: *)