
! script name: property.d/searchstring
! topic: search an info packet class directory for a specific string

!A
!A NAME:
!A
!A 	Search an Info Packet class directory for a specific string
!A
!A DESCRIPTION:
!A
!A 	This script searches an info packet class directory for specific
!A 	information. Use this script when you want to locate a packet that 
!A 	contains a specific ASCII string.
!A
!B INSTRUCTIONS:
!B
!B 	PACKET CLASS DIRECTORY: Select the packet class directory.
!B
!B 	SELECT DATA FIELD:  Select the data field of the class that
!B 	you wish to search.
!B
!B 	SEARCH STRING: Input the string that you wish to search for.
!B
!B 	MATCHING PACKET FILE NAME: Select the name of the matching 
!B 	packet file that you wish to see.
!B
!C NOTES:
!C
!C 	This script contains the following internal settings:
!C
!C 		Perfect_match= WsTrue:  String must match exactly.
!C 		Perfect_match= WsFalse: String need only contain search string.
!C 		First_match= WsTrue: Returns name of first match found.
!C 		First_match= WsFalse: Returns all matching names.
!C

!# see also - htdocs/help.d/property.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: packet string search")

DIM Destination$[512]
DIM Answer$[512]
DIM A$[512]
DIM Name$[512]
DIM Field_name$[512]
DIM Search_str$[512]
DIM Prop_dir$[512]
DIM Prop_class$[512]
DIM Class_dir$[512]
DIM Filename$[512]
DIM Class_name$[512]
DIM Data$[32000]
DIM Namelist$[32000]
DIM Namelist2$[32000]
DIM D_label$[512]
DIM Choice$[512]
DIM Mask$[32]
DIM Current_dir$[512]
DIM Ques$[512]

DeActivateUndo
Stat= NamedVarStr("properties dir",WsSystemVars,"/usr/weber/database/properties/",Prop_dir$)

Perfect_match= WsFalse
First_match= WsFalse

Start:!
D_label$="PACKET CLASSES"
Choice$="CLASS SELECTED"
Ques$= "PACKET CLASS DIRECTORY  List  "
Answer$= SelectDirectory(Prop_dir$,"*",Ques$,D_label$,Choice$,"",Current_dir$)
IF (ExitScript(Destination$)) THEN Leave
IF  Answer$= "CANCEL" THEN Leave
Answer$= TRIM$(Answer$)
Class_dir$= Answer$
Prop_class$= PathNameFile(Answer$)


List_fields:!
Namelist$=DirectoryNamesStr(Class_dir$,"*")
Prop_file$= DataFieldStr(Namelist$,",",1)
Filename$= FileNameString(Class_dir$,Prop_file$)
Namelist$= ExtFieldListStr(Filename$,":",",",WsAscending)

D_label$="DATA FIELDS"
Choice$="DATA FIELD SELECTED"
Mask$="*"
Stat=GeneralListBox(D_label$,Choice$,Namelist$)

Data_field:stat= SetInputFormat("a99","")
stat= GetValue("SELECT DATA FIELD ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF NOT LEN(Answer$) THEN Data_field
LowerSelectBox
SELECT Answer$
CASE "CANCEL"
	GOTO Start
END SELECT
Field_name$= Answer$&":"

Search_string:stat= SetInputFormat("a99","")
stat= GetValue("SEARCH STRING ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF NOT LEN(Answer$) THEN Search_str
Search_str$= Answer$


Namelist$= PropDirStrSearch(Class_dir$,Field_name$,Search_str$,Perfect_match,First_match)

IF POS(Namelist$,",") THEN
	D_label$="MATCHING PACKETS"
	Choice$="PACKET SELECTED"
	Stat= AlphabeticalOrder(Namelist$,",",WsAscending,Namelist2$)
	Stat=GeneralListBox(D_label$,Choice$,Namelist2$)

	File_name:stat= SetInputFormat("a99","")
	stat= GetValue("MATCHING PACKET FILE NAME ",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
	IF NOT LEN(Answer$) THEN File_name
	IF Answer$="CANCEL" THEN Leave
ELSE
	IF NOT LEN(Answer$) THEN File_name
	Answer$= TRIM$(Namelist$)
END IF

Filename$= FileNameString(Class_dir$,Answer$)
E1= ReadUserData(10000,"temp prop",Filename$)
IF ValidGeometry(E1) THEN
	Data$= UserData(E1)
	Stat= MessageStringBox(Data$,"User property: "&Name$)
	Stat= DeleteEntity(E1)
END IF

GOTO Start

Leave:!
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END


