/c/error.c
C | 265 lines | 189 code | 46 blank | 30 comment | 35 complexity | 4138f2e2cd7fb8baa2739fac53a1c923 MD5 | raw file
Possible License(s): GPL-2.0
- #include "modeldef.h"
- #include <shared.h>
- #include <string.h>
- #include <modecall.h>
- #include "owbasic.h"
- #include "comp.h"
- #include "graphic.h"
- #include "rc.h"
-
-
- void serror (int error)
- {
- uchar s = 0;
- serror1 (error, &s);
- }
-
- void serrortoken (int error)
- {
- *token_end = 0;
- serror1 (error, (uchar*) token_start);
- }
-
- static char FAR errormsg0a[] = "Line %d %s:\r%s\r\r%s";
- static char FAR errormsg0b[] = "%s,%d: %s";
- static char errormsg_expect[] = "Expected %s (%d)";
- static char errormsg_customtext[] = "%s\r>>%s<<";
-
- /*static char FAR errormsg1a[] = "Line %d %s:\rExpected %s (%d)\r\r%s";
- static char FAR errormsg1b[] = "%s,%d: Expected %c (%d)";*/
-
- /*static char FAR errormsg2a[] = "Line %d %s:\r%s\r>>%s<<\r\r%s";
- static char FAR errormsg2b[] = "%s,%d: %s >>%s<<";*/
-
- static char FAR rterrormsg1a[] = "Address: %d\rFound in: %s\rError: %s%s";
- /*static char FAR rterrormsg2a[] = "%s\r%s";*/
- static char FAR rterror_search[] = "\rSearch position?";
- /*static char FAR rterrormsg1b[] = "%s:%s";*/
- static char FAR rterrormsg1b[] = "%s:%s %s";
-
-
- static uchar eex_nothing[] = "";
- static uchar FAR eex_identifier[] = "identifier";
- static uchar FAR eex_to[] = "TO";
-
- static const uchar FAR* NEAR eex_name (int error)
- {
- static uchar eexc[2];
- switch (error)
- {
- case IDENT:
- return (eex_identifier);
- case TO:
- return (eex_to);
- default:
- if (error < 0x0100) /* character token */
- {
- eexc[0] = error;
- eexc[1] = '\0';
- return (eexc);
- }
- }
- return (eex_nothing);
- }
-
-
- void serror1 (int error, const uchar *cptr)
- {
- int h;
- int herror; /* format and content of error message */
- char disptext[400];
- uchar etext[300]; /* composition of error message */
- uchar emsg[80];
-
-
- uchar *hprog = prog - 5;
- herror = error / 1000;
- /*
- switch (herror & 3)
- 0 - normal message
- 1 - message "expected ... "
- 2 - message with *cptr as text
-
- herror & 4 - don't show context /+ for include file, undefined label +/
- */
-
- error %= 1000;
- auto_off_act = FALSE;
-
- if ((error == EC_ERROR_POSITION_FOUND) && (!isFindRTE))
- error = EC_LAST_CODE_REACHED;
-
- etext[0] = 0;
-
- /* program context of error */
- if (((herror & 4) == 0) && (!switches.remote)) /* no context in remote mode */
- {
- h = 0;
- while ((h < 20) && (*hprog != '\r') && (hprog > prog_start))
- {
- ++h;
- --hprog;
- }
- if (*hprog == '\r')
- ++hprog;
-
- h = 0;
-
- /* text before position */
- while (hprog < prog)
- etext[h++] = *(hprog++);
-
- /* mark position */
- etext[h++] = 0xD6 /* arrow */;
-
- /* fill with following */
- while ((h < 29) && (*hprog != 0) && (*hprog != '\r'))
- etext[h++] = *(hprog++);
- etext[h] = 0;
- }
-
- if (!(herror & 3))
- strcpy_nf (emsg, (const uchar FAR*) msg_errortable[error]);
-
- if (herror & 1) /* error expected ...(char or keyword) */
- sprintf ((char*) emsg,
- errormsg_expect,
- Near ((const char FAR*) eex_name (error)), error);
-
- if (herror & 2) /* error with *cptr as text */
- sprintf ((char*) emsg,
- errormsg_customtext,
- Near (msg_errortable[error]), cptr);
-
-
- #ifdef SIMULATOR_BINARY
- sprintf (disptext, Near (errormsg0b), /* "%s,%d: %s", */
- ITOS.fname, ITOS.line, emsg);
- far_strcpy (SYS_INP_BUF, disptext); /* for SIM use: copy error message to clipboard */
- #endif
- #ifdef REMOTE_CONTROL
- if (!switches.remote)
- {
- #endif
-
- sprintf (disptext, Near (errormsg0a), /* "Line %d %s:\r%s\r\r%s", */
- ITOS.line, ITOS.fname, emsg, etext);
-
- #ifdef REMOTE_CONTROL
- }
- else
- {
- sprintf (disptext, Near (errormsg0b), /* "%s,%d: %s", */
- ITOS.fname, ITOS.line, emsg);
- rc_finish (FALSE, disptext);
- }
- #endif
-
-
- msgbox ((const uchar*) disptext, msg_compilererror, 0.0, MBX_OK);
-
- auto_off_act = TRUE;
- longjmp (errorret, 1); /* terminate compilation */
- }
-
-
- #ifdef LSI_C
- uchar* rterrormsg = ((uchar*) IncStack) + MAXSTRLEN + 1;
- #else
- #ifdef __HITACHI__
- uchar* rterrormsg = (uchar*) IncStack;
- #else
- uchar _rterrormsg[30];
- uchar* rterrormsg = _rterrormsg;
- #endif
- #endif
-
- void rterror1 (uchar FAR* funcname, int err)
- {
- uchar emsg[40];
- uchar fname[NAMELEN];
- uchar msg[NAMELEN + 200];
- bool srchdlg = pref.searcherror && !xdata[errorhandler];
- uchar* caption = switches.comp ? msg_compilererror : msg_runtimeerror;
-
- unsigned int apc = pc.c - bin;
- int rterrormode = err / 1000;
-
- /*
- * rterrormode:
- * 0 - normal error message
- * 1 - error message with additional text
- *
- */
-
-
- err %= 1000;
-
- strcpy_nf (fname, funcname);
- strcpy_nf (emsg, (uchar FAR*) msg_errortable[err]);
- xdata[error] = err;
- if (block_errors == 0)
- {
- auto_off_act = FALSE;
- #ifdef REMOTE_CONTROL
- if (switches.remote)
- {
- sprintf ((char*) msg, (byte*) Near (rterrormsg1b),
- fname, emsg, (rterrormode == 1) ? rterrormsg : eex_nothing);
- /*if (rterrormode == 1)
- sprintf ((char*) msg, (byte*) Near (rterrormsg2b), fname, emsg, rterrormsg);
- else
- sprintf ((char*) msg, (byte*) Near (rterrormsg1b), fname, emsg);*/
- rc_finish (FALSE, msg);
- Restart (STATUS_RC);
- }
- else
- #endif
- {
- sprintf ((char*) msg, Near (rterrormsg1a),
- apc, fname, emsg, (rterrormode = 1) ? rterrormsg : eex_nothing);
- /*if (rterrormode = 1)
- strcat ((char*) msg, (char*) rterrormsg);*/
- if (srchdlg)
- strcat ((char*) msg, Near (rterror_search));
-
- #ifdef SIMULATOR_BINARY
- switches.rterror = TRUE;
- msgbox (msg, caption, 0.0, MBX_OK);
- mystatus = (mystatus & MC_CALLMASK) | STATUS_FIND_RTE;
-
- sprintf ((char*) msg, (byte*) Near (rterrormsg1b),
- fname, emsg, (rterrormode == 1) ? rterrormsg : eex_nothing);
- fbbinit ();
- fbbputstring (msg);
- saveshared ((byte*) "rtmsg", (byte*) PROGNAME, FBB, FBBNUM);
- #else
- if (switches.rterror = (byte) msgbox (msg, caption, 0.0, srchdlg ? MBX_YESNO : MBX_OK))
- mystatus = (mystatus & MC_CALLMASK) | STATUS_FIND_RTE;
- #endif
- fbbinit ();
- fbbputstring (progname);
- fbbputint (progcat);
- fbbputint (apc);
- saveshared ((byte*) "rterror", (byte*) PROGNAME, FBB, FBBNUM);
- }
-
- if (switches.comp) /* terminate compilation (MB,5.22) */
- longjmp (errorret, 1);
- else
- {
- auto_off_act = TRUE;
- if (xdata[errorhandler] && !switches.rterror)
- jump (errorhandler, err);
- else
- longjmp (rterrorret, 1);
- }
- }
- }
-
- void rterror (unsigned int fno, int err)
- {
- rterror1 (FUNCNAME (fno), err);
- }
-
-