-- FILE: driver.adb -- AUTHOR: G. Levine -- DATE: December 1996 -- PURPOSE: driver for the game of life implemented with tasks; -- specifically, each cell is implemented as a separate task with -- current cell condition (alive or dead) communicated -- between cells. This implementation may allow extension to -- more complex cell dynamics. with LIFE_GAME, TEXT_IO; with Ada.COMMAND_LINE; procedure Driver is Low1 : INTEGER := 1; -- dimensions of the grid Low2 : INTEGER := 1; High1 : INTEGER := 15; High2 : INTEGER := 15; Live_Mark : CHARACTER := '*'; -- output characters Dead_Mark : CHARACTER := ' '; Argument_Number: NATURAL; Last : Natural; package INT_IO is new TEXT_IO.INTEGER_IO (INTEGER); function Valid (Str: STRING) return BOOLEAN is Test :BOOLEAN; begin Test := (Str(1) >= '0' and then Str(1) <= '9') or else Str(1) = '-' or else Str(1) = '+' ; if Test then for i in Str'First + 1 .. Str'Last loop Test := (Str(i) >='0' and then str(i) <= '9'); exit when not Test; end loop; end if; return Test; end Valid; begin TEXT_IO.Put (Ada.COMMAND_LINE.Command_Name); Argument_Number := Ada.COMMAND_LINE.Argument_Count; if Argument_Number < 4 then TEXT_IO.Put_Line ("You did not enter any arguments"); elsif not Valid (Ada.Command_Line.Argument(1)) or else not Valid (Ada.Command_Line.Argument(2)) or else not Valid (Ada.Command_Line.Argument(3)) or else not Valid (Ada.Command_Line.Argument(4)) then TEXT_IO.Put_Line ("Invalid Arguments"); TEXT_IO.Put_Line ("Enter 4 arguments, low to high for grid size"); else Int_IO.Get( Ada.Command_Line.Argument (1), Low1,Last) ; Int_IO.Get (Ada.Command_Line.Argument (2), High1,Last); Int_IO.Get (Ada.Command_Line.Argument (3), Low2,Last); Int_IO.Get (Ada.Command_Line.Argument (4), High2,Last); if High1 - Low1 > 15 or else High1 - Low1 < 1 or else High2 - Low2 > 15 or else High2 - Low2 < 1 then TEXT_IO.Put_Line("Arguments must be integers low to high,low to high"); TEXT_IO.Put_Line("Maximum grid size 15 by 15"); else declare package LIFE is new Life_Game (High1, High2, Low1, Low2, Live_Mark, Dead_Mark); begin LIFE.Start; end; end if; end if; exception when others => NULL; end Driver;