osint.adb (Read_Default_Search_Dirs): correctly detect relative pathnames in UNIX and DOS style with drive letter.

* 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 for 8121-009.

From-SVN: r46503
This commit is contained in:
Pascal Obry 2001-10-25 23:23:44 +00:00 committed by Geert Bosch
parent 5c1ba4cc9c
commit 90a9fff2b0
2 changed files with 56 additions and 9 deletions

View File

@ -1,3 +1,14 @@
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 for 8121-009.
2001-10-25 Pascal Obry <obry@gnat.com> 2001-10-25 Pascal Obry <obry@gnat.com>
* g-dirope.adb (Basename): correctly compute offset between the * g-dirope.adb (Basename): correctly compute offset between the

View File

@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- $Revision: 1.258 $ -- $Revision$
-- -- -- --
-- Copyright (C) 1992-2001 Free Software Foundation, Inc. -- -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
-- -- -- --
@ -1676,11 +1676,31 @@ package body Osint is
------------------------------ ------------------------------
function Read_Default_Search_Dirs function Read_Default_Search_Dirs
(Search_Dir_Prefix : String_Access; (Search_Dir_Prefix : String_Access;
Search_File : String_Access; Search_File : String_Access;
Search_Dir_Default_Name : String_Access) Search_Dir_Default_Name : String_Access)
return String_Access return String_Access
is 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; Prefix_Len : constant Integer := Search_Dir_Prefix.all'Length;
Buffer : String (1 .. Prefix_Len + Search_File.all'Length + 1); Buffer : String (1 .. Prefix_Len + Search_File.all'Length + 1);
File_FD : File_Descriptor; File_FD : File_Descriptor;
@ -1693,8 +1713,23 @@ package body Osint is
Prev_Was_Separator : Boolean; Prev_Was_Separator : Boolean;
Nb_Relative_Dir : Integer; Nb_Relative_Dir : Integer;
begin 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.
-----------------
-- Is_Relative --
-----------------
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
begin
-- Construct a C compatible character string buffer. -- Construct a C compatible character string buffer.
Buffer (1 .. Search_Dir_Prefix.all'Length) Buffer (1 .. Search_Dir_Prefix.all'Length)
@ -1737,12 +1772,13 @@ package body Osint is
S (J) := Path_Separator; S (J) := Path_Separator;
end if; end if;
if S (J) = Path_Separator then if S (J) = Path_Separator then
Prev_Was_Separator := True; Prev_Was_Separator := True;
else else
if Prev_Was_Separator and S (J) /= Directory_Separator then if Prev_Was_Separator and then Is_Relative (S.all, J) then
Nb_Relative_Dir := Nb_Relative_Dir + 1; Nb_Relative_Dir := Nb_Relative_Dir + 1;
end if; end if;
Prev_Was_Separator := False; Prev_Was_Separator := False;
end if; end if;
end loop; end loop;
@ -1757,11 +1793,11 @@ package body Osint is
J1 := 1; J1 := 1;
Prev_Was_Separator := True; Prev_Was_Separator := True;
for J in 1 .. Len + 1 loop for J in 1 .. Len + 1 loop
if S (J) = Path_Separator then if S (J) = Path_Separator then
Prev_Was_Separator := True; Prev_Was_Separator := True;
else else
if Prev_Was_Separator and S (J) /= Directory_Separator then if Prev_Was_Separator and then Is_Relative (S.all, J) then
S1 (J1 .. J1 + Prefix_Len) := Search_Dir_Prefix.all; S1 (J1 .. J1 + Prefix_Len) := Search_Dir_Prefix.all;
J1 := J1 + Prefix_Len; J1 := J1 + Prefix_Len;
end if; end if;