]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/matita.ml
Code clean-up
[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  MatitaScript.script 
51    ~urichooser:(fun source_view uris ->
52      try
53        MatitaGui.interactive_uri_choice ~selection_mode:`SINGLE
54        ~title:"Matita: URI chooser" 
55        ~msg:"Select the URI" ~hide_uri_entry:true
56        ~hide_try:true ~ok_label:"_Apply" ~ok_action:`SELECT
57        ~copy_cb:(fun s -> source_view#buffer#insert ("\n"^s^"\n"))
58        () ~id:"boh?" uris
59      with MatitaTypes.Cancel -> [])
60    ~ask_confirmation:
61      (fun ~title ~message -> 
62          MatitaGtkMisc.ask_confirmation ~title ~message 
63          ~parent:gui#main#toplevel ())
64    ()
65
66 let _ =
67   Predefined_virtuals.load_predefined_virtuals ();
68   Predefined_virtuals.load_predefined_classes ();
69   
70   (* math viewers *)
71 let _ =
72   let sequents_viewer = MatitaMathView.sequentsViewer_instance () in
73   sequents_viewer#load_logo;
74   let browser_observer _ = MatitaMathView.refresh_all_browsers () in
75   let sequents_observer grafite_status =
76     sequents_viewer#reset;
77     match grafite_status#ng_mode with
78        `ProofMode ->
79         sequents_viewer#nload_sequents grafite_status;
80         (try
81           script#setGoal
82            (Some (Continuationals.Stack.find_goal grafite_status#stack));
83           let goal =
84            match script#goal with
85               None -> assert false
86             | Some n -> n
87           in
88            sequents_viewer#goto_sequent grafite_status goal
89         with Failure _ -> script#setGoal None);
90      | `CommandMode -> sequents_viewer#load_logo
91   in
92   script#addObserver sequents_observer;
93   script#addObserver browser_observer
94
95   (** {{{ Debugging *)
96 let _ =
97   if BuildTimeConf.debug ||
98      Helm_registry.get_bool "matita.debug_menu" 
99   then begin
100     gui#main#debugMenu#misc#show ();
101     let addDebugItem label callback =
102       let item =
103         GMenu.menu_item ~packing:gui#main#debugMenu_menu#append ~label () in
104       ignore (item#connect#activate callback) 
105     in
106     let addDebugCheckbox label ?(init=false) callback =
107       let item =
108         GMenu.check_menu_item 
109           ~packing:gui#main#debugMenu_menu#append ~label () in
110       item#set_active init;
111       ignore (item#connect#toggled (callback item)) 
112     in
113     let addDebugSeparator () =
114       ignore (GMenu.separator_item ~packing:gui#main#debugMenu_menu#append ())
115     in
116     addDebugItem "dump aliases" (fun _ ->
117       let status = script#grafite_status in
118       GrafiteDisambiguate.dump_aliases prerr_endline "" status);
119 (* FG: DEBUGGING   
120     addDebugItem "dump interpretations" (fun _ ->
121       let status = script#lexicon_status in
122       let filter = 
123        List.filter (function LexiconAst.Interpretation _ -> true | _ -> false)
124       in
125       HLog.debug (String.concat "\n"
126        (List.fold_right
127          (fun x l -> (LexiconAstPp.pp_command x)::l)
128          (filter status.LexiconEngine.lexicon_content_rev) [])));
129 *)
130     addDebugSeparator ();
131     addDebugCheckbox "high level pretty printer" ~init:true
132       (fun mi () -> assert false (* MATITA 1.0 *));
133     addDebugSeparator ();
134     addDebugItem "always show all disambiguation errors"
135       (fun _ -> MatitaGui.all_disambiguation_passes := true);
136     addDebugItem "prune disambiguation errors"
137       (fun _ -> MatitaGui.all_disambiguation_passes := false);
138     addDebugSeparator ();
139     addDebugCheckbox "multiple disambiguation passes" ~init:true
140       (fun mi () -> MultiPassDisambiguator.only_one_pass := mi#active);
141     addDebugCheckbox "tactics logging" 
142       (fun mi () -> NTacStatus.debug := mi#active);
143     addDebugCheckbox "disambiguation/refiner/unification/metasubst logging"
144       (fun mi () -> NCicRefiner.debug := mi#active; NCicUnification.debug :=
145               mi#active; MultiPassDisambiguator.debug := mi#active; NCicMetaSubst.debug := mi#active);
146     addDebugCheckbox "reduction logging"
147       (fun mi () -> NCicReduction.debug := mi#active);
148     addDebugSeparator ();
149     addDebugItem "Expand virtuals"
150     (fun _ -> (MatitaScript.current ())#expandAllVirtuals);
151   end
152   (** Debugging }}} *)
153
154   (** {2 Main} *)
155
156 let _ =
157   at_exit (fun () -> print_endline "\nThanks for using Matita!\n");
158   Sys.catch_break true;
159   let args = Helm_registry.get_list Helm_registry.string "matita.args" in
160   (try gui#loadScript (List.hd args) with Failure _ -> ());
161   gui#main#mainWin#show ();
162   try
163    GtkThread.main ()
164   with Sys.Break ->
165    Sys.set_signal Sys.sigint
166     (Sys.Signal_handle
167       (fun _ ->
168         prerr_endline "Still cleaning the library: don't be impatient!"));
169    prerr_endline "Matita is cleaning up. Please wait.";
170    (*CSC: MatitaScript.current () makes no sense here *)
171    let baseuri = 
172     (MatitaScript.current ())#grafite_status#baseuri
173    in
174      LibraryClean.clean_baseuris [baseuri]
175
176 (* vim:set foldmethod=marker: *)