]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/matita.ml
acic_procedural and tactics removed
[helm.git] / matita / matita / matita.ml
1 (* Copyright (C) 2004-2005, HELM Team.
2  * 
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.
6  * 
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.
11  * 
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.
16  *
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,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 (* $Id$ *)
27
28 open Printf
29
30 open MatitaGtkMisc
31 open GrafiteTypes
32
33 (** {2 Initialization} *)
34
35 let _ = 
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 ()
41 ;;
42
43 (* let _ = Saturation.init () (* ALB to link paramodulation *) *)
44
45 (** {2 GUI callbacks} *)
46
47 let gui = MatitaGui.instance ()
48
49 let script =
50   let s = 
51     MatitaScript.script 
52       ~source_view:gui#sourceView
53       ~mathviewer:(MatitaMathView.mathViewer ())
54       ~urichooser:(fun uris ->
55         try
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"))
61           () ~id:"boh?" uris
62         with MatitaTypes.Cancel -> [])
63       ~set_star:gui#setStar
64       ~ask_confirmation:
65         (fun ~title ~message -> 
66             MatitaGtkMisc.ask_confirmation ~title ~message 
67             ~parent:gui#main#toplevel ())
68       ()
69   in
70   Predefined_virtuals.load_predefined_virtuals ();
71   Predefined_virtuals.load_predefined_classes ();
72   gui#sourceView#source_buffer#begin_not_undoable_action ();
73   s#reset (); 
74   s#template (); 
75   gui#sourceView#source_buffer#end_not_undoable_action ();
76   s
77   
78   (* math viewers *)
79 let _ =
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
84     (Some (fun uri ->
85       let uri =
86        try
87         `Uri (UriManager.uri_of_string uri)
88        with
89         UriManager.IllFormedUri _ ->
90          `NRef (NReference.reference_of_string uri)
91       in
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#ng_mode with
97        `ProofMode ->
98         sequents_viewer#nload_sequents grafite_status;
99         (try
100           script#setGoal
101            (Some (Continuationals.Stack.find_goal grafite_status#stack));
102           let goal =
103            match script#goal with
104               None -> assert false
105             | Some n -> n
106           in
107            sequents_viewer#goto_sequent grafite_status goal
108         with Failure _ -> script#setGoal None);
109      | `CommandMode -> sequents_viewer#load_logo
110   in
111   script#addObserver sequents_observer;
112   script#addObserver browser_observer
113
114   (** {{{ Debugging *)
115 let _ =
116   if BuildTimeConf.debug ||
117      Helm_registry.get_bool "matita.debug_menu" 
118   then begin
119     gui#main#debugMenu#misc#show ();
120     let addDebugItem label callback =
121       let item =
122         GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label () in
123       ignore (item#connect#activate callback) 
124     in
125     let addDebugCheckbox label ?(init=false) callback =
126       let item =
127         GMenu.check_menu_item 
128           ~packing:gui#main#debugMenu_menu#append ~label () in
129       item#set_active init;
130       ignore (item#connect#toggled (callback item)) 
131     in
132     let addDebugSeparator () =
133       ignore (GMenu.separator_item ~packing:gui#main#debugMenu_menu#append ())
134     in
135     addDebugItem "dump aliases" (fun _ ->
136       let status = script#grafite_status in
137       LexiconEngine.dump_aliases prerr_endline "" status);
138 (* FG: DEBUGGING   
139     addDebugItem "dump interpretations" (fun _ ->
140       let status = script#lexicon_status in
141       let filter = 
142        List.filter (function LexiconAst.Interpretation _ -> true | _ -> false)
143       in
144       HLog.debug (String.concat "\n"
145        (List.fold_right
146          (fun x l -> (LexiconAstPp.pp_command x)::l)
147          (filter status.LexiconEngine.lexicon_content_rev) [])));
148 *)
149     addDebugSeparator ();
150     addDebugCheckbox "high level pretty printer" ~init:true
151       (fun mi () -> CicMetaSubst.use_low_level_ppterm_in_context := mi#active);
152     addDebugSeparator ();
153     addDebugItem "always show all disambiguation errors"
154       (fun _ -> MatitaGui.all_disambiguation_passes := true);
155     addDebugItem "prune disambiguation errors"
156       (fun _ -> MatitaGui.all_disambiguation_passes := false);
157     addDebugSeparator ();
158     addDebugCheckbox "multiple disambiguation passes" ~init:true
159       (fun mi () -> MultiPassDisambiguator.only_one_pass := mi#active);
160     addDebugCheckbox "tactics logging" 
161       (fun mi () -> NTacStatus.debug := mi#active);
162     addDebugCheckbox "disambiguation/refiner/unification/metasubst logging"
163       (fun mi () -> NCicRefiner.debug := mi#active; NCicUnification.debug :=
164               mi#active; MultiPassDisambiguator.debug := mi#active; NCicMetaSubst.debug := mi#active);
165     addDebugCheckbox "reduction logging"
166       (fun mi () -> NCicReduction.debug := mi#active; CicReduction.ndebug := mi#active);
167     addDebugSeparator ();
168     addDebugItem "Expand virtuals"
169     (fun _ -> (MatitaScript.current ())#expandAllVirtuals);
170   end
171   (** Debugging }}} *)
172
173   (** {2 Main} *)
174
175 let _ =
176   at_exit (fun () -> print_endline "\nThanks for using Matita!\n");
177   Sys.catch_break true;
178   let args = Helm_registry.get_list Helm_registry.string "matita.args" in
179   (try gui#loadScript (List.hd args) with Failure _ -> ());
180   gui#main#mainWin#show ();
181   try
182    GtkThread.main ()
183   with Sys.Break ->
184    Sys.set_signal Sys.sigint
185     (Sys.Signal_handle
186       (fun _ ->
187         prerr_endline "Still cleaning the library: don't be impatient!"));
188    prerr_endline "Matita is cleaning up. Please wait.";
189    let baseuri = 
190     (MatitaScript.current ())#grafite_status#baseuri
191    in
192      LibraryClean.clean_baseuris [baseuri]
193
194 (* vim:set foldmethod=marker: *)