source: WorldVistAEHR/trunk/r/VA_FILEMAN-ARJT-DI-DD-DM-DT-%DT-%RCR/ARJTDDKA.m@ 1259

Last change on this file since 1259 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 7.8 KB
RevLine 
[613]1ARJTDDKA ;WV/TOAD - FileMan Search All Routines ;5/24/2004 19:39
2 ;;3.0T1;OPENVISTA;;JUN 20, 2004
3 ;
4 ; not yet tested on GT.M on VMS
5 ; not tested on DSM since the overhaul to add GT.M support
6 ;
7 ; This routine is part of the VistA Software Search program,
8 ; designed to make it easy to search through all VistA
9 ; software (which can be a problem both because some VistA
10 ; software is in globals and because some searches are
11 ; syntactic rather than simple contains operations). This
12 ; particular routine is a companion to ARJTDDKR, which searches
13 ; selected routines; this one searches all routines. Traversing
14 ; all routines pre-1995-Standard-MUMPS is vendor-dependent, and
15 ; not all MUMPS vendors have implemented ^$ROUTINE to make it
16 ; portable. In particular, GT.M's routine directory handling
17 ; makes this code a touch tricky, thus this routine. The main
18 ; useful entry point is ALL^ARJTDDKA.
19 ;
20 ; need to write $$NEXTROU
21 ; need to test results
22 ; need to add to ARJTDDK* check for ^[]global
23 ; call David and email verified code to him for his report
24 ; then upload new Seattle meeting web page
25 ;
26 ; Change History:
27 ; 2004 05 24-25 created based on ALL^ARJTDDKR & GT.M %RSEL
28 ; program to make ALL not DSM-specific.
29 ;
30 ; Table of Contents:
31 ; ALL = public subroutine to search all routines
32 ; ROUDIR = public sub for GT.M to build array of paths
33 ; PATH = private sub for ROUDIR to check & format 1 path
34 ; $$NEXTROU = private function for ROUDIR to loop thru routines
35 ;
36 ;
37ALL(CONTAINS,FIND,EXIT) ; public subroutine: search all routines
38 ;
39 ; input:
40 ; .CONTAINS - array of simple contains searches to do
41 ; FIND - special code (like DSM) for more complex searches
42 ; DSM-specific ^ () global (name = space) - routine directory
43 ; GT.M-specific: $ZROUTINES, host OS directories
44 ; output:
45 ; .EXIT - whether user has asked searches to end ("^")
46 ; ^XTMP("DSMROUTINES") -- see ARJJTDDK routine for docs
47 ; current device for simple feedback
48 ; called by ALL^ARJTDDK -- master search option
49 ; calls:
50 ; $$FMADD^XLFDT - FileMan function to add days to a date
51 ; $$DT^XLFDT - today's date in FM format
52 ; ROUDIR - for GT.M, load array of source code directories
53 ; $$NEXTROU - for GT.M, return next routine name
54 ; FEEDBACK^ARJTDDKR - give routine search feedback
55 ; SEARCH^ARJTDDKR - search each routine
56 ; RESULTS^ARJTDDKU - report results of search
57 ;
58 W !!,"Searching all routines"
59 K ^XTMP("DSMROUTINES")
60 S ^XTMP("DSMROUTINES",0)=$$FMADD^XLFDT($$DT^XLFDT(),90)_U_$$DT^XLFDT()
61 I $ZV["GT.M" N DIRECTRY D ROUDIR(.DIRECTRY) ; load rtn direc array
62 ;
63 S EXIT=0 ; not interrupted so far
64 N PRE S PRE="" ; trace shifting prefixes
65 N COUNT ; number of routines searched
66 N FOUND S FOUND=0 ; number of matching routines found
67 N ROU S ROU="" ; name of each routine
68 F COUNT=0:1 D Q:ROU=""!EXIT
69 . I $ZV["GT.M" S ROU=$$NEXTROU(.DIRECTRY) ; GT.M stores in host OS
70 . I $ZV["DSM" S ROU=$O(^ (ROU)) ; DSM stores rtn direc in ^[space]
71 . Q:ROU=""
72 . I COUNT,'(COUNT#100) D FEEDBACK^ARJTDDKR(COUNT,ROU,.PRE,.EXIT) Q:EXIT
73 . D SEARCH^ARJTDDKR($P(ROU,"."),.CONTAINS,FIND,.FOUND)
74 D RESULTS^ARJTDDKU(EXIT,COUNT,FOUND,"Search","routine")
75 Q:EXIT
76 ; D COMPILE^ARJTDDKS(1)
77 ;
78 QUIT ; end of ALL
79 ;
80 ;
81ROUDIR(DIRS) ; public subroutine for GT.M: build array of routine directories
82 ;
83 ; another time, document syntax and examples of $ZRO
84 ;
85 ; Input: $ZROUTINES = GT.M special variable IDing source code paths
86 ; Output: .DIRS(#)=directory, source code directories
87 ; Context: for GT.M only. Called by ALL, but public as needed. Calls PATH
88 ;
89 ;
90 ; R1. set up variables & ensure $ZRO is not empty
91 ;
92 K DIRS ; clear output
93 Q:'$L($ZRO) ; done if no routine directory
94 ;
95 N PIECE ; each piece of $ZRO
96 N PIECECNT ; count pieces of $ZRO traversed
97 N DIRCNT S DIRCNT=0 ; count valid source code directories found in $ZRO
98 ;
99 N DELIM ; $ZRO piece delimiter
100 I $ZV["VMS" S DELIM="," ; GT.M on VMS delimits $ZROUTINES with commas
101 E S DELIM=" " ; GT.M on Unix delimits it with spaces
102 ;
103 N END
104 I $ZV["VMS" S END="" ; VMS directories do not end with "/"
105 E S END="/" ; Unix directories do end with "/"
106 ;
107 ;
108 ; R2. loop through $ZRO's pieces
109 ;
110 F PIECECNT=1:1:$L($ZRO,DELIM) D ; traverse all the pieces of $ZROUTINES
111 . S PIECE=$P($ZRO,DELIM,PIECECNT) ; get next piece
112 . ;
113 . ;
114 . ; R3. handle Unix directories
115 . ;
116 . I $ZV["Linux",PIECE'["(" D PATH Q ; no source info - it does both
117 . ;
118 . ;
119 . ; R4. handle VMS directories
120 . ;
121 . I $ZV["VMS",PIECE[".olb" Q ; it's an object library and we don't poke in them
122 . I $ZV["VMS",PIECE'["/" D PATH Q ; no source info - it does both
123 . ;
124 . I $ZV["VMS" S PIECE=$P(PIECE,"=",2) ; grab 1st source directory
125 . I $ZV["VMS",$E(PIECE)'="(" D PATH Q ; /SRC or /NOSRC - we're done
126 . ;
127 . ;
128 . ; R5. handle VMS & Linux: parentheses
129 . ;
130 . S PIECE=$P(PIECE,"(",2) ; strip the opening paren
131 . I PIECE[")" S PIECE=$P(PIECE,")") D PATH Q ; if only one path in parens
132 . ;
133 . ;
134 . ; R6. handle VMS & Linux: list of paths in parens
135 . ;
136 . D PATH ; check and format first path name in list
137 . N LISTEND S LISTEND=0 ; have we found the close paren yet?
138 . F PIECECNT=PIECECNT+1:1 D Q:LISTEND ; traverse the rest of the paren list
139 . . S PIECE=$P($ZRO,DELIM,PIECECNT) ; get the next path name in the parens
140 . . Q:'$L(PIECE) ; skip empties
141 . . I PIECE[")" S LISTEND=1,PIECE=$P(PIECE,")") ; handle end of list
142 . . D PATH ; check and format path from list
143 ;
144 QUIT ; end of ROUDIR
145 ;
146 ;
147PATH ; private subroutine: check and format path name
148 ;
149 ; Input:
150 ; PIECE = path name to check and format
151 ; END = proper end of path ("/" for Unix)
152 ;
153 ; Output:
154 ; DIRCNT = count of source code directories found
155 ; DIRS = array by count of source code directories
156 ;
157 ; Context:
158 ; Called only by ROUDIR. Calls nothing.
159 ;
160 I $L(PIECE) S PIECE=$P($ZPARSE(PIECE_END,"","*"),"*") ; if path not empty, format it
161 I $L(PIECE) S DIRCNT=DIRCNT+1,DIRS(DIRCNT)=PIECE ; if valid, record it
162 ;
163 QUIT ; end of PATH
164 ;
165 ;
166NEXTROU(ROUDIRS) ; private function: for GT.M
167 ;
168 ; Consider eventually describing $ZSEARCH in here.
169 ;
170 ; This is the GT.M equivalent of DSM's $O(^ (routine)); it traverses GT.M's routine
171 ; directories in the order they are prioritized in $ZROUTINES and returns each of
172 ; the routine names found there, one routine per call. It uses the unusual GT.M
173 ; intrinsic function $ZSEARCH which remembers its own context, which is why the
174 ; previous routine name need not be passed in to get the next one. We are assuming
175 ; $ZSEARCH is not already mid-search beneath us in the stack, but we use context
176 ; number 1 just in case, leaving 0 in case someone else has one already running.
177 ; See the GT.M Programmer Manual for documentation on how this unusual function
178 ; works. We also use the GT.M $ZPARSE function to extract the routine name from the
179 ; path and extension, since the former varies by OS.
180 ;
181 ; Input:
182 ; ROUDIRS(#)=source code path
183 ; ROUDIRS(0)=current path #
184 ; Output:
185 ; ROUDIRS(0)=current path # (when changed--this slowly loops thru list)
186 ; Context:
187 ; private, GT.M-specific, called only by ALL above. Calls nothing.
188 ;
189 I '$D(ROUDIRS(0)) S ROUDIRS(0)=1 ; if 1st call, we start with 1st path
190 N ROUFILE S ROUFILE=$ZSEARCH(ROUDIRS(ROUDIRS(0))_"*.m",1) ; get next routine file
191 I ROUFILE="" D ; if we've run out of routine files in current directory
192 . S ROUDIRS(0)=ROUDIRS(0)+1 ; advance to next source code directory
193 . I '$D(ROUDIRS(ROUDIRS(0))) S ROUTINE="" Q ; if we've run out of paths we're done
194 . S ROUFILE=$$NEXTROU(.ROUDIRS) ; recursively get next routine file
195 . I ROUFILE="" S ROUTINE="" Q ; if rest of paths are empty we're done
196 ;
197 I ROUFILE'="" D ; if we did get another routine source code file...
198 . S ROUTINE=$ZPARSE(ROUFILE,"NAME") ; extract routine name from path & extension
199 . I $E(ROUTINE)="_" S $E(ROUTINE)="%" ; GT.M translates % to _ for file naming
200 ;
201 QUIT ROUTINE ; end of NEXTROU
202 ;
203 ;
Note: See TracBrowser for help on using the repository browser.