summaryrefslogtreecommitdiff
path: root/src/util.ml
blob: afa0ef3c1e6b95705af73bee1ed3bcb104996229 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(* Unavoidable module for functions that don't fit anywhere else *)

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

(* Dirty pretty printer *)
let string_of_path path =
    let rec aux xs acc =
        match xs with
        | [] -> acc
        | x :: xs' -> aux xs' (Printf.sprintf "%s %s" acc x)
    in
    match path with
    | [] -> ""
    | x :: xs -> Printf.sprintf "%s%s" x (aux xs "")

let substitute_default o d =
    match o with
    | None -> d
    | Some v -> v

let absolute_path relative_path =
    FilePath.make_absolute (Sys.getcwd ()) relative_path