.enable quiet
.enable substitution
;
;	EXE.CMD - Command file to compile and build programs
;
;	Don Rubin	1.0
;	"	"	1.1	Added C source capability, and EDT lookup
;

.;	If null argument then use EDT.TMP for name to compile

.if p1 <> "" .goto 2

	.testfile edt.tmp
	.if <filerr> = 1 .goto 5
		.disable quiet
		;	Error - Cant find saved file
		.goto 1
.5:
	.openr	#1 edt.tmp
	.read	#1 p1		!read in the saved filename to compile
	.close	#1

.2:
.parse p1 "." p1 extent
.if extent = "C" .goto cstuff
.if extent = "c" .goto cstuff
.if extent = "ftn" .goto fstuff
.if extent = "FTN" .goto fstuff
.if extent = ""  .goto guess
.disable quiet
;	Error - Invalid file extension for 'p1'
.goto 1

.guess:
.testfile 'p1'.c
.if <filerr> = 1 .goto cstuff
.testfile 'p1'.ftn
.if <filerr> = 1 .goto fstuff
.disable quiet
;	Error - Cant find .FTN or .C file for 'p1'
.goto 1

.fstuff:
f77 'p1'='p1'/-wr'p2'
.if <exstat> ne 1 .goto 1
.testfile 'p1'.tkb
.if <filerr> = 1 .goto 3
.open #1 'p1'.tkb
.data #1 'p1'/fp='p1'
.data #1 /
.data #1 clstr=f77cls,fcsres:ro
.data #1 //
.close #1
.goto 3

.cstuff:
run $cc/cmd="xcc 'p1'"
.if <exstat> <> 1 .goto 1
run $as/cmd="xas 'p1'"
.if <exstat> <> 1 .goto 1
.testfile 'p1'.tkb
.if <filerr> = 1 .goto 3
.open 'p1'.tkb
.enable data
'p1','p1'/-sp/-wi='p1'
lb:[1,1]c/lb,cx/lb
/
stack=1000
libr=fcsres:ro
//
.disable data
.close

.3:
tkb @'p1'.tkb
.if <exstat> ne 1 .goto 1
pip 'p1'.*/pu
.1:
.if <exstat> = 1 .stop
.disable quiet
;	Error status '<exstat>' returned from compilation or TKB
