/* CMD: ½InfoOnError                                                    */
/* By Brett Evan Hester      13032 Copenhill Rd. Dallas, Tx. 75240-5302 */
	MacrosName = "InfoOnError"
/* Macro Type:                                                          */
/* SPECIAL                                                              */
/* Description:                                                         */

Info1A = "!Info On Error ©               Information 1 of 2"
Info1B = ""
Info1C = "@This macro works one of two ways:               "
Info1D = ""
Info1E = "@þ If an error has occured in any of the PLUG-INS"
Info1F = "@  this macro might help better explain the      "
Info1G = "@  problem. Features include showing the macros  "
Info1H = "@  name, filename & path, error number, error    "
Info1I = "@  description, and showing the area in the macro"
Info1J = "@  where the crash occured.                      "
Info1K = ""
Info1L = "@þ If no error has occured or is not a PLUG-IN,  "
Info1M = "@  this macro will describe each error given an  "
Info1N = "@  ARexx error number ranging from 1-48.         "

Info2A = "!Info On Error ©               Information 2 of 2"
Info2B = "@               Plug-Ins and Go! ©               "
Info2C = "                           Hester and associates"
Info2D = "                           13032 Copenhill Road "
Info2E = "                           Dallas, Texas 75240  "
Info2F = "@Special Thanks to:                              "
Info2G = "Arnie Cachelin  Henry Ribron    Mark J. Holland "
Info2H = "J. Phil Kelso   Terry Wester    Steven K. Simms "
Info2I = "Kevin DeRita    Greg Glaser     William S. Hawes"
Info2J = "NewTek ©        Commodore ©     INOVAtronics ©  "
Info2K = ""
Info2L = "@This macro represents a lot of time & hard work."
Info2M = "@Encourage people to create new ones and not kill"
Info2N = "@that possibility by stealing those that are out."

/* -------------------------------------------------------------------- */
                                     /* Start Error Detection (See End) */
SIGNAL ON ERROR
SIGNAL ON SYNTAX
                                                   /* Address LightWave */
VT3DLib = ADDLIB("LWModelerARexx.port",0)
ADDRESS "LWModelerARexx.port"

/* -------------------------------------------------------------------- */
                   /* Determining Interface: ErrorFound or NoErrorFound */
ErrorMacro = GETCLIP("ErrorMacro")

/* -------------------------------------------------------------------- */
                                                      /* No Error Found */
IF ErrorMacro = "" THEN DO

	ErrorCode = 1

	DO FOREVER

		CALL Descriptions

		ErrorDesc = ERRORTEXT(ErrorCode)
		IF ErrorCode = 4 THEN ErrorDesc = "Invalid character"       /* not normally listed*/
		IF ErrorCode = 7 THEN ErrorDesc = "Clause too long"         /* not normally listed*/
		IF ErrorCode = 38 THEN ErrorDesc = "Invalid TRACE request"  /* not normally listed*/

		CALL Req_Begin("Info On Error ©                             by Brett Hester")

		ReqA = Req_AddControl("",'N',"0")
		CALL Req_AddControl("",'T',CENTER(ErrorDesc,60))
		CALL Req_AddControl("",'T',"")
		CALL Req_AddControl("",'T',DescA)
		CALL Req_AddControl("",'T',DescB)
		CALL Req_AddControl("",'T',DescC)
		CALL Req_AddControl("",'T',DescD)
		CALL Req_AddControl("",'T',DescE)
		CALL Req_AddControl("",'T',DescF)
		ReqB = Req_AddControl("",'CH',"Information")

		CALL Req_SetVal(ReqA, ErrorCode)
		CALL Req_SetVal(ReqB, 0)

		OKorCancel = Req_Post()
		IF OKorCancel = 0 THEN CALL Exiting

		ErrorCode = Req_GetVal(ReqA)
		BEHInfo = Req_GetVal(ReqB)

		CALL Req_End()

		ErrorCode = TRUNC(ErrorCode)
		IF ErrorCode > 48 THEN ErrorCode = 48
		IF ErrorCode < 1 THEN ErrorCode = 1

		IF BEHInfo = 1 THEN CALL InformationWindows

	END
END

/* -------------------------------------------------------------------- */
                                                         /* Error Found */
