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

KMPDU2.m

Go to the documentation of this file.
  1. KMPDU2 ;OAK/RAK - CM Tools Routine Utilities ;08/31/11 09:21
  1. ;;3.0;KMPD;;Jan 22, 2009;Build 42
  1. ;
  1. IRSRC(KMPDDA) ;-- extrinsic function - check for local mods in INSTALL file
  1. ;-----------------------------------------------------------------------
  1. ; KMPDDA... DA as defined in fileman programmers manual.
  1. ;
  1. ; Return: "NO" - no local mods.
  1. ; "YES" - local mods.
  1. ;
  1. ; This extrinsic function is called from computed field #573099 (LOCAL
  1. ; MODIFICATIONS) in file #9.7 (INSTALL).
  1. ;-----------------------------------------------------------------------
  1. ;
  1. Q:'$G(KMPDDA) "NO"
  1. ;
  1. N I,RTN,RETURN
  1. S I=0,RETURN="NO"
  1. F S I=$O(^XPD(9.7,KMPDDA,"RTN",I)) Q:'I D Q:RETURN="YES"
  1. .Q:'$D(^XPD(9.7,KMPDDA,"RTN",I,0)) S RTN=$P(^(0),U)
  1. .S:$$ROUSRC1(RTN,"LOCAL MOD/") RETURN="YES"
  1. .;S:$$ROUSRC1(RTN,"/LOCAL MOD/") RETURN="YES"
  1. ;
  1. Q RETURN
  1. ;
  1. ROUFIND(KMPDY,KMPDRNM,KMPDGBL) ;-- find routines.
  1. ;-----------------------------------------------------------------------
  1. ; KMPDRNM.. Routine name to search for.
  1. ; KMPDGBL... Global to store data. Stored in format:
  1. ; RoutineName^RoutineSize^Checksum
  1. ;-----------------------------------------------------------------------
  1. ;
  1. K KMPDY
  1. ;
  1. S KMPDRNM=$G(KMPDRNM),KMPDGBL=$G(KMPDGBL)
  1. ;
  1. I KMPDRNM="" S KMPDY="[Routine not defined]" Q
  1. I KMPDGBL="" S KMPDY="[Global for storage is not defined]" Q
  1. ;
  1. N DATA,LN,ROU,RTN,X,Y
  1. ;
  1. ; kill global with check for ^tmp or ^utility.
  1. D KILL^KMPDU(.DATA,KMPDGBL)
  1. ; if error.
  1. I $E(DATA)="[" S KMPDY=DATA Q
  1. ;
  1. S KMPDY=$NA(@KMPDGBL)
  1. ;
  1. ; remove all spaces
  1. S KMPDRNM=$TR(KMPDRNM," ","")
  1. ; if just one routine
  1. I $E(KMPDRNM,$L(KMPDRNM))'["*" D Q
  1. .; if invalid routine name
  1. .I '$$ROUNAME(KMPDRNM) S @KMPDGBL@(0)="<"_KMPDRNM_" contains invalid characters or is greater than 8 characters length>" Q
  1. .; if routine not defined.
  1. .I '$D(^$ROUTINE(KMPDRNM)) S @KMPDGBL@(0)="<Routine "_KMPDRNM_" not defined>" Q
  1. .I $G(^%ZOSF("OS"))["OpenM",'$D(^ROUTINE(KMPDRNM)) S @KMPDGBL@(0)="<Routine "_KMPDRNM_" missing source code>" Q
  1. .; if defined.
  1. .S $P(@KMPDGBL@(0),U)=KMPDRNM
  1. .; checksum
  1. .S X=KMPDRNM X ^%ZOSF("RSUM1") S $P(@KMPDGBL@(0),U,2)=Y
  1. ;
  1. ; remove "*" if any.
  1. S:$E(KMPDRNM,$L(KMPDRNM))="*" KMPDRNM=$E(KMPDRNM,1,$L(KMPDRNM)-1)
  1. I '$$ROUNAME(KMPDRNM) S @KMPDGBL@(0)="<"_KMPDRNM_" contains invalid characters or is greater than 8 characters in length>" Q
  1. S ROU=$$ENDCHAR(KMPDRNM),RTN=KMPDRNM,LN=0
  1. F S ROU=$O(^$ROUTINE(ROU)) Q:ROU=""!($E(ROU,1,$L(RTN))'=RTN)!(LN>1000) D
  1. .I $G(^%ZOSF("OS"))["OpenM",'$D(^ROUTINE(ROU)) S @KMPDGBL@(LN)=ROU_"^no source",LN=LN+1 Q
  1. .S $P(@KMPDGBL@(LN),U)=ROU
  1. .; checksum
  1. .S X=ROU X ^%ZOSF("RSUM1") S $P(@KMPDGBL@(LN),U,2)=Y
  1. .S LN=LN+1
  1. ;
  1. S:'$D(@KMPDGBL) KMPDY(0)="<No Data To Report>"
  1. ;
  1. Q
  1. ;
  1. ROUINQ(KMPDY,KMPDROU) ;-- routine inquiry.
  1. ;----------------------------------------------------------------------
  1. ; KMPDROU.. Routine(s) to search (this may be a partial name.
  1. ;----------------------------------------------------------------------
  1. ;
  1. K KMPDY
  1. ;
  1. S KMPDROU=$G(KMPDROU)
  1. I KMPDROU="" S KMPDY(0)="[Routine name not defined]" Q
  1. I '$$ROUNAME(KMPDROU) S @KMPDGBL@(0)="<"_KMPDROU_" contains invalid characters or is greater than 8 characters in length>" Q
  1. I '$D(^$ROUTINE(KMPDROU)) S KMPDY(0)="[Routine '"_KMPDROU_"' not defined]" Q
  1. ;
  1. N DIF,I,LN,ROU,X,XCNP
  1. ;
  1. S DIF="ROU(",XCNP=0
  1. S X=KMPDROU X ^%ZOSF("TEST")
  1. I '$T S KMPDY(0)="[Routine '"_KMPDROU_"' not defined]" Q
  1. I $G(^%ZOSF("OS"))["OpenM",'$D(^ROUTINE(KMPDROU)) S KMPDY(0)="[Unable to load routine - no source code]" Q
  1. X ^%ZOSF("LOAD")
  1. S (I,LN,LN(0))=0
  1. F S I=$O(ROU(I)) Q:'I I $D(ROU(I,0)) D
  1. .S X=$P(ROU(I,0)," ",1),ROU(I,0)=$P(ROU(I,0)," ",2,999)
  1. .I $A($E(X))>32 S LN(0)=0
  1. .I LN(0)>0,(LN(0)#10)=0 S X="[+"_LN(0)_"]"
  1. .S KMPDY(LN)=$$LJ^XLFSTR(X,8," ")_ROU(I,0),LN=LN+1,LN(0)=LN(0)+1
  1. ;
  1. S:'$D(KMPDY) KMPDY(0)="[Unable to load routine]"
  1. ;
  1. Q
  1. ;
  1. ROUSRC(KMPDY,KMPDROU,KMPDTXT) ;-- routine search
  1. ;----------------------------------------------------------------------
  1. ; KMPDROU.. Routine(s) to search (this may be a partial name.
  1. ; KMPDTXT.. Text to search for in routine.
  1. ;----------------------------------------------------------------------
  1. ;
  1. K KMPDY
  1. ;
  1. S KMPDROU=$G(KMPDROU),KMPDTXT=$$UP^XLFSTR($G(KMPDTXT))
  1. ;
  1. I KMPDROU="" S KMPDY(0)="[Routine(s) not defined]" Q
  1. I KMPDTXT="" S KMPDY(0)="[Search Text not defined]" Q
  1. ;
  1. N LN,RN,RTN,STAR
  1. ;
  1. S RTN=KMPDROU,STAR=$E(RTN,$L(RTN))
  1. S:STAR="*" RTN=$E(RTN,1,$L(RTN)-1)
  1. ;
  1. ; if just one routine.
  1. I STAR'="*" D Q
  1. .I '$$ROUNAME(RTN) S @KMPDGBL@(0)="<"_RTN_" contains invalid characters or is greater than 8 characters in length>" Q
  1. .; if match.
  1. .I $$ROUSRC1(RTN,KMPDTXT) S KMPDY(0)=RTN Q
  1. .; else no match.
  1. .S KMPDY(0)="<No Matches Found>"
  1. ;
  1. S RN=RTN,LN=0
  1. F S RN=$O(^$ROUTINE(RN)) Q:RN=""!($E(RN,1,$L(RTN))'=RTN) D
  1. .; if match.
  1. .I $$ROUSRC1(RN,KMPDTXT) S KMPDY(LN)=RN,LN=LN+1 Q
  1. ;
  1. S:'$D(KMPDY) KMPDY(0)="<No Matches Found>"
  1. ;
  1. Q
  1. ;
  1. ROUSRC1(KMPDROU,KMPDTXT) ;-- extrinsic function - check for text.
  1. ;----------------------------------------------------------------------
  1. ; KMPDROU.. Routine(s) to search (this may be a partial name.
  1. ; KMPDTXT.. Text to search for in routine.
  1. ;
  1. ; Return: 0 - no match.
  1. ; 1 - match.
  1. ;----------------------------------------------------------------------
  1. ;
  1. S KMPDROU=$G(KMPDROU),KMPDTXT=$$UP^XLFSTR($G(KMPDTXT))
  1. ;
  1. Q:KMPDROU="" 0
  1. Q:KMPDTXT="" 0
  1. ;
  1. N DIF,I,RETURN,ROU,X,XCNP
  1. ;
  1. S DIF="ROU(",(I,RETURN,XCNP)=0,RETURN=0
  1. S X=KMPDROU X ^%ZOSF("TEST")
  1. Q:'$T 0
  1. I $G(^%ZOSF("OS"))["OpenM",'$D(^ROUTINE(KMPDROU)) Q
  1. X ^%ZOSF("LOAD")
  1. F S I=$O(ROU(I)) Q:'I I $D(ROU(I,0)) D Q:RETURN
  1. .I $$UP^XLFSTR(ROU(I,0))[KMPDTXT S RETURN=1
  1. ;
  1. Q RETURN
  1. ;
  1. ROUSRC2(KMPDY,KMPDTXT,KMPDGBL,KMPDROU) ;-- search for text in routine.
  1. ;----------------------------------------------------------------------
  1. ; KMPDTXT.. Text to search for in routine.
  1. ; KMPDGBL... Global to store data.
  1. ; KMPDROU.. array containing routine names to be searches.
  1. ;-----------------------------------------------------------------------
  1. ;
  1. K KMPDY
  1. ;
  1. S KMPDTXT=$G(KMPDTXT),KMPDGBL=$G(KMPDGBL)
  1. ;
  1. I '$D(KMPDROU) S @KMPDGBL@(0)="[Routine(s) name not defined]" Q
  1. I KMPDTXT="" S @KMPDGBL@(0)="[Search text not defined]" Q
  1. I KMPDGBL="" S KMPDY="[Global for storage is not defined]" Q
  1. ;
  1. N DATA,DIF,I,LABEL,LN,OFFSET,ROU,RTN,X,XCNP
  1. ;
  1. ; kill global with check for ^tmp or ^utility.
  1. D KILL^KMPDU(.DATA,KMPDGBL)
  1. ; if error.
  1. I $E(DATA)="[" S KMPDY=DATA Q
  1. ;
  1. S KMPDY=$NA(@KMPDGBL)
  1. ;
  1. S KMPDTXT=$$UP^XLFSTR(KMPDTXT)
  1. ;
  1. S ROU="",LN=0
  1. F S ROU=$O(KMPDROU(ROU)) Q:ROU="" D
  1. .K ROUT
  1. .S DIF="ROUT(",(I,OFFSET,XCNP)=0,LABEL=ROU
  1. .S X=ROU X ^%ZOSF("TEST") Q:'$T
  1. .I $G(^%ZOSF("OS"))["OpenM",'$D(^ROUTINE(ROU)) Q
  1. .X ^%ZOSF("LOAD")
  1. .F S I=$O(ROUT(I)) Q:'I I $D(ROUT(I,0)) D
  1. ..S OFFSET=OFFSET+1
  1. ..; if new label.
  1. ..I $E(ROUT(I,0))'=" " S LABEL=$$ROULABEL^KMPDU2(ROUT(I,0)),OFFSET=0
  1. ..; quit if no match.
  1. ..Q:$$UP^XLFSTR(ROUT(I,0))'[KMPDTXT
  1. ..S @KMPDGBL@(LN)=ROU_"^"_LABEL_$S(OFFSET:"+"_OFFSET,1:"")_" "_ROUT(I,0)
  1. ..S LN=LN+1
  1. ;
  1. S:'$D(@KMPDGBL) @KMPDGBL@(0)="<No Match Found>"
  1. ;
  1. Q
  1. ;
  1. ROULABEL(TEXT) ;-- routine label.
  1. Q:$G(TEXT)="" ""
  1. N I,LABEL
  1. S LABEL=""
  1. F I=1:1 Q:$E(TEXT,I)=" "!($E(TEXT,I)="(") S LABEL=$E(TEXT,0,I)
  1. Q LABEL
  1. ;
  1. ROUNAME(KMPDRNM) ;-- extrinsic function - determine if routine name is valid
  1. ;--------------------------------------------------------------------
  1. ; KMPDRNM... free text - routine name
  1. ;--------------------------------------------------------------------
  1. ; routine name must begin with alpha and then be 1 to 7 additional
  1. ; alpha or numeric characters.
  1. S KMPDRNM=$G(KMPDRNM)
  1. Q KMPDRNM?1A!(KMPDRNM?1A1.7AN)!(KMPDRNM?1"%"1.7AN)
  1. ;
  1. ENDCHAR(RTN) ;-- extrinsic function - determine last character for $ordering
  1. ;--------------------------------------------------------------------
  1. ; RTN - routine name
  1. ;--------------------------------------------------------------------
  1. Q:$G(RTN)="" ""
  1. ; less than one
  1. Q:($A($E(RTN,$L(RTN)))<49) $E(RTN,1,$L(RTN)-1)
  1. ; numbers
  1. Q:($A($E(RTN,$L(RTN)))<58) $E(RTN,1,$L(RTN)-1)_$C(($A($E(RTN,$L(RTN)))-1))_"z"
  1. ; if RTN = 'A'
  1. Q:RTN="A" "%z"
  1. ; if 'A' then use '%'
  1. Q:($E(RTN,$L(RTN))="A") $E(RTN,1,$L(RTN)-1)_"9z"
  1. ; if 91 through 97
  1. Q:($A($E(RTN,$L(RTN)))>90)&($A($E(RTN,$L(RTN)))<98) $E(RTN,1,$L(RTN)-1)_"Z"
  1. ; if lowercase
  1. Q:($A($E(RTN,$L(RTN)))<123) $E(RTN,1,$L(RTN)-1)_$C(($A($E(RTN,$L(RTN)))-1))_"z"
  1. ; if greater than 122
  1. Q:($A($E(RTN,$L(RTN)))>122) $E(RTN,1,$L(RTN)-1)_"y"
  1. ; default
  1. Q RTN