with text_io; use Text_io; procedure REPORT is package IIO is new Text_IO.Integer_io(integer); --need integer output type WORD is record LENGTH:integer:=0; S:string(1..100); end record; task BLOCKS is entry Get(W:out WORD); entry STOP; end BLOCKS; task TELEGRAMS is entry Put(W: in WORD; DONE:out boolean); end TELEGRAMS; W:WORD; DONE:boolean:=false; task body TELEGRAMS is separate; task body BLOCKS is separate; procedure dbg(S:string) is begin put_line(" REPORT: "&S); end; begin --dbg("start"); while not DONE loop BLOCKS.Get(W); --dbg(w.s(1..w.length)); TELEGRAMS.Put(W,DONE); --dbg(boolean'image(done)); end loop; --dbg("stop"); BLOCKS.STOP; --dbg("endit"); end REPORT; with Text_io; with INPUT_FILE; use input_file; separate(REPORT) task body BLOCKS is DONE:boolean:=false; W:WORD; C:character; procedure dbg(S:STRING) is begin text_io.put_line("blocks: "&S); end; begin Open; Get_block; FILE:while not done loop -- start of a block --dbg("start block") C:=FIRST_CHAR; BLOCK_BODY:while not EOB and not done loop WORD_OR_SPACE:while not EOB and not done loop if C =' ' then C:=NEXT_CHAR; else W.LENGTH:=0; GET_WORD:while C/=' ' and not EOB loop W.LENGTH:=W.LENGTH+1; W.S(W.LENGTH):=C; C:=NEXT_CHAR; end loop GET_WORD; select accept Get(W:out WORD) do Get.W:=BLOCKS.W; DONE:=false; end Get; or accept STOP do DONE:=true; --dbg("Blocks got STOP!"); end STOP; end select; exit FILE when DONE; end if; end loop WORD_OR_SPACE; end loop BLOCK_BODY; Get_block; end loop FILE; Close; end; with Text_io; use Text_io; with iio; separate(REPORT) task body TELEGRAMS is tgm_nbr:integer:=0; nwords:INTEGER:=0; noswords:INTEGER:=0; EOTGM:BOOLEAN:=false; w:WORD; function ZZZZ(W:WORD) return boolean is begin return W.LENGTH =4 and W.S(1..4)="ZZZZ"; end; begin accept Put(W:in WORD; DONE:out boolean) do TELEGRAMS.W:=Put.W; EOTGM:=ZZZZ(Put.W); DONE:=EOTGM; -- if EOTGM at start then NULL input file end Put; Put(" "); put_line("TGRAM NBR No. Words Oversize WOrds"); NON_NULL_TELEGRAMS:while not EOTGM loop -- if first word in Telegram is ZZZZ then NULL TGM nwords:=0; noswords:=0; TELEGRAM:while not EOTGM Loop --start a word inside a telegram if W.LENGTH > 13 then noswords:=noswords+1; end if; nwords:=nwords+1; accept Put(W:in WORD; DONE:out boolean) do TELEGRAMS.W:=Put.W; EOTGM:=ZZZZ(Put.W); DONE:=false; -- End of THIS telegram is not end of input. end Put; end loop TELEGRAM; tgm_nbr:=tgm_nbr+1; Put(" "); iio.Put(tgm_nbr, width=>7); iio.Put(nwords,width=>12); iio.put(noswords,width=>12); new_line; accept Put(W:in WORD; DONE:out boolean) do TELEGRAMS.W:=Put.W; EOTGM:=ZZZZ(Put.W); DONE:=EOTGM; --next telegram is the NULL telegram! end Put; end loop NON_NULL_TELEGRAMS; --NULL_TELEGRAM Put(" "); put_line("====================================="); end;