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"
78 let appl x = if x then "Appx" else "Appr"
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 "layer", N.to_string st n
103 let sort, degr = a.E.n_main in
104 ["main-sort", string_of_int sort;
105 "main-degree", string_of_int degr;
109 let sort, degr = a.E.n_side in
110 ["side-sort", string_of_int sort;
111 "side-degree", string_of_int degr;
115 "level", string_of_int a.E.n_apix
120 | E.InProp -> "InProp"
121 | E.Progress -> "Progress"
122 | E.Private -> "Private"
124 "meta", String.concat " " (List.rev_map map a.E.r_meta)
126 (* TODO: the string tx must be quoted *)
128 let err () = ["lang", ""; "info", ""] in
129 let f lg tx = ["lang", lg; "info", tx] in
132 let export_entity pp_term (ra, na, u, b) =
133 let path = path_of_uri !G.xdir u in
134 let _ = Sys.command (Printf.sprintf "mkdir -p %s" (KF.dirname path)) in
135 let och = open_out (path ^ ext) in
136 let out = output_string och in
137 xml out "1.0" "UTF-8"; doctype out obj_root system;
138 let na = {na with E.n_name = Some (U.name_of_uri u, true)} in
139 let attrs = uri u :: name na :: apix na :: meta ra :: info ra in
140 let contents = match b with
141 | E.Abst w -> tag "GDec" attrs ~contents:(pp_term w)
142 | E.Abbr v -> tag "GDef" attrs ~contents:(pp_term v)
143 | E.Void -> assert false
145 let opts = if !G.si then "si" else "" in
146 let shp = H.string_of_graph () in
147 let attrs = [xmlns; "hierarchy", shp; "options", opts] in
148 tag obj_root attrs ~contents out 0;