open Printf
-let debug = false
+let debug = true
let debug_print s =
if debug then prerr_endline ("Helm_registry debugging: " ^ s)
Xml.pp_to_outchan token_stream oc;
close_out oc
-let load_from_absolute registry fname =
- let path = ref [] in (* <section> elements entered so far *)
+let rec load_from_absolute ?path registry fname =
+ let _path = ref (match path with None -> [] | Some p -> p)in
+ (* <section> elements entered so far *)
let in_key = ref false in (* have we entered a <key> element? *)
let cdata = ref "" in (* collected cdata (inside <key> *)
- let push_path name = path := name :: !path in
- let pop_path () = path := List.tl !path in
+ let push_path name = _path := name :: !_path in
+ let pop_path () = _path := List.tl !_path in
let start_element tag attrs =
match tag, attrs with
| "section", ["name", name] -> push_path name
| "key", ["name", name] -> in_key := true; push_path name
| "helm_registry", _ -> ()
+ | "include", ["href", fname] ->
+ debug_print ("including file " ^ fname);
+ load_from_absolute ~path:!_path registry fname
| tag, _ ->
raise (Parse_error (fname, ~-1, ~-1,
(sprintf "unexpected element <%s> or wrong attribute set" tag)))
match tag with
| "section" -> pop_path ()
| "key" ->
- let key = String.concat "." (List.rev !path) in
+ let key = String.concat "." (List.rev !_path) in
set registry ~key ~value:!cdata;
cdata := "";
in_key := false;
pop_path ()
- | "helm_registry" -> ()
+ | "include" | "helm_registry" -> ()
| _ -> assert false
in
let character_data text =
} in
let xml_parser = XmlPushParser.create_parser callbacks in
let backup = backup_registry registry in
- Hashtbl.clear registry;
+ if path = None then Hashtbl.clear registry;
try
XmlPushParser.parse xml_parser (`File fname)
with exn ->
<key name="mode">remote</key>
<key name="url">http://localhost:58081</key>
</section>
+ <section name="triciclo">
+ <include href="sample_include.xml" />
+ </section>
<section name="types">
<key name="string">debian</key>
<key name="int">1</key>
<key name="int_list">19</key>
<key name="int_float_pair">19 23.2</key>
</section>
- <section name="triciclo">
- <section name="foo1">
- <key name="bar2">aaa</key>
- <key name="bar3">bbb</key>
- </section>
- <section name="foo2">
- <key name="bar1">quux</key>
- </section>
- <key name="basedir">/public/helm_library</key>
- <key name="constant_type_file">$(triciclo.basedir)/constanttype</key>
- <key name="environment_file">$(triciclo.basedir)/environment</key>
- <key name="inner_types_file">$(triciclo.basedir)/innertypes</key>
- <key name="proof_file">$(triciclo.basedir)/currentproof</key>
- <key name="proof_file_type">$(triciclo.basedir)/currentprooftype</key>
- </section>
<section name="uwobo">
<key name="url">http://localhost:58080/</key>
</section>
--- /dev/null
+<helm_registry>
+ <section name="foo1">
+ <key name="bar2">aaa</key>
+ <key name="bar3">bbb</key>
+ </section>
+ <section name="foo2">
+ <key name="bar1">quux</key>
+ </section>
+ <key name="basedir">/public/helm_library</key>
+ <key name="constant_type_file">$(triciclo.basedir)/constanttype</key>
+ <key name="environment_file">$(triciclo.basedir)/environment</key>
+ <key name="inner_types_file">$(triciclo.basedir)/innertypes</key>
+ <key name="proof_file">$(triciclo.basedir)/currentproof</key>
+ <key name="proof_file_type">$(triciclo.basedir)/currentprooftype</key>
+</helm_registry>