
! 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$="/usr/share/emc/ncfiles"
IF DoesFileExist(Storage_dir$)<>2 THEN Storage_dir$="/"
Dir$= NamedVariableStr("post dir",WsSystemVars,"/usr/weber/post_formats/")

IF 0 THEN
	File_name$="tapefile"
	GOTO Save_file_as
ELSE
	Post_name$=FileNameString(Dir$,"smithy")
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

IF NOT POS(Answer$,".ngc") THEN
Answer$=Answer$&".ngc"
END IF

Copy_file:!
	Stat= DisplayMessage("Storing Job: "&Job_name$)
	Stat= SynergySleep(1)
	Stat=CopyFile(File_name$,Answer$)

LoadToControl: !
Stat=SetInputFormat("a1=",",Y,N,")
Stat=SetEqualsValue(0,"N")
Stat=GetValue("SEND TO CONTROL - Yes, No ",A$)
IF A$="Y" THEN
Stat=DumpDebug("NAME ="&Answer$)
stat=ChangeLabelStr("LoadToControl,",Answer$)
stat=ChangeLabelStr("ScriptNameStatus","XXXXXXXXXXXXXXXXXXXXXXXXXXXXX ")
END IF

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

