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