let status = ref (new MatitaEngine.status "cic:/matita");;
+let history = ref [!status];;
let include_paths = ["/home/barolo/matitaB/matita/lib"];;
+let html_of_status s =
+ let _,_,metasenv,subst,_ = s#obj in
+ let txt = List.fold_left
+ (fun acc (nmeta,_ as meta) ->
+ let txt0 = snd (ApplyTransformation.ntxt_of_cic_sequent
+ ~metasenv ~subst ~map_unicode_to_tex:false 80 s meta)
+ in
+ prerr_endline ("### txt0 = " ^ txt0);
+ ("<B>Goal ?" ^ (string_of_int nmeta) ^ "</B>\n" ^ txt0)::acc)
+ [] metasenv
+ in
+ String.concat "\n\n" txt
+;;
+
let advance text (* (?bos=false) *) =
- (* if bos then LibraryClean.clean_baseuris [self#buri_of_current_file];
- (* HLog.debug ("evaluating: " ^ first_line s ^ " ...");*)
- let time1 = Unix.gettimeofday () in
- let entries, newtext, parsed_len = *)
- let (st,_),_,parsed_len =
+ let (st,new_statements),(* newtext TODO *) _,parsed_len =
(* try *)
eval_statement include_paths (*buffer*) !status (`Raw text)
(* with End_of_file -> raise Margin *)
in
- status := st;
- let _,_,metasenv,subst,_ = !status#obj in
- let txt = List.fold_left
- (fun acc (nmeta,_ as meta) ->
- let txt0 = snd (ApplyTransformation.ntxt_of_cic_sequent
- ~metasenv ~subst ~map_unicode_to_tex:false 80 !status
- meta) in
- prerr_endline ("### txt0 = " ^ txt0);
- ("<B>Goal ?" ^ (string_of_int nmeta) ^ "</B>\n" ^ txt0)::acc)
- [] metasenv
- in
- let txt = String.concat "\n\n" txt in
+ status := st;
+ history := st :: !history;
+ let txt = html_of_status !status in
parsed_len, txt
- (*in
- let time2 = Unix.gettimeofday () in
- HLog.debug ("... done in " ^ string_of_float (time2 -. time1) ^ "s");
- let new_statuses, new_statements =
- let statuses, texts = List.split entries in
- statuses, texts
- in
- history <- new_statuses @ history;
- statements <- new_statements @ statements;
- let start = buffer#get_iter_at_mark (`MARK locked_mark) in
- let new_text = String.concat "" (List.rev new_statements) in
- if statement <> None then
- buffer#insert ~iter:start new_text
- else begin
- let parsed_text = String.sub s 0 parsed_len in
- if new_text <> parsed_text then begin
- let stop = start#copy#forward_chars (Glib.Utf8.length parsed_text) in
- buffer#delete ~start ~stop;
- buffer#insert ~iter:start new_text;
- end;
- end;
- self#moveMark (Glib.Utf8.length new_text);
- buffer#insert ~iter:(buffer#get_iter_at_mark (`MARK locked_mark)) newtext*)
+;;
+
+let retract () =
+ let new_history,new_status =
+ match !history with
+ _::(status::_ as history) ->
+ history, status
+ | [_] -> failwith "retract"
+ | _ -> assert false in
+ NCicLibrary.time_travel !status;
+ history := new_history;
+ status := new_status;
+ html_of_status !status
;;
let read_file fname =
e -> Http_daemon.respond ~code:(`Code 500) outchan
;;
+
let callback req outchan =
let str =
(sprintf "request path = %s\n" req#path) ^
with e -> prerr_endline ("inner exception: " ^
Printexc.to_string e));
prerr_endline "end status";
- let _,_,metasenv,subst,_ = !status#obj in
- let txt = List.fold_left
- (fun acc (nmeta,_ as meta) ->
- let txt0 = snd (ApplyTransformation.ntxt_of_cic_sequent
- ~metasenv ~subst ~map_unicode_to_tex:false 80 !status
- meta) in
- prerr_endline ("### txt0 = " ^ txt0);
- ("<B>Goal ?" ^ (string_of_int nmeta) ^ "</B>\n" ^ txt0)::acc)
- [] metasenv
- in
- let txt = String.concat "\n\n" txt in
+ let txt = html_of_status !status in
(0,txt), Printexc.to_string e, `Code 500)
in
let txt = Netencoding.Url.encode ~plus:false txt in
let body = (string_of_int parsed_len) ^ "#" ^ txt in
Http_daemon.respond ~code ~body outchan
+ | "/retract" ->
+ (try
+ let txt = retract () in
+ Http_daemon.respond ~code:(`Code 200) ~body:txt outchan
+ with e ->
+ (prerr_endline (Printexc.to_string e);
+ Http_daemon.respond ~code:(`Code 500) outchan))
| url -> Http_daemon.respond_not_found ~url outchan
;;