1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
with Gnat.Directory_Operations;
use Gnat.Directory_Operations;
with Ada.Strings.Unbounded;
use Ada.Strings.Unbounded;
with Compare_Strings_access;
use Compare_Strings_access;
with Ada.Containers.Generic_Array_Sort;
package body Files_Managment is
type T_Content_Tab is array (Integer range <>) of
Ada.Strings.Unbounded.String_Access;
procedure Dir_Sort is new Ada.Containers.Generic_Array_Sort
(Integer, Ada.Strings.Unbounded.String_Access, T_Content_Tab, Compare_Strings_Access."<");
function Expand_Path(Path_Name : in String) return String is
begin
return Gnat.Directory_Operations.Expand_Path(Path_Name);
end Expand_Path;
procedure Completed_Content(Pattern : in String;
Content : out T_Pile) is
Directory_Type : Dir_Type;
Readed_Filename : String(1..1024) :=
(others => Character'Val(32));
Last_Readed_Filename : Natural := 0;
Ptr_Readed_Filename : Ada.Strings.Unbounded.String_Access;
Developped_Pattern : String(1..1030);
begin
if Pattern(1) = '~' then
Developped_Pattern(1..Pattern'Length+4) := "$HOME" & Pattern(2..Pattern'Length);
else
Developped_Pattern(1..Pattern'Length) := Pattern;
end if;
--if Base_Name(Expanded_Path(Pattern)) / "" then
-- find;
if Is_Directory(Dir_Name
(Gnat.Directory_Operations.Expand_Path(Developped_Pattern))) then
Open
(Directory_Type,Dir_Name
(Gnat.Directory_Operations.Expand_Path(Developped_Pattern)));
Read(Directory_Type, Readed_Filename, Last_Readed_Filename);
Read(Directory_Type, Readed_Filename, Last_Readed_Filename);
loop
Read(Directory_Type, Readed_Filename, Last_Readed_Filename);
exit when Last_Readed_Filename = 0;
Ptr_Readed_Filename := new String ' (Readed_Filename(1..Last_Readed_Filename));
Empiler(Ptr_Readed_Filename, content);
end loop;
if Haut_De_Pile(Content) > 1 then
declare
Content_Tab : T_Content_Tab(1..Haut_De_Pile(Content));
begin
for I in 1..Haut_De_Pile(Content) loop
Depiler(Content_Tab(I), Content);
end loop;
Dir_Sort(Content_Tab);
for I in 1..Content_Tab'Length loop
empiler(Content_Tab(I), Content);
end loop;
end;
end if;
end if;
end Completed_Content;
procedure Free(Stack : in out T_Pile) is
Temp : Ada.Strings.Unbounded.String_Access;
begin
while Haut_De_Pile(Stack) /= 0 loop
Depiler(Temp, Stack);
Ada.Strings.Unbounded.Free(Temp);
end loop;
end Free;
end Files_Managment; |
Partager