/********************************************/
/* Edit a SOURCE or NOTE file from Origins */
/********************************************/

/* NOTE:
   This file is the same as EditGen.rexx, except it specifically calls
   TurboText as the editor of choice.

   To function correctly, this script must be renamed EditGen.rexx and copied
   to the REXX: directory.

   This script will attempt to load the SOURCE or NOTE file requested by
   Origins into TurboText.  The function may be blocking or non-blocking by
   your choice.  As written, the function is non-blocking.

   When Origins calls this script, it does so in a blocking manner; the
   program won't continue until the script returns.  If you wish this
   behaviour, make the script block until you are done with the file.
   Otherwise, make the script return immediately.

   If TurboText is running in the background, it will pop to the front when
   called by Origins.

   Thanks to Ed Dunifon for digging out the proper info for calling
   TurboText from Origins.
*/

/* Enable error handling routines */
Signal On Error
Signal On Syntax
Signal On Halt
Signal On IOErr

/* The name of TurboText's ARexx port.  Always  */
/* remember that port names are case-sensitive. */
MyPort = 'TURBOTEXT'

/* Get the name of the file to edit into this variable */
parse arg Filename

/* If the editor isn't up, start it */
If (~Show('P',MyPort)) then do
	address command 'run TurboText ' || Filename
	Exit
End

/* Else, set up the address... */
address value MyPort

/* ...and tell the editor to load this file */
'OpenDoc NAME ' || Filename

Exit

/**********************************************************************/
/*                           Error Handling                           */
/**********************************************************************/

Error:
	Parse Source Type Num MacroName Script Prog Port
	say 'ERROR: Macro "'MacroName'", Error: #'RC' ("'ErrorText(RC)'") on line 'SIGL' **'
	exit

Syntax:
	Parse Source Type Num MacroName Script Prog Port
	say 'SYNTAX: Macro "'MacroName'", Error: #'RC' ("'ErrorText(RC)'") on line 'SIGL' **'
	exit

Halt:
	Parse Source Type Num MacroName Script Prog Port
	say 'HALT: Macro "'MacroName'", Error: #'RC' on line 'SIGL' **'
	exit

IOErr:
	Parse Source Type Num MacroName Script Prog Port
	say 'IOERR: Macro "'MacroName'", Error: #'RC' on line 'SIGL' **'
	exit
