KBBVFND	;Portland/jeb Barebones search for global or routine strings May 2016
	;;v2.0 June 2019
	;; This program is free software: you can redistribute it and/or modify
	;; it under the terms of the GNU General Public License as published by
	;; the Free Software Foundation, either version 3 of the License, or
	;; (at your option) any later version.
	;;
	;; This program is distributed in the hope that it will be useful,
	;; but WITHOUT ANY WARRANTY; without even the implied warranty of
	;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	;; GNU General Public License for more details.
	;;
	;; You should have received a copy of the GNU General Public License
	;; along with this program.  If not, see <http://www.gnu.org/licenses>
	;
EN	;
	K %ZR,%ZG S ANS=""
EN2	R !,"Search [G]lobal or (R)outine or [H]elp: ",WHAT:30 I '$L(WHAT) K WHAT,ANS Q
	S WHAT=$E($$UP^XLFSTR(WHAT),1)  ;Upcase it
	I WHAT="H" D HELP G EN2
	I WHAT="R" D
	. R !?5,"[L]abel or [S]tring: ",W1:30 S W1=$E($$UP^XLFSTR(W1),1) Q:'$L(W1)
	. I W1="L" R !?7,"Enter part or full label or [A]ll for all labels: ",W2:30 Q:'$L(W2)  D LAB($S(W2="A":"",1:W2),$S(W2="A":W2,1:"C"))
	. I W1="S" R !?7,"Search for string: ",MATCH:30 G EN2:'$L(MATCH) D STR(MATCH) G EN2
	;Q  ;Testing
	I WHAT="G" R !?2,"Search for String: ",MATCH:30 G EN2:'$L(MATCH) D GSRCH(MATCH)
	K WHAT,WHERE,ANS,R,X,I,J,W1,W2,MATCH
	W ! G EN2
	;
LAB(MATCH,ANS)  ;
	D ^%RSEL
	Q:$D(%ZR)#11  ;No selection array
	D ^%ZIS U IO
	S R="" F  S R=$O(%ZR(R)) Q:R=""  D
	. S MATCH=$S('$L($G(MATCH)):"",1:MATCH)
	. F I=1:1 S X=$T(@R+I^@R) Q:X=""  S LABEL=$P(X," ") I $L(LABEL) D
	.. I ANS="A",MATCH="" S %ZR(R,$O(%ZR(R," "),-1)+1)="+"_$J(I,5)_" "_X Q
	.. I ANS="C",X[MATCH S %ZR(R,$O(%ZR(R," "),-1)+1)="+"_$J(I,5)_" "_X Q
	.. ;I ANS="E",X=MATCH S %ZR(R,$O(%ZR(R," "),-1)+1)=X Q
	D WR,^%ZISC
	K I,ANS,MATCH,R,LABEL,X,%ZR
	Q
	;
STR(MATCH)	;Strings in the code
	I '$L(MATCH) W !?4,"Dude! No info!" Q
	D ^%RSEL
	Q:$D(%ZR)#11  ;No selection array
	D ^%ZIS U IO
	S R="" F  S R=$O(%ZR(R)) Q:R=""  D
	. F I=1:1 S X=$T(@R+I^@R) Q:X=""  D
	.. F J=1:1:$L(X,MATCH) I X[MATCH S %ZR(R,$O(%ZR(" "),-1)+1)="+"_I_" ->"_X
	D WR,^%ZISC
	K %ZR,R,X,I
	Q
	;
WR	;Go through %ZR array and only print path/routine name
	;						target...
	W !,"Searching for ",MATCH
	S R="" F  S R=$O(%ZR(R)) Q:R=""  D:$O(%ZR(R,0))
	. W !,%ZR(R)_R
	. S N=0 F  S N=$O(%ZR(R,N)) Q:'+N  W !?2,%ZR(R,N)
	Q
	;
	;ROUTINE fini
	;
GSRCH(MATCH)	;Global search for string
	D CALL^%GSEL Q:$D(%ZG)#11
G1	W !,"Searching for ",MATCH,"...working...."
	S N="" F  S N=$O(%ZG(N)) Q:N=""  S X=N W "." D
	. F  S X=$Q(@X) Q:X=""  I X[MATCH!(@X[MATCH) W !,X,"->",@X
	. K %ZG(N)
	K WHERE,N,X,%ZG,MATCH
	Q
	;Global fini
	;
HELP	F I=1:1 S X=$P($T(HELP+I^STUFF),";;",2) Q:'$L(X)  W !,X
	;;G________Select to search a Global. Both node(subscript) and
	;;	 content of the subscript will be searched. Return
	;;	 will be any matches containing the string.
	;;  HINT: To avoid searching a full global, use Merge to move
	;;	the subscripted global to a temp/scratch global and
	;;	just search that.
	;;
	;;R________Select to search a string in selected routine(s).
	;;  If L for Label search is selected:
	;;	Entering an A at the prompt will show all labels at
	;;	the location in the routine, otherwise it will search
	;;	for labels containing the string.
	;;  If S for string is selected, search will be for the string
	;;  specified in the body of the routine. All matches will get listed.
	W !
	Q
	;