This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Ada] Fix problem with relative paths in UNIX and DOS style
- To: gcc-patches at gcc dot gnu dot org
- Subject: [Ada] Fix problem with relative paths in UNIX and DOS style
- From: bosch at gnat dot com
- Date: Thu, 25 Oct 2001 19:24:15 -0400 (EDT)
Checked in for Pascal. -Geert
2001-10-25 Pascal Obry <obry@gnat.com>
* osint.adb (Read_Default_Search_Dirs): correctly detect relative
pathnames in UNIX and DOS style with drive letter.
(Is_Relative): new routine.
* osint.adb: Minor reformatting
* osint.adb (Is_Relative): implementation using
GNAT.OS_Lib.Is_Absolute_Path. Better fix.
*** osint.adb 2001/09/02 03:00:52 1.258
--- osint.adb 2001/10/04 20:22:05 1.259
***************
*** 1681,1686 ****
--- 1681,1706 ----
Search_Dir_Default_Name : String_Access)
return String_Access
is
+ function Is_Relative (S : String; K : Positive) return Boolean;
+ -- Returns True if a relative directory specification is found in S at
+ -- position K.
+
+ function Is_Relative (S : String; K : Positive) return Boolean is
+ begin
+ return
+ not (Is_Directory_Separator (S (K)) -- Unix style absolute pathname
+
+ or else -- DOS style absolute pathname with drive letter
+
+ (S'Last > K + 2
+ and then
+ (S (K) in 'a' .. 'z' or else S (K) in 'A' .. 'Z')
+ and then
+ S (K + 1) = ':'
+ and then
+ Is_Directory_Separator (S (K + 2))));
+ end Is_Relative;
+
Prefix_Len : constant Integer := Search_Dir_Prefix.all'Length;
Buffer : String (1 .. Prefix_Len + Search_File.all'Length + 1);
File_FD : File_Descriptor;
***************
*** 1737,1746 ****
S (J) := Path_Separator;
end if;
! if S (J) = Path_Separator then
Prev_Was_Separator := True;
else
! if Prev_Was_Separator and S (J) /= Directory_Separator then
Nb_Relative_Dir := Nb_Relative_Dir + 1;
end if;
Prev_Was_Separator := False;
--- 1757,1766 ----
S (J) := Path_Separator;
end if;
! if S (J) = Path_Separator then
Prev_Was_Separator := True;
else
! if Prev_Was_Separator and then Is_Relative (S.all, J) then
Nb_Relative_Dir := Nb_Relative_Dir + 1;
end if;
Prev_Was_Separator := False;
***************
*** 1757,1767 ****
J1 := 1;
Prev_Was_Separator := True;
for J in 1 .. Len + 1 loop
! if S (J) = Path_Separator then
Prev_Was_Separator := True;
else
! if Prev_Was_Separator and S (J) /= Directory_Separator then
S1 (J1 .. J1 + Prefix_Len) := Search_Dir_Prefix.all;
J1 := J1 + Prefix_Len;
end if;
--- 1777,1787 ----
J1 := 1;
Prev_Was_Separator := True;
for J in 1 .. Len + 1 loop
! if S (J) = Path_Separator then
Prev_Was_Separator := True;
else
! if Prev_Was_Separator and then Is_Relative (S.all, J) then
S1 (J1 .. J1 + Prefix_Len) := Search_Dir_Prefix.all;
J1 := J1 + Prefix_Len;
end if;
*** osint.adb 2001/10/04 20:22:05 1.259
--- osint.adb 2001/10/05 04:18:34 1.260
***************
*** 1676,1689 ****
------------------------------
function Read_Default_Search_Dirs
! (Search_Dir_Prefix : String_Access;
! Search_File : String_Access;
Search_Dir_Default_Name : String_Access)
! return String_Access
is
function Is_Relative (S : String; K : Positive) return Boolean;
! -- Returns True if a relative directory specification is found in S at
! -- position K.
function Is_Relative (S : String; K : Positive) return Boolean is
begin
--- 1676,1705 ----
------------------------------
function Read_Default_Search_Dirs
! (Search_Dir_Prefix : String_Access;
! Search_File : String_Access;
Search_Dir_Default_Name : String_Access)
! return String_Access
is
+ Prefix_Len : constant Integer := Search_Dir_Prefix.all'Length;
+ Buffer : String (1 .. Prefix_Len + Search_File.all'Length + 1);
+ File_FD : File_Descriptor;
+ S, S1 : String_Access;
+ Len : Integer;
+ Curr : Integer;
+ Actual_Len : Integer;
+ J1 : Integer;
+
+ Prev_Was_Separator : Boolean;
+ Nb_Relative_Dir : Integer;
+
function Is_Relative (S : String; K : Positive) return Boolean;
! -- Returns True if a relative directory specification is found
! -- in S at position K, False otherwise.
!
! -----------------
! -- Is_Relative --
! -----------------
function Is_Relative (S : String; K : Positive) return Boolean is
begin
***************
*** 1701,1720 ****
Is_Directory_Separator (S (K + 2))));
end Is_Relative;
! Prefix_Len : constant Integer := Search_Dir_Prefix.all'Length;
! Buffer : String (1 .. Prefix_Len + Search_File.all'Length + 1);
! File_FD : File_Descriptor;
! S, S1 : String_Access;
! Len : Integer;
! Curr : Integer;
! Actual_Len : Integer;
! J1 : Integer;
!
! Prev_Was_Separator : Boolean;
! Nb_Relative_Dir : Integer;
begin
-
-- Construct a C compatible character string buffer.
Buffer (1 .. Search_Dir_Prefix.all'Length)
--- 1717,1725 ----
Is_Directory_Separator (S (K + 2))));
end Is_Relative;
! -- Start of processing for Read_Default_Search_Dirs
begin
-- Construct a C compatible character string buffer.
Buffer (1 .. Search_Dir_Prefix.all'Length)
***************
*** 1763,1768 ****
--- 1768,1774 ----
if Prev_Was_Separator and then Is_Relative (S.all, J) then
Nb_Relative_Dir := Nb_Relative_Dir + 1;
end if;
+
Prev_Was_Separator := False;
end if;
end loop;
*** osint.adb 2001/10/05 04:18:34 1.260
--- osint.adb 2001/10/05 08:58:00 1.261
***************
*** 1694,1699 ****
--- 1694,1700 ----
Nb_Relative_Dir : Integer;
function Is_Relative (S : String; K : Positive) return Boolean;
+ pragma Inline (Is_Relative);
-- Returns True if a relative directory specification is found
-- in S at position K, False otherwise.
***************
*** 1703,1720 ****
function Is_Relative (S : String; K : Positive) return Boolean is
begin
! return
! not (Is_Directory_Separator (S (K)) -- Unix style absolute pathname
!
! or else -- DOS style absolute pathname with drive letter
!
! (S'Last > K + 2
! and then
! (S (K) in 'a' .. 'z' or else S (K) in 'A' .. 'Z')
! and then
! S (K + 1) = ':'
! and then
! Is_Directory_Separator (S (K + 2))));
end Is_Relative;
-- Start of processing for Read_Default_Search_Dirs
--- 1704,1710 ----
function Is_Relative (S : String; K : Positive) return Boolean is
begin
! return not Is_Absolute_Path (S (K .. S'Last));
end Is_Relative;
-- Start of processing for Read_Default_Search_Dirs