@@ -21360,6 +21360,8 @@ val module_name_of_file_if_any : string -> string
21360
21360
*)
21361
21361
val combine : string -> string -> string
21362
21362
21363
+ val normalize_absolute_path : string -> string
21364
+
21363
21365
end = struct
21364
21366
#1 "ext_filename.ml"
21365
21367
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -21599,6 +21601,69 @@ let combine p1 p2 =
21599
21601
Filename.concat p1 p2
21600
21602
else p2
21601
21603
21604
+
21605
+
21606
+ (**
21607
+ {[
21608
+ split_aux "//ghosg//ghsogh/";;
21609
+ - : string * string list = ("/", ["ghosg"; "ghsogh"])
21610
+ ]}
21611
+ *)
21612
+ let split_aux p =
21613
+ let rec go p acc =
21614
+ let dir = Filename.dirname p in
21615
+ if dir = p then dir, acc
21616
+ else go dir (Filename.basename p :: acc)
21617
+ in go p []
21618
+
21619
+
21620
+
21621
+
21622
+ (*TODO: could be hgighly optimized later
21623
+ {[
21624
+ normalize_absolute_path "/gsho/./..";;
21625
+
21626
+ normalize_absolute_path "/a/b/../c../d/e/f";;
21627
+
21628
+ normalize_absolute_path "/gsho/./..";;
21629
+
21630
+ normalize_absolute_path "/gsho/./../..";;
21631
+
21632
+ normalize_absolute_path "/a/b/c/d";;
21633
+
21634
+ normalize_absolute_path "/a/b/c/d/";;
21635
+
21636
+ normalize_absolute_path "/a/";;
21637
+
21638
+ normalize_absolute_path "/a";;
21639
+ ]}
21640
+ *)
21641
+ let normalize_absolute_path x =
21642
+ let drop_if_exist xs =
21643
+ match xs with
21644
+ | [] -> []
21645
+ | _ :: xs -> xs in
21646
+ let rec normalize_list acc paths =
21647
+ match paths with
21648
+ | [] -> acc
21649
+ | "." :: xs -> normalize_list acc xs
21650
+ | ".." :: xs ->
21651
+ normalize_list (drop_if_exist acc ) xs
21652
+
21653
+ | x :: xs ->
21654
+ normalize_list (x::acc) xs
21655
+ in
21656
+ let root, paths = split_aux x in
21657
+ let rev_paths = normalize_list [] paths in
21658
+ let rec go acc rev_paths =
21659
+ match rev_paths with
21660
+ | [] -> Filename.concat root acc
21661
+ | last::rest -> go (Filename.concat last acc ) rest in
21662
+ match rev_paths with
21663
+ | [] -> root
21664
+ | last :: rest -> go last rest
21665
+
21666
+
21602
21667
end
21603
21668
module Js_config : sig
21604
21669
#1 "js_config.mli"
0 commit comments