catch.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /*
  6. Module: default modula-2 trap handler
  7. Author: Ceriel J.H. Jacobs
  8. Version: $Header$
  9. */
  10. #include <em_abs.h>
  11. #include <m2_traps.h>
  12. #include <signal.h>
  13. static struct errm {
  14. int errno;
  15. char *errmes;
  16. } errors[] = {
  17. { EARRAY, "array bound error"},
  18. { ERANGE, "range bound error"},
  19. { ESET, "set bound error"},
  20. { EIOVFL, "integer overflow"},
  21. { EFOVFL, "real overflow"},
  22. { EFUNFL, "real underflow"},
  23. { EIDIVZ, "divide by 0"},
  24. { EFDIVZ, "divide by 0.0"},
  25. { EIUND, "undefined integer"},
  26. { EFUND, "undefined real"},
  27. { ECONV, "conversion error"},
  28. { ESTACK, "stack overflow"},
  29. { EHEAP, "heap overflow"},
  30. { EILLINS, "illegal instruction"},
  31. { EODDZ, "illegal size argument"},
  32. { ECASE, "case error"},
  33. { EMEMFLT, "addressing non existent memory"},
  34. { EBADPTR, "bad pointer used"},
  35. { EBADPC, "program counter out of range"},
  36. { EBADLAE, "bad argument of lae"},
  37. { EBADMON, "bad monitor call"},
  38. { EBADLIN, "argument if LIN too high"},
  39. { EBADGTO, "GTO descriptor error"},
  40. { M2_TOOLARGE, "stack size of process too large"},
  41. { M2_TOOMANY, "too many nested traps + handlers"},
  42. { M2_NORESULT, "no RETURN from procedure function"},
  43. { M2_UOVFL, "cardinal overflow"},
  44. { M2_FORCH, "Warning: FOR-loop control variable was changed in the body"},
  45. { M2_UUVFL, "cardinal underflow"},
  46. { M2_INTERNAL, "internal error; ask an expert for help"},
  47. { M2_UNIXSIG, "got a unix signal"},
  48. { -1, 0}
  49. };
  50. extern exit();
  51. catch(trapno)
  52. int trapno;
  53. {
  54. register struct errm *ep = &errors[0];
  55. char *errmessage;
  56. char buf[20];
  57. register char *p, *s;
  58. char *q;
  59. while (ep->errno != trapno && ep->errmes != 0) ep++;
  60. if (p = ep->errmes) {
  61. while (*p) p++;
  62. _Traps__Message(ep->errmes, 0, (int) (p - ep->errmes), 1);
  63. }
  64. else {
  65. int i = trapno;
  66. q = "error number xxxxxxxxxxxxx";
  67. p = &q[13];
  68. s = buf;
  69. if (i < 0) {
  70. i = -i;
  71. *p++ = '-';
  72. }
  73. do
  74. *s++ = i % 10 + '0';
  75. while (i /= 10);
  76. while (s > buf) *p++ = *--s;
  77. *p = 0;
  78. _Traps__Message(q, 0, (int) (p - q), 1);
  79. }
  80. #ifndef em24
  81. #ifndef em44
  82. #ifndef em22
  83. if (trapno == M2_UNIXSIG) {
  84. extern int __signo;
  85. signal(__signo, SIG_DFL);
  86. _cleanup();
  87. kill(getpid(), __signo);
  88. _exit(trapno);
  89. }
  90. #endif
  91. #endif
  92. #endif
  93. if (trapno != M2_FORCH) exit(trapno);
  94. SIG(catch);
  95. }