
! script name: property.d/newpropfile
! topic: create a new info packet from an existing one

!A
!A NAME:
!A
!A 	Create Property
!A
!A DESCRIPTION:
!A
!A	This script will create a new info packet based on an existing one.
!A 	In some cases, you may need an entire set of info packets that only
!A 	differ slightly from a set that already exists. Use this script to
!A 	quickly generate specific info packets for specific purposes where
!A 	only a few of the components vary.
!A
!B INSTRUCTIONS:
!B
!B 	PACKET CLASS DIRECTORY:  Select the packet's class.
!B
!B 	EXISTING PACKET FILE NAME:  Select the info packet of that you are
!B 	going to duplicate and then modify. 
!B
!B 	SELECT DATA FIELD , Store:  Select the data field to change, or select
!B 	"S" to store the packet.
!B
!B 	NEW PACKET FILE NAME:  Enter the new file name you are going to store
!B 	the packet as. The new name must be the same as the one appearing in
!B 	the packet's "Name:" data field.
!B
!# see also - htdocs/help.d/property.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: make a new info packet file")

DIM Destination$[512]
DIM Answer$[512]
DIM A$[512]
DIM B$[512]
DIM C$[512]
DIM Name$[512]
DIM Prop_dir$[512]
DIM Prop_class$[512]
DIM Class_dir$[512]
DIM Class_name$[512]
DIM Filename$[512]
DIM Oldname$[512]
DIM Oldpropname$[512]
DIM Newpropname$[512]
DIM Data$[32000]
DIM Namelist$[32000]
DIM D_label$[512]
DIM Choice$[512]
DIM Current_dir$[512]
DIM Ques$[512]

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

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$)

Ask_file:!
D_label$= Prop_class$
Choice$= Prop_class$&" SELECTED"
Stat=DirListBox(Class_dir$,"*",D_label$,Choice$,WsAscending)

File_name:stat= SetInputFormat("a99","")
stat= GetValue("EXISTING PACKET FILE NAME ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Start
IF NOT LEN(Answer$) THEN File_name
Oldname$= Answer$
Filename$= FileNameString(Class_dir$,Oldname$)

Id_number=GetExtUserValue(Filename$,"Class id number:")
Name$= ExtUserDataStr(Filename$,"Name:")
E1= ReadUserData(Id_number,Name$,Filename$)
Oldpropname$= UserDataStr(E1,"Name:")

List_fields:!
Namelist$= DataFieldListStr(E1,":",",",WsNoOrder,WsTrue)

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

Data_field:stat= SetInputFormat("a99","",WsFalse)
stat= GetValue("SELECT DATA FIELD , Store ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF NOT LEN(Answer$) THEN Data_field
LowerSelectBox
SELECT Answer$
CASE "CANCEL"
	Stat= DeleteEntity(E1)
	GOTO Ask_file
CASE "Store","S","s","store"
	GOTO Store_prop
END SELECT
IF POS(Answer$,"=") THEN
	A$= DataFieldStr(Answer$,"=",1)
	B$= DataFieldStr(Answer$,"=",2)
	B$= TRIM$(B$)
ELSE
	A$= Answer$
	B$=""
END IF
GOTO New_value

New_value:!
IF LEN(B$) THEN
	Stat= AddBackSlashChars(B$,C$)
	stat= SetInputFormat("a99=","",WsFalse)
	Stat= SetEqualsValue(0,C$)
	Stat=SetEditString(C$)
ELSE
	stat= SetInputFormat("a99","",WsFalse)
END IF
stat= GetValue(A$&" = ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Answer$= TRIM$(Answer$)
IF NOT LEN(Answer$) THEN New_value
Stat= BackSlashChars(Answer$,B$)
Stat= PutUserString(E1,A$&":",B$)

GOTO List_fields

Store_prop:!
Newpropname$= UserDataStr(E1,"Name:")
IF (NOT LEN(Newpropname$)) OR (Oldpropname$= Newpropname$) THEN
	stat= SetInputFormat("a99=","")
	Stat= SetEqualsValue(0,Oldname$)
	stat= GetValue("NEW PACKET FILE NAME ",Answer$)
	IF (ExitScript(Destination$)) THEN
		Stat= DeleteEntity(E1)
		GOTO  Leave
	END IF
	IF NOT LEN(Answer$) THEN Store_prop
	Name$= MakeNameValid(Answer$,WsValidFileName)
ELSE
	Name$= MakeNameValid(Newpropname$,WsValidFileName)
END IF

Filename$= FileNameString(Class_dir$,Name$)
Stat= PutUserString(E1,"Name:",Name$)
Class_name$= UserDataStr(E1,"Class name:")
Data$= UserData(E1)

Stat= MessageStringBox(Data$,Class_name$&" : "&Name$)
Stat= OutputUserData(E1,Filename$,WsNewFile)
Stat= DeleteEntity(E1)

GOTO Ask_file

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


