ack/lang/pc/libpc/catch.c

157 lines
3.1 KiB
C
Raw Permalink Normal View History

1994-06-24 14:02:31 +00:00
/* $Id$ */
1984-07-20 10:44:57 +00:00
/*
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
*
* This product is part of the Amsterdam Compiler Kit.
*
* Permission to use, sell, duplicate or disclose this software must be
* obtained in writing. Requests for such permissions may be sent to
*
* Dr. Andrew S. Tanenbaum
* Wiskundig Seminarium
* Vrije Universiteit
* Postbox 7161
* 1007 MC Amsterdam
* The Netherlands
*
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <em_abs.h>
2018-06-17 20:30:27 +00:00
#include "pc.h"
1984-07-20 10:44:57 +00:00
2018-06-17 14:11:29 +00:00
static struct errm
{
1989-05-03 09:53:25 +00:00
int errno;
2018-06-17 14:11:29 +00:00
char* errmes;
1989-05-03 09:53:25 +00:00
} errors[] = {
2018-06-17 14:11:29 +00:00
{ EARRAY, "array bound error" },
{ ERANGE, "range bound error" },
{ ESET, "set bound error" },
{ EIOVFL, "integer overflow" },
{ EFOVFL, "real overflow" },
{ EFUNFL, "real underflow" },
{ EIDIVZ, "divide by 0" },
{ EFDIVZ, "divide by 0.0" },
{ EIUND, "undefined integer" },
{ EFUND, "undefined real" },
{ ECONV, "conversion error" },
1989-05-03 09:53:25 +00:00
2018-06-17 14:11:29 +00:00
{ ESTACK, "stack overflow" },
{ EHEAP, "heap overflow" },
{ EILLINS, "illegal instruction" },
{ EODDZ, "illegal size argument" },
{ ECASE, "case error" },
{ EMEMFLT, "addressing non existent memory" },
{ EBADPTR, "bad pointer used" },
{ EBADPC, "program counter out of range" },
{ EBADLAE, "bad argument of lae" },
{ EBADMON, "bad monitor call" },
{ EBADLIN, "argument if LIN too high" },
{ EBADGTO, "GTO descriptor error" },
1989-05-03 09:53:25 +00:00
2018-06-17 14:11:29 +00:00
{ EARGC, "more args expected" },
{ EEXP, "error in exp" },
{ ELOG, "error in ln" },
{ ESQT, "error in sqrt" },
{ EASS, "assertion failed" },
{ EPACK, "array bound error in pack" },
{ EUNPACK, "array bound error in unpack" },
{ EMOD, "only positive j in 'i mod j'" },
{ EBADF, "file not yet open" },
{ EFREE, "dispose error" },
{ EFUNASS, "function not assigned" },
{ EWIDTH, "illegal field width" },
1989-05-03 09:53:25 +00:00
2018-06-17 14:11:29 +00:00
{ EWRITEF, "not writable" },
{ EREADF, "not readable" },
{ EEOF, "end of file" },
{ EFTRUNC, "truncated" },
{ ERESET, "reset error" },
{ EREWR, "rewrite error" },
{ ECLOSE, "close error" },
{ EREAD, "read error" },
{ EWRITE, "write error" },
{ EDIGIT, "digit expected" },
{ EASCII, "non-ASCII char read" },
{ -1, 0 }
1989-05-03 09:53:25 +00:00
};
1984-07-20 10:44:57 +00:00
2018-06-17 20:30:27 +00:00
void _catch(unsigned int erno)
2018-06-17 14:11:29 +00:00
{
register struct errm* ep = &errors[0];
char *p, *q, *s, **qq;
1989-05-03 09:53:25 +00:00
char buf[20];
unsigned i;
int j = erno;
2018-06-17 14:11:29 +00:00
char* pp[11];
char xbuf[100];
1984-07-20 10:44:57 +00:00
qq = pp;
if (p = FILN)
*qq++ = p;
else
*qq++ = _pargv[0];
1989-05-03 09:53:25 +00:00
2018-06-17 14:11:29 +00:00
while (ep->errno != erno && ep->errmes != 0)
ep++;
p = buf;
s = xbuf;
2018-06-17 14:11:29 +00:00
if (i = LINO)
{
1984-07-20 10:44:57 +00:00
*qq++ = ", ";
do
*p++ = i % 10 + '0';
1984-07-20 10:44:57 +00:00
while (i /= 10);
2018-06-17 14:11:29 +00:00
while (p > buf)
*s++ = *--p;
1984-07-20 10:44:57 +00:00
}
*s++ = ':';
*s++ = ' ';
*s++ = '\0';
*qq++ = xbuf;
2018-06-17 14:11:29 +00:00
if ((erno & ~037) == 0140 && (_curfil->flags & 0377) == MAGIC)
{
1984-07-20 10:44:57 +00:00
/* file error */
*qq++ = "file ";
*qq++ = _curfil->fname;
*qq++ = ": ";
}
2018-06-17 14:11:29 +00:00
if (ep->errmes)
*qq++ = ep->errmes;
else
{
*qq++ = "error number ";
*qq++ = s;
p = buf;
2018-06-17 14:11:29 +00:00
if (j < 0)
{
1989-05-03 09:53:25 +00:00
j = -j;
*s++ = '-';
1989-05-03 09:53:25 +00:00
}
do
*p++ = j % 10 + '0';
1989-05-03 09:53:25 +00:00
while (j /= 10);
2018-06-17 14:11:29 +00:00
while (p > buf)
*s++ = *--p;
*s = 0;
1989-05-03 09:53:25 +00:00
}
*qq++ = "\n";
1984-07-20 10:44:57 +00:00
*qq = 0;
qq = pp;
2018-06-17 14:11:29 +00:00
while (q = *qq++)
{
1984-07-20 10:44:57 +00:00
p = q;
while (*p)
p++;
2018-06-17 14:11:29 +00:00
if (write(2, q, (int)(p - q)) < 0)
1984-07-20 10:44:57 +00:00
;
}
2018-06-17 14:11:29 +00:00
_exit(erno + 1);
1984-07-20 10:44:57 +00:00
error:
_trp(erno);
}