AZHLSCU2 ; IHS/ADC/GTH:KEU - UNDEF CHECKER. PROCESS "GRB" ;
;;5.0;AZHLSC;;JUL 10, 1996
% S LINE=GRB,COM="" F I=0:0 S STR=$P(LINE,$C(9),1),LINE=$P(LINE,$C(9),2,999),NOA=0 D:STR]"" ARGG Q:LINE']""
Q
;Process argument
ARGG D ^AZHLSCU9 S I=0,AC=999 F %=0:0 S %=$O(LV(%)) Q:%'>0 S I(%)=0
ARGS ;Proccess all agruments at this level
S AC=LI+AC F Q:AC'>LI D INC Q:S="" D ARG
Q
;
ARG ;Process one argument
I CH="," D PEEK Q
Q:CH=Q
I (CH?1A)!(CH="%") D LOC Q
I CH="^" S LOC="G" G NAK:S="^",EXTGLO:S["[",GLO Q
I CH="$" D FUN Q
I CH="?" D PAT Q
I CH="(" D INC S NOA=S D DN,INC Q
Q
;
NAK S LOC="N" G GLO
EXTGLO D EG,INC S S=U_S
G GLO
EG N GK,LOC S GK="",LOC="L" ;HANDLE EXTENDED GLOBAL
F D INC Q:"]"[CH D ARG
Q
GLO S X=$E(S,2,99)
I S1="(" S S=S_S1 D PEEKDN S:(Y?1.N)!($A(Y)=34)!("^$J^$I^$H^"[(U_Y)) S=S_Y
D ST(LOC,S) I S1="(" D INC2 S NOA=S D DN,INC
Q
LOC S LOC="L"
I S1="(" S S=S_S1 D PEEKDN S:(Y?1.N)!($A(Y)=34) S=S_Y
D ST(LOC,S) I S1="(" D INC2 S NOA=S D DN,INC
Q
PEEK S Y=$G(LV(LV,LI+1)) Q
INC2 S LI=LI+1 ;Drop into INC
INC S LI=LI+1,S=$G(LV(LV,LI)),S1=$G(LV(LV,LI+1)),CH=$E(S) G:$A(S)=10 ERR Q
DN S LI(LV)=LI,LI(LV,1)=AC,LV=LV+1,LI=LI(LV),AC=NOA
D ARGS,UP Q
UP ;Inc LI as we save to skip the $C(10).
D PEEK D:$A(Y)'=10 ERR S LI(LV)=LI+1,LV=LV-1,LI=LI(LV),AC=LI(LV,1) Q
PEEKDN S Y=$G(LV(LV+1,LI(LV+1)+1)) Q
ERR S (S,S1,CH)="" Q
S Z=$P(LV(LV+1),$C(9),LI(LV+1),99),Z=$P(Z,$C(10)) W !,"COUNT=",$L(Z,",")
;functions
FUN N FUN S FUN=S G EXT:S["$$",SPV:S1'["(" S NOA=$P(S,"^",2)
D INC2
I FUN'["$$" G:FUN["$TE" TEXT I FUN["$N" D ST("MK","$N")
S Y=1 F Z1=LI(LV+1)+1:1 S X=$G(LV(LV+1,Z1)) Q:$A(X)=10!(X="") S:X="," Y=Y+1
S NOA=S D DN,INC
Q
;
TEXT D PEEKDN S NOA=S D ST("MK","$T("_$S($$VN(Y):Y,1:"")) I $$VN(Y) S LI(LV+1)=LI(LV+1)+1,NOA=NOA-1 D ST("I",Y)
D DN,INC Q
;special variables
SPV ;
Q
EXT ;Extrinsic functions
I $E(S1)="^" S Y=$E(S1,2,99)_" "_S D INC S S=Y ;Build S and fall thru
D ST($S(S[" ":"X",1:"I"),S) ;Internal, eXternal
I S1["(" D INC2 S NOA=S D DN,INC ;Process param.
Q
PAT F I=2:1 S CH=$E(S,I) D PATQ:CH=Q I CH=""!(CH'?1N&("ACELNPU."'[CH)) Q
S S=$E(S,I,999) Q
PATQ F I=I+1:1 S CH=$E(S,I) Q:CH=""!(CH=Q)
S I=I+1,CH=$E(S,I) G:CH=Q PATQ
Q
ST(LOC,S) S:'$D(V(LOC,S)) V(LOC,S)="" I $D(GK),GK]"",V(LOC,S)'[GK S V(LOC,S)=V(LOC,S)_GK
S GK="" Q
VN(X) ;Check if a valid name
Q (X?1A.7AN)!(X?1"%".7AN)!(X?1.8N)
AZHLSCU2 ; IHS/ADC/GTH:KEU - UNDEF CHECKER. PROCESS "GRB" ;
+1 ;;5.0;AZHLSC;;JUL 10, 1996
% SET LINE=GRB
SET COM=""
FOR I=0:0
SET STR=$PIECE(LINE,$CHAR(9),1)
SET LINE=$PIECE(LINE,$CHAR(9),2,999)
SET NOA=0
IF STR]""
DO ARGG
IF LINE']""
QUIT
+1 QUIT
+2 ;Process argument
ARGG DO ^AZHLSCU9
SET I=0
SET AC=999
FOR %=0:0
SET %=$ORDER(LV(%))
IF %'>0
QUIT
SET I(%)=0
ARGS ;Proccess all agruments at this level
+1 SET AC=LI+AC
FOR
IF AC'>LI
QUIT
DO INC
IF S=""
QUIT
DO ARG
+2 QUIT
+3 ;
ARG ;Process one argument
+1 IF CH=","
DO PEEK
QUIT
+2 IF CH=Q
QUIT
+3 IF (CH?1A)!(CH="%")
DO LOC
QUIT
+4 IF CH="^"
SET LOC="G"
IF S="^"
GOTO NAK
IF S["["
GOTO EXTGLO
GOTO GLO
QUIT
+5 IF CH="$"
DO FUN
QUIT
+6 IF CH="?"
DO PAT
QUIT
+7 IF CH="("
DO INC
SET NOA=S
DO DN
DO INC
QUIT
+8 QUIT
+9 ;
NAK SET LOC="N"
GOTO GLO
EXTGLO DO EG
DO INC
SET S=U_S
+1 GOTO GLO
EG ;HANDLE EXTENDED GLOBAL
NEW GK,LOC
SET GK=""
SET LOC="L"
+1 FOR
DO INC
IF "]"[CH
QUIT
DO ARG
+2 QUIT
GLO SET X=$EXTRACT(S,2,99)
+1 IF S1="("
SET S=S_S1
DO PEEKDN
IF (Y?1.N)!($ASCII(Y)=34)!("^$J^$I^$H^"[(U_Y))
SET S=S_Y
+2 DO ST(LOC,S)
IF S1="("
DO INC2
SET NOA=S
DO DN
DO INC
+3 QUIT
LOC SET LOC="L"
+1 IF S1="("
SET S=S_S1
DO PEEKDN
IF (Y?1.N)!($ASCII(Y)=34)
SET S=S_Y
+2 DO ST(LOC,S)
IF S1="("
DO INC2
SET NOA=S
DO DN
DO INC
+3 QUIT
PEEK SET Y=$GET(LV(LV,LI+1))
QUIT
INC2 ;Drop into INC
SET LI=LI+1
INC SET LI=LI+1
SET S=$GET(LV(LV,LI))
SET S1=$GET(LV(LV,LI+1))
SET CH=$EXTRACT(S)
IF $ASCII(S)=10
GOTO ERR
QUIT
DN SET LI(LV)=LI
SET LI(LV,1)=AC
SET LV=LV+1
SET LI=LI(LV)
SET AC=NOA
+1 DO ARGS
DO UP
QUIT
UP ;Inc LI as we save to skip the $C(10).
+1 DO PEEK
IF $ASCII(Y)'=10
DO ERR
SET LI(LV)=LI+1
SET LV=LV-1
SET LI=LI(LV)
SET AC=LI(LV,1)
QUIT
PEEKDN SET Y=$GET(LV(LV+1,LI(LV+1)+1))
QUIT
ERR SET (S,S1,CH)=""
QUIT
+1 SET Z=$PIECE(LV(LV+1),$CHAR(9),LI(LV+1),99)
SET Z=$PIECE(Z,$CHAR(10))
WRITE !,"COUNT=",$LENGTH(Z,",")
+2 ;functions
FUN NEW FUN
SET FUN=S
IF S["$$"
GOTO EXT
IF S1'["("
GOTO SPV
SET NOA=$PIECE(S,"^",2)
+1 DO INC2
+2 IF FUN'["$$"
IF FUN["$TE"
GOTO TEXT
IF FUN["$N"
DO ST("MK","$N")
+3 SET Y=1
FOR Z1=LI(LV+1)+1:1
SET X=$GET(LV(LV+1,Z1))
IF $ASCII(X)=10!(X="")
QUIT
IF X=","
SET Y=Y+1
+4 SET NOA=S
DO DN
DO INC
+5 QUIT
+6 ;
TEXT DO PEEKDN
SET NOA=S
DO ST("MK","$T("_$SELECT($$VN(Y):Y,1:""))
IF $$VN(Y)
SET LI(LV+1)=LI(LV+1)+1
SET NOA=NOA-1
DO ST("I",Y)
+1 DO DN
DO INC
QUIT
+2 ;special variables
SPV ;
+1 QUIT
EXT ;Extrinsic functions
+1 ;Build S and fall thru
IF $EXTRACT(S1)="^"
SET Y=$EXTRACT(S1,2,99)_" "_S
DO INC
SET S=Y
+2 ;Internal, eXternal
DO ST($SELECT(S[" ":"X",1:"I"),S)
+3 ;Process param.
IF S1["("
DO INC2
SET NOA=S
DO DN
DO INC
+4 QUIT
PAT FOR I=2:1
SET CH=$EXTRACT(S,I)
IF CH=Q
DO PATQ
IF CH=""!(CH'?1N&("ACELNPU."'[CH))
QUIT
+1 SET S=$EXTRACT(S,I,999)
QUIT
PATQ FOR I=I+1:1
SET CH=$EXTRACT(S,I)
IF CH=""!(CH=Q)
QUIT
+1 SET I=I+1
SET CH=$EXTRACT(S,I)
IF CH=Q
GOTO PATQ
+2 QUIT
ST(LOC,S) IF '$DATA(V(LOC,S))
SET V(LOC,S)=""
IF $DATA(GK)
IF GK]""
IF V(LOC,S)'[GK
SET V(LOC,S)=V(LOC,S)_GK
+1 SET GK=""
QUIT
VN(X) ;Check if a valid name
+1 QUIT (X?1A.7AN)!(X?1"%".7AN)!(X?1.8N)