46231 (588394), страница 8
Текст из файла (страница 8)
j:=1;
for i:=35 to 38 do begin {router 7, domain 1}
computers[i].addr.router:=7;computers[i].addr.domain:=1;
computers[i].addr.comp:=j;inc(j);
end;
{------------- END OF INITIALIZATION PART -------------}
End;
Procedure Error(ErrorNum:byte);
Begin
textcolor(lightred);
writeln(' Error !');
case ErrorNum of
1: writeln(' One (or two) of above addresses are not exist');
2: writeln(' FROM and TO are same');
end;
readln;halt;
End;
VAR tmpStr :string;
tmpFrom :TAddr;
tmpTo :TAddr;
tmpData :string;
i,j :integer;
tmpX,tmpY:integer;
FromNum,ToNum:byte; {index FROM and TO computers in array}
BEGIN {------------- MAIN PROGRAM ---------------}
Initialization;
ShowGraphics(false);readln;CloseGraph;
ClrScr;TextColor(LightGreen);
write(' Global Network Emulation ');ShowTime(70,1);writeln;
{------------- ADDRESS AND DATA REQUEST ---------------}
Write(' Enter FROM address (X.X.X) : ');readln(tmpStr);{FROM request-------}
Val(tmpStr[1],tmpFrom.router,i);Val(tmpStr[3],tmpFrom.domain,i);
Val(tmpStr[5],tmpFrom.comp,i);{target request-----------------------------}
Write(' Enter TO address (X.X.X) : ');readln(tmpStr);
Val(tmpStr[1],tmpTo.router,i);Val(tmpStr[3],tmpTo.domain,i);
Val(tmpStr[5],tmpTo.comp,i);
Write(' Enter string-type DATA : ');readln(tmpData);
{------------- SEARCH 'FROM' TERMINAL -------------------}
for i:=1 to 38 do if
(computers[i].addr.router=tmpFrom.router) AND (computers[i].addr.domain=tmpFrom.domain)
AND (computers[i].addr.comp=tmpFrom.comp) then FromNum:=i;
{------------- SEARCH 'TO' TERMINAL ----------------------}
for i:=1 to 38 do if
(computers[i].addr.router=tmpTo.router) AND (computers[i].addr.domain=tmpTo.domain)
AND (computers[i].addr.comp=tmpTo.comp) then ToNum:=i;
if (FromNum=0) OR (ToNum=0) then Error(1);
if FromNum=ToNum then Error(2);{computer cannot send batch to itself}
{------------- FILL 'ADDRESS' FIELDS-----------------------}
computers[FromNum].mem.to_.router:=tmpTo.router;
computers[FromNum].mem.to_.domain:=tmpTo.domain;
computers[FromNum].mem.to_.comp:=tmpTo.comp;
computers[FromNum].mem.from.router:=tmpFrom.router;
computers[FromNum].mem.from.domain:=tmpFrom.domain;
computers[FromNum].mem.from.comp:=tmpFrom.comp;
{------------- FILL DATA FIELDS-----------------------}
computers[FromNum].mem.data:=tmpData;
writeln;
OptPathPtr:=0;
if computers[FromNum].mem.from.router<>computers[FromNum].mem.to_.router
then routers[tmpFrom.router].CalcMinPath(tmpFrom.router,tmpTo.router);
OptPathPtr:=2;
WHILE TRUE DO BEGIN {-------------- GLOBAL NET SCANNING ------------------}
for i:=1 to 38 do {------scanning terminals for data for sending --------}
{} if computers[i].mem.data<>'' then begin
if (computers[i].addr.router=computers[i].mem.to_.router)
AND (computers[i].addr.domain=computers[i].mem.to_.domain)
AND (computers[i].addr.comp<>computers[i].mem.to_.comp)
then begin
computers[i].send(computers[i].mem);{into domain sending}
break;
end else if (computers[i].addr.router<>computers[i].mem.to_.router)
OR (computers[i].addr.domain<>computers[i].mem.to_.domain)
then computers[i].Send2Router(computers[i].mem); {send to router}
{} end;{if data for sending found}
for i:=1 to 7 do {------scanning routers for receiving data}
if routers[i].memory.data<>'' then begin
routers[i].receive(i,routers[i].memory);
if routers[i].memory.to_.router=i then begin {if send into domain}
routers[i].send2comp(routers[i].memory);
break;
end else begin
routers[i].send2nextRouter(routers[i].memory,i);
break;
end;
end; {-------------------------------}
for i:=1 to 38 do {------scanning terminals for receiving data}
if computers[i].mem.data<>'' then begin
if (computers[i].addr.router=computers[i].mem.to_.router)
AND (computers[i].addr.domain=computers[i].mem.to_.domain)
then begin {into domain receiving}
computers[i].receive(computers[i].mem,false);
break;
end; {---------------------}
computers[i].receive(computers[i].mem,true);{receiving from router}
break;
end;{if receive data found}
for i:=1 to 38 do
if (computers[i].mem.data<>'')
AND(computers[i].addr.router=computers[i].mem.to_.router)
AND (computers[i].addr.domain=computers[i].mem.to_.domain)
AND (computers[i].addr.comp=computers[i].mem.to_.comp)
then while true do begin {---------Batch received !---------}
HiddenCursor;
tmpX:=wherex;tmpY:=whereY;
ShowTime(70,1);
gotoXY(tmpX,tmpY);
if keypressed then begin
readkey;
ShowGraphics(true);
readln;
CloseGraph;
NormVideo;
NormalCursor;
halt;
end;
end;
tmpX:=wherex;tmpY:=whereY;
ShowTime(70,1);
gotoXY(tmpX,tmpY);
END;{-------------- END OF GLOBAL NET SCANNING ---------------------------}
END.