/*
** F0.adpro
**
** $VER: F0.adpro 1.2.0 (16.11.93)
** 
** This ARexx program can be used to get around the limit of only being
** able to launch 100 pre-defined ARexx programs from ADPro/MorphPlus.
**
** This script requires ADPro v2.5.0 (or higher).
**
** Copyright © 1990-1993 ASDG, Incorporated
** All Rights Reserved
*/


ADDRESS "ADPro"
OPTIONS RESULTS

NL = '0A'X
SQ = '27'X
DQ = '22'X
TRUE  = 1
FALSE = 0
TempDefaults = "T:TempADProDefaults"


/*
** Save the current environment.
*/

SAVE_DEFAULTS TempDefaults


/*
** Specify the location of the RX program.
*/

RXFile = GETCLIP( "RXFile" )
IF (RXFile = "") THEN DO
	continue = FALSE
	DO UNTIL (continue = TRUE)
		CALL "FREDSCRIPTS:FREDFunctions/GetAFile" '"Enter Location of RC"' '"SYS:REXXC"' '"RX"' FALSE
		RXFile = RESULT
		IF (RXFile = DQ||DQ) THEN
			CALL ErrorOut 10

		IF (EXISTS( RXFile )) THEN
			continue = TRUE
		ELSE DO
			ADPRO_TO_FRONT

			OKAYN '"F0"' '"RX doesn''t exist in specified directory"' '"Retry|Cancel"'
			IF (RC = 0) THEN
				CALL ErrorOut 10
		END
	END

	SETCLIP( "RXFile", RXFile )
END


/*
** Specify the directory where the scripts are located.
*/

REXXDir = GETCLIP( "REXXDir" )
IF (REXXDir = "") THEN DO
	CALL "FREDSCRIPTS:FREDFunctions/GetADir" '"Enter REXX: Directory"' '"REXX:"' TRUE
	REXXDir = RESULT
	IF (REXXDir = DQ||DQ) THEN
		CALL ErrorOut 10

	SETCLIP( "REXXDir", REXXDir )
END


/*
** Specify the Rexx script to execute.
*/

CALL "FREDSCRIPTS:FREDFunctions/GetAFile" '"Enter Rexx Program To Execute"' '"'REXXDir'"' '""""' TRUE
Filename = RESULT
IF (Filename = DQ||DQ) THEN
	CALL ErrorOut 10


ADDRESS "COMMAND" RXFile Filename

CALL ErrorOut 0


ErrorOut:
	PARSE ARG ExitCode

	IF (EXISTS( TempDefaults )) THEN DO
		LOAD_DEFAULTS TempDefaults
		IF (RC ~= 0) THEN DO
			ADPRO_TO_FRONT
			OKAY1 "Error restoring settings."
		END

		ADDRESS COMMAND "Delete >NIL:" TempDefaults
	END

	EXIT ExitCode