IF ErrorMacro ~= "" THEN DO

	ErrorLine = GETCLIP("ErrorLine")
	ErrorCode = GETCLIP("ErrorCode")
	ErrorDesc = GETCLIP("ErrorDesc")
	ErrorFile = GETCLIP("ErrorFile")

	CALL Descriptions

	CALL OPEN(ProblemFile, ErrorFile, 'R')
	DO i = 1 UNTIL EOF(ProblemFile)
		Problem.i = LEFT(READLN(ProblemFile),60)
	END
	CALL CLOSE(ProblemFile)

	LineA = ErrorLine - 3
	LineB = ErrorLine - 2
	LineC = ErrorLine - 1
	LineE = ErrorLine + 1
	LineF = ErrorLine + 2
	LineG = ErrorLine + 3

	TextA = "-" LineA Problem.LineA
	TextB = "-" LineB Problem.LineB
	TextC = "-" LineC Problem.LineC
	TextD = "½" ErrorLine Problem.ErrorLine
	TextE = "-" LineE Problem.LineE
	TextF = "-" LineF Problem.LineF
	TextG = "-" LineG Problem.LineG

	BEHInfo = 1
	DO WHILE BEHInfo = 1

		CALL Req_Begin("Info On Error ©                                         by Brett Hester")

		CALL Req_AddControl("Macro",'T',"-" ErrorMacro)
		CALL Req_AddControl("File ",'T',"-" ErrorFile)
		CALL Req_AddControl("",'T',"")
		CALL Req_AddControl("Error",'T',"-" ErrorCode "-" UPPER(ErrorDesc), "-" DescA, "-" DescB, "-" DescC, "-" DescD, "-" DescE, "-" DescF)
		CALL Req_AddControl("",'T',"")
		CALL Req_AddControl("Line ",'T',TextA,TextB,TextC,TextD,TextE,TextF,TextG)
		ReqA = Req_AddControl("",'CH',"Information")

		CALL Req_SetVal(ReqA, 0)

		OKorCancel = Req_Post()
		IF OKorCancel = 0 THEN CALL Exiting

		BEHInfo = Req_GetVal(ReqA)

		CALL Req_End()

		IF BEHInfo = 1 THEN CALL InformationWindows

	END

	CALL SETCLIP("ErrorMacro")
	CALL SETCLIP("ErrorLine")
	CALL SETCLIP("ErrorCode")
	CALL SETCLIP("ErrorDesc")
	CALL SETCLIP("ErrorFile")

END

/* -------------------------------------------------------------------- */
                                                              /* Ending */
Exiting:

	IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
	EXIT

RETURN

/* -------------------------------------------------------------------- */
                                                 /* Information Windows */
InformationWindows:

	OKorCancel = Notify(2, Info1A, Info1B, Info1C, Info1D, Info1E, Info1F, Info1G, Info1H, Info1I, Info1J, Info1K, Info1L, Info1M, Info1N)
	IF OKorCancel = 1 THEN CALL Notify(1, Info2A, Info2B, Info2C, Info2D, Info2E, Info2F, Info2G, Info2H, Info2I, Info2J, Info2K, Info2L, Info2M, Info2N)

RETURN

/* -------------------------------------------------------------------- */

Descriptions:

	DescA = ""
	DescB = ""
	DescC = ""
	DescD = ""
	DescE = ""
	DescF = ""

	IF ErrorCode = 1 THEN DO
		DescA = "The named program could not be found or was not an ARexx"
		DescB = "program. ARexx programs are expected to start with a"
		DescC = "comment (/*...*/). This error is detected by the external"
		DescD = "interface and cannot be trapped by the SYNTAX interrupt."
		DescE = "    POSSIBLE PROBLEM: File not at specified location."
		DescF = '    VERIFY LOCATION VIA "<<CONFIGURE LIST>>"'
	END
	IF ErrorCode = 2 THEN DO
		DescA = "A Ctrl+C break or an external halt request was received and"
		DescB = "the program terminated. This error will be trapped if the"
		DescC = "HALT interrupt has been enabled."
		DescD = "    NOTE: a HALT of all ARexx programs can be made by"
		DescE = '          typing "hi" in a Shell or CLI window.'
	END
	IF ErrorCode = 3 THEN DO
		DescA = "The interpreter was unable to allocate enough memory for an"
		DescB = "operation. Since memory space is required for all parsing"
		DescC = "and execution operations, this error cannot usually be"
		DescD = "trapped by the SYNTAX interrupt."
	END
	IF ErrorCode = 4 THEN DO
		DescA = "A non-ASCII character was found in the program. Control"
		DescB = "codes and other non-ASCII characters may be used in a"
		DescC = "program by defining them as hex or binary strings. This"
		DescD = "is a scan-phase error and cannot be trapped by the SYNTAX"
		DescE = "interrupt."
	END
	IF ErrorCode = 5 THEN DO
		DescA = "A closing single or double quote was missing. Check that"
		DescB = "each string is properly delimited. This is a scan-phase"
		DescC = "error and cannot be trapped by the SYNTAX interrupt."
	END
	IF ErrorCode = 6 THEN DO
		DescA = "The closing */ of a comment was not found. Remember that"
		DescB = "comments may be nested, so each /* must be matched by a */."
		DescC = "This is a scan- phase error and cannot be trapped by the"
		DescD = "SYNTAX interrupt."
	END
	IF ErrorCode = 7 THEN DO
		DescA = "A clause was too long for the internal buffer. The source"
		DescB = "line should be broken into smaller parts. This is a scan-"
		DescC = "phase error and cannot be trapped by the SYNTAX interrupt."
	END
	IF ErrorCode = 8 THEN DO
		DescA = "An unrecognized lexical token was found, or a clause could"
		DescB = "not be properly classified. This is a scan-phase error and"
		DescC = "cannot be trapped by the SYNTAX interrupt."
	END
	IF ErrorCode = 9 THEN DO
		DescA = "An attempt was made to create a string longer than the"
		DescB = "maximum allowed."
	END
	IF ErrorCode = 10 THEN DO
		DescA = "An invalid action code was found in a message packet sent to"
		DescB = "the ARexx resident process. The packet was returned without"
		DescC = "being processed. This error is detected by the external"
		DescD = "interface and cannot be trapped by the SYNTAX interrupt."
	END
	IF ErrorCode = 11 THEN DO
		DescA = "A command string could not be processed. This error is"
		DescB = "detected by the external interface and cannot be trapped"
		DescC = "by the SYNTAX interrupt."
	END
	IF ErrorCode = 12 THEN DO
		DescA = "An external function returned a non-zero error code. Check"
		DescB = "that the correct parameters were supplied to the function."
	END
	IF ErrorCode = 13 THEN DO
		DescA = "The message port corresponding to a host address string"
		DescB = "could not be found. Check that the required external host"
		DescC = "is active."
	END
	IF ErrorCode = 14 THEN DO
		DescA = "An attempt was made to open a function library included in"
		DescB = "the Library List, but the library could not be opened. Check"
		DescC = "that the correct name and version of the library were"
		DescD = "specified when the library was added to the resource list."
	END
	IF ErrorCode = 15 THEN DO
		DescA = "A function was called that could not be found in any of the"
		DescB = "currently accessible libraries and could not be located as"
		DescC = "an external program. Check that the appropriate function"
		DescD = "libraries have been added to the Libraries List."
	END
	IF ErrorCode = 16 THEN DO
		DescA = "A function was called which failed to return a result"
		DescB = "string, but did not otherwise report an error. Check that"
		DescC = "the function was programed correctly or invoke it using"
		DescD = "the CALL instruction."
		DescE = '     POSSIBLE PROBLEM: "CALL" instruction missing.'
		DescF = '     EXAMPLE:          IF X=Y THEN CALL Notify(1,"Hello")'
	END
	IF ErrorCode = 17 THEN DO
		DescA = "A call was made to a function which expected a different"
		DescB = "number of arguments. This error will be generated if a"
		DescC = "built-in or external function is called with more arguments"
		DescD = "than can be accommodated in the message packet used for"
		DescE = "external communications."
	END
	IF ErrorCode = 18 THEN DO
		DescA = "An in appropriate argument was supplied to a function or a"
		DescB = "required argument was missing. Check the parameter"
		DescC = "requirements specified for the function."
	END
	IF ErrorCode = 19 THEN DO
		DescA = "A PROCEDURE instruction was issued in an invalid context."
		DescB = "Either no internal functions were active or a PROCEDURE had"
		DescC = "already been issued in the current storage environment."
	END
	IF ErrorCode = 20 THEN DO
		DescA = "A WHEN or THEN instruction was executed outside of a"
		DescB = "valid context. The WHEN instruction is valid only within a"
		DescC = "SELECT range, and THEN must be the instruction"
		DescD = "following an IF or WHEN."
	END
	IF ErrorCode = 21 THEN DO
		DescA = "An ELSE or OTHERWISE was found outside of a valid context."
		DescB = "The OTHERWISE instruction is valid only within a SELECT"
		DescC = "range, ELSE is valid only following the THEN branch or"
		DescD = "an IF range."
	END
	IF ErrorCode = 22 THEN DO
		DescA = "The BREAK instruction is valid only within a DO range or"
		DescB = "inside an INTERPRETed string. The LEAVE and ITERATE"
		DescC = "instructions are valid only within an iterative DO range."
	END
	IF ErrorCode = 23 THEN DO
		DescA = "An invalid statement was encountered within a SELECT range."
		DescB = "Only WHEN, THEN, and OTHERWISE statements are valid within"
		DescC = "a SELECT range, except for the conditional statements"
		DescD = "following THEN or OTHERWISE clauses."
	END
	IF ErrorCode = 24 THEN DO
		DescA = "An expected THEN clause was not found or another THEN was"
		DescB = "found after one had already been executed."
	END
	IF ErrorCode = 25 THEN DO
		DescA = "None of the WHEN clauses in a SELECT succeded,"
		DescB = "but no OTHERWISE clause was supplied."
	END
	IF ErrorCode = 26 THEN DO
		DescA = "The program source ended before an END was found for a DO"
		DescB = "or SELECT instruction, or an END was encountered outside a"
		DescC = "DO or SELECT range."
	END
	IF ErrorCode = 27 THEN DO
		DescA = "The symbol specified on an END, ITERATE or LEAVE instruction"
		DescB = "did not match the index variable for the DO range. Check"
		DescC = "that the active loops have been nested properly."
	END
	IF ErrorCode = 28 THEN DO
		DescA = "An invalid DO instruction was executed. An initializer"
		DescB = "expression must be given if a TO or BY expression is"
		DescC = "specified. A FOR expression must yield a non-negative"
		DescD = "integer result."
	END
	IF ErrorCode = 29 THEN DO
		DescA = "An IF or SELECT range ended before all of the required"
		DescB = "statements were found. Check whether the conditional"
		DescC = "statement following a THEN, ELSE, or OTHERWISE clause"
		DescD = "was omitted."
	END
	IF ErrorCode = 30 THEN DO
		DescA = "A label specified by a SIGNAL instruction or implicitly"
		DescB = "referenced by a enabled interrupt could not be found in the"
		DescC = "program source. Labels defined dynamically by an INTERPRET"
		DescD = "instruction or by interactive input are not included in"
		DescE = "the search."
	END
	IF ErrorCode = 31 THEN DO
		DescA = "A non-symbol token was found where only a symbol token is"
		DescB = "valid. The DROP, END, LEAVE, ITERATE, and UPPER instructions"
		DescC = "may only be followed by a symbol token. This message will"
		DescD = "also be issued if a required symbol is missing."
	END
	IF ErrorCode = 32 THEN DO
		DescA = "An invalid token was found in a context where only a"
		DescB = "symbol or string is valid."
	END
	IF ErrorCode = 33 THEN DO
		DescA = "A symbol token in an instruction clause was identified as a"
		DescB = "keyword, but was invalid in the specific context."
	END
	IF ErrorCode = 34 THEN DO
		DescA = "An instruction clause required a specific keyword token to"
		DescB = "be present, but it was not supplied. This message will be"
		DescC = "issued if a SIGNAL ON instruction is not followed by one of"
		DescD = "the interrupt keywords (e.g.,SYNTAX)."
	END
	IF ErrorCode = 35 THEN DO
		DescA = "A seemingly valid statement was executed, but extra"
		DescB = "characters were found at the end of the clause."
	END
	IF ErrorCode = 36 THEN DO
		DescA = "Two mutually exclusive keywords were included in an"
		DescB = "instruction clause, or a keyword was included twice"
		DescC = "in the same instruction."
	END
	IF ErrorCode = 37 THEN DO
		DescA = "The template provided with an ARG, PARSE, or PULL"
		DescB = "instruction was not properly constructed."
	END
	IF ErrorCode = 38 THEN DO
		DescA = "The alphabetic keyword supplied with a TRACE instruction or"
		DescB = "as the argument to the TRACE() built-in function was"
		DescC = "not valid."
	END
	IF ErrorCode = 39 THEN DO
		DescA = "An attempt was made to use an unitialialized variable"
		DescB = "while the NOVALUE interrupt was enabled."
	END
	IF ErrorCode = 40 THEN DO
		DescA = "An attempt was made to assign a value to a fixed symbol."
	END
	IF ErrorCode = 41 THEN DO
		DescA = "An error was detected during the evaluation of an"
		DescB = "expression. Check that each operator has the correct number"
		DescC = "of operands and that no extraneous tokens appear in the"
		DescD = "expression. This error will be detected only in expressions"
		DescE = "that are actually evaluated. No checking is performed on"
		DescF = "expressions in clauses that are being skipped."
	END
	IF ErrorCode = 42 THEN DO
		DescA = "An expression was found with an unequal number of opening"
		DescB = "and closing parentheses."
	END
	IF ErrorCode = 43 THEN DO
		DescA = "The number of subexpressions in an expressions was greater"
		DescB = "than the maximum allowed. Simplify the expression by"
		DescC = "breaking it into two or more intermediate expressions."
	END
	IF ErrorCode = 44 THEN DO
		DescA = "The result of an expression was not valid within its"
		DescB = "context. This message will be issued if an increment or"
		DescC = "limit expression in a DO instruction yields a"
		DescD = "non-numeric result."
	END
	IF ErrorCode = 45 THEN DO
		DescA = "An expression was omitted in a context where one is"
		DescB = "required. For example, the SIGNAL instruction, if not"
		DescC = "followed by the keywords ON or OFF, must be followed"
		DescD = "by an expression."
	END
	IF ErrorCode = 46 THEN DO
		DescA = "An expression result was expected to yield a boolean result,"
		DescB = "but evaluated to something other than 0 or 1."
	END
	IF ErrorCode = 47 THEN DO
		DescA = "A non-numeric operand was used in an operation requiring"
		DescB = "numeric operands. This message will also be generated by an"
		DescC = "invalid hex or binary string."
	END
	IF ErrorCode = 48 THEN DO
		DescA = "An operand was not valid for the intended operation. This"
		DescB = "message will be generated if ab attempt is made to divide"
		DescC = "by 0 or if a fractional exponent is used in an"
		DescD = "exponentiation operation."
	END

