/*
 * error
 *
 * USAGE: CALL 'dos/error'(errcode,errline,infoline,srcline)
 *
 * This is a global error handling routine.
 *
 * $(C): (1995, Rocco Coluccelli, Bologna)
 * $VER: error 1.01 (29.May.1995)
 */

SIGNAL ON halt
SIGNAL ON break_c

nl = '0a'x
logfile = 'REXX:.errors.log'

str.1 = 'Error:'
str.2 = 'Line:'
str.3 = 'Press return to continue...'

PARSE ARG errcode,errline,infoline,srcline

CALL CLOSE(STDIN)
CALL OPEN(STDIN,"*")

info = 	nl ||,
		infoline || nl ||,
		str.1 errcode str.2 errline || nl ||,
		srcline || nl ||,
		ERRORTEXT(errcode) || nl || nl

SAY info

/*
 *	ENVS:
 *		opt.LOG = output log file
 *		opt.EDIT = ASCII editor
 */
opt.LOG  = 0
opt.EDIT = ''

IF OPEN(bug,'ENV:debugxx','r') THEN
DO
	INTERPRET READCH(bug,512)
	CALL CLOSE(bug)

	IF opt.LOG = 1 THEN DO
		IF ~OPEN(log,logfile,'a') THEN
			IF ~OPEN(log,logfile,'w') THEN BREAK

		CALL WRITECH(log,info)
		CALL CLOSE(log)
	END

	IF opt.EDIT ~= '' & WORDS(infoline) = 6 THEN
		ADDRESS COMMAND opt.EDIT WORD(infoline,4)
END

/*
 *	Wait user for press ENTER
 */
OPTIONS PROMPT str.3
PULL char


halt:
break_c:
	RETURN
