-- sigdemo3.adb
--   Purpose:    Show answers to signal questions.
--   Question 1: Does the handler stay in effect after a signal arrives?
--   Question 2: What if a signalX arrives while handling signalX?
--   Question 3: What if a signalX arrives while handling signalY?
--   Question 4: What happens to read() when a signal arrives?

with
  Ada.Text_IO,
  POSIX.IO,
  C_Signals;

with Int_Handler;
with Quit_Handler;

procedure Signal_Demo_3 is
   use
     POSIX,
     POSIX.IO,
     C_Signals;
   Input       : IO_Buffer (1 .. 100);
   Read, Wrote : Natural;
begin
   Attach (Handler => Int_Handler'Access,
           To      => Signal_Interrupt);
   Attach (Handler => Quit_Handler'Access,
           To      => Signal_Quit);

   loop
      Ada.Text_IO.New_Line;
      Ada.Text_IO.Put_Line ("Type a message");
      NONSTANDARD_Read (File   => Standard_Input,
                        Buffer => Input,
                        Last   => Read);
      NONSTANDARD_Write (File   => Standard_Output,
                         Buffer => "You typed: " & Input (1 .. Read),
                         Last   => Wrote);
      exit when Input (1 .. 4) = "quit";
   end loop;
end Signal_Demo_3;

