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_______________________________________________________________ *)
18 (* internal functions *******************************************************)
26 let system = "http://helm.cs.unibo.it/lambda-delta/" ^ base ^ "/ld.dtd"
29 F.concat base (Str.string_after (U.string_of_uri uri) 3)
31 (* interface functions ******************************************************)
33 type och = string -> unit
35 type attr = string * string
37 type pp = och -> int -> unit
39 let attribute out (name, contents) =
40 if contents <> "" then begin
41 out " "; out name; out "=\""; out contents; out "\""
44 let xml out version encoding =
46 attribute out ("version", version);
47 attribute out ("encoding", encoding);
50 let doctype out root system =
51 out "<!DOCTYPE "; out root; out " SYSTEM \""; out system; out "\">\n\n"
53 let tag tag attrs ?contents out indent =
54 let spc = String.make indent ' ' in
55 out spc; out "<"; out tag; List.iter (attribute out) attrs;
59 out ">\n"; cont out (indent + 3); out spc;
60 out "</"; out tag; out ">\n"
81 "position", string_of_int i
84 let contents = if j > 0 then string_of_int j else "" in
88 "uri", U.string_of_uri u
91 let contents = if n > 1 then string_of_int n else "" in
96 let n = if r then n else "^" ^ n in
97 let spc = if i then "" else " " in
100 let f s = "name", s in
104 let err () = "mark", "" in
105 let f i = "mark", string_of_int i in
108 let export_entity pp_term si g (a, u, b) =
109 let path = path_of_uri u in
110 let _ = Sys.command (Printf.sprintf "mkdir -p %s" (F.dirname path)) in
111 let och = open_out (path ^ obj_ext) in
112 let out = output_string och in
113 xml out "1.0" "UTF-8"; doctype out root system;
114 let a = Y.Name (U.name_of_uri u, true) :: a in
115 let attrs = [uri u; name a; mark a] in
116 let contents = match b with
117 | Y.Abst w -> tag "ABST" attrs ~contents:(pp_term w)
118 | Y.Abbr v -> tag "ABBR" attrs ~contents:(pp_term v)
119 | Y.Void -> assert false
121 let opts = if si then "si" else "" in
122 let shp = H.string_of_graph g in
123 let attrs = ["hierarchy", shp; "options", opts] in
124 tag root attrs ~contents out 0;