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 ->