2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
21 (* internal functions *******************************************************)
27 let obj_root = "CONSTANT"
29 let home = "http://lambdadelta.info/"
31 let system = KF.concat (KF.concat home base) "ld.dtd"
33 let xmlns = "xmlns", home
35 let path_of_uri xdir uri =
36 let base = KF.concat xdir base in
37 KF.concat base (Str.string_after (U.string_of_uri uri) 3)
39 (* interface functions ******************************************************)
41 type och = string -> unit
43 type attr = string * string
45 type pp = och -> int -> unit
47 let attribute out (name, contents) =
48 if contents <> "" then begin
49 out " "; out name; out "=\""; out contents; out "\""
52 let xml out version encoding =
54 attribute out ("version", version);
55 attribute out ("encoding", encoding);
58 let doctype out root system =
59 out "<!DOCTYPE "; out root; out " SYSTEM \""; out system; out "\">\n\n"
61 let tag tag attrs ?contents out indent =
62 let spc = String.make indent ' ' in
63 out spc; out "<"; out tag; List.iter (attribute out) attrs;
67 out ">\n"; cont out (indent + 3); out spc;
68 out "</"; out tag; out ">\n"
89 "position", string_of_int i
92 "uri", U.string_of_uri u
95 let err () = "name", "" in
96 let f n r = "name", if r then n else "-" ^ n in
100 "position", string_of_int a.E.n_apix
103 "layer", N.to_string st n
106 "position", string_of_int a.E.n_sort
111 | E.InProp -> "InProp"
112 | E.Progress -> "Progress"
113 | E.Private -> "Private"
115 "meta", String.concat " " (List.rev_map map a.E.r_meta)
117 (* TODO: the string tx must be quoted *)
119 let err () = ["lang", ""; "info", ""] in
120 let f lg tx = ["lang", lg; "info", tx] in
123 let export_entity pp_term (ra, na, u, b) =
124 let path = path_of_uri !G.xdir u in
125 let _ = Sys.command (Printf.sprintf "mkdir -p %s" (KF.dirname path)) in
126 let och = open_out (path ^ ext) in
127 let out = output_string och in
128 xml out "1.0" "UTF-8"; doctype out obj_root system;
129 let na = {na with E.n_name = Some (U.name_of_uri u, true)} in
130 let attrs = uri u :: name na :: apix na :: meta ra :: info ra in
131 let contents = match b with
132 | E.Abst w -> tag "GDec" attrs ~contents:(pp_term w)
133 | E.Abbr v -> tag "GDef" attrs ~contents:(pp_term v)
134 | E.Void -> assert false
136 let opts = if !G.si then "si" else "" in
137 let shp = H.string_of_graph () in
138 let attrs = [xmlns; "hierarchy", shp; "options", opts] in
139 tag obj_root attrs ~contents out 0;