]> matita.cs.unibo.it Git - helm.git/blob - helm/gTopLevel/hbugs.ml
added methods to start/stop web services
[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 "DEBUG: %s" s)
35 ;;
36
37 exception NoProofInProgress;;
38
39 let hbugs_client = ref None
40 let use_hint_callback = ref ignore
41
42 let quit () =
43         match !hbugs_client with
44         | Some c -> c#unregisterFromBroker ()
45         | None -> ()
46
47 let hbugs_enabled = ref false
48
49 let get_hbugs_client () =
50         match !hbugs_client with
51         | Some c -> c
52         | None -> assert false
53
54 let disable () =
55         match !hbugs_client with None -> () | Some c -> c#hide ()
56
57 let notify () =
58         try
59                 if !hbugs_enabled then begin
60                         let client = get_hbugs_client () in
61                         let goal =
62                                 match !ProofEngine.goal with
63                                 | Some g -> g
64                                 | None -> raise NoProofInProgress
65                         in
66                         let (type_string, body_string) =
67                                 let (type_xml, body_xml) = ProofEngine.get_current_status_as_xml () in
68                                 (Xml.pp_to_string type_xml, Xml.pp_to_string body_xml)
69                         in
70                         let new_state =
71                                 (Misc.strip_xml_headings type_string,
72                                  Misc.strip_xml_headings body_string,
73                                  goal)
74                         in
75                         client#stateChange (Some new_state)
76                 end
77         with NoProofInProgress -> ()
78
79 let clear () =
80  if !hbugs_enabled then
81   begin
82          let client = get_hbugs_client () in
83           client#stateChange None
84   end
85
86 let rec enable () =
87         (match !hbugs_client with
88         | None -> (* create an hbugs client and show its window *)
89                         hbugs_client :=
90                                 (try
91                                         Some (new Hbugs_client.hbugsClient
92             ~use_hint_callback:!use_hint_callback ())
93                                 with e ->
94                                         prerr_endline (sprintf "Can't start HBugs client: %s"
95                                                 (Printexc.to_string e));
96                                         None);
97                         (match !hbugs_client with
98                         |Some client ->
99                                         client#show ();
100                                         client#subscribeAll ()
101                         | None -> ())
102         | Some c -> (* show hbugs client window *)
103                         c#show ())
104
105 let toggle state =
106         if state <> !hbugs_enabled then (* status has been changed *)
107                 (if state then enable () else disable ());
108         hbugs_enabled := state
109
110 module type Unit = sig end
111
112 module Initialize (Tactics: InvokeTactics.Tactics) : Unit =
113   struct
114     let use_hint = function
115       | Use_ring_Luke -> Tactics.ring ()
116       | Use_fourier_Luke -> Tactics.fourier ()
117       | Use_reflexivity_Luke -> Tactics.reflexivity ()
118       | Use_symmetry_Luke -> Tactics.symmetry ()
119       | Use_assumption_Luke -> Tactics.assumption ()
120       | Use_contradiction_Luke -> Tactics.contradiction ()
121       | Use_exists_Luke -> Tactics.exists ()
122       | Use_split_Luke -> Tactics.split ()
123       | Use_left_Luke -> Tactics.left ()
124       | Use_right_Luke -> Tactics.right ()
125       | Use_apply_Luke term ->
126          (* we remove the "cic:" prefix *)
127          let term' = String.sub term 4 (String.length term - 4) in
128           Tactics.apply ~term:term' ()
129       | Hints _ -> assert false
130
131     let _ = use_hint_callback := use_hint
132   end
133
134 let start_web_services () = ignore (Unix.system "make -C ../hbugs/ start")
135 let stop_web_services () = ignore (Unix.system "make -C ../hbugs/ stop")
136