with Text_io; procedure CAL is -- list successive dates etc. Example of Tasks DATE:string(1..20); Day:string(1..3); ANSWER:string(1..1); task YEARS is -- keep track of years, months and dates entry Get(DATE:out string); entry STOP; end YEARS; task WEEKS is -- keep track of days in week entry Get(DAY_OF_WEEK:out string); entry STOP; end WEEKS; procedure DBG(S:string) is begin Text_io.Put_line("Debug: " & S); end DBG; task body YEARS is separate; task body WEEKS is separate; begin loop DBG("l1"); YEARS.Get(DATE); DBG("l2"); WEEKS.Get(Day); Text_io.Put(Day & " " & DATE); Text_io.New_line; Text_io.Put("More (Y/N)?"); Text_io.Get(ANSWER); exit when ANSWER /="Y" and ANSWER/="y"; end loop; YEARS.STOP; WEEKS.STOP; end CAL; separate(CAL) task body YEARS is-- is a temporary body for testing purposes Year:integer:=1991; type MONTHS is (JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC); subtype POSS_DAYS is integer range 1..31; type DAY_IN_MONTH_T is array(MONTHS) of POSS_DAYS; DAYS_IN_MONTH:DAY_IN_MONTH_T:= DAY_IN_MONTH_T'(SEP|APR|JUN|NOV=>30, FEB=>28, others=>31); Month:MONTHS:=MAY; Day:POSS_DAYS:=20; DONE:boolean:=false; function LAST_DAY(M:MONTHS) return POSS_DAYS is begin if M/=FEB then return DAYS_IN_MONTH(M); elsif (Year mod 100/=0 and Year mod 4=0) or (Year mod 100=0 and (Year/100) mod 4 = 0) then return 29; else return 28; end if; end LAST_DAY; procedure DBG(S:string) is begin Text_io.Put_line("Debug: " & S); end DBG; begin DBG("y1"); Time: loop -- beginning of the year DBG("y2"); loop -- beginning of a month DBG("y3"); loop -- beginning of a day DBG("y4"); select accept Get(DATE:out string) do DATE:=integer'image(Day)&"/"&MONTHS'image(Month)&"/" & integer'image(Year); DONE:=false; end; or accept STOP do DONE:=true; end; end select; exit Time when DONE; exit when Day=LAST_DAY(Month); Day:=Day+1; end loop; exit Time when DONE; -- day=last_day(month); Day:=1; exit when Month=DEC; Month:=MONTHS'succ(Month); end loop; exit Time when DONE; -- day=1 and month=Dec Month:=JAN; Year:=Year+1; end loop Time; end YEARS; separate(CAL) task body WEEKS is-- starting calendar on a Monday only type WEEK is (MON, TUE, WED, THU, FRI, SAT, SUN); package WIO is new Text_io.ENUMERATION_IO(WEEK); DONE:boolean:=false; begin Time: loop for Day in WEEK loop select accept STOP do DONE:=true; end; or accept Get(DAY_OF_WEEK:out string) do DAY_OF_WEEK:=WEEK'image(Day); DONE:=false; end; end select; exit Time when DONE; end loop; end loop Time; end WEEKS;