Commit df957272 by Nicolas Roche Committed by Arnaud Charlet

g-diopit.adb (Wildcard_Iterator): Return directly if Path is equal to ""

2005-06-14  Nicolas Roche  <roche@adacore.com>

	* g-diopit.adb (Wildcard_Iterator): Return directly if Path is equal
	to ""
	(Next_Level): Fix minor bug in handling of ../dir case
	(Read): Add dir separator to Directory name so that "" is understood as
	 "/"

From-SVN: r101040
parent ee936a69
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 2001-2003 Ada Core Technologies, Inc. -- -- Copyright (C) 2001-2005 Adacore, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -91,8 +91,9 @@ package body GNAT.Directory_Operations.Iteration is ...@@ -91,8 +91,9 @@ package body GNAT.Directory_Operations.Iteration is
declare declare
Dir_Entry : constant String := Buffer (1 .. Last); Dir_Entry : constant String := Buffer (1 .. Last);
Pathname : constant String Pathname : constant String :=
:= Make_Pathname (Directory, Dir_Entry); Make_Pathname (Directory, Dir_Entry);
begin begin
if Regexp.Match (Dir_Entry, File_Regexp) then if Regexp.Match (Dir_Entry, File_Regexp) then
Quit := False; Quit := False;
...@@ -203,7 +204,7 @@ package body GNAT.Directory_Operations.Iteration is ...@@ -203,7 +204,7 @@ package body GNAT.Directory_Operations.Iteration is
-- We have "../dir" -- We have "../dir"
Read (Current_Path & "..", Read (Current_Path & "..",
SP (SP'First + 4 .. DS - 1), SP (SP'First + 3 .. DS - 1),
SP (DS .. SP'Last)); SP (DS .. SP'Last));
end if; end if;
...@@ -308,7 +309,7 @@ package body GNAT.Directory_Operations.Iteration is ...@@ -308,7 +309,7 @@ package body GNAT.Directory_Operations.Iteration is
---------- ----------
Quit : Boolean := False; Quit : Boolean := False;
-- Global state to be able to exit all recursive calls. -- Global state to be able to exit all recursive calls
procedure Read procedure Read
(Directory : String; (Directory : String;
...@@ -322,8 +323,8 @@ package body GNAT.Directory_Operations.Iteration is ...@@ -322,8 +323,8 @@ package body GNAT.Directory_Operations.Iteration is
Last : Natural; Last : Natural;
begin begin
if OS_Lib.Is_Directory (Directory) then if OS_Lib.Is_Directory (Directory & Dir_Separator) then
Open (Dir, Directory); Open (Dir, Directory & Dir_Separator);
Dir_Iterator : loop Dir_Iterator : loop
Read (Dir, Buffer, Last); Read (Dir, Buffer, Last);
...@@ -343,7 +344,6 @@ package body GNAT.Directory_Operations.Iteration is ...@@ -343,7 +344,6 @@ package body GNAT.Directory_Operations.Iteration is
(Dir_Entry = ".." and then File_Pattern /= "..")) (Dir_Entry = ".." and then File_Pattern /= ".."))
then then
if Regexp.Match (Dir_Entry, File_Regexp) then if Regexp.Match (Dir_Entry, File_Regexp) then
if Suffix_Pattern = "" then if Suffix_Pattern = "" then
-- No more matching needed, call user's callback -- No more matching needed, call user's callback
...@@ -352,15 +352,12 @@ package body GNAT.Directory_Operations.Iteration is ...@@ -352,15 +352,12 @@ package body GNAT.Directory_Operations.Iteration is
begin begin
Action (Pathname, Index, Quit); Action (Pathname, Index, Quit);
exception exception
when others => when others =>
Close (Dir); Close (Dir);
raise; raise;
end; end;
exit Dir_Iterator when Quit;
else else
-- Down one level -- Down one level
...@@ -372,8 +369,10 @@ package body GNAT.Directory_Operations.Iteration is ...@@ -372,8 +369,10 @@ package body GNAT.Directory_Operations.Iteration is
end if; end if;
end; end;
exit Dir_Iterator when Quit; -- Exit if Quit set by call to Action, either at this level
-- or at at some lower recursive call to Next_Level.
exit Dir_Iterator when Quit;
end loop Dir_Iterator; end loop Dir_Iterator;
Close (Dir); Close (Dir);
...@@ -381,6 +380,10 @@ package body GNAT.Directory_Operations.Iteration is ...@@ -381,6 +380,10 @@ package body GNAT.Directory_Operations.Iteration is
end Read; end Read;
begin begin
if Path = "" then
return;
end if;
Next_Level ("", Path); Next_Level ("", Path);
end Wildcard_Iterator; end Wildcard_Iterator;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment