text stringlengths 0 234 |
|---|
procedure Skip_Int; |
procedure Parse_Files (Value : out File_Vectors.Vector); |
procedure Expect (Char : Ada.Streams.Stream_Element); |
procedure Parse_File |
(Path : out League.String_Vectors.Universal_String_Vector; |
Length : out Ada.Streams.Stream_Element_Count); |
procedure Parse_Info |
(Name : out League.Strings.Universal_String; |
Piece_Len : out Ada.Streams.Stream_Element_Count; |
Files : out File_Vectors.Vector; |
Pieces : out League.Stream_Element_Vectors.Stream_Element_Vector); |
procedure Read_Buffer; |
subtype Digit is Ada.Streams.Stream_Element |
range Character'Pos ('0') .. Character'Pos ('9'); |
Input : Ada.Streams.Stream_IO.File_Type; |
Buffer : Ada.Streams.Stream_Element_Array (1 .. 1024); |
Last : Ada.Streams.Stream_Element_Count := 0; |
Next : Ada.Streams.Stream_Element_Count := 1; |
Error : constant String := "Can't parse torrent file."; |
SHA_From : Ada.Streams.Stream_Element_Count := Buffer'Last + 1; |
Context : GNAT.SHA1.Context := GNAT.SHA1.Initial_Context; |
Codec : constant League.Text_Codecs.Text_Codec := |
League.Text_Codecs.Codec (+"utf-8"); |
package Constants is |
Announce : constant League.Strings.Universal_String := +"announce"; |
Files : constant League.Strings.Universal_String := +"files"; |
Info : constant League.Strings.Universal_String := +"info"; |
Length : constant League.Strings.Universal_String := +"length"; |
Name : constant League.Strings.Universal_String := +"name"; |
Path : constant League.Strings.Universal_String := +"path"; |
Pieces : constant League.Strings.Universal_String := +"pieces"; |
Announce_List : constant League.Strings.Universal_String := |
+"announce-list"; |
Piece_Length : constant League.Strings.Universal_String := |
+"piece length"; |
end Constants; |
----------------- |
-- Read_Buffer -- |
----------------- |
procedure Read_Buffer is |
begin |
if SHA_From <= Last then |
GNAT.SHA1.Update (Context, Buffer (SHA_From .. Last)); |
SHA_From := 1; |
end if; |
Ada.Streams.Stream_IO.Read (Input, Buffer, Last); |
Next := 1; |
end Read_Buffer; |
------------ |
-- Expect -- |
------------ |
procedure Expect (Char : Ada.Streams.Stream_Element) is |
begin |
if Buffer (Next) = Char then |
Next := Next + 1; |
if Next > Last then |
Read_Buffer; |
end if; |
else |
raise Constraint_Error with Error; |
end if; |
end Expect; |
---------------- |
-- Parse_File -- |
---------------- |
procedure Parse_File |
(Path : out League.String_Vectors.Universal_String_Vector; |
Length : out Ada.Streams.Stream_Element_Count) |
is |
Key : League.Strings.Universal_String; |
begin |
Expect (Character'Pos ('d')); |
while Buffer (Next) /= Character'Pos ('e') loop |
Parse_String (Key); |
if Key = Constants.Length then |
Parse_Int (Length); |
elsif Key = Constants.Path then |
Parse_String_List (Path); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.