Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: XML1CRC

XML1CRC.m

Go to the documentation of this file.
XML1CRC ;(WASH ISC)/RJ-OS Check Sum ;04/17/2002  10:58
 ;;8.0;MailMan;**45**;Jun 28, 2002;Build 9
OPEN D GET,OP
 S:'$D(XMESC) XMESC="~" S:'$D(XMFS) XMFS=255 S:'$D(XM) XM="" S (XMSSQ,XMRSQ)=1 Q
GET S X=XMCHAN,DIC="^DIC(3.4,",DIC(0)="Z" D ^DIC S XMCHAN=+Y
 I '$D(^DIC(3.4,XMCHAN,0)) S ER=1,Y="Invalid channel" Q
G2 S XMPROT=$P(^DIC(3.4,XMCHAN,0),U)
 F X=1:1:4 S @($P("XMSEN^XMREC^XMOPEN^XMCLOSE",U,X))=$S($D(^(X)):^(X),1:"Q")
 Q
OP I $D(XMOPEN) X:$L(XMOPEN) XMOPEN
 I '$D(XMQUIET) S X=255 X ^%ZOSF("RM")
 Q
C X ^%ZOSF("EON")
 I $D(XMCLOSE) X:$L(XMCLOSE) XMCLOSE
 Q
SEND ;returns ER(0 OR 1), XMLER=number of "soft" errors
 I $L(XMSG)>255 S XMLER=0,ER=1 G SRQ
 I XMSG'?.ANP F %=1:1:$L(XMSG) I $E(XMSG,%)?1C,$A(XMSG,%)'=9 S XMSG=$E(XMSG,1,%-1)_$E(XMSG,%+1,999) Q:XMSG?.ANP  S %=%-1
 D SRINIT S X=XMSG D SUM
 I $G(XMINST) D XMTSTAT^XMTDR(XMINST,"S",XMSG,0) ; 1SCP
SL S XMLER=XMLER+1 I (XMLER+1)>XMLMAXER D NEWSTRAT
 I ER W XMLERR,$C(13) G SRQ
 D BUFLUSH W XMSG,$C(13),XMLINE,U,XMSUM,$C(13) R XMLX:XMLTIME G:XMLX=(XMLINE_U_XMLACK) SRQ
 S XMLY=XMLX=(XMLINE_U_XMLNAK),XMLZ=0 D:'XMLY ENQ G SL:XMLY,SRQ
ENQ ;ACK/NAK garbled / re-establish contact
 S XMLZ=XMLZ+1 I XMLZ>XMLMAXER S (ER,XMLY)=1 Q
 D BUFLUSH W XMLENQ,$C(13) R XMLX:XMLTIME Q:XMLX=(XMLINE_U_XMLACK)
 I XMLX[XMLACK!(XMLX[XMLNAK),+XMLX=XMLINE!(+XMLX=XMLINE-1) S XMLY=1 Q
 H 1 G ENQ
REC ;SEE SEND
 D SRINIT S:'$D(XMLAN) XMLAN=XMLINE_U_XMLNAK
 I $D(XMRG),$G(XMINST) D XMTSTAT^XMTDR(XMINST,"R",XMRG,0) ; 1SCP
RL S XMLER=XMLER+1 I (XMLER+1)>XMLMAXER D NEWSTRAT I ER=1 G SRQ
 R XMRG#255:$S($D(XMSTIME):XMSTIME,1:XMLTIME)
 S XMLZ=$S('$T:-1,XMRG=XMLENQ:0,XMRG=XMLERR:2,1:1)
 S ER=XMLZ=2 G:XMLZ>1 SRQ I 'XMLZ D BUFLUSH W XMLAN,$C(13) G RL
 R XMLY:XMLTIME I +XMLY=XMLINE S X=XMRG D SUM S XMLZ=XMSUM=$P(XMLY,U,2) G RL2
 S XMLZ=0 I +XMLY=(XMLINE-1),XMLINE'=1 D BUFLUSH W +XMLY,U,XMLACK,$C(13) G RL
RL2 S XMLAN=XMLINE_U_$S(XMLZ:XMLACK,1:XMLNAK) D BUFLUSH W XMLAN,$C(13)
 G SRQ:XMLZ,RL
SRINIT ;
 S XMLINE=$S('$D(XMLINE):1,1:XMLINE+1),XMLACK="ACK",XMLNAK="NAK"
 S XMLENQ=$C(9)_"ENQ"_$C(9),XMLERR=$C(9)_"ERROR"_$C(9)
 S XMLER=-1 ;soft error count
 S XMLMAXER=5 ;maximum allowable soft errors
 S XMLTIME=30 ;length of READ time
 S ER=0 ;non-recoverable error flag
 Q
NEWSTRAT ;machines have various loads
 I XMLMAXER=5 S ER=1 Q  ;already tried new strategy, give up.
 S XMTLER=$S('$D(XMTLER):XMLER,1:XMTLER+XMLER),XMLER=0 ;add to total
 S XMLMAXER=5 ;reduce allowable soft errors
 S XMLTIME=30 ;increase the READ time
 Q
SRQ ;Exit from Send/Receive
 S XMTLER=$S('$D(XMTLER):XMLER,1:XMTLER+XMLER) ;Total errors
 K XMLACK,XMLNAK,XMLENQ,XMLERR,XMLMAXER,XMLTIME,XMLX,XMLY,XMLZ
 Q
BUFLUSH ;Flush any characters out of the buffer
 Q:'$D(XMBFLUSH)
 X ^%ZOSF("TRMON") S X=$P($H,",",2) F %=1:1 R %:0 Q:'$T  S %=$P($H,",",2) S:%<X %=%+86400 Q:%-X>15
 X ^%ZOSF("TRMOFF") Q
SUM ;Calculate checksum
 I '$D(XMOS) D LPC^XMLSWP0
 I $D(XMOS(0)) X XMOS(0) S XMSUM=Y Q
 I XMOS["VAX DSM" X "S XMSUM=$ZC(%LPC,X)" Q
 I XMOS["DSM" X "S XMSUM=$ZC(LPC,X)" Q
 I XMOS["M/11"!(XMOS["M/VX") X "S XMSUM=$ZC(X)" Q
 S XMSUM=$A(X) Q:$L(X)=1  S I=1
A S I=I+1 I $L(X)<I K %,%0,%1 S XMSUM=XMSUM+$L(X)*$L(X) Q
 S Y=$A(X,I) F %=256:0 Q:%\4<Y  S %=%\2
B S %0=XMSUM#%,%=%\2 G A:%=0 S %0=%0\%,%1=Y\% I %1=1 S Y=Y-%
 G B:%1+%0=0 I %1'=%0 S:%0=0 XMSUM=XMSUM+% G B
 G B:%0=0 S XMSUM=XMSUM-%
 G B