catch.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* $Id$ */
  2. /*
  3. * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. *
  5. * This product is part of the Amsterdam Compiler Kit.
  6. *
  7. * Permission to use, sell, duplicate or disclose this software must be
  8. * obtained in writing. Requests for such permissions may be sent to
  9. *
  10. * Dr. Andrew S. Tanenbaum
  11. * Wiskundig Seminarium
  12. * Vrije Universiteit
  13. * Postbox 7161
  14. * 1007 MC Amsterdam
  15. * The Netherlands
  16. *
  17. */
  18. #include <em_abs.h>
  19. #include <pc_err.h>
  20. #include <pc_file.h>
  21. /* to make it easier to patch ... */
  22. extern struct file *_curfil;
  23. static struct errm {
  24. int errno;
  25. char *errmes;
  26. } errors[] = {
  27. { EARRAY, "array bound error"},
  28. { ERANGE, "range bound error"},
  29. { ESET, "set bound error"},
  30. { EIOVFL, "integer overflow"},
  31. { EFOVFL, "real overflow"},
  32. { EFUNFL, "real underflow"},
  33. { EIDIVZ, "divide by 0"},
  34. { EFDIVZ, "divide by 0.0"},
  35. { EIUND, "undefined integer"},
  36. { EFUND, "undefined real"},
  37. { ECONV, "conversion error"},
  38. { ESTACK, "stack overflow"},
  39. { EHEAP, "heap overflow"},
  40. { EILLINS, "illegal instruction"},
  41. { EODDZ, "illegal size argument"},
  42. { ECASE, "case error"},
  43. { EMEMFLT, "addressing non existent memory"},
  44. { EBADPTR, "bad pointer used"},
  45. { EBADPC, "program counter out of range"},
  46. { EBADLAE, "bad argument of lae"},
  47. { EBADMON, "bad monitor call"},
  48. { EBADLIN, "argument if LIN too high"},
  49. { EBADGTO, "GTO descriptor error"},
  50. { EARGC, "more args expected" },
  51. { EEXP, "error in exp" },
  52. { ELOG, "error in ln" },
  53. { ESQT, "error in sqrt" },
  54. { EASS, "assertion failed" },
  55. { EPACK, "array bound error in pack" },
  56. { EUNPACK, "array bound error in unpack" },
  57. { EMOD, "only positive j in 'i mod j'" },
  58. { EBADF, "file not yet open" },
  59. { EFREE, "dispose error" },
  60. { EFUNASS, "function not assigned" },
  61. { EWIDTH, "illegal field width" },
  62. { EWRITEF, "not writable" },
  63. { EREADF, "not readable" },
  64. { EEOF, "end of file" },
  65. { EFTRUNC, "truncated" },
  66. { ERESET, "reset error" },
  67. { EREWR, "rewrite error" },
  68. { ECLOSE, "close error" },
  69. { EREAD, "read error" },
  70. { EWRITE, "write error" },
  71. { EDIGIT, "digit expected" },
  72. { EASCII, "non-ASCII char read" },
  73. { -1, 0}
  74. };
  75. extern int _pargc;
  76. extern char **_pargv;
  77. extern char **_penvp;
  78. extern char *_hol0();
  79. extern _trp();
  80. extern _exit();
  81. extern int _write();
  82. _catch(erno) unsigned erno; {
  83. register struct errm *ep = &errors[0];
  84. char *p,*q,*s,**qq;
  85. char buf[20];
  86. unsigned i;
  87. int j = erno;
  88. char *pp[11];
  89. char xbuf[100];
  90. qq = pp;
  91. if (p = FILN)
  92. *qq++ = p;
  93. else
  94. *qq++ = _pargv[0];
  95. while (ep->errno != erno && ep->errmes != 0) ep++;
  96. p = buf;
  97. s = xbuf;
  98. if (i = LINO) {
  99. *qq++ = ", ";
  100. do
  101. *p++ = i % 10 + '0';
  102. while (i /= 10);
  103. while (p > buf) *s++ = *--p;
  104. }
  105. *s++ = ':';
  106. *s++ = ' ';
  107. *s++ = '\0';
  108. *qq++ = xbuf;
  109. if ((erno & ~037) == 0140 && (_curfil->flags&0377)==MAGIC) {
  110. /* file error */
  111. *qq++ = "file ";
  112. *qq++ = _curfil->fname;
  113. *qq++ = ": ";
  114. }
  115. if (ep->errmes) *qq++ = ep->errmes;
  116. else {
  117. *qq++ = "error number ";
  118. *qq++ = s;
  119. p = buf;
  120. if (j < 0) {
  121. j = -j;
  122. *s++ = '-';
  123. }
  124. do
  125. *p++ = j % 10 + '0';
  126. while (j /= 10);
  127. while (p > buf) *s++ = *--p;
  128. *s = 0;
  129. }
  130. *qq++ = "\n";
  131. *qq = 0;
  132. qq = pp;
  133. while (q = *qq++) {
  134. p = q;
  135. while (*p)
  136. p++;
  137. if (_write(2,q,(int)(p-q)) < 0)
  138. ;
  139. }
  140. _exit(erno+1);
  141. error:
  142. _trp(erno);
  143. }