Skip to content

F.1. Self referencing code

Julio edited this page Mar 30, 2020 · 1 revision
-- self_print.adb

with Ada.Strings.Fixed;
with Ada.Text_IO;

procedure self_print is
   FileName: String
           := "self_print.adb";
   File    : Ada.Text_IO.File_Type;
   Line_Count : Natural;
   begin
      Ada.Text_IO.
         Open(  File => File,
                Mode => Ada.Text_IO.In_File,
                Name => FileName);
      while not Ada.Text_IO.End_Of_File(File) loop 
       declare
         Line: String := Ada.Text_IO.Get_Line(File);
       begin
         if Ada.Strings.Fixed.Count(Line, "Ada") > 0
         -- Print if line contains Ada
         then
            Ada.Text_IO.Put_Line(Line);
            end if;
       end;
      end loop;
      Ada.Text_IO.Close(File);
   end self_print;
Clone this wiki locally