summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/compat.ml42
-rw-r--r--lib/gmapl.ml4
-rw-r--r--lib/system.ml32
-rw-r--r--lib/system.mli6
4 files changed, 39 insertions, 5 deletions
diff --git a/lib/compat.ml4 b/lib/compat.ml4
index 0947f5fb..7ea3ff66 100644
--- a/lib/compat.ml4
+++ b/lib/compat.ml4
@@ -20,7 +20,9 @@ let unloc (b,e) =
let loc = (b.Lexing.pos_cnum,e.Lexing.pos_cnum) in
(* Ensure that we unpack a char location that was encoded as a line-col
location by make_loc *)
+(* Gram.Entry.parse may send bad loc in 3.08, see caml-bugs #2954
assert (dummy_loc = (b,e) or make_loc loc = (b,e));
+*)
loc
end
else
diff --git a/lib/gmapl.ml b/lib/gmapl.ml
index dcb2eb94..5eb4e110 100644
--- a/lib/gmapl.ml
+++ b/lib/gmapl.ml
@@ -6,7 +6,7 @@
(* * GNU Lesser General Public License Version 2.1 *)
(************************************************************************)
-(* $Id: gmapl.ml,v 1.2.16.1 2004/07/16 19:30:29 herbelin Exp $ *)
+(* $Id: gmapl.ml,v 1.2.16.2 2006/01/03 20:31:16 herbelin Exp $ *)
open Util
@@ -21,7 +21,7 @@ let fold = Gmap.fold
let add x y m =
try
let l = Gmap.find x m in
- Gmap.add x (if List.mem y l then l else y::l) m
+ Gmap.add x (y::list_except y l) m
with Not_found ->
Gmap.add x [y] m
diff --git a/lib/system.ml b/lib/system.ml
index fd782fe6..9bbcc308 100644
--- a/lib/system.ml
+++ b/lib/system.ml
@@ -6,7 +6,7 @@
(* * GNU Lesser General Public License Version 2.1 *)
(************************************************************************)
-(* $Id: system.ml,v 1.31.8.1 2004/07/16 19:30:31 herbelin Exp $ *)
+(* $Id: system.ml,v 1.31.8.3 2006/01/10 17:06:23 barras Exp $ *)
open Pp
open Util
@@ -22,6 +22,8 @@ let safe_getenv_def var def =
flush Pervasives.stdout;
def
+let getenv_else s dft = try Sys.getenv s with Not_found -> dft
+
let home = (safe_getenv_def "HOME" ".")
let safe_getenv n = safe_getenv_def n ("$"^n)
@@ -60,6 +62,34 @@ let glob s = expand_macros true s 0
type physical_path = string
type load_path = physical_path list
+(* Hints to partially detects if two paths refer to the same repertory *)
+let rec remove_path_dot p =
+ let curdir = Filename.concat Filename.current_dir_name "" in (* Unix: "./" *)
+ let n = String.length curdir in
+ if String.length p > n && String.sub p 0 n = curdir then
+ remove_path_dot (String.sub p n (String.length p - n))
+ else
+ p
+
+let strip_path p =
+ let cwd = Filename.concat (Sys.getcwd ()) "" in (* Unix: "`pwd`/" *)
+ let n = String.length cwd in
+ if String.length p > n && String.sub p 0 n = cwd then
+ remove_path_dot (String.sub p n (String.length p - n))
+ else
+ remove_path_dot p
+
+let canonical_path_name p =
+ let current = Sys.getcwd () in
+ try
+ Sys.chdir p;
+ let p' = Sys.getcwd () in
+ Sys.chdir current;
+ p'
+ with Sys_error _ ->
+ (* We give up to find a canonical name and just simplify it... *)
+ strip_path p
+
(* All subdirectories, recursively *)
let exists_dir dir =
diff --git a/lib/system.mli b/lib/system.mli
index 86d78b52..dc172b70 100644
--- a/lib/system.mli
+++ b/lib/system.mli
@@ -6,7 +6,7 @@
(* * GNU Lesser General Public License Version 2.1 *)
(************************************************************************)
-(*i $Id: system.mli,v 1.17.16.1 2004/07/16 19:30:31 herbelin Exp $ i*)
+(*i $Id: system.mli,v 1.17.16.3 2006/01/10 17:06:23 barras Exp $ i*)
(*s Files and load paths. Load path entries remember the original root
given by the user. For efficiency, we keep the full path (field
@@ -16,6 +16,8 @@
type physical_path = string
type load_path = physical_path list
+val canonical_path_name : string -> physical_path
+
val all_subdirs : unix_path:string -> (physical_path * string list) list
val is_in_path : load_path -> string -> bool
val where_in_path : load_path -> string -> physical_path * string
@@ -24,7 +26,7 @@ val make_suffix : string -> string -> string
val file_readable_p : string -> bool
val glob : string -> string
-
+val getenv_else : string -> string -> string
val home : string
val exists_dir : string -> bool