-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.ml
More file actions
38 lines (35 loc) · 982 Bytes
/
Copy pathhelpers.ml
File metadata and controls
38 lines (35 loc) · 982 Bytes
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
31
32
33
34
35
36
37
38
(* Patchdep
*
* dependency.ml
* Copyright (C) 2007-2008
* Sapan Bhatia <sapanb@cs.princeton.edu>
* PlanetLab
*)
open Printf
let remove_parent_directory patchlevel str =
let len = String.length str in
let rec prune idx level =
if (level=0) then
String.sub str idx (len-idx)
else
let i = try String.index_from str idx '/' with e->
begin
printf "Bad filename: %s\n" str;raise e
end
in
prune (i+1) (level-1)
in
prune 0 patchlevel
let read_list_from_file f =
if (f="") then []
else
let f_file = try open_in f with e -> printf "Could not open file
%s\n" f;flush Pervasives.stdout;raise e
in
let rec read_file cur_list =
let next_line = try Some(input_line f_file) with _ -> None in
match next_line with
| Some(inp_line) -> read_file (cur_list@[inp_line])
| None -> close_in f_file;cur_list
in
read_file []