
! script name: lathetools.d/newholderfile
! topic: create a new holder packet from an existing one

!A
!A NAME:
!A
!A 	Create Lathe Holder File
!A
!A DESCRIPTION:
!A
!A	This script will create a new holder info packet which can be used 
!A	to generate generic lathe tool shapes. This script only changes
!A	the data. There is no graphic verification.
!A
!B INSTRUCTIONS:
!B
!B 	HOLDER CLASS DIRECTORY:  Select the holders's class.
!B
!B 	EXISTING HOLDER FILE NAME:  Select the holder file 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 holder file.
!B
!B 	NEW HOLDER FILE NAME:  Enter the new file name you are going to store
!B 	the holder as. The new name must be the same as the one appearing in
!B 	the holder's "Name:" data field.
!B
!# see also - htdocs/help.d/property.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: make a new holder info 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$)

Prop_dir$=Prop_dir$&"/Holders.d"

Start:!
D_label$="HOLDER CLASSES"
Choice$="CLASS SELECTED"
Ques$= "HOLDER 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 HOLDER 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 HOLDER 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


