text
stringlengths
0
234
Last : Positive := Line'First;
Last_Index : Positive := Line'First;
Values : array (1 .. 4) of Natural := (others => 0);
Current_Value_Index : Positive := Positive'First;
begin
while Last <= Line'Last loop
if Line (Last) not in '0' .. '9' then
if Line (First .. Last - 1) /= "" then
Get (Line (First .. Last - 1), Values (Current_Value_Index), Last_Index);
Current_Value_Index := Current_Value_Index + 1;
end if;
First := Last + 1;
Last := First;
elsif Last = Line'Last then
Get (Line (First .. Line'Last), Values (Current_Value_Index), Last_Index);
Last := Last + 1;
else
Last := Last + 1;
end if;
end loop;
if Values (1) > Max_Lines then
Max_Lines := Values (1);
elsif Values (3) > Max_Lines then
Max_Lines := Values (3);
end if;
if Values (2) > Max_Columns then
Max_Columns := Values (2);
elsif Values (4) > Max_Columns then
Max_Columns := Values (4);
end if;
Segments.Append ((
Start_Line => (Line => Values (1), Column => Values (2)),
End_Line => (Line => Values (3), Column => Values (4))
));
Function Definition: procedure Main is
Function Body: use Ada.Containers,
Ada.Execution_Time,
Ada.Real_Time,
Ada.Text_IO;
use Utils;
type Coordinate_2D is record
Line : Natural;
Column : Natural;
end record;
type Segment is record
Start_Line : Coordinate_2D;
End_Line : Coordinate_2D;
end record;
package Segment_Vectors is new Ada.Containers.Vectors (Natural, Segment);
use Segment_Vectors;
File : File_Type;
Start_Time, End_Time : CPU_Time;
Execution_Duration : Time_Span;
Segments : Vector := Empty_Vector;
Max_Lines, Max_Columns : Positive := Positive'First;
Nb_Dangerous_Cells : Natural := Natural'First;
begin
Get_File (File);
if End_Of_File (File) then
raise Program_Error with "Empty file";
end if;
-- Get all segments
while not End_Of_File (File) loop
declare
use Ada.Integer_Text_IO;
Line : constant String := Get_Line (File);
First : Positive := Line'First;
Last : Positive := Line'First;
Last_Index : Positive := Line'First;
Values : array (1 .. 4) of Natural := (others => 0);
Current_Value_Index : Positive := Positive'First;
begin
while Last <= Line'Last loop
if Line (Last) not in '0' .. '9' then
if Line (First .. Last - 1) /= "" then
Get (Line (First .. Last - 1), Values (Current_Value_Index), Last_Index);
Current_Value_Index := Current_Value_Index + 1;
end if;
First := Last + 1;
Last := First;
elsif Last = Line'Last then
Get (Line (First .. Line'Last), Values (Current_Value_Index), Last_Index);
Last := Last + 1;
else
Last := Last + 1;
end if;
end loop;
if Values (1) > Max_Lines then