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

/* This script will attempt to load the SOURCE or NOTE file requested by
   Origins into Ed.  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.

   Since Ed doesn't do a ScreenToFront() when called, you'll have to
   switch to the Workbench screen to see it.

   There appears to be a bug in Ed such that when you load an existing file,
   and then load a new file, Ed returns error #3 (Insufficient memory).
   This does not seem to cause any harm; the file is still created OK.  We
   just thought you'd like to know this.
*/

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

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

/* 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 Ed ' || Filename
	Exit
End

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

/* ...and tell the editor to load this file */
'OP /' || 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
