diff options
author | John Estabrook <jestabro@vyos.io> | 2023-05-01 11:02:52 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2023-05-10 22:52:25 -0500 |
commit | 38a54abb6231bc0ef5adae9c6c010de743e13956 (patch) | |
tree | 70b7e73baaaaf5b34bd1439c6c39c5c6140f323c | |
parent | ed85b2c0dc325058ebf8f9a583c7dd013f100ebf (diff) | |
download | vyos1x-config-38a54abb6231bc0ef5adae9c6c010de743e13956.tar.gz vyos1x-config-38a54abb6231bc0ef5adae9c6c010de743e13956.zip |
T5194: add util functions for reference tree
-rw-r--r-- | src/reference_tree.ml | 15 | ||||
-rw-r--r-- | src/util.ml | 4 | ||||
-rw-r--r-- | src/util.mli | 2 |
3 files changed, 19 insertions, 2 deletions
diff --git a/src/reference_tree.ml b/src/reference_tree.ml index cfafaa5..9c704d4 100644 --- a/src/reference_tree.ml +++ b/src/reference_tree.ml @@ -66,6 +66,17 @@ let load_constraint_from_xml d c = | _ -> raise (Bad_interface_definition "Malformed constraint") in Xml.fold aux d c +(** Find a child node in xml-lite *) +let find_xml_child name xml = + let find_aux e = + match e with + | Xml.Element (name', _, _) when name' = name -> true + | _ -> false + in + match xml with + | Xml.Element (_, _, children) -> Vylist.find find_aux children + | Xml.PCData _ -> None + let data_from_xml d x = let aux d x = match x with @@ -90,7 +101,7 @@ let data_from_xml d x = let rec insert_from_xml basepath reftree xml = match xml with | Xml.Element (tag, _, _) -> - let props = Util.find_xml_child "properties" xml in + let props = find_xml_child "properties" xml in let data = (match props with | None -> default_data @@ -107,7 +118,7 @@ let rec insert_from_xml basepath reftree xml = (match node_type with | Leaf -> new_tree | _ -> - let children = Util.find_xml_child "children" xml in + let children = find_xml_child "children" xml in (match children with | None -> raise (Bad_interface_definition (Printf.sprintf "Node %s has no children" name)) | Some c -> List.fold_left (insert_from_xml path) new_tree (Xml.children c))) diff --git a/src/util.ml b/src/util.ml index bb30645..9c5df23 100644 --- a/src/util.ml +++ b/src/util.ml @@ -34,3 +34,7 @@ let default default_value opt = let lexical_numeric_compare s t = lex_numeric_compare s t + +(** Convert a relative path to an absolute path based on the current working directory *) +let absolute_path relative_path = + FilePath.make_absolute (Sys.getcwd ()) relative_path diff --git a/src/util.mli b/src/util.mli index f51adb1..f9bfba6 100644 --- a/src/util.mli +++ b/src/util.mli @@ -7,3 +7,5 @@ val escape_string : string -> string val default : 'a -> 'a option -> 'a val lexical_numeric_compare : string -> string -> int + +val absolute_path : FilePath.filename -> FilePath.filename |