.key PROJECT/A,PRI
.bra {
.ket }

; $VER: MoPac_Shell 1.0 (18.5.96)

Echo "*N*E[33mMoPac V5.0 for AmigaDOS*E[0m"
Echo "Original concept by James J. P. Stewart"
Echo "AmigaDOS porting by Alessandro Pedretti*N"

Set MoPacPri -1
Set MoPacPri {PRI}

If NOT EXISTS {PROJECT}.dat
	Echo "MoPac: *"{PROJECT}.dat*" not found.*N"
	Quit
EndIf

Ask  "Background run (y/*E[33mn*E[0m) ?"
If WARN
	Set MoPacOut ">{PROJECT}.out"
	Set MoPacRun "Run"
Else
	Set MoPacRun ""
	Set MoPacOut ""
EndIf

; Check for CPU type:

Resident C:Cpu ADD
Cpu CHECK 68040 >NIL:
If NOT WARN
	Set MoPacName "MoPac040"
Else
	Cpu CHECK 68030 >NIL:
	If NOT WARN
		Set MoPacName "MoPac030"
	Else
		Cpu CHECK 68020 >NIL:
		If NOT WARN
			Set MoPacName "MoPac020"
		Else
			Echo "Sorry, you need a 68020 or greather.*N"
			Quit
		EndIf
	EndIf
	Cpu CHECK 68881 >NIL:
	If WARN
		Echo "Sorry, you need a math coprocessor.*N"
		Quit
	EndIf
EndIf
Resident Cpu REMOVE

Set MoPacExe "$MoPacName $MoPacOut <{PROJECT}.dat {PROJECT}.arc {PROJECT}.syb {PROJECT}.den {PROJECT}.res {PROJECT}.gpt"

; Backup files:

If EXISTS {PROJECT}.arc
	Copy {PROJECT}.arc {PROJECT}.arc~
EndIf

If EXISTS {PROJECT}.out
	Copy {PROJECT}.out {PROJECT}.out~
EndIf

If EXISTS {PROJECT}.syb
	Copy {PROJECT}.syb {PROJECT}.syb~
EndIf

If EXISTS {PROJECT}.den
	Copy {PROJECT}.den {PROJECT}.den~
EndIf

If EXISTS {PROJECT}.res
	Copy {PROJECT}.res {PROJECT}.res~
EndIf

If EXISTS {PROJECT}.gpt
	Copy {PROJECT}.gpt {PROJECT}.gpt~
EndIf

Delete {PROJECT}.arc {PROJECT}.out {PROJECT}.syb {PROJECT}.gpt QUIET >NIL:

; Launch MoPac:

If $MoPacRun EQ "Run"
	Echo >T:MoPac_$process "Echo >KILLME *"Break >NIL: *$process*""
	Echo >>T:MoPac_$process "Echo >>KILLME *"Echo ***"MoPac Killed***"*""
	Echo >>T:MoPac_$process "Protect KILLME +s QUIET"
	Echo >>T:MoPac_$process "Stack 100000"
	Echo >>T:MoPac_$process "ChangeTaskPri $MoPacPri"
	Echo >>T:MoPac_$process $MoPacExe
	Echo >>T:MoPac_$process "Delete SHUTDOWN KILLME QUIET"
	Run Execute T:MoPac_$process
	Echo "MoPac started as background task.*N"
Else
	ChangeTaskPri $MoPacPri
	Stack 100000
	$MoPacExe
	Stack 4000
	ChangeTaskPri 0
	Delete SHUTDOWN QUIET
	Echo ""
EndIf

UnSet MoPacExe
UnSet MoPacName
UnSet MoPacOut
UnSet MoPacPri
UnSet MoPacRun
