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