
! script name: wscmill.d/tapetodnc
! topic: export ascii tapefile to CNC

!A
!A NAME:
!A
!A 	Export Current Tapefile
!A
!A DESCRIPTION:
!A
!A 	Export ascii tapefile to CNC.  This script converts a tape
!A 	file into code to be exported via dnc.
!A

stat=ChangeLabelStr("ScriptNameStatus","Function: export ascii tapefile to CNC ")

DIM Answer$[256]
DIM Destination$[256]
DIM Dir$[256]
DIM Post_name$[256]
DIM File_name$[256]
DIM Storage_dir$[256]
DIM Job_name$[256]

StdWorkplane
Storage_dir$="/MMDATA/NCPROG/"
IF DoesFileExist(Storage_dir$)<>2 THEN Storage_dir$="C:/"
Dir$= NamedVariableStr("post dir",WsSystemVars,"/usr/weber/post_formats/")

IF 0 THEN
	File_name$="tapefile"
	GOTO Save_file_as
ELSE
	Post_name$=FileNameString(Dir$,"machinemate")
END IF

Stat= AddEndOfBlock("tapefile","tdata",Post_name$,Tape_format$)

File_name$="tdata"

Save_file_as:!
Num_lines=FileLineCount(File_name$)
FOR J= 1 TO Num_lines
        Stat= GetFileLine(File_name$,J,Job_name$)
	IF Job_name$[1,1]="P" THEN
		Answer$= Job_name$[1,5]
		Answer$=FileNameString(Storage_dir$,Job_name$)
		GOTO Copy_file
	END IF
NEXT J
Stat=UserFileBox(Storage_dir$,"*","","","","","SAVE")
Stat=SetInputFormat("a99","")
Stat=GetValue("JOB FILE NAME TO STORE",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "CANCEL" THEN Leave

Copy_file:!
SELECT DoesFileExist(Answer$)
CASE 0
	Stat= DisplayMessage("Storing Job: "&Job_name$)
	Stat= SynergySleep(1)
	Stat=CopyFile(File_name$,Answer$)
CASE 1
	Stat=SetInputFormat("a1",",Y,N,")
	Stat=GetValue("Job "&Job_name$&" EXISTS. REPLACE Yes / No ",A$)
	IF ExitScript(Destination$) THEN Leave
	IF A$="N" THEN
		Stat=UserFileBox(Storage_dir$,"*","","","","","SAVE")
		Stat=SetInputFormat("a99","")
		Stat=GetValue("JOB FILE NAME TO STORE",Answer$)
		IF ExitScript(Destination$) THEN Leave
		IF Answer$= "CANCEL" THEN Leave
		Job_name$= PathNameFile(Answer$)
		GOTO Copy_file
	END IF
	Stat=CopyFile(File_name$,Answer$)
END SELECT

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

