+let require0 ~baseuri = require_path (path_of_baseuri baseuri);;
+
+let db_path () = Helm_registry.get "matita.basedir" ^ "/ng_db.ng";;
+
+type timestamp =
+ (NUri.uri * NCic.obj) list *
+ (NUri.uri * string * NReference.reference) list *
+ NCic.obj NUri.UriMap.t;;
+
+let time0 = [],[],NUri.UriMap.empty;;
+let storage = ref [];;
+let local_aliases = ref [];;
+let set_global_aliases,get_global_aliases =
+ let global_aliases = ref [] in
+ let store_db () =
+ let ch = open_out (db_path ()) in
+ Marshal.to_channel ch (magic,!global_aliases) [];
+ close_out ch;
+ in
+ (fun ga -> global_aliases := ga; store_db ()),
+ (fun () -> !global_aliases)
+;;
+
+let init () =
+ try
+ set_global_aliases (require_path (db_path ()))
+ with
+ Sys_error _ -> ()
+;;
+
+let cache = ref NUri.UriMap.empty;;
+
+class status =
+ object
+ val timestamp = (time0 : timestamp)
+ method timestamp = timestamp
+ method set_timestamp v = {< timestamp = v >}
+ method set_library_status
+ : 'status. < timestamp : timestamp; .. > as 'status -> 'self
+ = fun o -> {< timestamp = o#timestamp >}
+ end
+
+let time_travel status =
+ let sto,ali,cac = status#timestamp in
+ storage := sto; local_aliases := ali; cache := cac
+;;
+