
! script name: vedit.d/replaceembdstr
! var_topic: change embedded record file names

!A
!A NAME:
!A
!A      Change Embed File Name      VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will find records that have EMBED: in the description
!A	and list those records. Then the user can choose a record and change
!A	the string constant of the embded record.
!A
!B INSTRUCTIONS:
!B
!B 	PICK RECORD TO SWITCH: Pick the record to be switched.  The record can
!B		CANNOT be picked graphically.  Only from the list.
!B
!B NOTE: 
!B
!B	This function will not work on merged records unless the description
!B	contains the EMBED: marker.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: change embed file name")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Descr$[256]
DIM File$[256]
DIM Title$[256]
DIM A$[512]
DIM Onoff$[256]
DIM Namelist$[32000],List_str$[256]
DIM Feat_desc$[256]
DIM Dir$[512],Constants$[512],Oldstring$[512],Newstring$[512]

On_color=4
Off_color=2
File$="tempdata"

DeActivateUndo
Start:!
Group= SearchRecordDescr("EMBED:",WsTrue,WsFalse)
IF NOT ValidGeometry(Group) THEN Leave

Namelist$= ""
Num_recs= GroupCount(Group)
FOR I= 1 TO Num_recs
        Op_record= GroupElement(Group,I)
        Stat= GetDescription(Op_record,Feat_desc$)
        J= POS(Feat_desc$,":")
	OUTPUT A$ USING "A,3D,#,K"; "#",I
        Namelist$= Namelist$&A$&Feat_desc$[J+1]&","
NEXT I

Ask_ques:Stat=GeneralListBox("Features","Feature Chosen",Namelist$)
Stat= SetInputFormat("a99","")
Stat= GetValue("CHOOSE RECORD TO EDIT ",Answer$)
IF ExitScript(Destination$) OR Answer$="CANCEL" THEN Leave
FOR K= 1 TO Num_recs
	Stat= StringFieldStr(Namelist$,",",K,List_str$)
	IF List_str$= Answer$ THEN Pick_record
NEXT K
GOTO Ask_ques

Pick_record:!
Stat= NamedVarStr("retrieve dir",WsSystemVars,"/usr/weber/ST/",Dir$)
Var_record= GroupElement(Group,K)

Num_para=VRecStrConstList(Var_record,Constants$)
Stat=ReplaceChar(Constants$,","," ",Oldstring$)
Oldstring$=TRIM$(Oldstring$)

Stat=SetEditString(Oldstring$)
Stat=UserFileBox(Dir$,"*","DIR","SUB DIRS","FILES","FILE CHOSEN")
Stat=SetInputFormat("a99","")
Stat=GetValue("SELECT EXISTING FILE ",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat= BackSlashChars(Answer$,A$)
Stat= ReplaceString(A$,"\n",CHR$(10),Newstring$)
PRINT Newstring$
Stat=ReplaceStringConst(Var_record,Oldstring$,Newstring$)
Stat= RecordDescr(Var_record,"EMBED: "&Newstring$)

LowerFileBox
Output_script=0
Stat= CleanNonVarGrps
Stat= DisplayMessage("CALCULATING CHANGES")
Stat=OutputAllObjects("tempscript","vedit.d/replaceembdstr",0,0)
IF Stat=1 THEN Start
LOAD "tempscript"

Leave:!
LowerSelectBox
IF (NOT LEN(Destination$)) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