RETURN

/* -------------------------------------------------------------------- */
                                                      /* Error Handling */
SYNTAX:
ERROR:

	ErrCode = RC
	ErrLine = SIGL
	ErrInfo = ERRORTEXT(ErrCode)

	Err1 = "!Sorry!"
	Err2 = "An Error has been detected"
	Err3 = "@þ Macro -            "
	Err4 = "@þ Line Number -      "
	Err5 = "@þ Error Code -       "
	Err6 = "@þ Error Description -"
	Err7 = "@¤ Please Inform -    "
	Err8 = '  "Error Notice"     '
	Err9 = "  13032 Copenhill Rd."
	Err10 = "  Dallas, TX. 75240  "

	Call Notify(1,Err1,Err2,Err3,MacrosName,Err4,ErrLine,Err5,ErrCode,Err6,ErrInfo,Err7,Err8,Err9,Err10)

/* -------------------------------------------------------------------- */
                                             /* Advanced Error Handling */
	CALL SETCLIP("ErrorMacro",MacrosName)
	CALL SETCLIP("ErrorLine",ErrLine)
	CALL SETCLIP("ErrorCode",ErrCode)
	CALL SETCLIP("ErrorDesc",ErrInfo)

	PARSE SOURCE TempA TempB ErrFile TempC TempD TempE

	CALL SETCLIP("ErrorFile",ErrFile)

/* -------------------------------------------------------------------- */

	IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
	EXIT
