catch.c 3.3 KB

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