with Ada.Command_Line;  use Ada.Command_Line;
with Ada.Text_IO;       use Ada.Text_IO;
with Ada.Containers;    use Ada.Containers;
with Ada.Strings.Equal_Case_Insensitive;  use Ada.Strings;

with Parser;

with Data_Maps;      use Data_Maps;
with Relation_Maps;  use Relation_Maps;

procedure Read_File (Name : in String) is
begin

   Parser.Initialize (Name);

   declare
      procedure Process
        (Student : String;
         Advisor : String;
         Place   : String;
         Date    : String) is
      begin
         Insert (Places, Name => Student, New_Item => Place);
         Insert (Dates, Name => Student, New_Item => Date);
      end;
   begin
      Parser.Iterate (Process'Access);
   end;


   declare
      procedure Process
        (Student : String;
         Advisor : String;
         Place   : String;
         Date    : String) is
      begin
         Insert (Students, Key => Advisor, New_Name => Student);
         Insert (Advisors, Key => Student, New_Name => Advisor);
      end;
   begin
      Parser.Iterate (Process'Access);
   end;


   declare

      procedure Process (S : String) is
         C : Data_Maps.Cursor := Find (Dates, S);
      begin
         Put ("   ");
         Put (S);

         if Has_Element (C) then
            Put (" (");
            Put (Element (C));
            Put (")");
         end if;

         New_Line;
      end;

      procedure Process (K : String; E : Set) is
         C : Data_Maps.Cursor := Find (Dates, K);
      begin
         Put (K);

         if Has_Element (C) then
            Put (" (");
            Put (Element (C));
            Put (")");
         end if;

         New_Line;

         Iterate (E, Process'Access);

         New_Line;
      end;

   begin
      Iterate (Advisors, Process'Access);
   end;


end Read_File;


