source: trunk/minix/lib/ack/libp/catch.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 3.3 KB
Line 
1/* $Header: /cvsup/minix/src/lib/ack/libp/catch.c,v 1.1 2005/10/10 15:27:46 beng Exp $ */
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
19#include <em_abs.h>
20#include <pc_err.h>
21#include <pc_file.h>
22
23/* to make it easier to patch ... */
24extern struct file *_curfil;
25
26static 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
42 { ESTACK, "stack overflow"},
43 { EHEAP, "heap overflow"},
44 { EILLINS, "illegal instruction"},
45 { EODDZ, "illegal size argument"},
46 { ECASE, "case error"},
47 { EMEMFLT, "addressing non existent memory"},
48 { EBADPTR, "bad pointer used"},
49 { EBADPC, "program counter out of range"},
50 { EBADLAE, "bad argument of lae"},
51 { EBADMON, "bad monitor call"},
52 { EBADLIN, "argument if LIN too high"},
53 { EBADGTO, "GTO descriptor error"},
54
55 { EARGC, "more args expected" },
56 { EEXP, "error in exp" },
57 { ELOG, "error in ln" },
58 { ESQT, "error in sqrt" },
59 { EASS, "assertion failed" },
60 { EPACK, "array bound error in pack" },
61 { EUNPACK, "array bound error in unpack" },
62 { EMOD, "only positive j in 'i mod j'" },
63 { EBADF, "file not yet open" },
64 { EFREE, "dispose error" },
65 { EFUNASS, "function not assigned" },
66 { EWIDTH, "illegal field width" },
67
68 { EWRITEF, "not writable" },
69 { EREADF, "not readable" },
70 { EEOF, "end of file" },
71 { EFTRUNC, "truncated" },
72 { ERESET, "reset error" },
73 { EREWR, "rewrite error" },
74 { ECLOSE, "close error" },
75 { EREAD, "read error" },
76 { EWRITE, "write error" },
77 { EDIGIT, "digit expected" },
78 { EASCII, "non-ASCII char read" },
79 { -1, 0}
80};
81
82extern int _pargc;
83extern char **_pargv;
84extern char ***_penviron;
85
86extern char *_hol0();
87extern _trp();
88extern _exit();
89extern int _write();
90
91_catch(erno) unsigned erno; {
92 register struct errm *ep = &errors[0];
93 char *p,*q,*s,**qq;
94 char buf[20];
95 unsigned i;
96 int j = erno;
97 char *pp[11];
98 char xbuf[100];
99
100 qq = pp;
101 if (p = FILN)
102 *qq++ = p;
103 else
104 *qq++ = _pargv[0];
105
106 while (ep->errno != erno && ep->errmes != 0) ep++;
107 p = buf;
108 s = xbuf;
109 if (i = LINO) {
110 *qq++ = ", ";
111 do
112 *p++ = i % 10 + '0';
113 while (i /= 10);
114 while (p > buf) *s++ = *--p;
115 }
116 *s++ = ':';
117 *s++ = ' ';
118 *s++ = '\0';
119 *qq++ = xbuf;
120 if ((erno & ~037) == 0140 && (_curfil->flags&0377)==MAGIC) {
121 /* file error */
122 *qq++ = "file ";
123 *qq++ = _curfil->fname;
124 *qq++ = ": ";
125 }
126 if (ep->errmes) *qq++ = ep->errmes;
127 else {
128 *qq++ = "error number ";
129 *qq++ = s;
130 p = buf;
131 if (j < 0) {
132 j = -j;
133 *s++ = '-';
134 }
135 do
136 *p++ = j % 10 + '0';
137 while (j /= 10);
138 while (p > buf) *s++ = *--p;
139 *s = 0;
140 }
141 *qq++ = "\n";
142 *qq = 0;
143 qq = pp;
144 while (q = *qq++) {
145 p = q;
146 while (*p)
147 p++;
148 if (_write(2,q,(int)(p-q)) < 0)
149 ;
150 }
151 _exit(erno);
152error:
153 _trp(erno);
154}
Note: See TracBrowser for help on using the repository browser.