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