text
stringlengths
0
234
Put(Item => "Lines: ");
Ada.Integer_Text_IO.Put(LineCount);
New_Line;
Put(Item => "Words: ");
Ada.Integer_Text_IO.Put(WordCount);
Function Definition: function Convert is new Ada.Unchecked_Conversion
Function Body: (Source => Watch_Bits, Target => Interfaces.C.unsigned);
Result : constant Interfaces.C.int := Inotify_Add_Watch
(Object.Instance, Interfaces.C.To_C (Path), Convert (Mask));
begin
if Result = -1 then
raise Program_Error;
end if;
Object.Watches.Include (Result, Path);
return (Watch => Result);
end Add_Watch;
procedure Add_Watch
(Object : in out Instance;
Path : String;
Mask : Watch_Bits := All_Events)
is
Result : constant Watch := Instance'Class (Object).Add_Watch (Path, Mask);
begin
pragma Assert (Result.Watch /= -1);
end Add_Watch;
procedure Remove_Watch (Object : in out Instance; Subject : Watch) is
function Inotify_Remove_Watch
(Instance : GNAT.OS_Lib.File_Descriptor;
Watch : Interfaces.C.int) return Interfaces.C.int
with Import, Convention => C, External_Name => "inotify_rm_watch";
begin
-- Procedure Process_Events might read multiple events for a specific
-- watch and the callback for the first event may immediately try to
-- remove the watch
if Object.Defer_Remove then
if not Object.Pending_Removals.Contains (Subject) then
Object.Pending_Removals.Append (Subject);
end if;
return;
end if;
if Inotify_Remove_Watch (Object.Instance, Subject.Watch) = -1 then
raise Program_Error;
end if;
Object.Watches.Delete (Subject.Watch);
end Remove_Watch;
function Has_Watches (Object : in out Instance) return Boolean is
(not Object.Watches.Is_Empty);
function Name (Object : Instance; Subject : Watch) return String is
(Object.Watches.Element (Subject.Watch));
-----------------------------------------------------------------------------
type Inotify_Event is record
Watch : Interfaces.C.int; -- -1 if event queue has overflowed
Mask : Interfaces.C.unsigned;
Cookie : Interfaces.C.unsigned;
Length : Interfaces.C.unsigned;
end record
with Convention => C,
Alignment => 4;
type Event_Bits is record
Event : Event_Kind;
Queue_Overflowed : Boolean := False;
Ignored : Boolean := False;
Is_Directory : Boolean := False;
end record;
for Event_Bits use record
Event at 0 range 0 .. 13;
Queue_Overflowed at 0 range 14 .. 14;
Ignored at 0 range 15 .. 15;
Is_Directory at 0 range 30 .. 30;
end record;
for Event_Bits'Size use Interfaces.C.unsigned'Size;
for Event_Bits'Alignment use Interfaces.C.unsigned'Alignment;
procedure Process_Events
(Object : in out Instance;
Handle : not null access procedure
(Subject : Watch;
Event : Event_Kind;
Is_Directory : Boolean;
Name : String);
Move_Handle : not null access procedure
(Subject : Watch;
Is_Directory : Boolean;
From, To : String))
is