Mercurial > hg > CbC > CbC_gcc
diff gcc/ada/libgnat/a-direct.adb @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
line wrap: on
line diff
--- a/gcc/ada/libgnat/a-direct.adb Thu Oct 25 07:37:49 2018 +0900 +++ b/gcc/ada/libgnat/a-direct.adb Thu Feb 13 11:34:05 2020 +0900 @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 2004-2018, Free Software Foundation, Inc. -- +-- Copyright (C) 2004-2019, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -33,6 +33,8 @@ with Ada.Calendar.Formatting; use Ada.Calendar.Formatting; with Ada.Characters.Handling; use Ada.Characters.Handling; with Ada.Directories.Validity; use Ada.Directories.Validity; +with Ada.Directories.Hierarchical_File_Names; +use Ada.Directories.Hierarchical_File_Names; with Ada.Strings.Fixed; with Ada.Strings.Maps; use Ada.Strings.Maps; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; @@ -224,31 +226,22 @@ Strings.Fixed.Index (Name, Dir_Seps, Going => Strings.Backward); begin - if Last_DS = 0 then - - -- There is no directory separator, returns "." representing - -- the current working directory. - - return "."; - -- If Name indicates a root directory, raise Use_Error, because -- it has no containing directory. - elsif Name = "/" - or else - (Windows - and then - (Name = "\" - or else - (Name'Length = 3 - and then Name (Name'Last - 1 .. Name'Last) = ":\" - and then (Name (Name'First) in 'a' .. 'z' - or else - Name (Name'First) in 'A' .. 'Z')))) + if Is_Parent_Directory_Name (Name) + or else Is_Current_Directory_Name (Name) + or else Is_Root_Directory_Name (Name) then raise Use_Error with "directory """ & Name & """ has no containing directory"; + elsif Last_DS = 0 then + -- There is no directory separator, so return ".", representing + -- the current working directory. + + return "."; + else declare Last : Positive := Last_DS - Name'First + 1; @@ -262,31 +255,14 @@ -- number on Windows. while Last > 1 loop - exit when - Result (Last) /= '/' - and then - Result (Last) /= Directory_Separator; - - exit when Windows - and then Last = 3 - and then Result (2) = ':' - and then - (Result (1) in 'A' .. 'Z' - or else - Result (1) in 'a' .. 'z'); + exit when Is_Root_Directory_Name (Result (1 .. Last)) + or else (Result (Last) /= Directory_Separator + and then Result (Last) /= '/'); Last := Last - 1; end loop; - -- Special case of "..": the current directory may be a root - -- directory. - - if Last = 2 and then Result (1 .. 2) = ".." then - return Containing_Directory (Current_Directory); - - else - return Result (1 .. Last); - end if; + return Result (1 .. Last); end; end if; end; @@ -806,6 +782,20 @@ end if; if Exists = 1 then + -- Ignore special directories "." and ".." + + if (Full_Name'Length > 1 + and then + Full_Name + (Full_Name'Last - 1 .. Full_Name'Last) = "\.") + or else + (Full_Name'Length > 2 + and then + Full_Name + (Full_Name'Last - 2 .. Full_Name'Last) = "\..") + then + Exists := 0; + end if; -- Now check if the file kind matches the filter @@ -1280,17 +1270,31 @@ function Simple_Name_Internal (Path : String) return String is Cut_Start : Natural := Strings.Fixed.Index (Path, Dir_Seps, Going => Strings.Backward); - Cut_End : Natural; + + -- Cut_End points to the last simple name character + + Cut_End : Natural := Path'Last; begin - -- Cut_Start pointS to the first simple name character + -- Root directories are considered simple + + if Is_Root_Directory_Name (Path) then + return Path; + end if; + + -- Handle trailing directory separators + + if Cut_Start = Path'Last then + Cut_End := Path'Last - 1; + Cut_Start := Strings.Fixed.Index + (Path (Path'First .. Path'Last - 1), + Dir_Seps, Going => Strings.Backward); + end if; + + -- Cut_Start points to the first simple name character Cut_Start := (if Cut_Start = 0 then Path'First else Cut_Start + 1); - -- Cut_End point to the last simple name character - - Cut_End := Path'Last; - Check_For_Standard_Dirs : declare BN : constant String := Path (Cut_Start .. Cut_End); @@ -1301,7 +1305,7 @@ begin if BN = "." or else BN = ".." then - return ""; + return BN; elsif Has_Drive_Letter and then BN'Length > 2