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_______________________________________________________________ *)
20 (* internal functions *******************************************************)
26 let obj_root = "ENTITY"
28 let ccs_name = "ccs.ldc"
32 let home = "http://lambdadelta.info/"
34 let system = F.concat (F.concat home base) "ld.dtd"
36 let xmlns = "xmlns", home
38 let path_of_uri xdir uri =
39 let base = F.concat xdir base in
40 F.concat base (Str.string_after (U.string_of_uri uri) 3)
42 (* interface functions ******************************************************)
44 type och = string -> unit
46 type attr = string * string
48 type pp = och -> int -> unit
50 let attribute out (name, contents) =
51 if contents <> "" then begin
52 out " "; out name; out "=\""; out contents; out "\""
55 let xml out version encoding =
57 attribute out ("version", version);
58 attribute out ("encoding", encoding);
61 let doctype out root system =
62 out "<!DOCTYPE "; out root; out " SYSTEM \""; out system; out "\">\n\n"
64 let tag tag attrs ?contents out indent =
65 let spc = String.make indent ' ' in
66 out spc; out "<"; out tag; List.iter (attribute out) attrs;
70 out ">\n"; cont out (indent + 3); out spc;
71 out "</"; out tag; out ">\n"
92 "position", string_of_int i
95 "uri", U.string_of_uri u
98 let err () = "name", "" in
99 let f n r = "name", if r then n else "-" ^ n in
103 let err () = "age", "" in
104 let f i = "age", string_of_int i in
108 "level", N.to_string st n
113 | E.InProp -> "InProp"
114 | E.Progress -> "Progress"
115 | E.Private -> "Private"
117 "meta", String.concat " " (List.rev_map map a.E.r_meta)
119 (* TODO: the string tx must be quoted *)
121 let err () = ["lang", ""; "info", ""] in
122 let f lg tx = ["lang", lg; "info", tx] in
125 let export_entity pp_term (ra, na, u, b) =
126 let path = path_of_uri !G.xdir u in
127 let _ = Sys.command (Printf.sprintf "mkdir -p %s" (F.dirname path)) in
128 let och = open_out (path ^ ext) in
129 let out = output_string och in
130 xml out "1.0" "UTF-8"; doctype out obj_root system;
131 let na = {na with E.n_name = Some (U.name_of_uri u, true)} in
132 let attrs = uri u :: name na :: apix na :: meta ra :: info ra in
133 let contents = match b with
134 | E.Abst w -> tag "GDec" attrs ~contents:(pp_term w)
135 | E.Abbr v -> tag "GDef" attrs ~contents:(pp_term v)
136 | E.Void -> assert false
138 let opts = if !G.si then "si" else "" in
139 let shp = H.string_of_graph () in
140 let attrs = [xmlns; "hierarchy", shp; "options", opts] in
141 tag obj_root attrs ~contents out 0;