matitacleanLib.cmo \
matitaDisambiguator.cmo \
matitaEngine.cmo \
+ matitacLib.cmo \
matitaScript.cmo \
matitaGeneratedGui.cmo \
matitaGtkMisc.cmo \
| `Message -> self#message (s ^ "\n")
| `Warning -> self#warning (s ^ "\n")
end
+
+let clean_current_baseuri status =
+ try
+ let baseuri = MatitaTypes.get_string_option status "baseuri" in
+ MatitacleanLib.clean_baseuris [baseuri]
+ with MatitaTypes.Option_error _ -> ()
+
+let ask_and_save_moo_if_needed parent fname status =
+ let save () =
+ MatitacLib.dump_moo_to_file fname status.MatitaTypes.moo_content_rev
+ in
+ if (MatitaScript.instance ())#eos then
+ begin
+ let mooname =
+ MatitaMisc.obj_file_of_script fname
+ in
+ let rc =
+ MatitaGtkMisc.ask_confirmation
+ ~title:"A .moo can be generated"
+ ~message:(Printf.sprintf
+ "%s can be generated for %s.\n<i>Should I generate it?</i>"
+ mooname fname)
+ ~parent ()
+ in
+ let b =
+ match rc with
+ | `YES -> true
+ | `NO -> false
+ | `CANCEL -> raise MatitaTypes.Cancel
+ in
+ if b then
+ save ()
+ else
+ clean_current_baseuri status
+ end
+ else
+ clean_current_baseuri status
+
+let ask_unsaved parent =
+ MatitaGtkMisc.ask_confirmation
+ ~parent ~title:"Unsaved work!"
+ ~message:("Your work is <b>unsaved</b>!\n\n"^
+ "<i>Do you want to save the script before exiting?</i>")
+ ()
class gui () =
(* creation order _is_ relevant for windows placement *)
script_fname <- None;
self#main#saveMenuItem#misc#set_sensitive false
in
- let loadScript () =
- let script = s () in
- match self#chooseFile () with
- | Some f ->
- script#reset ();
- script#assignFileName f;
- script#loadFromFile ();
- console#message ("'"^f^"' loaded.\n");
- self#_enableSaveTo f
- | None -> ()
- in
let saveAsScript () =
let script = s () in
match self#chooseFile ~ok_not_exists:true () with
(s ())#saveToFile ();
console#message ("'"^f^"' saved.\n");
in
+ let loadScript () =
+ let script = s () in
+ let status = script#status in
+ try
+ if source_view#buffer#modified then
+ begin
+ match ask_unsaved main#toplevel with
+ | `YES -> saveScript ()
+ | `NO -> ()
+ | `CANCEL -> raise MatitaTypes.Cancel
+ end;
+ (match script_fname with
+ | None -> ()
+ | Some fname ->
+ ask_and_save_moo_if_needed main#toplevel fname status);
+ match self#chooseFile () with
+ | Some f ->
+ script#reset ();
+ script#assignFileName f;
+ script#loadFromFile ();
+ console#message ("'"^f^"' loaded.\n");
+ self#_enableSaveTo f
+ | None -> ()
+ with MatitaTypes.Cancel -> ()
+ in
let newScript () = (s ())#reset (); disableSave () in
let cursor () =
source_buffer#place_cursor
in
(* quit *)
self#setQuitCallback (fun () ->
+ let status = (MatitaScript.instance ())#status in
if source_view#buffer#modified then
begin
- let rc =
- MatitaGtkMisc.ask_confirmation
- ~parent:main#toplevel
- ~title:"Unsaved work!"
- ~message:("Your work is <b>unsaved</b>!\n\n"^
- "<i>Do you want to save the script before exiting?</i>")
- ()
- in
- match rc with
- | `YES -> saveScript ();
- if not source_view#buffer#modified then
- GMain.Main.quit ()
- | `NO -> GMain.Main.quit ()
- | `CANCEL -> ()
- end else GMain.Main.quit ());
+ let rc = ask_unsaved main#toplevel in
+ try
+ match rc with
+ | `YES -> saveScript ();
+ if not source_view#buffer#modified then
+ begin
+ (match script_fname with
+ | None -> ()
+ | Some fname ->
+ ask_and_save_moo_if_needed
+ main#toplevel fname status);
+ GMain.Main.quit ()
+ end
+ | `NO -> GMain.Main.quit ()
+ | `CANCEL -> raise MatitaTypes.Cancel
+ with MatitaTypes.Cancel -> ()
+ end
+ else
+ begin
+ (match script_fname with
+ | None -> clean_current_baseuri status
+ | Some fname ->
+ try
+ ask_and_save_moo_if_needed main#toplevel fname status;
+ GMain.Main.quit ()
+ with MatitaTypes.Cancel -> ())
+ end);
connect_button self#main#scriptAdvanceButton advance;
connect_button self#main#scriptRetractButton retract;
connect_button self#main#scriptTopButton top;
let module TA = TacticAst in
let module TAPp = TacticAstPp in
let module MD = MatitaDisambiguator in
+ let module ML = MatitacleanLib in
let parsed_text_length = String.length parsed_text in
match ex with
| TA.Command (loc, _) | TA.Tactical (loc, _) ->
- (match MatitacleanLib.baseuri_of_baseuri_decl (TA.Executable (loc,ex))with
- | None -> ()
- | Some u ->
- if not (MatitacleanLib.is_empty u) then
- match
- ask_confirmation
- ~title:"Baseuri redefinition"
- ~message:(
- "Baseuri " ^ u ^ " already exists.\n" ^
- "Do you want to redefine the corresponding "^
- "part of the library?")
- with
- | `YES -> MatitacleanLib.clean_baseuris [u]
- | `NO -> ()
- | `CANCEL -> raise MatitaTypes.Cancel);
- eval_with_engine status user_goal parsed_text (TA.Executable (loc, ex))
+ (try
+ (match ML.baseuri_of_baseuri_decl (TA.Executable (loc,ex)) with
+ | None -> ()
+ | Some u ->
+ if not (MatitacleanLib.is_empty u) then
+ match
+ ask_confirmation
+ ~title:"Baseuri redefinition"
+ ~message:(
+ "Baseuri " ^ u ^ " already exists.\n" ^
+ "Do you want to redefine the corresponding "^
+ "part of the library?")
+ with
+ | `YES -> MatitacleanLib.clean_baseuris [u]
+ | `NO -> ()
+ | `CANCEL -> raise MatitaTypes.Cancel);
+ eval_with_engine status user_goal parsed_text (TA.Executable (loc, ex))
+ with MatitaTypes.Cancel -> [], 0)
| TA.Macro (_,mac) ->
eval_macro status mathviewer urichooser parsed_text script mac
match pos with
| `Top -> self#goto_top; self#notify
| `Bottom ->
- (try while true do self#_advance () done; self#notify with Margin -> ())
+ (try
+ let getpos _ = buffer#get_iter_at_mark (`MARK locked_mark) in
+ let rec dowhile pos =
+ self#_advance ();
+ if pos#compare (getpos ()) < 0 then
+ dowhile (getpos ())
+ in
+ dowhile (getpos ());
+ self#notify
+ with Margin -> ())
| `Cursor ->
let locked_iter () = buffer#get_iter_at_mark (`NAME "locked") in
let cursor_iter () = buffer#get_iter_at_mark `INSERT in
method proofContext = MatitaMisc.get_proof_context self#status
method setGoal n = userGoal <- n
+ method eos =
+ let s = self#getFuture in
+ let rec is_there_and_executable s =
+ if Pcre.pmatch ~rex:only_dust_RE s then raise Margin;
+ let st = CicTextualParser2.parse_statement (Stream.of_string s) in
+ match st with
+ | TacticAst.Comment (loc,_)->
+ let parsed_text_length = snd (CicAst.loc_of_floc loc) in
+ let remain_len = String.length s - parsed_text_length in
+ let next = String.sub s parsed_text_length remain_len in
+ is_there_and_executable next
+ | TacticAst.Executable (loc, ex) -> false
+ in
+ try
+ is_there_and_executable s
+ with
+ | CicTextualParser2.Parse_error _ -> false
+ | Margin -> true
+
+
+
(* debug *)
method dump () =
MatitaLog.debug "script status:";
method setGoal: int -> unit
+ (** end of script, true if the whole script has been executed *)
+ method eos: bool
+
(* debug *)
method dump : unit -> unit
(** go initializes the status and calls interactive_loop *)
val go : unit -> unit
val main : mode:[ `COMPILER | `TOPLEVEL ] -> unit
+
+(** fname is the .ma *)
val dump_moo_to_file: string -> string list -> unit
(** clean_exit n
+(* Copyright (C) 2005, HELM Team.
+ *
+ * This file is part of HELM, an Hypertextual, Electronic
+ * Library of Mathematics, developed at the Computer Science
+ * Department, University of Bologna, Italy.
+ *
+ * HELM is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * HELM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HELM; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ *
+ * For details, see the HELM World-Wide-Web page,
+ * http://helm.cs.unibo.it/
+ *)
+
+let debug = false
+let debug_prerr = if debug then prerr_endline else ignore
+
module HGT = Http_getter_types;;
module HG = Http_getter;;
module HGM = Http_getter_misc;;
| l -> let uris, next = close_uri_list l in fix uris next @ uris
let clean_baseuris ?(verbose=true) buris =
+ Hashtbl.clear cache_of_processed_baseuri;
let buris = List.map HGM.strip_trailing_slash buris in
- (* List.iter prerr_endline buris; *)
+ debug_prerr "clean_baseuris called on:";
+ if debug then
+ List.iter debug_prerr buris;
let l = fix [] buris in
let l = MatitaMisc.list_uniq (List.fast_sort Pervasives.compare l) in
let l = List.map UriManager.uri_of_string l in
- (* List.iter (fun u -> prerr_endline (UriManager.string_of_uri u)) l; *)
+ debug_prerr "clean_baseuri will remove:";
+ if debug then
+ List.iter (fun u -> debug_prerr (UriManager.string_of_uri u)) l;
List.iter (MatitaSync.remove ~verbose) l
let is_empty buri = HG.ls (HGM.strip_trailing_slash buri ^ "/") = []