!********************** !* nsiw77s/nsiw77y * !* date: 27.jan.82 * !********************* %conststring (13) vsn = "nsiw:vsne01f " !! stack = 400, streams = 3 !! note: for versions that are run out of a 2900 fep system, !! messages from the network should be enabled - see !! the comment at 'messages enabled' %control 1 %include "deimosperm" %constinteger nsiw ser = 6; ! private service no %recordformat xf(%byteinteger unit,fsys,%byteintegerarray fname(0:5)) %begin %predicatespec read fname(%record(xf)%name file) %%recordformat itpf(%byteinteger cnsl,hb1,hb2, %c (%byteinteger len, %byteintegerarray data(0:127) %or %string (241) s)) %recordformat messagef((%byteintegerarray data(0:241) %or %string (241) s)) %recordformat rjef(%integer uflag, %byteintegerarray data(0:239)); !$e %recordformat nsif(%integer st,port,rc,tc, %c (%integer uflag, %record (itpf) itp %or %record (rjef) rje %or %c %integer fac, term, node, %record (messagef) message)) %recordformat mef(%record(mef)%name link,%byteinteger len,type, %c %record(nsif) nsl) %recordformat pf(%byteinteger service,reply,fn,port, %c (%record(mef)%name mes,%byteinteger len,s1 %or %c %byteinteger x, y, term, facility)) %ownrecord(pf) p %record(rjef)%name block %record(itpf)%name frame %record (messagef) %name message %owninteger node, term, strm %recordformat hostf(%integer number, %c %integer cr count,cr k,lp count,lp k, node) %recordformat strdf(%integer a,b,c,d,%record(xf) file,%integer e,f,g,h) %recordformat strpf(%record(strdf)%name strd) %record(strdf)%name strd %ownrecord(xf) lp base file, cr file %record(hostf) host %owninteger cr port = -1, lp port = -1, cr status = 0, lp status = 0 %constbyteintegerarray spool base(0:5)='V','L','P','0','0','0' %constbyteintegerarray kill(0:4)=4,'K','I','L','L' %constbyteintegerarray status(0:6)=6,'S','T','A','T','U','S' %constbyteintegerarray int(0:3)=3,'I','N','T' %constbyteintegerarray filen(0:4)=4,'F','I','L','E' %constbyteintegerarray printer(0:3)=3,'L','P', ' ' %constbyteintegerarray fen(0:3) = 3, 'F', 'E', ' ' %constbyteintegerarray emas name(0:5)=4,'2','9','7','2',0 %constbyteintegerarray do enable(0:6) = 6, 'E', 'N', 'A','B','L','E' %constbyteintegerarray e2970 name(0:4) = 4, '2','9','0','0' %constbyteintegerarray info name(0:5) = 4, 'I','N','F','O',0 %constbyteintegerarray e2980 name(0:5) = 4,'2','9','8','0',0 %constinteger emas number=9, e2970 number=72, info number=156 %constinteger e2980t = 80 %byteintegerarrayname buff %ownstring (99) old line, cr line %owninteger clp %owninteger setbflag, binflag %constinteger set pr = 13; ! paper tape reader stream %constinteger max com = 10 %switch sw(0:max com) %conststring (3) %array coms(0:max com) = " ", "TT", "OP", "ZZ", "CR", "SP", "LP", "TL", "SM", "LI", "ST" %ownstring (3) new = " " %ownbyteintegerarray line(-1:119) %owninteger tt port=-1 %owninteger lptr,good text,gah ct,tt host,tt state,line length,i,j %owninteger garbage,cr timer %constinteger gate ser=16, buffer manager=17 %constinteger rd=0, echo off=10 %constinteger request buffer=0, release buffer=1 %constinteger enable facility=1, disable facility=2, call reply=3 %constinteger enable input=4, put output=5, close call=6 %constinteger abort call=7, open call=8, open message=9 %constinteger open call reply=1, incoming call=2, input recd=3 %constinteger output transmitted=4, call closed=5, call aborted=6 %constinteger open reply a=7, open reply b=8, message in=9, message reply=10 %constinteger itp hello=1, itp gah=2, itp mess=3, itp int=4 %constinteger cr data=7, social call=8 %constinteger reject=0 %constinteger idle=0, starting=1, running=2, opened=3, stopping=4, stopping2=5 %constinteger closed=6 %conststring(9)%array stat(0:6)="idle","starting", "running", "enabled", "stopping"(2), "running" %constinteger buffer size=230 %owninteger cr strm %owninteger pend gah = 0 %predicatespec match(%byteintegerarrayname master) %integerfnspec exist(%record (xf) %name file) %predicate read fname(%record(xf)%name file) %integer unit,fsys,i %integerarray fname(0:5) %constbyteintegername df == k'160055' %integerfn next %result = charno(cr line, clp) %end clp = clp+1 %while next=' ' %if next = '<' %start file_unit = 255; clp = clp+1 %true %finish %if '0'<=next<='4' %start unit=next-'0'; clp = clp+1 ->false %unless next='.' clp = clp+1 %finish %else unit=0 ->false %unless 'A'<=next<='Z' fname(i)=' ' %for i=0,1,5 i=0 %while 'A'<=next<='Z' %or '0'<=next<='9' %cycle fname(i)=next %if i<6; clp = clp+1 i=i+1 %repeat %if next='(' %start clp = clp+1 ->false %unless '0'<=next<='9' fsys=next-'0'; clp = clp+1 fsys=8*fsys+next-'0' %and clp = clp+1 %if '0'<=next<='9' ->false %if next#')'; clp = clp+1 %finish %else fsys=df clp = clp+1 %while next=' ' ->false %unless next=nl %or next='+' file_unit=unit; file_fsys=fsys file_fname(i)=fname(i) %for i=0,1,5 %true false: clp = clp+1 %until next=nl clp = clp+1 %false %end %routine to tt(%integer fn) %recordformat pf(%byteinteger service,reply,%integer a1,%byteintegername %c a2,%integer a3) %record(pf) p p_service=tt no; p_reply=nsiw ser p_a1=fn; p_a2==line(0); p_a3=120 pon(p) %end %integerfn read address !! uses globals node, term and strm %integer k %integerfn sig lptr = lptr+1 %while line(lptr)=' ' %result = line(lptr) %end %integerfn r num %integer j, n n=0 %cycle j=line(lptr) %unless '0' <= j <= '9' %then %result = n lptr = lptr+1 n = n*10+j-'0' %repeat %end node = 0 %if match(emas name) %then term=emas number %and %result=1; !$e %if match(e2970name) %then term=e2970number %and ->add node %if match(info name) %then term=info number %and ->add node %if match(e2980 name) %start term = e2980t add node: node = term; %result = 1 %finish k = sig; lptr = lptr+1 %if k = 'N' %or k = 'n' %start; ! specify node number node = rnum k = line(lptr); lptr = lptr+1 %finish %result = 0 %unless k='T' %or k = 't' term = rnum; k=line(lptr); lptr=lptr+1 %if k='S' %or k = 's' %start strm = rnum; k=line(lptr); lptr=lptr+1 %finish %result = 0 %unless k = ' ' %or k = nl lptr = lptr-1 %result = 1 %end %predicate match(%byteintegerarrayname master) %integer i, n lptr=lptr+1 %while line(lptr)=' ' %cycle i=1,1,master(0) n = line(lptr+i-1) %if 'a' <= n <= 'z' %then n = n-'a'+'A' %if n#master(i) %then %false %repeat lptr=lptr+i %true %end %routine set stream(%integer stream,%record(xf)%name file) %constintegerarray disc(0:3)=3,3,8,14 %ownrecord (strdf) %name strd5 %record (strpf) %name strp strp == record(k'160032'+stream<<1) %if strp_strd == null %then strp_strd == strd5 strd == strp_strd %if file_unit=255 %start; ! dummy strd5 == strd; ! remeber its address strp_strd == null; ! null stream %return %finish strd_a=0; strd_b=2; strd_c=0; strd_d=id<<8!disc(file_unit) strd_file=file; strd_e=0; strd_f=0; strd_g=0; strd_h=k'172' %end %routine print count(%integer k,units) print symbol(',') write(k,0) %and print string("k +") %if k>0 write(units, 1); print string(" chars") %end %routine print file(%integer stream) %integer i,j %record(xf)%name file %record (strpf) %name strp strp == record(k'160032'+stream<<1) %if strp_strd == null %then printstring(".null ") %and %return file==strp_strd_file print symbol(file_unit+'0'); print symbol('.') %cycle i=0,1,5 j=file_fname(i); %exit %if j=' ' print symbol(j) %repeat print symbol('('); print symbol(file_fsys>>3+'0') print symbol(file_fsys&7+'0'); print symbol(')') %end %routine fill buffer %integer get,end,i,j,char,x %owninteger flag = 0 %on %event 9 %start; -> eof; %finish select input(1) %unless cr file_unit = 255 %cycle i = 2, 1, 239 %if cr file_unit # 255 %start readsymbol(char) %else %if flag # 0 %then flag = 0 %and char = -1 %else %start char = charno(cr line, clp); clp=clp+1 %if char = '>' %then char = nl %and flag = 1 %finish %finish %if (set b flag=0 %and char=4) %or char<0 %start eof: %if charno(cr line, clp)='+' %start; ! more to go printstring("CR:file done ") select input(0) set bflag = bin flag clp = clp+1 x = exist(cr file) %exit %if x = 0 set stream(1, cr file) select input(1) %continue; ! get next symbol %finish cr status = stopping %exit %finish block_data(i) = char %repeat i = i-1 %unless i = 239 i = i-1 host_cr count = host_cr count+i %if host_cr count>=1024 %then host_cr count=host_cr count-1024 %and %c host_cr k = host_cr k+1 block_data(0) = x'80'; block_data(1) = i p_mes_len=i+2+2; !$e (i+2)+integer uflag %end %integerfn exist(%record(xf)%name file) %recordformat pf(%byteinteger service,reply,%integer a1, %c %record(xf)%name a2,%integer a3) %record(pf) p %constintegerarray dirt(0:4)=4,4,9,15,29 %if read fname(file) %start %result = 1 %if file_unit = 255 p_service=dirt(file_unit); p_reply=id p_a1=0; p_a2==file; p_a3=0 ponoff(p) %result=1 %if p_a1#0 %finish printstring("CR:no file ") %result=0 %end %routine get buffer(%integer reason) p_service=buffer manager; p_reply=id p_fn=request buffer; p_len=0; p_s1=reason pon(p) %end %routine free buffer(%record(mef)%name mes) p_service=buffer manager; p_reply=id p_fn=release buffer; p_mes==mes pon(p) %end %routine connect(%integer host no,facility) p_service=gate ser; p_reply=id p_fn=open call; p_port=1; p_facility=facility p_x = node p_term=host no pon(p) %end %routine to gate(%integer fn,%record(mef)%name mes,%integer flag) p_service=gate ser; p_reply=id p_fn=fn; p_mes==mes; p_s1=flag %if fn = put output %start %if addr(mes) = 0 %or addr(mes)&k'140000' = k'140000' %start printstring("nsiw: crunch! ") %cycle; %repeat %finish %finish pon(p) %end %routine do itp(%record (mef) %name mes) %record (itpf) %name frame %return %if tt state=stopping frame == mes_nsl_itp gah ct=gah ct+1 %if frame_hb1&2#0 %if frame_hb1&4#0 %start tt state = stopping to gate(abort call, null, 0) %return %finish %if frame_hb1&1=1 %start %if frame_hb2&2#0 %and frame_data(0)=1 %and frame_data(1)=0 %then %c to tt(echo off) %if frame_hb2&4#0 %then good text=8 %if frame_hb2&8#0 %then garbage=garbage+1 %return %finish garbage=garbage-1 %if frame_hb2&8#0 %if garbage=0 %start printstring(frame_s) printsymbol(k'100000') %if frame_hb2&2 # 0 %if frame_hb2&4=0 %then get buffer(itp gah) %c %else prompt("") %and tt state=opened; ! was a prompt %finish %else %if frame_hb2&4=0 %start get buffer(itp gah); ! after int:a and is text %finish %end %routine from gate !================= %integer i,k,l,len,port %record (mef) %name mes %record (messagef) %name message %switch sw(open call reply:message reply) port = p_port mes == p_mes ->sw(p_fn) sw(open call reply):%return sw(incoming call): %if lp status=opened %start lp port=port printstring("LP:starting ") p_len=16 %if p_len=0 to gate(call reply,p_mes,p_len) lp status=running set stream(5,lp base file) j=lp base file_fname(5)+1 %if j>'9' %start k=lp base file_fname(4)+1 %if k>'4' %start lp base file_fsys=lp base file_fsys+1 k='0' %finish lp base file_fname(4)=k j='0' %finish lp base file_fname(5)=j host_lp count=0; host_lp k=0 print file(5); newline %return %finish to gate(call reply,null,reject) %return sw(input recd): len = mes_len-2-1; ! -2 for 'uflag' -1 because of form of loop beneath to gate(enable input,null,0) %if port=tt port %then do itp(mes) %else %start %if port=lp port %start select output(1) k=0; buff == mes_nsl_rje_data l = mes_nsl_rje_uflag %cycle; !$e %if buff(k)>127 %then k=k+1 %exit %if k>len; !$e printstring(string(addr(buff(k)))) j = buff(k) k = k+j+1 j=j+host_lp count j=j-1024 %and host_lp k=host_lp k+1 %if %c j>=1024 host_lp count=j %repeat select output(0) %finish %finish free buffer(mes) %return sw(output transmitted): %if port=cr port %start %if cr status=stopping %start to gate(close call,null,0) cr status=stopping2 %else p_port=1 get buffer(cr data) %finish %return %finish %if port = tt port %and pend gah#0 %start !! send a go ahead get buffer(itp gah) pend gah = pend gah-1 %finish %return sw(call closed): %if port=tt port %start to gate(close call,null,0) %unless tt state=stopping printstring("tt: closed ") tt state=idle; tt port=-1 %return %finish %if port=lp port %start to gate(close call,null,0) printstring("lp: finished") print count(host_lp k,host_lp count) newline %if lp status=closed %then lp status=idle %c %else lp status=opened; lp port=-1 select output(1); close output set stream(1+4,lp base file); ! frig to get round perm fault %return %finish %if port=cr port %and cr status=stopping2 %start printstring("cr: finished") print count(host_cr k,host_cr count) newline cr status=idle; cr port=-1 %return %finish %return sw(call aborted): %if port=tt port %start to gate(abort call,null,0) %unless tt state=stopping printstring(" tt:aborted ") tt state=idle; tt port=-1 %return %finish %if port = cr port %start to gate(abort call, null, 0) printstring("CR: Aborted ") cr status = idle; cr port = -1 %finish %if port = lp port %start to gate(call aborted, null, 0) printstring("LP: Aborted ") lp status = idle; lp port = -1 select output(1); close output %finish %return sw(open reply a): %if p_facility=18 %then tt port=p_x %else cr port=p_x %return sw(open reply b): %if port=tt port %start %if p_s1#0 %start printstring("tt:connect fails"); write(p_s1,1); newline tt state=idle; tt port=-1 to tt(rd) %else printstring("tt:connected ") tt state=running get buffer(itp hello) pend gah = 3 %finish %return %finish %if port=cr port %start %if p_s1#0 %start alarm(100) %and %return %if cr timer=1 printstring("CR:connect fails "); write(p_s1,0); newline %if cr timer=0 %and cr strm#set pr %start printstring("CR:will keep trying ") alarm(100); cr timer=1 %else cr status=idle; cr port=-1 %finish %else printstring("cr:connected ") host_cr count=0; host_cr k=0 p_port=1 set b flag = bin flag get buffer(cr data) cr status=running cr timer=0 %finish to tt(rd) %return %finish %return sw(message in): message == mes_nsl_message i=p_term; !address write(i,1) print symbol(':') i=0 %cycle spaces(3) %unless i=0 %if message_data(i)>127 %then i=i+1 printstring(string(addr(message_data(i)))) i = i+message_data(i) l = message_data(i); i = i+1 newline %unless l=nl %repeat %until i>=mes_len mes_len = 4 to gate(call reply,mes,128) %return sw(message reply): ! gate vsn 3 onwards printstring("sm:"); write(p_s1, 3); newline free buffer(mes) %end %routine from buffer manager %integer i,j %record (mef) %name mes %record (itpf) %name frame %switch sw(itp hello:social call) mes == p_mes frame==mes_nsl_itp; frame_cnsl=0 block==mes_nsl_rje message==mes_nsl_message ->sw(p_s1) sw(itp hello): frame_hb1=8; frame_hb2=0; frame_len=line length-3 frame_data(i)=line(i+3) %for i=0,1,frame_len-1 mes_len=5+frame_len; !$e to tt(rd) ->end sw(itp gah): free buffer(mes) %and %return %if tt state=idle %orc tt state=stopping frame_hb1=3; frame_hb2=0; frame_len=0; mes_len=4 ->end sw(itp mess): %if gah ct>0 %then gah ct=gah ct-1 %else %start printstring("TT:no gah ") free buffer(mes) to tt(rd) %return %finish frame_hb1=0; frame_hb2=2+good text; frame_len=line length+1 good text=0 frame_data(i)=line(i) %for i=0,1,line length-2 frame_data(i+1)=13; frame_data(i+2)=10 mes_len=4+frame_len tt state=running p_port=tt port to tt(rd) ->end sw(itp int): frame_hb1=1; frame_hb2=1 lptr=lptr+1 %while line(lptr)=' ' frame_len=line length-lptr-1 frame_data(i)=line(lptr+i) %for i=0,1,frame_len-1 mes_len=frame_len+4 p_port=tt port to tt(rd) ->end sw(social call): message_data(i)=line(lptr+i) %for i=1,1,line length-lptr-1 message_data(0)=line length-lptr-1 p_term=p_port; p_port=0; mes_len=line length-lptr mes_nsl_node = node; !$e nasty, but only way to gate(open message,mes,strm) to tt(rd) %return sw(cr data): fill buffer mes_nsl_rje_uflag = 5; ! allways binary now p_port=cr port to gate(put output,mes,0) %return end: mes_len = mes_len+2; !$e allow for uflag word to gate(put output,mes,0) %end %integerfn do tt %integer i %if match(status) %start printstring("TT:"); printstring(stat(tt state)); newline %result=1 %finish %if tt state=idle %start i=1 %if read address#0 %start tt host = term connect(tt host,18) tt state=starting %result=2 %finish %finish%else %if tt state#starting %start %if match(int) %start get buffer(itp int) %result=2 %finish %if match(kill) %start p_port=tt port to gate(abort call,null,0) %unless tt state=stopping tt state=stopping %result=1 %finish %finish %result=0 %end %integerfn do op(%integer stream) %integer i strm = stream %if match(do enable) %start; ! enable messages from gate to gate(enable facility, null, 1) to gate(enable facility, null, 2) to gate(enable facility, null, 4) to gate(enable facility, null, 6); ! pp to gate(enable facility, null, 7); ! bt %result = 1 %finish %if read address # 0 %start p_port=term get buffer(social call) %result=2 %finish %result=0 %end %integerfn do cr %integer i %constbyteintegerarray binx(0:7) = 6, 'B','I','N','A','R','Y',' ' %if match(status) %start printstring("CR:"); printstring(stat(cr status)) %if cr status=running %start print count(host_cr k,host_cr count) print string(", from "); print file(1) %finish newline %result=1 %finish %if cr status=idle %start cr strm = set pr %result = 0 %if read address=0 host_number = term; host_node = node bin flag = 0 %if match(binx) %then bin flag = 1 %if match(printer) %then cr strm = 4 %if match(fen) %then cr strm = 9; ! special fep stream cr line = old line; clp = lptr+1 i = exist(cr file) %if i = 0 %then %result = 1 set stream(1, cr file) connect(term,cr strm) cr status=starting %result=2 %finish %result=0 %end %integerfn do lp %integer i,j %constbyteintegerarray nulla(0:5) = 4, 'N','U','L','L',0 %if match(status) %start i=1 printstring("LP:"); printstring(stat(lp status)) %unless closed#lp status#running %start print count(host_lp k,host_lp count) print string(", to "); print file(i+4) %finish newline %result=1 %finish %if match(nulla) %start lp base file_unit = 255 %result = 1 %finish %if match(filen) %start %result = 0 %unless read fname(lp base file) lp base file_fname(4)='0'; lp base file_fname(5)='0' %result=1 %finish i=1 %if match(do enable) %start j=lp status %if j=idle %or j=closed %start printstring("LP:enabled") %if j=idle %then j=opened %else j=running %else printstring("LP:disabled") %if j=running %then j=closed %else j=idle %finish lp status=j newline %result=1 %finish %result=0 %end lp base file_unit=0; lp base file_fsys=k'16' lp base file_fname(i)=spool base(i) %for i=0,1,5 printstring(vsn) i = map virt(buffer manager,5,4) i = map virt(buffer manager, 6, 5) to gate(enable facility,null,9) printstring(" lp:enabled sm:disabled ") to tt(rd) lp status = opened linkin(nsiw ser) %cycle p_service=0; poff(p) %if p_reply=gate ser %start from gate %finish%else %if p_reply =buffer manager %start from buffer manager %finish%else %if p_reply=tt no %start line length=0 line length=line length+1 %while line(line length)#nl line length = line length+1 line(-1) = line length old line = string(addr(line(-1))) lptr=3 %if line(2)='/' %start i=0 charno(new, 1) = line(0)&(\32); charno(new, 2) = line(1)&(\32) %cycle j = 1, 1, max com ->sw(j) %if coms(j) = new %repeat ->bot sw(1): ! tt i=do tt ->bot sw(2): ! op i = do op(11) ->bot sw(4): ! cr i = do cr; -> bot sw(5): ! sp (special) i = 0; ->bot sw(6): ! lp i = do lp; -> bot sw(7): ! tl (tell) sw(8): ! sm (send message) i = do op(2); ->bot sw(3): ! zz sw(9): sw(10): !stop to gate(disable facility,null,9) to gate(disable facility,null,6) to gate(disable facility,null,7) to gate(disable facility, null, 4) to gate(disable facility, null, 2) %exit bot: to tt(rd) %if i=1 %continue %if i>0 %finish %if tt state>=running %then get buffer(itp mess) %else %start printstring("tt:invalid ") to tt(rd) %finish %else connect(host_number,cr strm) %finish %repeat !map virt(gate ser,7,4) !gate int='d' !to tt(12) %endofprogram }