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_______________________________________________________________ *)
19 (* internal functions *******************************************************)
27 let system = "http://helm.cs.unibo.it/lambda-delta/" ^ base ^ "/ld.dtd"
29 let path_of_uri xdir uri =
30 let base = F.concat xdir base in
31 F.concat base (Str.string_after (U.string_of_uri uri) 3)
33 (* interface functions ******************************************************)
35 type och = string -> unit
37 type attr = string * string
39 type pp = och -> int -> unit
41 let attribute out (name, contents) =
42 if contents <> "" then begin
43 out " "; out name; out "=\""; out contents; out "\""
46 let xml out version encoding =
48 attribute out ("version", version);
49 attribute out ("encoding", encoding);
52 let doctype out root system =
53 out "<!DOCTYPE "; out root; out " SYSTEM \""; out system; out "\">\n\n"
55 let tag tag attrs ?contents out indent =
56 let spc = String.make indent ' ' in
57 out spc; out "<"; out tag; List.iter (attribute out) attrs;
61 out ">\n"; cont out (indent + 3); out spc;
62 out "</"; out tag; out ">\n"
83 "position", string_of_int i
86 let contents = if j > 0 then string_of_int j else "" in
90 "uri", U.string_of_uri u
93 let contents = if n > 1 then string_of_int n else "" in
98 let n = if r then n else "-" ^ n in
99 let spc = if i then "" else " " in
102 let f s = "name", s in
106 let err () = "mark", "" in
107 let f i = "mark", string_of_int i in
111 "level", N.to_string n
113 (* TODO: the string s must be quoted *)
115 let err () = "meta", "" in
116 let f s = "meta", s in
119 let export_entity pp_term si xdir (a, u, b) =
120 let path = path_of_uri xdir u in
121 let _ = Sys.command (Printf.sprintf "mkdir -p %s" (F.dirname path)) in
122 let och = open_out (path ^ obj_ext) in
123 let out = output_string och in
124 xml out "1.0" "UTF-8"; doctype out root system;
125 let a = E.Name (U.name_of_uri u, true) :: a in
126 let attrs = [uri u; name a; mark a; meta a] in
127 let contents = match b with
128 | E.Abst (n, w) -> tag "ABST" (level n :: attrs) ~contents:(pp_term w)
129 | E.Abbr v -> tag "ABBR" attrs ~contents:(pp_term v)
130 | E.Void -> assert false
132 let opts = if si then "si" else "" in
133 let shp = H.string_of_graph () in
134 let attrs = ["hierarchy", shp; "options", opts] in
135 tag root attrs ~contents out 0;