From 90a9fff2b07b27a3d6fae98f3565ab0536f981c6 Mon Sep 17 00:00:00 2001 From: Pascal Obry Date: Thu, 25 Oct 2001 23:23:44 +0000 Subject: [PATCH] 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 --- gcc/ada/ChangeLog | 11 +++++++++++ gcc/ada/osint.adb | 54 +++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 0790bbd..58187a0 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,5 +1,16 @@ 2001-10-25 Pascal Obry + * 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 + * g-dirope.adb (Basename): correctly compute offset between the original Path and the translated one. diff --git a/gcc/ada/osint.adb b/gcc/ada/osint.adb index 5d5bf72..b43f2d7 100644 --- a/gcc/ada/osint.adb +++ b/gcc/ada/osint.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- $Revision: 1.258 $ +-- $Revision$ -- -- -- Copyright (C) 1992-2001 Free Software Foundation, Inc. -- -- -- @@ -1676,11 +1676,31 @@ package body Osint is ------------------------------ function Read_Default_Search_Dirs - (Search_Dir_Prefix : String_Access; - Search_File : String_Access; + (Search_Dir_Prefix : String_Access; + Search_File : String_Access; Search_Dir_Default_Name : String_Access) - return 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; @@ -1693,8 +1713,23 @@ package body Osint is Prev_Was_Separator : Boolean; 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. Buffer (1 .. Search_Dir_Prefix.all'Length) @@ -1737,12 +1772,13 @@ package body Osint is S (J) := Path_Separator; end if; - if S (J) = Path_Separator then + if S (J) = Path_Separator then Prev_Was_Separator := True; 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; end if; + Prev_Was_Separator := False; end if; end loop; @@ -1757,11 +1793,11 @@ package body Osint is J1 := 1; Prev_Was_Separator := True; for J in 1 .. Len + 1 loop - if S (J) = Path_Separator then + if S (J) = Path_Separator then Prev_Was_Separator := True; 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; J1 := J1 + Prefix_Len; end if; -- 2.7.4