|
Packit |
9ff65e |
(******************************************************************************)
|
|
Packit |
9ff65e |
(* ocaml-fileutils: files and filenames common operations *)
|
|
Packit |
9ff65e |
(* *)
|
|
Packit |
9ff65e |
(* Copyright (C) 2003-2014, Sylvain Le Gall *)
|
|
Packit |
9ff65e |
(* *)
|
|
Packit |
9ff65e |
(* This library is free software; you can redistribute it and/or modify it *)
|
|
Packit |
9ff65e |
(* under the terms of the GNU Lesser General Public License as published by *)
|
|
Packit |
9ff65e |
(* the Free Software Foundation; either version 2.1 of the License, or (at *)
|
|
Packit |
9ff65e |
(* your option) any later version, with the OCaml static compilation *)
|
|
Packit |
9ff65e |
(* exception. *)
|
|
Packit |
9ff65e |
(* *)
|
|
Packit |
9ff65e |
(* This library is distributed in the hope that it will be useful, but *)
|
|
Packit |
9ff65e |
(* WITHOUT ANY WARRANTY; without even the implied warranty of *)
|
|
Packit |
9ff65e |
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file *)
|
|
Packit |
9ff65e |
(* COPYING for more details. *)
|
|
Packit |
9ff65e |
(* *)
|
|
Packit |
9ff65e |
(* You should have received a copy of the GNU Lesser General Public License *)
|
|
Packit |
9ff65e |
(* along with this library; if not, write to the Free Software Foundation, *)
|
|
Packit |
9ff65e |
(* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *)
|
|
Packit |
9ff65e |
(******************************************************************************)
|
|
Packit |
9ff65e |
|
|
Packit |
9ff65e |
open FilePath_type
|
|
Packit |
9ff65e |
|
|
Packit |
9ff65e |
include CommonPath
|
|
Packit |
9ff65e |
|
|
Packit |
9ff65e |
|
|
Packit |
9ff65e |
let rec dir_writer lst =
|
|
Packit |
9ff65e |
match lst with
|
|
Packit |
9ff65e |
Root s :: tl -> (s^":\\")^(dir_writer tl)
|
|
Packit |
9ff65e |
| [ CurrentDir Short ] -> ""
|
|
Packit |
9ff65e |
| lst ->
|
|
Packit |
9ff65e |
let dir_writer_aux cmp =
|
|
Packit |
9ff65e |
match cmp with
|
|
Packit |
9ff65e |
(* We should raise an exception here *)
|
|
Packit |
9ff65e |
Root s -> s
|
|
Packit |
9ff65e |
| ParentDir -> ".."
|
|
Packit |
9ff65e |
| CurrentDir _ -> "."
|
|
Packit |
9ff65e |
| Component s -> s
|
|
Packit |
9ff65e |
in
|
|
Packit |
9ff65e |
String.concat "\\" (List.map dir_writer_aux lst)
|
|
Packit |
9ff65e |
|
|
Packit |
9ff65e |
|
|
Packit |
9ff65e |
let dir_reader str =
|
|
Packit |
9ff65e |
let fn_part_of_string =
|
|
Packit |
9ff65e |
function
|
|
Packit |
9ff65e |
| ".." -> ParentDir
|
|
Packit |
9ff65e |
| "." -> CurrentDir Long
|
|
Packit |
9ff65e |
| str -> Component str
|
|
Packit |
9ff65e |
in
|
|
Packit |
9ff65e |
let fn_part_split str =
|
|
Packit |
9ff65e |
let lst =
|
|
Packit |
9ff65e |
List.flatten
|
|
Packit |
9ff65e |
(List.map
|
|
Packit |
9ff65e |
(StringExt.split ~map:fn_part_of_string '\\')
|
|
Packit |
9ff65e |
(StringExt.split ~map:(fun s -> s) '/' str))
|
|
Packit |
9ff65e |
in
|
|
Packit |
9ff65e |
match lst with
|
|
Packit |
9ff65e |
(* TODO: we don't make the difference between c:a and c:\a *)
|
|
Packit |
9ff65e |
| Component "" :: tl -> tl
|
|
Packit |
9ff65e |
| lst -> lst
|
|
Packit |
9ff65e |
in
|
|
Packit |
9ff65e |
try
|
|
Packit |
9ff65e |
let drive_letter, str = StringExt.break_at_first ':' str in
|
|
Packit |
9ff65e |
Root drive_letter :: (fn_part_split str)
|
|
Packit |
9ff65e |
with Not_found ->
|
|
Packit |
9ff65e |
fn_part_split str
|
|
Packit |
9ff65e |
|
|
Packit |
9ff65e |
|
|
Packit |
9ff65e |
let path_writer lst = String.concat ";" lst
|
|
Packit |
9ff65e |
|
|
Packit |
9ff65e |
|
|
Packit |
9ff65e |
let path_reader str = StringExt.split ~map:(fun s -> s) ';' str
|