]> matita.cs.unibo.it Git - helm.git/blob - helm/gTopLevel/hbugs.ml
ocaml 3.09 transition
[helm.git] / helm / gTopLevel / hbugs.ml
1 (*
2  * Copyright (C) 2003:
3  *    Stefano Zacchiroli <zack@cs.unibo.it>
4  *    for the HELM Team http://helm.cs.unibo.it/
5  *
6  *  This file is part of HELM, an Hypertextual, Electronic
7  *  Library of Mathematics, developed at the Computer Science
8  *  Department, University of Bologna, Italy.
9  *
10  *  HELM is free software; you can redistribute it and/or
11  *  modify it under the terms of the GNU General Public License
12  *  as published by the Free Software Foundation; either version 2
13  *  of the License, or (at your option) any later version.
14  *
15  *  HELM is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with HELM; if not, write to the Free Software
22  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23  *  MA  02111-1307, USA.
24  *
25  *  For details, see the HELM World-Wide-Web page,
26  *  http://helm.cs.unibo.it/
27  *)
28
29 open Hbugs_types;;
30 open Printf;;
31
32 let debug_print = 
33   let debug = true in
34   fun s -> prerr_endline (sprintf "HBUGS DEBUG: %s" s)
35 ;;
36
37 exception NoProofInProgress;;
38
39 let hbugs_client = ref None
40 let use_hint_callback = ref ignore
41 let describe_hint_callback = ref ignore
42
43 let set_describe_hint_callback c = describe_hint_callback := c
44
45 let quit () =
46   match !hbugs_client with
47   | Some c -> c#unregisterFromBroker ()
48   | None -> ()
49
50 let hbugs_enabled = ref false
51
52 let get_hbugs_client () =
53   match !hbugs_client with
54   | Some c -> c
55   | None -> assert false
56
57 let disable () =
58   match !hbugs_client with None -> () | Some c -> c#hide ()
59
60 let notify () =
61   try
62     if !hbugs_enabled then begin
63       let client = get_hbugs_client () in
64       let goal =
65         match !ProofEngine.goal with
66         | Some g -> g
67         | None -> raise NoProofInProgress
68       in
69       let (type_string, body_string) =
70         let (type_xml, body_xml) = ProofEngine.get_current_status_as_xml () in
71         (Xml.pp_to_string type_xml, Xml.pp_to_string body_xml)
72       in
73       let new_state =
74         (Misc.strip_xml_headings type_string,
75          Misc.strip_xml_headings body_string,
76          goal)
77       in
78       client#stateChange (Some new_state)
79     end
80   with NoProofInProgress -> ()
81
82 let clear () =
83  if !hbugs_enabled then
84   begin
85    let client = get_hbugs_client () in
86     client#stateChange None
87   end
88
89 let rec enable () =
90   (match !hbugs_client with
91   | None -> (* create an hbugs client and show its window *)
92       hbugs_client :=
93         (try
94           Some (new Hbugs_client.hbugsClient
95             ~use_hint_callback:!use_hint_callback
96             ~describe_hint_callback:!describe_hint_callback
97               ())
98         with e ->
99           prerr_endline (sprintf "Can't start HBugs client: %s"
100             (Printexc.to_string e));
101           None);
102       (match !hbugs_client with
103       |Some client ->
104           client#show ();
105           client#subscribeAll ()
106       | None -> ())
107   | Some c -> (* show hbugs client window *)
108       c#show ())
109
110 let toggle state =
111   if state <> !hbugs_enabled then begin (* status has been changed *)
112     if state then enable () else disable ();
113     clear ()
114   end;
115   hbugs_enabled := state
116
117 module type Unit = sig end
118
119 module Initialize (Tactics: InvokeTactics.Tactics) : Unit =
120   struct
121     let use_hint = function
122       | Use_ring -> Tactics.ring ()
123       | Use_fourier -> Tactics.fourier ()
124       | Use_reflexivity -> Tactics.reflexivity ()
125       | Use_symmetry -> Tactics.symmetry ()
126       | Use_assumption -> Tactics.assumption ()
127       | Use_contradiction -> Tactics.contradiction ()
128       | Use_exists -> Tactics.exists ()
129       | Use_split -> Tactics.split ()
130       | Use_left -> Tactics.left ()
131       | Use_right -> Tactics.right ()
132       | Use_apply term ->
133          (* we remove the "cic:" prefix *)
134          let term' = String.sub term 4 (String.length term - 4) in
135           Tactics.apply ~term:term' ()
136       | Hints _ -> assert false
137
138     let _ = use_hint_callback := use_hint
139   end
140
141 let start_web_services () = ignore (Unix.system "make -C ../hbugs/ start")
142 let stop_web_services () = ignore (Unix.system "make -C ../hbugs/ stop")
143