text
stringlengths
0
234
UTF : constant League.Text_Codecs.Text_Codec :=
League.Text_Codecs.Codec (+"utf-8");
S : aliased Simple_Stream :=
(Ada.Streams.Root_Stream_Type with
Size => Value'Length,
Last => 0,
Data => Value);
Result : League.Strings.Universal_String;
Proto : Protocol_Name;
Length : Ada.Streams.Stream_Element_Count;
begin
while S.Last < S.Size loop
Protocol_Name'Read (S'Access, Proto);
Result.Append ('/');
Result.Append (Image (Proto));
case Proto is
when ip4 =>
declare
Addr : IP4_Raw;
begin
Result.Append ('/');
IP4_Raw'Read (S'Access, Addr);
Result.Append (Image (Addr (1)));
for X in 2 .. 4 loop
Result.Append ('.');
Result.Append (Image (Addr (X)));
end loop;
Function Definition: procedure Main is
Function Body: use Ada.Execution_Time,
Ada.Real_Time,
Ada.Strings.Unbounded,
Ada.Text_IO;
use Utils;
subtype Big_Cave_Character is Character range 'A' .. 'Z';
subtype Small_Cave_Character is Character range 'a' .. 'z';
package Cave_Vectors is new Ada.Containers.Indefinite_Vectors (Index_Type => Positive,
Element_Type => String,
"=" => "=");
use Cave_Vectors;
type Cave_Kind is (K_Start, K_Big, K_Small, K_End);
Start_Name : constant String := "start";
End_Name : constant String := "end";
-- Given the name of a node, it retreive the corresponding kind
function Get_Kind (Name : String) return Cave_Kind;
--------------
-- Get_Kind --
--------------
function Get_Kind (Name : String) return Cave_Kind is
begin
if Name = Start_Name then
return K_Start;
elsif Name = End_Name then
return K_End;
elsif Name (Name'First) in Big_Cave_Character then
return K_Big;
elsif Name (Name'First) in Small_Cave_Character then
return K_Small;
end if;
raise Constraint_Error with "Unexpected cave name: " & Name;
end Get_Kind;
type Cave_Info (Length : Positive) is record
Name : String (1 .. Length);
Kind : Cave_Kind;
Adjacent : Vector;
end record;
package Cave_Maps is new Ada.Containers.Indefinite_Hashed_Maps
(Key_Type => String,
Element_Type => Cave_Info,
Hash => Ada.Strings.Hash,
Equivalent_Keys => "=");
package String_Sets is new Ada.Containers.Indefinite_Hashed_Sets (Element_Type => String,
Hash => Ada.Strings.Hash,
Equivalent_Elements => "=",
"=" => "=");
type Cave_Explorer is record
Name : Unbounded_String;
Already_Visited_Small_Cave_Name : Unbounded_String;
Already_Visited_Small_Cave : String_Sets.Set;
end record;
package Explored_Cave_Interfaces is
new Ada.Containers.Synchronized_Queue_Interfaces
(Element_Type => Cave_Explorer);
package Explored_Cave_Queue is new Ada.Containers.Unbounded_Synchronized_Queues
(Queue_Interfaces => Explored_Cave_Interfaces);