PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/c/error.c

https://bitbucket.org/mbeutel/owbasic
C | 265 lines | 189 code | 46 blank | 30 comment | 35 complexity | 4138f2e2cd7fb8baa2739fac53a1c923 MD5 | raw file
Possible License(s): GPL-2.0
  1. #include "modeldef.h"
  2. #include <shared.h>
  3. #include <string.h>
  4. #include <modecall.h>
  5. #include "owbasic.h"
  6. #include "comp.h"
  7. #include "graphic.h"
  8. #include "rc.h"
  9. void serror (int error)
  10. {
  11. uchar s = 0;
  12. serror1 (error, &s);
  13. }
  14. void serrortoken (int error)
  15. {
  16. *token_end = 0;
  17. serror1 (error, (uchar*) token_start);
  18. }
  19. static char FAR errormsg0a[] = "Line %d %s:\r%s\r\r%s";
  20. static char FAR errormsg0b[] = "%s,%d: %s";
  21. static char errormsg_expect[] = "Expected %s (%d)";
  22. static char errormsg_customtext[] = "%s\r>>%s<<";
  23. /*static char FAR errormsg1a[] = "Line %d %s:\rExpected %s (%d)\r\r%s";
  24. static char FAR errormsg1b[] = "%s,%d: Expected %c (%d)";*/
  25. /*static char FAR errormsg2a[] = "Line %d %s:\r%s\r>>%s<<\r\r%s";
  26. static char FAR errormsg2b[] = "%s,%d: %s >>%s<<";*/
  27. static char FAR rterrormsg1a[] = "Address: %d\rFound in: %s\rError: %s%s";
  28. /*static char FAR rterrormsg2a[] = "%s\r%s";*/
  29. static char FAR rterror_search[] = "\rSearch position?";
  30. /*static char FAR rterrormsg1b[] = "%s:%s";*/
  31. static char FAR rterrormsg1b[] = "%s:%s %s";
  32. static uchar eex_nothing[] = "";
  33. static uchar FAR eex_identifier[] = "identifier";
  34. static uchar FAR eex_to[] = "TO";
  35. static const uchar FAR* NEAR eex_name (int error)
  36. {
  37. static uchar eexc[2];
  38. switch (error)
  39. {
  40. case IDENT:
  41. return (eex_identifier);
  42. case TO:
  43. return (eex_to);
  44. default:
  45. if (error < 0x0100) /* character token */
  46. {
  47. eexc[0] = error;
  48. eexc[1] = '\0';
  49. return (eexc);
  50. }
  51. }
  52. return (eex_nothing);
  53. }
  54. void serror1 (int error, const uchar *cptr)
  55. {
  56. int h;
  57. int herror; /* format and content of error message */
  58. char disptext[400];
  59. uchar etext[300]; /* composition of error message */
  60. uchar emsg[80];
  61. uchar *hprog = prog - 5;
  62. herror = error / 1000;
  63. /*
  64. switch (herror & 3)
  65. 0 - normal message
  66. 1 - message "expected ... "
  67. 2 - message with *cptr as text
  68. herror & 4 - don't show context /+ for include file, undefined label +/
  69. */
  70. error %= 1000;
  71. auto_off_act = FALSE;
  72. if ((error == EC_ERROR_POSITION_FOUND) && (!isFindRTE))
  73. error = EC_LAST_CODE_REACHED;
  74. etext[0] = 0;
  75. /* program context of error */
  76. if (((herror & 4) == 0) && (!switches.remote)) /* no context in remote mode */
  77. {
  78. h = 0;
  79. while ((h < 20) && (*hprog != '\r') && (hprog > prog_start))
  80. {
  81. ++h;
  82. --hprog;
  83. }
  84. if (*hprog == '\r')
  85. ++hprog;
  86. h = 0;
  87. /* text before position */
  88. while (hprog < prog)
  89. etext[h++] = *(hprog++);
  90. /* mark position */
  91. etext[h++] = 0xD6 /* arrow */;
  92. /* fill with following */
  93. while ((h < 29) && (*hprog != 0) && (*hprog != '\r'))
  94. etext[h++] = *(hprog++);
  95. etext[h] = 0;
  96. }
  97. if (!(herror & 3))
  98. strcpy_nf (emsg, (const uchar FAR*) msg_errortable[error]);
  99. if (herror & 1) /* error expected ...(char or keyword) */
  100. sprintf ((char*) emsg,
  101. errormsg_expect,
  102. Near ((const char FAR*) eex_name (error)), error);
  103. if (herror & 2) /* error with *cptr as text */
  104. sprintf ((char*) emsg,
  105. errormsg_customtext,
  106. Near (msg_errortable[error]), cptr);
  107. #ifdef SIMULATOR_BINARY
  108. sprintf (disptext, Near (errormsg0b), /* "%s,%d: %s", */
  109. ITOS.fname, ITOS.line, emsg);
  110. far_strcpy (SYS_INP_BUF, disptext); /* for SIM use: copy error message to clipboard */
  111. #endif
  112. #ifdef REMOTE_CONTROL
  113. if (!switches.remote)
  114. {
  115. #endif
  116. sprintf (disptext, Near (errormsg0a), /* "Line %d %s:\r%s\r\r%s", */
  117. ITOS.line, ITOS.fname, emsg, etext);
  118. #ifdef REMOTE_CONTROL
  119. }
  120. else
  121. {
  122. sprintf (disptext, Near (errormsg0b), /* "%s,%d: %s", */
  123. ITOS.fname, ITOS.line, emsg);
  124. rc_finish (FALSE, disptext);
  125. }
  126. #endif
  127. msgbox ((const uchar*) disptext, msg_compilererror, 0.0, MBX_OK);
  128. auto_off_act = TRUE;
  129. longjmp (errorret, 1); /* terminate compilation */
  130. }
  131. #ifdef LSI_C
  132. uchar* rterrormsg = ((uchar*) IncStack) + MAXSTRLEN + 1;
  133. #else
  134. #ifdef __HITACHI__
  135. uchar* rterrormsg = (uchar*) IncStack;
  136. #else
  137. uchar _rterrormsg[30];
  138. uchar* rterrormsg = _rterrormsg;
  139. #endif
  140. #endif
  141. void rterror1 (uchar FAR* funcname, int err)
  142. {
  143. uchar emsg[40];
  144. uchar fname[NAMELEN];
  145. uchar msg[NAMELEN + 200];
  146. bool srchdlg = pref.searcherror && !xdata[errorhandler];
  147. uchar* caption = switches.comp ? msg_compilererror : msg_runtimeerror;
  148. unsigned int apc = pc.c - bin;
  149. int rterrormode = err / 1000;
  150. /*
  151. * rterrormode:
  152. * 0 - normal error message
  153. * 1 - error message with additional text
  154. *
  155. */
  156. err %= 1000;
  157. strcpy_nf (fname, funcname);
  158. strcpy_nf (emsg, (uchar FAR*) msg_errortable[err]);
  159. xdata[error] = err;
  160. if (block_errors == 0)
  161. {
  162. auto_off_act = FALSE;
  163. #ifdef REMOTE_CONTROL
  164. if (switches.remote)
  165. {
  166. sprintf ((char*) msg, (byte*) Near (rterrormsg1b),
  167. fname, emsg, (rterrormode == 1) ? rterrormsg : eex_nothing);
  168. /*if (rterrormode == 1)
  169. sprintf ((char*) msg, (byte*) Near (rterrormsg2b), fname, emsg, rterrormsg);
  170. else
  171. sprintf ((char*) msg, (byte*) Near (rterrormsg1b), fname, emsg);*/
  172. rc_finish (FALSE, msg);
  173. Restart (STATUS_RC);
  174. }
  175. else
  176. #endif
  177. {
  178. sprintf ((char*) msg, Near (rterrormsg1a),
  179. apc, fname, emsg, (rterrormode = 1) ? rterrormsg : eex_nothing);
  180. /*if (rterrormode = 1)
  181. strcat ((char*) msg, (char*) rterrormsg);*/
  182. if (srchdlg)
  183. strcat ((char*) msg, Near (rterror_search));
  184. #ifdef SIMULATOR_BINARY
  185. switches.rterror = TRUE;
  186. msgbox (msg, caption, 0.0, MBX_OK);
  187. mystatus = (mystatus & MC_CALLMASK) | STATUS_FIND_RTE;
  188. sprintf ((char*) msg, (byte*) Near (rterrormsg1b),
  189. fname, emsg, (rterrormode == 1) ? rterrormsg : eex_nothing);
  190. fbbinit ();
  191. fbbputstring (msg);
  192. saveshared ((byte*) "rtmsg", (byte*) PROGNAME, FBB, FBBNUM);
  193. #else
  194. if (switches.rterror = (byte) msgbox (msg, caption, 0.0, srchdlg ? MBX_YESNO : MBX_OK))
  195. mystatus = (mystatus & MC_CALLMASK) | STATUS_FIND_RTE;
  196. #endif
  197. fbbinit ();
  198. fbbputstring (progname);
  199. fbbputint (progcat);
  200. fbbputint (apc);
  201. saveshared ((byte*) "rterror", (byte*) PROGNAME, FBB, FBBNUM);
  202. }
  203. if (switches.comp) /* terminate compilation (MB,5.22) */
  204. longjmp (errorret, 1);
  205. else
  206. {
  207. auto_off_act = TRUE;
  208. if (xdata[errorhandler] && !switches.rterror)
  209. jump (errorhandler, err);
  210. else
  211. longjmp (rterrorret, 1);
  212. }
  213. }
  214. }
  215. void rterror (unsigned int fno, int err)
  216. {
  217. rterror1 (FUNCNAME (fno), err);
  218. }