+let save_object_to_disk uri obj =
+ let ensure_path_exists path =
+ let dir = Filename.dirname path in
+ try
+ let stats = Unix.stat dir in
+ if stats.Unix.st_kind <> Unix.S_DIR then
+ raise (Failure (dir ^ " already exists and is not a directory"))
+ else
+ ()
+ with
+ Unix.Unix_error (_,_,_) ->
+ let pstatus = Unix.system ("mkdir -p " ^ dir) in
+ match pstatus with
+ | Unix.WEXITED n when n = 0 -> ()
+ | _ -> raise (Failure ("Unable to create " ^ dir))
+ in
+ (* generate annobj, ids_to_inner_sorts and ids_to_inner_types *)
+ let annobj,_,_,ids_to_inner_sorts,ids_to_inner_types,_,_ =
+ Cic2acic.acic_object_of_cic_object ~eta_fix:false obj
+ in
+ (* prepare XML *)
+ let xml, bodyxml =
+ Cic2Xml.print_object uri ~ids_to_inner_sorts ~ask_dtd_to_the_getter:false
+ annobj
+ in
+ let xmlinnertypes =
+ Cic2Xml.print_inner_types uri ~ids_to_inner_sorts ~ids_to_inner_types
+ ~ask_dtd_to_the_getter:false
+ in
+ (* prepare URIs and paths *)
+ let innertypesuri = UriManager.innertypesuri_of_uri uri in
+ let bodyuri = UriManager.bodyuri_of_uri uri in
+ let innertypesfilename = Str.replace_first (Str.regexp "^cic:") ""
+ (UriManager.string_of_uri innertypesuri) ^ ".xml.gz" in
+ let innertypespath = !(Lazy.force basedir) ^ "/" ^ innertypesfilename in
+ let xmlfilename = Str.replace_first (Str.regexp "^cic:/") ""
+ (UriManager.string_of_uri uri) ^ ".xml.gz" in
+ let xmlpath = !(Lazy.force basedir) ^ "/" ^ xmlfilename in
+ let xmlbodyfilename = Str.replace_first (Str.regexp "^cic:/") ""
+ (UriManager.string_of_uri uri) ^ ".body.xml.gz" in
+ let xmlbodypath = !(Lazy.force basedir) ^ "/" ^ xmlbodyfilename in
+ let path_scheme_of path = "file://" ^ path in
+ MatitaMisc.mkdirs (List.map Filename.dirname [innertypespath; xmlpath]);
+ (* now write to disk *)
+ ensure_path_exists innertypespath;
+ Xml.pp ~gzip:true xmlinnertypes (Some innertypespath) ;
+ ensure_path_exists xmlpath;
+ Xml.pp ~gzip:true xml (Some xmlpath) ;
+
+ (* now register to the getter *)
+ Http_getter.register' innertypesuri (path_scheme_of innertypespath);
+ Http_getter.register' uri (path_scheme_of xmlpath);
+ (* now the optional body, both write and register *)
+ (match bodyxml,bodyuri with
+ None,None -> ()
+ | Some bodyxml,Some bodyuri->
+ ensure_path_exists xmlbodypath;
+ Xml.pp ~gzip:true bodyxml (Some xmlbodypath) ;
+ Http_getter.register' bodyuri (path_scheme_of xmlbodypath)
+ | _-> assert false)
+
+ (* TODO ZACK a lot more to be done here:
+ * - save universe file *)
+let add_constant_to_world ~(console: #MatitaTypes.console)
+ ~dbd ~uri ?body ~ty ?(params = []) ?(attrs = []) ~ugraph ()
+=
+ let suri = UriManager.string_of_uri uri in
+ if CicEnvironment.in_library uri then
+ error (sprintf "%s constant already defined" suri)
+ else begin
+ let name = UriManager.name_of_uri uri in
+ let obj = Cic.Constant (name, body, ty, params, attrs) in
+ let ugraph = CicUnivUtils.clean_and_fill uri obj ugraph in
+ CicEnvironment.add_type_checked_term uri (obj, ugraph);
+ MetadataDb.index_constant ~dbd ~uri ~body ~ty;
+ save_object_to_disk uri obj;
+ console#echo_message (sprintf "%s constant defined" suri)
+ end
+
+let add_inductive_def_to_world ~(console: #MatitaTypes.console)
+ ~dbd ~uri ~indTypes ?(params = []) ?(leftno = 0) ?(attrs = []) ~ugraph ()