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

XMC1A.m

Go to the documentation of this file.
  1. XMC1A ;(WASH ISC)/THM-Script Interpreter (Look) ;12/04/2002 15:04
  1. ;;8.0;MailMan;**11**;Jun 28, 2002
  1. ;LOOK For Text
  1. ;
  1. ; There can only be one 'B' in a LOOK command. It may be preceeded by
  1. ; at least one 'A' and succeeded by as many 'C's as desired.
  1. ; The 'B' parameter may be null. In this case two spaces would
  1. ; separate the 'A' parameters for the 'C' parameters.
  1. ;
  1. ;X=SCRIPT COMMAND 'L:Timeout A A A ... B C C C ...'
  1. ;
  1. ;The string represented by 'x' must always have a length >0.
  1. ;The string being looked for must always be surrounded by '|'s.
  1. ;To use the new form, the looked for strings must be surrounded by '|'s.
  1. ; If no '|'s are found, it is assumed to be of the old form
  1. ; (see example 4 below).
  1. ;There must not be any '|'s for the "OLD" form as the 1st character
  1. ; after the 1st space in the string.
  1. ;The 1st character after the 1st space in the string must be a '|'
  1. ; in the "NEW" form.
  1. ;Condition A is always checked first
  1. ;
  1. ;WHERE 'A' (mandatory) has form 'x' / QUIT on finding string 'x'
  1. ; or 'x:y' / GOTO line 'y' on finding 'x'
  1. ;
  1. ;WHERE 'C' (optional) has form 'x' / QUIT setting ER=1 on finding 'x'
  1. ;
  1. ;WHERE 'B' (optional) has form 'y' / GOTO 'y' on timeout
  1. ;
  1. ;********************************************************************
  1. ;
  1. ;Examples:
  1. ;
  1. ; 1. Look for "LINE" or "CONNECTED" on a timeout just error out
  1. ; (Where the command is on line 3)
  1. ;
  1. ; L |LINE|:3 |CONNECTED|:3
  1. ; or
  1. ; L |LINE| |CONNECTED|
  1. ;
  1. ; 2. Look for "LINE" and if found go to line 15 of this script
  1. ; Look for "CONNECTED" and if found go to line 18 of this script.
  1. ; Go to line 25 of this script on a time out.
  1. ; If "DISCON" is found error out.
  1. ;
  1. ; L |LINE|:15 |CONNECTED|:18 25 |DISCON|
  1. ;
  1. ; 3. Same case as 2 except that on a timeout just error out.
  1. ;
  1. ; L |LINE|:15 |CONNECTED|:18 |DISCON|
  1. ;
  1. ; (Note that '18' is followed by 2 spaces [Timeout is null])
  1. ;
  1. ; 4. Look for 'ON LINE', then look for the string 'CONNECTED'
  1. ;
  1. ; L |ON LINE|:6 |CONNECTED|
  1. ;
  1. ; This is a little tricky. The old syntax for looking for a
  1. ; string took $P(X," ",2,999) as the argument, where X is the
  1. ; entire script command. To be backwards compatible, there must
  1. ; be '|'s surrounding all of the strings being looked for.
  1. ;
  1. ;****************************************************************
  1. ;
  1. ; The old syntax still works:
  1. ;
  1. ; L ON LINE
  1. ;
  1. ; is interpreted in the old way as look for the phrase "ON LINE"
  1. ;
  1. ;*****************************************************************
  1. ;
  1. ; VARIABLES
  1. ;
  1. ;XMC1A(,,) === Array of checks XMC1A(1,,)=success checks
  1. ; XMC1A(2,1,1)=timout (also XMC1A(2))
  1. ; XMC1A(3,,)=failure checks
  1. ;failure is type 'C', success is type 'A', time-out is Type 'B' above
  1. LOOK ;For Text (See documentation above)
  1. ; X = command line from file 4.6
  1. ; = 'L:180 220'
  1. N XMC1A,XMK,XMTIME,C,I,J,Y,%
  1. S XMC1A("TIMEOUT")=+$P($P(X," "),":",2)
  1. I 'XMC1A("TIMEOUT") S XMC1A("TIMEOUT")=45
  1. S XMTIME=$$TSTAMP^XMXUTIL1+XMC1A("TIMEOUT")
  1. S XMK=1
  1. S Y=1
  1. ;Recode encoded control characters
  1. S XMC1A("LOOK")=XMC1
  1. I XMC1["~" S XMC1=$$RTRAN^XMCU1(XMC1)
  1. ;Parse to separate time-outs/success/error conditions
  1. ;'OLD' form
  1. I $E(XMC1)'="|",XMC1'?1.N1" |".E S XMC1A(1,1,1)=XMC1,XMC1A(1,1,2)="" G G
  1. ;'NEW' form
  1. S I=0
  1. E ;
  1. S I=I+1
  1. I Y=1,XMC1?1.N1" |".E D TIMOUT G F
  1. I Y=1,XMC1?1" " S Y=2,XMC1=$E(XMC1,3,999) G F
  1. S %=Y
  1. S Y=$S(Y=3:Y,Y=2:3,XMC1?1.N1" |".E:2,$E(XMC1,1,2)=" ":3,XMC1?1" "1.N1" ":2,XMC1?1" "1.N:2,Y=1&(I>1)&(XMC1?1.N):2,XMC1?1" |".E:3,1:Y)
  1. I Y=2 S:$E(XMC1)=" " XMC1=$E(XMC1,2,999) D TIMOUT G F
  1. S:Y>% I=1
  1. S X=$P(XMC1,"|",2)
  1. S XMC1=$E(XMC1,$L($P(XMC1,"|",1,2))+1,999)
  1. S %=""
  1. I $E(XMC1,1,2)="|:" S %=$P($P(XMC1," "),":",2),XMC1=$P(XMC1,"|:",2,99) I %,$E(XMC1,1,2)'=" " S XMC1=$P(XMC1," ",2,99) G E1
  1. I $E(XMC1)="|" S XMC1=$E(XMC1,2,99)
  1. E1 ;
  1. I $S($L(X):1,$L(%):1,1:0) S XMC1A(Y,I,1)=X,XMC1A(Y,I,2)=%
  1. F ;
  1. G E:$L(XMC1)
  1. ;Save Timeout for efficient access
  1. I $D(XMC1A(2)) S XMC1A(2)=XMC1A(2,1,1)
  1. G ;
  1. D DOTRAN^XMC1(42240,XMC1A("TIMEOUT"),XMC1A("LOOK")) ;Look: Timeout=|1|, Command String='|2|'
  1. U IO
  1. X ^%ZOSF("TRMON")
  1. S ER=0,Y=^%ZOSF("TRMRD"),XMC1A("TRMRD")="N Y "_Y_" S C=Y Q"
  1. L1 ;
  1. S Y=""
  1. D L2
  1. S XMK=XMK+1
  1. I XMC("SHOW TRAN")["R" D DOTRAN^XMC1("R: "_Y)
  1. G LQ:$D(XMC1A("OK"))
  1. I ER=1 D ERTRAN^XMC1(37001) S J=$G(XMC1A(2)) G LQ:'J S ER=0 G GO ;Time out.
  1. I XMK>199 D DOTRAN^XMC1(42241) S J=$G(XMC1A(2)) G GO:J S ER=1 Q ;200 Reads!
  1. G L1
  1. L2 ;
  1. N C,X
  1. L3 ;
  1. X "R X#"_$S(XMC1A("LOOK")[220:3,220-$L(Y)>0:220-$L(Y),1:1)_$S($D(XMDECNET):"",1:":1")
  1. S Y=Y_X
  1. X XMC1A("TRMRD")
  1. I C>0 S Y=Y_"~"_$S(C+64<255:$C(C+64),1:"~")
  1. F I=1,3 F %=0:0 S %=$O(XMC1A(I,%)) Q:'% I Y[XMC1A(I,%,1) S J=XMC1A(I,%,2) G GO:J'="",OK:I=1 S ER=1 Q
  1. I $S($L(Y)>220:1,C=13:1,1:0) Q
  1. I $$TSTAMP^XMXUTIL1<XMTIME H 1 G L3 ; H 1 added to slow loop
  1. S ER=1
  1. Q
  1. LQ ;
  1. K XMC1A
  1. X ^%ZOSF("TRMOFF")
  1. Q
  1. GO ;
  1. S XMCI=J-.00001
  1. OK ;
  1. S XMC1A("OK")=1
  1. Q
  1. TIMOUT ;
  1. S Y=2,XMC1A(2,1,1)=+XMC1,XMC1=$P(XMC1," ",2,99)
  1. Q