
! script name: ncout.d/storedtopunch
! topic: Sample - export stored tapefile to punch tape

!A
!A NAME:
!A
!A      Export stored tapefile to punch tape
!A
!A DESCRIPTION:
!A
!A 	This script converts a stored tape file into code to
!A 	export to a punch.
!A
!B INSTRUCTIONS:
!B
!B 	NO HELP AVAILABLE AT THIS TIME
!B
!C NOTE:
!C
!C 	This is an unsupported sample script.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: export stored tapefile to tape punch ")

DIM Answer$[256]
DIM Destination$[256]
DIM Tape_format$[256]
DIM Dir$[256]
DIM D_label$[256]
DIM Sub_label$[256]
DIM Namelist$[4000]
DIM Namelist2$[5000]
DIM F_label$[256]
DIM Choice$[256]
DIM Mask$[32]
DIM Post_name$[256]
DEG

Show_tape= 1

StdWorkplane

Dir$="/usr/weber/post_formats/"
D_label$="POST FORMATS AVAILABLE"
Choice$="POST FORMAT SELECTED"
Mask$="[A-z]*"

Stat=DirectoryNames(Dir$,Mask$,Namelist$)
Stat= AlphabeticalOrder(Namelist$,",",WsAscending,Namelist2$)
Stat=GeneralListBox(D_label$,Choice$,Namelist2$)
Stat=SetInputFormat("a99","")
Stat=GetValue("TURBO POST NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Leave
LowerSelectBox
Post_name$= FileNameString(Dir$,Answer$)

Start_file:!

Stat= NamedVarStr("retrieve dir",WsSystemVars,"/usr/weber/ST/",Dir$)
D_label$="DIRECTORY"
Sub_label$="SUB DIRECTORIES"
F_label$="FILES"
Choice$="FILE TO OPEN"
Mask$="*"

Stat=UserFileBox(Dir$,Mask$,D_label$,Sub_label$,F_label$,Choice$)
Stat=SetInputFormat("a99","")
Stat=GetValue("STORED FILE TO SEND",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "CANCEL" THEN Leave
LowerFileBox

Move_back= 0

Stat= DisplayMessage("RETRIEVING TAPEFILE FROM "&Answer$)
Stat= CopyFile("tapefile","/tmp/tpe.fle")
Stat= RemoveFile("tapefile")
Stat= ReadStoredFile(Answer$,4,0)
IF Show_tape THEN Stat= MessageFileBox("tapefile","TAPE FILE TO SEND","")

Move_back= 1

Stat=SetInputFormat("n0a1",",N,")
Port_no=GetValue("PORT #, New",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "N" THEN Start_file

Stat=SetInputFormat("n0","")
Num_inches=GetValue("NUMBER OF INCHES OF LEADER",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Stat= AddEndOfBlock("tapefile","tdata",Post_name$,Tape_format$)
Stat= TapeLeaderFile("leader",Num_inches,WsNewFile)

LOOP

Stat=SetInputFormat("a99","")
Num_inches=GetValue("MAN-READABLES, PROCEED ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
EXIT IF Answer$= "PROCEED"

Stat= StartProcess("/usr/weber/bin/manread "&CHR$(34)&Answer$&CHR$(34)&" >> leader")

END LOOP

Move_back= 0

Stat= TapeLeaderFile("leader",3,WsAppend)

SELECT Tape_format$
CASE "EIA"
	Stat=AsciiToEia("tdata","tdata2")
	Stat= StartProcess("cat leader tdata2 > tdata")
	Stat= StartProcess("/usr/weber/bin/send.ksh tdata "&VAL$(Port_no))
CASE "ASCII"
	Stat=AsciiOddToEven("tdata","tdata2")
	Stat= StartProcess("cat leader tdata2 > tdata")
	Stat= StartProcess("/usr/weber/bin/send.ksh tdata "&VAL$(Port_no))
CASE "ASCII-NON"
	Stat= StartProcess("cat leader tdata > tdata2")
	Stat= StartProcess("/usr/weber/bin/send.ksh tdata2 "&VAL$(Port_no))
END SELECT

Stat= CopyFile("/tmp/tpe.fle","tapefile")
Stat= RemoveFile("/tmp/tpe.fle")

Leave:!
IF Move_back THEN
	Stat= CopyFile("/tmp/tpe.fle","tapefile")
	Stat= RemoveFile("/tmp/tpe.fle")
END IF
LowerSelectBox
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

