]> matita.cs.unibo.it Git - helm.git/blob - helm/gTopLevel/gTopLevel.ml
* Abst removed from the DTD
[helm.git] / helm / gTopLevel / gTopLevel.ml
1 (* Copyright (C) 2000, 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://cs.unibo.it/helm/.
24  *)
25
26 (******************************************************************************)
27 (*                                                                            *)
28 (*                               PROJECT HELM                                 *)
29 (*                                                                            *)
30 (*                Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>               *)
31 (*                                 06/01/2002                                 *)
32 (*                                                                            *)
33 (*                                                                            *)
34 (******************************************************************************)
35
36 (* GLOBAL CONSTANTS *)
37
38 let helmns = Gdome.domString "http://www.cs.unibo.it/helm";;
39
40 let htmlheader =
41  "<html>" ^
42  " <body bgColor=\"white\">"
43 ;;
44
45 let htmlfooter =
46  " </body>" ^
47  "</html>"
48 ;;
49
50 (* GLOBAL REFERENCES (USED BY CALLBACKS) *)
51
52 let htmlheader_and_content = ref htmlheader;;
53
54 let current_cic_infos = ref None;;
55 let current_goal_infos = ref None;;
56 let current_scratch_infos = ref None;;
57
58
59 (* MISC FUNCTIONS *)
60
61 let domImpl = Gdome.domImplementation ();;
62
63 let parseStyle name =
64  let style =
65   domImpl#createDocumentFromURI
66 (*
67    ~uri:("http://phd.cs.unibo.it:8081/getxslt?uri=" ^ name) ?mode:None
68 *)
69    ~uri:("styles/" ^ name) ()
70  in
71   Gdome_xslt.processStylesheet style
72 ;;
73
74 let d_c = parseStyle "drop_coercions.xsl";;
75 let tc1 = parseStyle "objtheorycontent.xsl";;
76 let hc2 = parseStyle "content_to_html.xsl";;
77 let l   = parseStyle "link.xsl";;
78
79 let c1 = parseStyle "rootcontent.xsl";;
80 let g  = parseStyle "genmmlid.xsl";;
81 let c2 = parseStyle "annotatedpres.xsl";;
82
83
84 let getterURL = Configuration.getter_url;;
85 let processorURL = Configuration.processor_url;;
86
87 let mml_styles = [d_c ; c1 ; g ; c2 ; l];;
88 let mml_args =
89  ["processorURL", "'" ^ processorURL ^ "'" ;
90   "getterURL", "'" ^ getterURL ^ "'" ;
91   "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
92   "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
93   "UNICODEvsSYMBOL", "'symbol'" ;
94   "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
95   "encoding", "'iso-8859-1'" ;
96   "media-type", "'text/html'" ;
97   "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
98   "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
99   "naturalLanguage", "'yes'" ;
100   "annotations", "'no'" ;
101   "explodeall", "'true()'" ;
102   "topurl", "'http://phd.cs.unibo.it/helm'" ;
103   "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
104 ;;
105
106 let sequent_styles = [d_c ; c1 ; g ; c2 ; l];;
107 let sequent_args =
108  ["processorURL", "'" ^ processorURL ^ "'" ;
109   "getterURL", "'" ^ getterURL ^ "'" ;
110   "draw_graphURL", "'http%3A//phd.cs.unibo.it%3A8083/'" ;
111   "uri_set_queueURL", "'http%3A//phd.cs.unibo.it%3A8084/'" ;
112   "UNICODEvsSYMBOL", "'symbol'" ;
113   "doctype-public", "'-//W3C//DTD%20XHTML%201.0%20Transitional//EN'" ;
114   "encoding", "'iso-8859-1'" ;
115   "media-type", "'text/html'" ;
116   "keys", "'d_c%2CC1%2CG%2CC2%2CL'" ;
117   "interfaceURL", "'http%3A//phd.cs.unibo.it/helm/html/cic/index.html'" ;
118   "naturalLanguage", "'no'" ;
119   "annotations", "'no'" ;
120   "explodeall", "'true()'" ;
121   "topurl", "'http://phd.cs.unibo.it/helm'" ;
122   "CICURI", "'cic:/Coq/Init/Datatypes/bool_ind.con'" ]
123 ;;
124
125 let parse_file filename =
126  let inch = open_in filename in
127   let rec read_lines () =
128    try
129     let line = input_line inch in
130      line ^ read_lines ()
131    with
132     End_of_file -> ""
133   in
134    read_lines ()
135 ;;
136
137 let applyStylesheets input styles args =
138  List.fold_left (fun i style -> Gdome_xslt.applyStylesheet i style args)
139   input styles
140 ;;
141
142 let mml_of_cic_object uri annobj ids_to_inner_sorts ids_to_inner_types =
143  let xml =
144   Cic2Xml.print_object uri ids_to_inner_sorts annobj 
145  in
146  let xmlinnertypes =
147   Cic2Xml.print_inner_types uri ids_to_inner_sorts
148    ids_to_inner_types
149  in
150   let input = Xml2Gdome.document_of_xml domImpl xml in
151 (*CSC: We save the innertypes to disk so that we can retrieve them in the  *)
152 (*CSC: stylesheet. This DOES NOT work when UWOBO and/or the getter are not *)
153 (*CSC: local.                                                              *)
154    Xml.pp xmlinnertypes (Some "/public/sacerdot/innertypes") ;
155    let output = applyStylesheets input mml_styles mml_args in
156     output
157 ;;
158
159
160 (* CALLBACKS *)
161
162 exception RefreshSequentException of exn;;
163 exception RefreshProofException of exn;;
164
165 let refresh_proof (output : GMathView.math_view) =
166  try
167   let uri,currentproof =
168    match !ProofEngine.proof with
169       None -> assert false
170     | Some (uri,metasenv,bo,ty) ->
171        uri,(Cic.CurrentProof (UriManager.name_of_uri uri, metasenv, bo, ty))
172   in
173    let
174     (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
175      ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
176    =
177     Cic2acic.acic_object_of_cic_object currentproof
178    in
179     let mml =
180      mml_of_cic_object uri acic ids_to_inner_sorts ids_to_inner_types
181     in
182      output#load_tree mml ;
183      current_cic_infos :=
184       Some (ids_to_terms,ids_to_father_ids,ids_to_conjectures,ids_to_hypotheses)
185  with
186   e ->
187  match !ProofEngine.proof with
188     None -> assert false
189   | Some (uri,metasenv,bo,ty) ->
190 prerr_endline ("Offending proof: " ^ CicPp.ppobj (Cic.CurrentProof ("questa",metasenv,bo,ty))) ; flush stderr ;
191    raise (RefreshProofException e)
192 ;;
193
194 let refresh_sequent (proofw : GMathView.math_view) =
195  try
196   match !ProofEngine.goal with
197      None -> proofw#unload
198    | Some metano ->
199       let metasenv =
200        match !ProofEngine.proof with
201           None -> assert false
202         | Some (_,metasenv,_,_) -> metasenv
203       in
204       let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
205        let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
206         SequentPp.XmlPp.print_sequent metasenv currentsequent
207        in
208         let sequent_doc =
209          Xml2Gdome.document_of_xml domImpl sequent_gdome
210         in
211          let sequent_mml =
212           applyStylesheets sequent_doc sequent_styles sequent_args
213          in
214           proofw#load_tree ~dom:sequent_mml ;
215           current_goal_infos :=
216            Some (ids_to_terms,ids_to_father_ids,ids_to_hypotheses)
217  with
218   e ->
219 let metano =
220   match !ProofEngine.goal with
221      None -> assert false
222    | Some m -> m
223 in
224 let metasenv =
225  match !ProofEngine.proof with
226     None -> assert false
227   | Some (_,metasenv,_,_) -> metasenv
228 in
229 let currentsequent = List.find (function (m,_,_) -> m=metano) metasenv in
230 prerr_endline ("Offending sequent: " ^ SequentPp.TextualPp.print_sequent currentsequent) ; flush stderr ;
231    raise (RefreshSequentException e)
232 ;;
233
234 (*
235 ignore(domImpl#saveDocumentToFile ~doc:sequent_doc
236  ~name:"/public/sacerdot/guruguru1" ~indent:true ()) ;
237 *)
238
239 let mml_of_cic_term metano term =
240  let metasenv =
241   match !ProofEngine.proof with
242      None -> []
243    | Some (_,metasenv,_,_) -> metasenv
244  in
245  let context =
246   match !ProofEngine.goal with
247      None -> []
248    | Some metano ->
249       let (_,canonical_context,_) =
250        List.find (function (m,_,_) -> m=metano) metasenv
251       in
252        canonical_context
253  in
254    let sequent_gdome,ids_to_terms,ids_to_father_ids,ids_to_hypotheses =
255     SequentPp.XmlPp.print_sequent metasenv (metano,context,term)
256    in
257     let sequent_doc =
258      Xml2Gdome.document_of_xml domImpl sequent_gdome
259     in
260      let res =
261       applyStylesheets sequent_doc sequent_styles sequent_args ;
262      in
263       current_scratch_infos :=
264        Some (term,ids_to_terms,ids_to_father_ids,ids_to_hypotheses) ;
265       res
266 ;;
267
268 let output_html outputhtml msg =
269  htmlheader_and_content := !htmlheader_and_content ^ msg ;
270  outputhtml#source (!htmlheader_and_content ^ htmlfooter) ;
271  outputhtml#set_topline (-1)
272 ;;
273
274 (***********************)
275 (*       TACTICS       *)
276 (***********************)
277
278 let call_tactic tactic rendering_window () =
279  let proofw = (rendering_window#proofw : GMathView.math_view) in
280  let output = (rendering_window#output : GMathView.math_view) in
281  let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
282  let savedproof = !ProofEngine.proof in
283  let savedgoal  = !ProofEngine.goal in
284   begin
285    try
286     tactic () ;
287     refresh_sequent proofw ;
288     refresh_proof output
289    with
290       RefreshSequentException e ->
291        output_html outputhtml
292         ("<h1 color=\"red\">Exception raised during the refresh of the " ^
293          "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
294        ProofEngine.proof := savedproof ;
295        ProofEngine.goal := savedgoal ;
296        refresh_sequent proofw
297     | RefreshProofException e ->
298        output_html outputhtml
299         ("<h1 color=\"red\">Exception raised during the refresh of the " ^
300          "proof: " ^ Printexc.to_string e ^ "</h1>") ;
301        ProofEngine.proof := savedproof ;
302        ProofEngine.goal := savedgoal ;
303        refresh_sequent proofw ;
304        refresh_proof output
305     | e ->
306        output_html outputhtml
307         ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
308        ProofEngine.proof := savedproof ;
309        ProofEngine.goal := savedgoal ;
310   end
311 ;;
312
313 let call_tactic_with_input tactic rendering_window () =
314  let proofw = (rendering_window#proofw : GMathView.math_view) in
315  let output = (rendering_window#output : GMathView.math_view) in
316  let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
317  let inputt = (rendering_window#inputt : GEdit.text) in
318  let savedproof = !ProofEngine.proof in
319  let savedgoal  = !ProofEngine.goal in
320 (*CSC: Gran cut&paste da sotto... *)
321   let inputlen = inputt#length in
322   let input = inputt#get_chars 0 inputlen ^ "\n" in
323    let lexbuf = Lexing.from_string input in
324    let curi =
325     match !ProofEngine.proof with
326        None -> assert false
327      | Some (curi,_,_,_) -> curi
328    in
329    let metasenv =
330     match !ProofEngine.proof with
331        None -> assert false
332      | Some (_,metasenv,_,_) -> metasenv
333    in
334    let context =
335     List.map
336      (function
337          Some (n,_) -> Some n
338        | None -> None)
339      (match !ProofEngine.goal with
340          None -> assert false
341        | Some metano ->
342           let (_,canonical_context,_) =
343            List.find (function (m,_,_) -> m=metano) metasenv
344           in
345            canonical_context
346      )
347    in
348     try
349      while true do
350       match
351        CicTextualParserContext.main curi context CicTextualLexer.token lexbuf
352       with
353          None -> ()
354        | Some expr ->
355           tactic expr ;
356           refresh_sequent proofw ;
357           refresh_proof output
358      done
359     with
360        CicTextualParser0.Eof ->
361         inputt#delete_text 0 inputlen
362      | RefreshSequentException e ->
363         output_html outputhtml
364          ("<h1 color=\"red\">Exception raised during the refresh of the " ^
365           "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
366         ProofEngine.proof := savedproof ;
367         ProofEngine.goal := savedgoal ;
368         refresh_sequent proofw
369      | RefreshProofException e ->
370         output_html outputhtml
371          ("<h1 color=\"red\">Exception raised during the refresh of the " ^
372           "proof: " ^ Printexc.to_string e ^ "</h1>") ;
373         ProofEngine.proof := savedproof ;
374         ProofEngine.goal := savedgoal ;
375         refresh_sequent proofw ;
376         refresh_proof output
377      | e ->
378         output_html outputhtml
379          ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
380         ProofEngine.proof := savedproof ;
381         ProofEngine.goal := savedgoal ;
382 ;;
383
384 let call_tactic_with_goal_input tactic rendering_window () =
385  let module L = LogicalOperations in
386  let module G = Gdome in
387   let proofw = (rendering_window#proofw : GMathView.math_view) in
388   let output = (rendering_window#output : GMathView.math_view) in
389   let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
390   let savedproof = !ProofEngine.proof in
391   let savedgoal  = !ProofEngine.goal in
392    match proofw#get_selection with
393      Some node ->
394       let xpath =
395        ((node : Gdome.element)#getAttributeNS
396          ~namespaceURI:helmns
397          ~localName:(G.domString "xref"))#to_string
398       in
399        if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
400        else
401         begin
402          try
403           match !current_goal_infos with
404              Some (ids_to_terms, ids_to_father_ids,_) ->
405               let id = xpath in
406                tactic (Hashtbl.find ids_to_terms id) ;
407                refresh_sequent rendering_window#proofw ;
408                refresh_proof rendering_window#output
409            | None -> assert false (* "ERROR: No current term!!!" *)
410          with
411             RefreshSequentException e ->
412              output_html outputhtml
413               ("<h1 color=\"red\">Exception raised during the refresh of the " ^
414                "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
415              ProofEngine.proof := savedproof ;
416              ProofEngine.goal := savedgoal ;
417              refresh_sequent proofw
418           | RefreshProofException e ->
419              output_html outputhtml
420               ("<h1 color=\"red\">Exception raised during the refresh of the " ^
421                "proof: " ^ Printexc.to_string e ^ "</h1>") ;
422              ProofEngine.proof := savedproof ;
423              ProofEngine.goal := savedgoal ;
424              refresh_sequent proofw ;
425              refresh_proof output
426           | e ->
427              output_html outputhtml
428               ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
429              ProofEngine.proof := savedproof ;
430              ProofEngine.goal := savedgoal ;
431         end
432    | None ->
433       output_html outputhtml
434        ("<h1 color=\"red\">No term selected</h1>")
435 ;;
436
437 let call_tactic_with_input_and_goal_input tactic rendering_window () =
438  let module L = LogicalOperations in
439  let module G = Gdome in
440   let proofw = (rendering_window#proofw : GMathView.math_view) in
441   let output = (rendering_window#output : GMathView.math_view) in
442   let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
443   let inputt = (rendering_window#inputt : GEdit.text) in
444   let savedproof = !ProofEngine.proof in
445   let savedgoal  = !ProofEngine.goal in
446    match proofw#get_selection with
447      Some node ->
448       let xpath =
449        ((node : Gdome.element)#getAttributeNS
450          ~namespaceURI:helmns
451          ~localName:(G.domString "xref"))#to_string
452       in
453        if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
454        else
455         begin
456          try
457           match !current_goal_infos with
458              Some (ids_to_terms, ids_to_father_ids,_) ->
459               let id = xpath in
460                (* Let's parse the input *)
461                let inputlen = inputt#length in
462                let input = inputt#get_chars 0 inputlen ^ "\n" in
463                 let lexbuf = Lexing.from_string input in
464                 let curi =
465                  match !ProofEngine.proof with
466                     None -> assert false
467                   | Some (curi,_,_,_) -> curi
468                 in
469                 let metasenv =
470                  match !ProofEngine.proof with
471                     None -> assert false
472                   | Some (_,metasenv,_,_) -> metasenv
473                 in
474                 let context =
475                  List.map
476                   (function
477                       Some (n,_) -> Some n
478                     | None -> None)
479                   (match !ProofEngine.goal with
480                       None -> assert false
481                     | Some metano ->
482                        let (_,canonical_context,_) =
483                         List.find (function (m,_,_) -> m=metano) metasenv
484                        in
485                         canonical_context
486                   )
487                 in
488                  begin
489                   try
490                    while true do
491                     match
492                      CicTextualParserContext.main curi context
493                       CicTextualLexer.token lexbuf
494                     with
495                        None -> ()
496                      | Some expr ->
497                         tactic ~goal_input:(Hashtbl.find ids_to_terms id)
498                          ~input:expr ;
499                         refresh_sequent proofw ;
500                         refresh_proof output
501                    done
502                   with
503                      CicTextualParser0.Eof ->
504                       inputt#delete_text 0 inputlen
505                  end
506            | None -> assert false (* "ERROR: No current term!!!" *)
507          with
508             RefreshSequentException e ->
509              output_html outputhtml
510               ("<h1 color=\"red\">Exception raised during the refresh of the " ^
511                "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
512              ProofEngine.proof := savedproof ;
513              ProofEngine.goal := savedgoal ;
514              refresh_sequent proofw
515           | RefreshProofException e ->
516              output_html outputhtml
517               ("<h1 color=\"red\">Exception raised during the refresh of the " ^
518                "proof: " ^ Printexc.to_string e ^ "</h1>") ;
519              ProofEngine.proof := savedproof ;
520              ProofEngine.goal := savedgoal ;
521              refresh_sequent proofw ;
522              refresh_proof output
523           | e ->
524              output_html outputhtml
525               ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
526              ProofEngine.proof := savedproof ;
527              ProofEngine.goal := savedgoal ;
528         end
529    | None ->
530       output_html outputhtml
531        ("<h1 color=\"red\">No term selected</h1>")
532 ;;
533
534 let call_tactic_with_goal_input_in_scratch tactic scratch_window () =
535  let module L = LogicalOperations in
536  let module G = Gdome in
537   let mmlwidget = (scratch_window#mmlwidget : GMathView.math_view) in
538   let outputhtml = (scratch_window#outputhtml : GHtml.xmhtml) in
539   let savedproof = !ProofEngine.proof in
540   let savedgoal  = !ProofEngine.goal in
541    match mmlwidget#get_selection with
542      Some node ->
543       let xpath =
544        ((node : Gdome.element)#getAttributeNS
545          ~namespaceURI:helmns
546          ~localName:(G.domString "xref"))#to_string
547       in
548        if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
549        else
550         begin
551          try
552           match !current_scratch_infos with
553              (* term is the whole goal in the scratch_area *)
554              Some (term,ids_to_terms, ids_to_father_ids,_) ->
555               let id = xpath in
556                let expr = tactic term (Hashtbl.find ids_to_terms id) in
557                 let mml = mml_of_cic_term 111 expr in
558                  scratch_window#show () ;
559                  scratch_window#mmlwidget#load_tree ~dom:mml
560            | None -> assert false (* "ERROR: No current term!!!" *)
561          with
562           e ->
563            output_html outputhtml
564             ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
565         end
566    | None ->
567       output_html outputhtml
568        ("<h1 color=\"red\">No term selected</h1>")
569 ;;
570
571 let call_tactic_with_hypothesis_input tactic rendering_window () =
572  let module L = LogicalOperations in
573  let module G = Gdome in
574   let proofw = (rendering_window#proofw : GMathView.math_view) in
575   let output = (rendering_window#output : GMathView.math_view) in
576   let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
577   let savedproof = !ProofEngine.proof in
578   let savedgoal  = !ProofEngine.goal in
579    match proofw#get_selection with
580      Some node ->
581       let xpath =
582        ((node : Gdome.element)#getAttributeNS
583          ~namespaceURI:helmns
584          ~localName:(G.domString "xref"))#to_string
585       in
586        if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
587        else
588         begin
589          try
590           match !current_goal_infos with
591              Some (_,_,ids_to_hypotheses) ->
592               let id = xpath in
593                tactic (Hashtbl.find ids_to_hypotheses id) ;
594                refresh_sequent rendering_window#proofw ;
595                refresh_proof rendering_window#output
596            | None -> assert false (* "ERROR: No current term!!!" *)
597          with
598             RefreshSequentException e ->
599              output_html outputhtml
600               ("<h1 color=\"red\">Exception raised during the refresh of the " ^
601                "sequent: " ^ Printexc.to_string e ^ "</h1>") ;
602              ProofEngine.proof := savedproof ;
603              ProofEngine.goal := savedgoal ;
604              refresh_sequent proofw
605           | RefreshProofException e ->
606              output_html outputhtml
607               ("<h1 color=\"red\">Exception raised during the refresh of the " ^
608                "proof: " ^ Printexc.to_string e ^ "</h1>") ;
609              ProofEngine.proof := savedproof ;
610              ProofEngine.goal := savedgoal ;
611              refresh_sequent proofw ;
612              refresh_proof output
613           | e ->
614              output_html outputhtml
615               ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
616              ProofEngine.proof := savedproof ;
617              ProofEngine.goal := savedgoal ;
618         end
619    | None ->
620       output_html outputhtml
621        ("<h1 color=\"red\">No term selected</h1>")
622 ;;
623
624
625 let intros rendering_window = call_tactic ProofEngine.intros rendering_window;;
626 let exact rendering_window =
627  call_tactic_with_input ProofEngine.exact rendering_window
628 ;;
629 let apply rendering_window =
630  call_tactic_with_input ProofEngine.apply rendering_window
631 ;;
632 let elimintrossimpl rendering_window =
633  call_tactic_with_input ProofEngine.elim_intros_simpl rendering_window
634 ;;
635 let whd rendering_window =
636  call_tactic_with_goal_input ProofEngine.whd rendering_window
637 ;;
638 let reduce rendering_window =
639  call_tactic_with_goal_input ProofEngine.reduce rendering_window
640 ;;
641 let simpl rendering_window =
642  call_tactic_with_goal_input ProofEngine.simpl rendering_window
643 ;;
644 let fold rendering_window =
645  call_tactic_with_input ProofEngine.fold rendering_window
646 ;;
647 let cut rendering_window =
648  call_tactic_with_input ProofEngine.cut rendering_window
649 ;;
650 let change rendering_window =
651  call_tactic_with_input_and_goal_input ProofEngine.change rendering_window
652 ;;
653 let letin rendering_window =
654  call_tactic_with_input ProofEngine.letin rendering_window
655 ;;
656 let clearbody rendering_window =
657  call_tactic_with_hypothesis_input ProofEngine.clearbody rendering_window
658 ;;
659 let clear rendering_window =
660  call_tactic_with_hypothesis_input ProofEngine.clear rendering_window
661 ;;
662
663
664 let whd_in_scratch scratch_window =
665  call_tactic_with_goal_input_in_scratch ProofEngine.whd_in_scratch
666   scratch_window
667 ;;
668 let reduce_in_scratch scratch_window =
669  call_tactic_with_goal_input_in_scratch ProofEngine.reduce_in_scratch
670   scratch_window
671 ;;
672 let simpl_in_scratch scratch_window =
673  call_tactic_with_goal_input_in_scratch ProofEngine.simpl_in_scratch
674   scratch_window
675 ;;
676
677
678
679 (**********************)
680 (*   END OF TACTICS   *)
681 (**********************)
682
683 exception OpenConjecturesStillThere;;
684 exception WrongProof;;
685
686 let qed rendering_window () =
687  match !ProofEngine.proof with
688     None -> assert false
689   | Some (uri,[],bo,ty) ->
690      if
691       CicReduction.are_convertible []
692        (CicTypeChecker.type_of_aux' [] [] bo) ty
693      then
694       begin
695        (*CSC: Wrong: [] is just plainly wrong *)
696        let proof = Cic.Definition (UriManager.name_of_uri uri,bo,ty,[]) in
697         let
698          (acic,ids_to_terms,ids_to_father_ids,ids_to_inner_sorts,
699           ids_to_inner_types,ids_to_conjectures,ids_to_hypotheses)
700         =
701          Cic2acic.acic_object_of_cic_object proof
702         in
703          let mml =
704           mml_of_cic_object uri acic ids_to_inner_sorts ids_to_inner_types
705          in
706           (rendering_window#output : GMathView.math_view)#load_tree mml ;
707           current_cic_infos :=
708            Some
709             (ids_to_terms,ids_to_father_ids,ids_to_conjectures,
710              ids_to_hypotheses)
711       end
712      else
713       raise WrongProof
714   | _ -> raise OpenConjecturesStillThere
715 ;;
716
717 (*????
718 let dtdname = "http://www.cs.unibo.it/helm/dtd/cic.dtd";;
719 *)
720 let dtdname = "/projects/helm/V7/dtd/cic.dtd";;
721
722 let save rendering_window () =
723  let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
724   match !ProofEngine.proof with
725      None -> assert false
726    | Some (uri, metasenv, bo, ty) ->
727       let currentproof =
728        Cic.CurrentProof (UriManager.name_of_uri uri,metasenv,bo,ty)
729       in
730        let (acurrentproof,_,_,ids_to_inner_sorts,_,_,_) =
731         Cic2acic.acic_object_of_cic_object currentproof
732        in
733         let xml = Cic2Xml.print_object uri ids_to_inner_sorts acurrentproof in
734          let xml' =
735           [< Xml.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
736              Xml.xml_cdata
737               ("<!DOCTYPE CurrentProof SYSTEM \"" ^ dtdname ^ "\">\n\n") ;
738              xml
739           >]
740          in
741           Xml.pp ~quiet:true xml' (Some "/public/sacerdot/currentproof") ;
742           output_html outputhtml
743            ("<h1 color=\"Green\">Current proof saved to " ^
744              "/public/sacerdot/currentproof</h1>")
745 ;;
746
747 (* Used to typecheck the loaded proofs *)
748 let typecheck_loaded_proof metasenv bo ty =
749  let module T = CicTypeChecker in
750   (*CSC: bisogna controllare anche il metasenv!!! *)
751   ignore (T.type_of_aux' metasenv [] ty) ;
752   ignore (T.type_of_aux' metasenv [] bo)
753 ;;
754
755 let load rendering_window () =
756  let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
757  let output = (rendering_window#output : GMathView.math_view) in
758  let proofw = (rendering_window#proofw : GMathView.math_view) in
759   try
760    let uri = UriManager.uri_of_string "cic:/dummy.con" in
761     match CicParser.obj_of_xml "/public/sacerdot/currentproof" uri with
762        Cic.CurrentProof (_,metasenv,bo,ty) ->
763         typecheck_loaded_proof metasenv bo ty ;
764         ProofEngine.proof :=
765          Some (uri, metasenv, bo, ty) ;
766         ProofEngine.goal :=
767          (match metasenv with
768              [] -> None
769            | (metano,_,_)::_ -> Some metano
770          ) ;
771         refresh_proof output ;
772         refresh_sequent proofw ;
773          output_html outputhtml
774           ("<h1 color=\"Green\">Current proof loaded from " ^
775             "/public/sacerdot/currentproof</h1>")
776      | _ -> assert false
777   with
778      RefreshSequentException e ->
779       output_html outputhtml
780        ("<h1 color=\"red\">Exception raised during the refresh of the " ^
781         "sequent: " ^ Printexc.to_string e ^ "</h1>")
782    | RefreshProofException e ->
783       output_html outputhtml
784        ("<h1 color=\"red\">Exception raised during the refresh of the " ^
785         "proof: " ^ Printexc.to_string e ^ "</h1>")
786    | e ->
787       output_html outputhtml
788        ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
789 ;;
790
791 let proveit rendering_window () =
792  let module L = LogicalOperations in
793  let module G = Gdome in
794  let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
795   match rendering_window#output#get_selection with
796     Some node ->
797      let xpath =
798       ((node : Gdome.element)#getAttributeNS
799       (*CSC: OCAML DIVERGE
800       ((element : G.element)#getAttributeNS
801       *)
802         ~namespaceURI:helmns
803         ~localName:(G.domString "xref"))#to_string
804      in
805       if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
806       else
807        begin
808         try
809          match !current_cic_infos with
810             Some (ids_to_terms, ids_to_father_ids, _, _) ->
811              let id = xpath in
812               L.to_sequent id ids_to_terms ids_to_father_ids ;
813               refresh_proof rendering_window#output ;
814               refresh_sequent rendering_window#proofw
815           | None -> assert false (* "ERROR: No current term!!!" *)
816         with
817            RefreshSequentException e ->
818             output_html outputhtml
819              ("<h1 color=\"red\">Exception raised during the refresh of the " ^
820               "sequent: " ^ Printexc.to_string e ^ "</h1>")
821          | RefreshProofException e ->
822             output_html outputhtml
823              ("<h1 color=\"red\">Exception raised during the refresh of the " ^
824               "proof: " ^ Printexc.to_string e ^ "</h1>")
825          | e ->
826             output_html outputhtml
827              ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
828        end
829   | None -> assert false (* "ERROR: No selection!!!" *)
830 ;;
831
832 let focus rendering_window () =
833  let module L = LogicalOperations in
834  let module G = Gdome in
835  let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
836   match rendering_window#output#get_selection with
837     Some node ->
838      let xpath =
839       ((node : Gdome.element)#getAttributeNS
840       (*CSC: OCAML DIVERGE
841       ((element : G.element)#getAttributeNS
842       *)
843         ~namespaceURI:helmns
844         ~localName:(G.domString "xref"))#to_string
845      in
846       if xpath = "" then assert false (* "ERROR: No xref found!!!" *)
847       else
848        begin
849         try
850          match !current_cic_infos with
851             Some (ids_to_terms, ids_to_father_ids, _, _) ->
852              let id = xpath in
853               L.focus id ids_to_terms ids_to_father_ids ;
854               refresh_sequent rendering_window#proofw
855           | None -> assert false (* "ERROR: No current term!!!" *)
856         with
857            RefreshSequentException e ->
858             output_html outputhtml
859              ("<h1 color=\"red\">Exception raised during the refresh of the " ^
860               "sequent: " ^ Printexc.to_string e ^ "</h1>")
861          | RefreshProofException e ->
862             output_html outputhtml
863              ("<h1 color=\"red\">Exception raised during the refresh of the " ^
864               "proof: " ^ Printexc.to_string e ^ "</h1>")
865          | e ->
866             output_html outputhtml
867              ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
868        end
869   | None -> assert false (* "ERROR: No selection!!!" *)
870 ;;
871
872 exception NoPrevGoal;;
873 exception NoNextGoal;;
874
875 let prevgoal metasenv metano =
876  let rec aux =
877   function
878      [] -> assert false
879    | [(m,_,_)] -> raise NoPrevGoal
880    | (n,_,_)::(m,_,_)::_ when m=metano -> n
881    | _::tl -> aux tl
882  in
883   aux metasenv
884 ;;
885
886 let nextgoal metasenv metano =
887  let rec aux =
888   function
889      [] -> assert false
890    | [(m,_,_)] when m = metano -> raise NoNextGoal
891    | (m,_,_)::(n,_,_)::_ when m=metano -> n
892    | _::tl -> aux tl
893  in
894   aux metasenv
895 ;;
896
897 let prev_or_next_goal select_goal rendering_window () =
898  let module L = LogicalOperations in
899  let module G = Gdome in
900  let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
901   let metasenv =
902    match !ProofEngine.proof with
903       None -> assert false
904     | Some (_,metasenv,_,_) -> metasenv
905   in
906   let metano =
907    match !ProofEngine.goal with
908       None -> assert false
909     | Some m -> m
910   in
911    try
912     ProofEngine.goal := Some (select_goal metasenv metano) ;
913     refresh_sequent rendering_window#proofw
914    with
915       RefreshSequentException e ->
916        output_html outputhtml
917         ("<h1 color=\"red\">Exception raised during the refresh of the " ^
918          "sequent: " ^ Printexc.to_string e ^ "</h1>")
919     | e ->
920        output_html outputhtml
921         ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>")
922 ;;
923
924 exception NotADefinition;;
925
926 let open_ rendering_window () =
927  let inputt = (rendering_window#inputt : GEdit.text) in
928  let oldinputt = (rendering_window#oldinputt : GEdit.text) in
929  let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
930  let output = (rendering_window#output : GMathView.math_view) in
931  let proofw = (rendering_window#proofw : GMathView.math_view) in
932   let inputlen = inputt#length in
933   let input = inputt#get_chars 0 inputlen ^ "\n" in
934    try
935     let uri = UriManager.uri_of_string ("cic:" ^ input) in
936      CicTypeChecker.typecheck uri ;
937      let metasenv,bo,ty =
938       match CicEnvironment.get_cooked_obj uri 0 with
939          Cic.Definition (_,bo,ty,_) -> [],bo,ty
940        | Cic.CurrentProof (_,metasenv,bo,ty) -> metasenv,bo,ty
941        | Cic.Axiom _
942        | Cic.Variable _
943        | Cic.InductiveDefinition _ -> raise NotADefinition
944      in
945       ProofEngine.proof :=
946        Some (uri, metasenv, bo, ty) ;
947       ProofEngine.goal := None ;
948       refresh_sequent proofw ;
949       refresh_proof output ;
950       inputt#delete_text 0 inputlen ;
951       ignore(oldinputt#insert_text input oldinputt#length)
952    with
953       RefreshSequentException e ->
954        output_html outputhtml
955         ("<h1 color=\"red\">Exception raised during the refresh of the " ^
956          "sequent: " ^ Printexc.to_string e ^ "</h1>")
957     | RefreshProofException e ->
958        output_html outputhtml
959         ("<h1 color=\"red\">Exception raised during the refresh of the " ^
960          "proof: " ^ Printexc.to_string e ^ "</h1>")
961     | e ->
962        output_html outputhtml
963         ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
964 ;;
965
966 let state rendering_window () =
967  let inputt = (rendering_window#inputt : GEdit.text) in
968  let oldinputt = (rendering_window#oldinputt : GEdit.text) in
969  let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
970  let output = (rendering_window#output : GMathView.math_view) in
971  let proofw = (rendering_window#proofw : GMathView.math_view) in
972   let inputlen = inputt#length in
973   let input = inputt#get_chars 0 inputlen ^ "\n" in
974    (* Do something interesting *)
975    let lexbuf = Lexing.from_string input in
976     try
977      while true do
978       (* Execute the actions *)
979       match CicTextualParser.main CicTextualLexer.token lexbuf with
980          None -> ()
981        | Some expr ->
982           let _  = CicTypeChecker.type_of_aux' [] [] expr in
983            ProofEngine.proof :=
984             Some (UriManager.uri_of_string "cic:/dummy.con",
985                    [1,[],expr], Cic.Meta (1,[]), expr) ;
986            ProofEngine.goal := Some 1 ;
987            refresh_sequent proofw ;
988            refresh_proof output ;
989      done
990     with
991        CicTextualParser0.Eof ->
992         inputt#delete_text 0 inputlen ;
993         ignore(oldinputt#insert_text input oldinputt#length)
994      | RefreshSequentException e ->
995         output_html outputhtml
996          ("<h1 color=\"red\">Exception raised during the refresh of the " ^
997           "sequent: " ^ Printexc.to_string e ^ "</h1>")
998      | RefreshProofException e ->
999         output_html outputhtml
1000          ("<h1 color=\"red\">Exception raised during the refresh of the " ^
1001           "proof: " ^ Printexc.to_string e ^ "</h1>")
1002      | e ->
1003         output_html outputhtml
1004          ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1005 ;;
1006
1007 let check rendering_window scratch_window () =
1008  let inputt = (rendering_window#inputt : GEdit.text) in
1009  let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
1010  let output = (rendering_window#output : GMathView.math_view) in
1011  let proofw = (rendering_window#proofw : GMathView.math_view) in
1012   let inputlen = inputt#length in
1013   let input = inputt#get_chars 0 inputlen ^ "\n" in
1014   let curi,metasenv =
1015    match !ProofEngine.proof with
1016       None -> UriManager.uri_of_string "cic:/dummy.con", []
1017     | Some (curi,metasenv,_,_) -> curi,metasenv
1018   in
1019   let context,names_context =
1020    let context =
1021     match !ProofEngine.goal with
1022        None -> []
1023      | Some metano ->
1024         let (_,canonical_context,_) =
1025          List.find (function (m,_,_) -> m=metano) metasenv
1026         in
1027          canonical_context
1028    in
1029     context,
1030     List.map
1031      (function
1032          Some (n,_) -> Some n
1033        | None -> None
1034      ) context
1035   in
1036    (* Do something interesting *)
1037    let lexbuf = Lexing.from_string input in
1038     try
1039      while true do
1040       (* Execute the actions *)
1041       match
1042        CicTextualParserContext.main curi names_context CicTextualLexer.token
1043         lexbuf
1044       with
1045          None -> ()
1046        | Some expr ->
1047           try
1048            let ty  = CicTypeChecker.type_of_aux' metasenv context expr in
1049             let mml = mml_of_cic_term 111 (Cic.Cast (expr,ty)) in
1050              scratch_window#show () ;
1051              scratch_window#mmlwidget#load_tree ~dom:mml
1052           with
1053            e ->
1054             print_endline ("? " ^ CicPp.ppterm expr) ;
1055             raise e
1056      done
1057     with
1058        CicTextualParser0.Eof -> ()
1059      | e ->
1060        output_html outputhtml
1061         ("<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>") ;
1062 ;;
1063
1064 let locate rendering_window () =
1065  let inputt = (rendering_window#inputt : GEdit.text) in
1066  let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
1067   let inputlen = inputt#length in
1068   let input = inputt#get_chars 0 inputlen in
1069   output_html outputhtml (
1070      try
1071         match Str.split (Str.regexp "[ \t]+") input with
1072            | [] -> ""
1073            | head :: tail ->
1074                inputt#delete_text 0 inputlen;
1075                Mquery.locate head 
1076      with
1077         e -> "<h1 color=\"red\">" ^ Printexc.to_string e ^ "</h1>"
1078   )
1079 ;;
1080
1081 let backward rendering_window () =
1082    let outputhtml = (rendering_window#outputhtml : GHtml.xmhtml) in
1083    let inputt = (rendering_window#inputt : GEdit.text) in
1084     let inputlen = inputt#length in
1085     let input = inputt#get_chars 0 inputlen in
1086     let level = int_of_string input in
1087     let metasenv =
1088      match !ProofEngine.proof with
1089         None -> assert false
1090       | Some (_,metasenv,_,_) -> metasenv
1091     in
1092     let result =
1093        match !ProofEngine.goal with
1094           | None -> ""
1095           | Some metano ->
1096              let (_,_,ty) =
1097               List.find (function (m,_,_) -> m=metano) metasenv
1098              in
1099               Mquery.backward ty level
1100        in 
1101    output_html outputhtml result
1102       
1103 let choose_selection
1104      (mmlwidget : GMathView.math_view) (element : Gdome.element option)
1105 =
1106  let module G = Gdome in
1107   let rec aux element =
1108    if element#hasAttributeNS
1109        ~namespaceURI:helmns
1110        ~localName:(G.domString "xref")
1111    then
1112      mmlwidget#set_selection (Some element)
1113    else
1114       match element#get_parentNode with
1115          None -> assert false
1116        (*CSC: OCAML DIVERGES!
1117        | Some p -> aux (new G.element_of_node p)
1118        *)
1119        | Some p -> aux (new Gdome.element_of_node p)
1120   in
1121    match element with
1122      Some x -> aux x
1123    | None   -> mmlwidget#set_selection None
1124 ;;
1125
1126 (* STUFF TO BUILD THE GTK INTERFACE *)
1127
1128 (* Stuff for the widget settings *)
1129
1130 let export_to_postscript (output : GMathView.math_view) () =
1131  output#export_to_postscript ~filename:"output.ps" ();
1132 ;;
1133
1134 let activate_t1 (output : GMathView.math_view) button_set_anti_aliasing
1135  button_set_kerning button_set_transparency button_export_to_postscript
1136  button_t1 ()
1137 =
1138  let is_set = button_t1#active in
1139   output#set_font_manager_type
1140    (if is_set then `font_manager_t1 else `font_manager_gtk) ;
1141   if is_set then
1142    begin
1143     button_set_anti_aliasing#misc#set_sensitive true ;
1144     button_set_kerning#misc#set_sensitive true ;
1145     button_set_transparency#misc#set_sensitive true ;
1146     button_export_to_postscript#misc#set_sensitive true ;
1147    end
1148   else
1149    begin
1150     button_set_anti_aliasing#misc#set_sensitive false ;
1151     button_set_kerning#misc#set_sensitive false ;
1152     button_set_transparency#misc#set_sensitive false ;
1153     button_export_to_postscript#misc#set_sensitive false ;
1154    end
1155 ;;
1156
1157 let set_anti_aliasing output button_set_anti_aliasing () =
1158  output#set_anti_aliasing button_set_anti_aliasing#active
1159 ;;
1160
1161 let set_kerning output button_set_kerning () =
1162  output#set_kerning button_set_kerning#active
1163 ;;
1164
1165 let set_transparency output button_set_transparency () =
1166  output#set_transparency button_set_transparency#active
1167 ;;
1168
1169 let changefont output font_size_spinb () =
1170  output#set_font_size font_size_spinb#value_as_int
1171 ;;
1172
1173 let set_log_verbosity output log_verbosity_spinb () =
1174  output#set_log_verbosity log_verbosity_spinb#value_as_int
1175 ;;
1176
1177 class settings_window (output : GMathView.math_view) sw
1178  button_export_to_postscript selection_changed_callback
1179 =
1180  let settings_window = GWindow.window ~title:"GtkMathView settings" () in
1181  let vbox =
1182   GPack.vbox ~packing:settings_window#add () in
1183  let table =
1184   GPack.table
1185    ~rows:1 ~columns:3 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
1186    ~border_width:5 ~packing:vbox#add () in
1187  let button_t1 =
1188   GButton.toggle_button ~label:"activate t1 fonts"
1189    ~packing:(table#attach ~left:0 ~top:0) () in
1190  let button_set_anti_aliasing =
1191   GButton.toggle_button ~label:"set_anti_aliasing"
1192    ~packing:(table#attach ~left:0 ~top:1) () in
1193  let button_set_kerning =
1194   GButton.toggle_button ~label:"set_kerning"
1195    ~packing:(table#attach ~left:1 ~top:1) () in
1196  let button_set_transparency =
1197   GButton.toggle_button ~label:"set_transparency"
1198    ~packing:(table#attach ~left:2 ~top:1) () in
1199  let table =
1200   GPack.table
1201    ~rows:2 ~columns:2 ~homogeneous:false ~row_spacings:5 ~col_spacings:5
1202    ~border_width:5 ~packing:vbox#add () in
1203  let font_size_label =
1204   GMisc.label ~text:"font size:"
1205    ~packing:(table#attach ~left:0 ~top:0 ~expand:`NONE) () in
1206  let font_size_spinb =
1207   let sadj =
1208    GData.adjustment ~value:14.0 ~lower:5.0 ~upper:50.0 ~step_incr:1.0 ()
1209   in
1210    GEdit.spin_button 
1211     ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:0 ~fill:`NONE) () in
1212  let log_verbosity_label =
1213   GMisc.label ~text:"log verbosity:"
1214    ~packing:(table#attach ~left:0 ~top:1) () in
1215  let log_verbosity_spinb =
1216   let sadj =
1217    GData.adjustment ~value:0.0 ~lower:0.0 ~upper:3.0 ~step_incr:1.0 ()
1218   in
1219    GEdit.spin_button 
1220     ~adjustment:sadj ~packing:(table#attach ~left:1 ~top:1) () in
1221  let hbox =
1222   GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1223  let closeb =
1224   GButton.button ~label:"Close"
1225    ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1226 object(self)
1227  method show = settings_window#show
1228  initializer
1229   button_set_anti_aliasing#misc#set_sensitive false ;
1230   button_set_kerning#misc#set_sensitive false ;
1231   button_set_transparency#misc#set_sensitive false ;
1232   (* Signals connection *)
1233   ignore(button_t1#connect#clicked
1234    (activate_t1 output button_set_anti_aliasing button_set_kerning
1235     button_set_transparency button_export_to_postscript button_t1)) ;
1236   ignore(font_size_spinb#connect#changed (changefont output font_size_spinb)) ;
1237   ignore(button_set_anti_aliasing#connect#toggled
1238    (set_anti_aliasing output button_set_anti_aliasing));
1239   ignore(button_set_kerning#connect#toggled
1240    (set_kerning output button_set_kerning)) ;
1241   ignore(button_set_transparency#connect#toggled
1242    (set_transparency output button_set_transparency)) ;
1243   ignore(log_verbosity_spinb#connect#changed
1244    (set_log_verbosity output log_verbosity_spinb)) ;
1245   ignore(closeb#connect#clicked settings_window#misc#hide)
1246 end;;
1247
1248 (* Scratch window *)
1249
1250 class scratch_window outputhtml =
1251  let window =
1252   GWindow.window ~title:"MathML viewer" ~border_width:2 () in
1253  let vbox =
1254   GPack.vbox ~packing:window#add () in
1255  let hbox =
1256   GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1257  let whdb =
1258   GButton.button ~label:"Whd"
1259    ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1260  let reduceb =
1261   GButton.button ~label:"Reduce"
1262    ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1263  let simplb =
1264   GButton.button ~label:"Simpl"
1265    ~packing:(hbox#pack ~expand:false ~fill:false ~padding:5) () in
1266  let scrolled_window =
1267   GBin.scrolled_window ~border_width:10
1268    ~packing:(vbox#pack ~expand:true ~padding:5) () in
1269  let mmlwidget =
1270   GMathView.math_view
1271    ~packing:(scrolled_window#add) ~width:400 ~height:280 () in
1272 object(self)
1273  method outputhtml = outputhtml
1274  method mmlwidget = mmlwidget
1275  method show () = window#misc#hide () ; window#show ()
1276  initializer
1277   ignore(mmlwidget#connect#selection_changed (choose_selection mmlwidget)) ;
1278   ignore(window#event#connect#delete (fun _ -> window#misc#hide () ; true )) ;
1279   ignore(whdb#connect#clicked (whd_in_scratch self)) ;
1280   ignore(reduceb#connect#clicked (reduce_in_scratch self)) ;
1281   ignore(simplb#connect#clicked (simpl_in_scratch self))
1282 end;;
1283
1284 (* Main window *)
1285
1286 class rendering_window output proofw (label : GMisc.label) =
1287  let window =
1288   GWindow.window ~title:"MathML viewer" ~border_width:2 () in
1289  let hbox0 =
1290   GPack.hbox ~packing:window#add () in
1291  let vbox =
1292   GPack.vbox ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1293  let _ = vbox#pack ~expand:false ~fill:false ~padding:5 label#coerce in
1294  let scrolled_window0 =
1295   GBin.scrolled_window ~border_width:10
1296    ~packing:(vbox#pack ~expand:true ~padding:5) () in
1297  let _ = scrolled_window0#add output#coerce in
1298  let hbox1 =
1299   GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1300  let settingsb =
1301   GButton.button ~label:"Settings"
1302    ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1303  let button_export_to_postscript =
1304   GButton.button ~label:"export_to_postscript"
1305   ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1306  let qedb =
1307   GButton.button ~label:"Qed"
1308    ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1309  let saveb =
1310   GButton.button ~label:"Save"
1311    ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1312  let loadb =
1313   GButton.button ~label:"Load"
1314    ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1315  let closeb =
1316   GButton.button ~label:"Close"
1317    ~packing:(hbox1#pack ~expand:false ~fill:false ~padding:5) () in
1318  let hbox2 =
1319   GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1320  let proveitb =
1321   GButton.button ~label:"Prove It"
1322    ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1323  let focusb =
1324   GButton.button ~label:"Focus"
1325    ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1326  let prevgoalb =
1327   GButton.button ~label:"<"
1328    ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1329  let nextgoalb =
1330   GButton.button ~label:">"
1331    ~packing:(hbox2#pack ~expand:false ~fill:false ~padding:5) () in
1332  let oldinputt = GEdit.text ~editable:false ~width:400 ~height:180
1333    ~packing:(vbox#pack ~padding:5) () in
1334  let hbox4 =
1335   GPack.hbox ~packing:(vbox#pack ~expand:false ~fill:false ~padding:5) () in
1336  let stateb =
1337   GButton.button ~label:"State"
1338    ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1339  let openb =
1340   GButton.button ~label:"Open"
1341    ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1342  let checkb =
1343   GButton.button ~label:"Check"
1344    ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1345  let locateb =
1346   GButton.button ~label:"Locate"
1347    ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1348  let backwardb =
1349   GButton.button ~label:"Backward"
1350    ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1351  let inputt = GEdit.text ~editable:true ~width:400 ~height: 100
1352    ~packing:(vbox#pack ~padding:5) () in
1353  let vbox1 =
1354   GPack.vbox ~packing:(hbox0#pack ~expand:false ~fill:false ~padding:5) () in
1355  let scrolled_window1 =
1356   GBin.scrolled_window ~border_width:10
1357    ~packing:(vbox1#pack ~expand:true ~padding:5) () in
1358  let _ = scrolled_window1#add proofw#coerce in
1359  let hbox3 =
1360   GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
1361  let exactb =
1362   GButton.button ~label:"Exact"
1363    ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1364  let introsb =
1365   GButton.button ~label:"Intros"
1366    ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1367  let applyb =
1368   GButton.button ~label:"Apply"
1369    ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1370  let elimintrossimplb =
1371   GButton.button ~label:"ElimIntrosSimpl"
1372    ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1373  let whdb =
1374   GButton.button ~label:"Whd"
1375    ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1376  let reduceb =
1377   GButton.button ~label:"Reduce"
1378    ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1379  let simplb =
1380   GButton.button ~label:"Simpl"
1381    ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1382  let foldb =
1383   GButton.button ~label:"Fold"
1384    ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1385  let cutb =
1386   GButton.button ~label:"Cut"
1387    ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1388  let changeb =
1389   GButton.button ~label:"Change"
1390    ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1391  let letinb =
1392   GButton.button ~label:"Let ... In"
1393    ~packing:(hbox3#pack ~expand:false ~fill:false ~padding:5) () in
1394  let hbox4 =
1395   GPack.hbox ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5) () in
1396  let clearbodyb =
1397   GButton.button ~label:"ClearBody"
1398    ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1399  let clearb =
1400   GButton.button ~label:"Clear"
1401    ~packing:(hbox4#pack ~expand:false ~fill:false ~padding:5) () in
1402  let outputhtml =
1403   GHtml.xmhtml
1404    ~source:"<html><body bgColor=\"white\"></body></html>"
1405    ~width:400 ~height: 200
1406    ~packing:(vbox1#pack ~expand:false ~fill:false ~padding:5)
1407    ~show:true () in
1408  let scratch_window = new scratch_window outputhtml in
1409 object(self)
1410  method outputhtml = outputhtml
1411  method oldinputt = oldinputt
1412  method inputt = inputt
1413  method output = (output : GMathView.math_view)
1414  method proofw = (proofw : GMathView.math_view)
1415  method show = window#show
1416  initializer
1417   button_export_to_postscript#misc#set_sensitive false ;
1418
1419   (* signal handlers here *)
1420   ignore(output#connect#selection_changed
1421    (function elem -> proofw#unload ; choose_selection output elem)) ;
1422   ignore(proofw#connect#selection_changed (choose_selection proofw)) ;
1423   ignore(closeb#connect#clicked (fun _ -> GMain.Main.quit ())) ;
1424   let settings_window = new settings_window output scrolled_window0
1425    button_export_to_postscript (choose_selection output) in
1426   ignore(settingsb#connect#clicked settings_window#show) ;
1427   ignore(button_export_to_postscript#connect#clicked (export_to_postscript output)) ;
1428   ignore(qedb#connect#clicked (qed self)) ;
1429   ignore(saveb#connect#clicked (save self)) ;
1430   ignore(loadb#connect#clicked (load self)) ;
1431   ignore(proveitb#connect#clicked (proveit self)) ;
1432   ignore(focusb#connect#clicked (focus self)) ;
1433   ignore(prevgoalb#connect#clicked (prev_or_next_goal prevgoal self)) ;
1434   ignore(nextgoalb#connect#clicked (prev_or_next_goal nextgoal self)) ;
1435   ignore(window#event#connect#delete (fun _ -> GMain.Main.quit () ; true )) ;
1436   ignore(stateb#connect#clicked (state self)) ;
1437   ignore(openb#connect#clicked (open_ self)) ;
1438   ignore(checkb#connect#clicked (check self scratch_window)) ;
1439   ignore(locateb#connect#clicked (locate self)) ;
1440   ignore(backwardb#connect#clicked (backward self)) ;
1441   ignore(exactb#connect#clicked (exact self)) ;
1442   ignore(applyb#connect#clicked (apply self)) ;
1443   ignore(elimintrossimplb#connect#clicked (elimintrossimpl self)) ;
1444   ignore(whdb#connect#clicked (whd self)) ;
1445   ignore(reduceb#connect#clicked (reduce self)) ;
1446   ignore(simplb#connect#clicked (simpl self)) ;
1447   ignore(foldb#connect#clicked (fold self)) ;
1448   ignore(cutb#connect#clicked (cut self)) ;
1449   ignore(changeb#connect#clicked (change self)) ;
1450   ignore(letinb#connect#clicked (letin self)) ;
1451   ignore(clearbodyb#connect#clicked (clearbody self)) ;
1452   ignore(clearb#connect#clicked (clear self)) ;
1453   ignore(introsb#connect#clicked (intros self)) ;
1454   Logger.log_callback :=
1455    (Logger.log_to_html ~print_and_flush:(output_html outputhtml))
1456 end;;
1457
1458 (* MAIN *)
1459
1460 let initialize_everything () =
1461  let module U = Unix in
1462   let output = GMathView.math_view ~width:400 ~height:280 ()
1463   and proofw = GMathView.math_view ~width:400 ~height:275 ()
1464   and label = GMisc.label ~text:"gTopLevel" () in
1465     let rendering_window =
1466      new rendering_window output proofw label
1467     in
1468      rendering_window#show () ;
1469      GMain.Main.main ()
1470 ;;
1471
1472 let _ =
1473  CicCooking.init () ;
1474  Mquery.init () ;
1475  ignore (GtkMain.Main.init ()) ;
1476  initialize_everything () ;
1477  Mquery.close ()
1478 ;;