catch.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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: $Id$
  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 function procedure"},
  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. catch(trapno)
  51. int trapno;
  52. {
  53. register struct errm *ep = &errors[0];
  54. char *errmessage;
  55. char buf[20];
  56. register char *p, *s;
  57. while (ep->errno != trapno && ep->errmes != 0) ep++;
  58. if (p = ep->errmes) {
  59. while (*p) p++;
  60. _Traps__Message(ep->errmes, 0, (int) (p - ep->errmes), 1);
  61. }
  62. else {
  63. int i = trapno;
  64. static char q[] = "error number xxxxxxxxxxxxx";
  65. p = &q[13];
  66. s = buf;
  67. if (i < 0) {
  68. i = -i;
  69. *p++ = '-';
  70. }
  71. do
  72. *s++ = i % 10 + '0';
  73. while (i /= 10);
  74. while (s > buf) *p++ = *--s;
  75. *p = 0;
  76. _Traps__Message(q, 0, (int) (p - q), 1);
  77. }
  78. #if !defined(__em24) && !defined(__em44) && !defined(__em22)
  79. if (trapno == M2_UNIXSIG) {
  80. extern int __signo;
  81. signal(__signo, SIG_DFL);
  82. _cleanup();
  83. kill(getpid(), __signo);
  84. _exit(trapno+1);
  85. }
  86. #endif
  87. if (trapno != M2_FORCH) {
  88. _cleanup();
  89. _exit(trapno+1);
  90. }
  91. SIG(catch);
  92. }