xref: /original-bsd/usr.bin/pascal/libpc/ERROR.c (revision 6c57d260)
1 /* Copyright (c) 1979 Regents of the University of California */
2 
3 static char sccsid[] = "@(#)ERROR.c 1.6 03/18/81";
4 
5 #include	<stdio.h>
6 #include	<signal.h>
7 #include	"h00vars.h"
8 #include	"h01errs.h"
9 
10 /*
11  * Routine ERROR is called from the runtime library when a runtime error
12  * occurs. Its arguments are the internal number of the error which occurred,
13  * and an error specific piece of error data. The error file is constructed
14  * from errdata by the makefile using the editor script make.ed1.
15  */
16 long
17 ERROR(errnum, errdata)
18 
19 	int	errnum;
20 	union cvt {
21 		long	longdat;
22 		char	*strngdat;
23 		double	dbldat;
24 	} errdata;
25 {
26 	PFLUSH();
27 	if (_entry[errnum].entryaddr != 0) {
28 		(*_entry[errnum].entryaddr)(errdata);
29 		return;
30 	}
31 	fputc('\n',stderr);
32 	SETRACE();
33 	switch (errnum) {
34 	case ECHR:
35 		fprintf(stderr, "Argument to chr of %D is out of range\n"
36 			,errdata.longdat);
37 		return(errdata.longdat);
38 	case EHALT:
39 		fputs("Call to procedure halt\n",stderr);
40 		PCEXIT(0);
41 	case ENILPTR:
42 		fputs("Pointer value out of legal range\n",stderr);
43 		return(0);
44 	case EPASTEOF:
45 		fprintf(stderr,"%s: Tried to read past end of file\n"
46 			,errdata.strngdat);
47 		return(0);
48 	case EREADIT:
49 		fprintf(stderr,"%s: Attempt to read, but open for writing\n"
50 			,errdata.strngdat);
51 		return(0);
52 	case EWRITEIT:
53 		fprintf(stderr,"%s: Attempt to write, but open for reading\n"
54 			,errdata.strngdat);
55 		return(0);
56 	case ECLOSE:
57 		fprintf(stderr,"%s: Close failed\n",errdata.strngdat);
58 		return(0);
59 	case ELLIMIT:
60 		fprintf(stderr,"%s: Line limit exceeded\n",errdata.strngdat);
61 		return(0);
62 	case ESQRT:
63 		fprintf(stderr,"Negative argument of %e to sqrt\n"
64 			,errdata.dbldat);
65 		return(errdata.dbldat);
66 	case EREFINAF:
67 		fprintf(stderr,"%s: ",errdata.strngdat);
68 	case ENOFILE:
69 		fputs("Reference to an inactive file\n",stderr);
70 		return(0);
71 	case EWRITE:
72 		fputs("Could not write to ",stderr);
73 		perror(errdata.strngdat);
74 		return(0);
75 	case EOPEN:
76 		fputs("Could not open ",stderr);
77 		perror(errdata.strngdat);
78 		return(0);
79 	case ECREATE:
80 		fputs("Could not create ",stderr);
81 		perror(errdata.strngdat);
82 		return(0);
83 	case EREMOVE:
84 		fputs("Could not remove ",stderr);
85 		perror(errdata.strngdat);
86 		return(0);
87 	case ESEEK:
88 		fputs("Could not reset ",stderr);
89 		perror(errdata.strngdat);
90 		return(0);
91 	case ENAMESIZE:
92 		fprintf(stderr,"%s: File name too long\n",errdata.strngdat);
93 		return(0);
94 	case ELN:
95 		fprintf(stderr,"Non-positive argument of %e to ln\n"
96 			,errdata.dbldat);
97 		return(errdata.dbldat);
98 	case EBADINUM:
99 		fprintf(stderr,"%s: Bad data found on integer read\n"
100 			,errdata.strngdat);
101 		return(0);
102 	case EBADFNUM:
103 		fprintf(stderr,"%s: Bad data found on real read\n"
104 			,errdata.strngdat);
105 		return(0);
106 	case ENUMNTFD:
107 		fprintf(stderr,
108 			"Unknown name \"%s\" found on enumerated type read\n",
109 			errdata.strngdat);
110 		return(0);
111 	case ENAMRNG:
112 		fprintf(stderr,
113 			"Enumerated type value of %D is out of range on output\n",
114 			errdata.longdat);
115 		return(errdata.longdat);
116 	case EFMTSIZE:
117 		fprintf(stderr,"Non-positive format width: %D\n",errdata.longdat);
118 		return(0);
119 	case EGOTO:
120 		fputs("Active frame not found in non-local goto\n", stderr);
121 		return(0);
122 	case ECASE:
123 		fprintf(stderr,"Label of %D not found in case\n"
124 			,errdata.longdat);
125 		return(errdata.longdat);
126 	case EOUTOFMEM:
127 		fputs("Ran out of memory\n",stderr);
128 		return(0);
129 	case ECTLWR:
130 		fprintf(stderr, "Range lower bound of %D out of set bounds\n",
131 			errdata.longdat);
132 		return(0);
133 	case ECTUPR:
134 		fprintf(stderr, "Range upper bound of %D out of set bounds\n",
135 			errdata.longdat);
136 		return(0);
137 	case ECTSNG:
138 		fprintf(stderr, "Value of %D out of set bounds\n",
139 			errdata.longdat);
140 		return(0);
141 	case EARGV:
142 		fprintf(stderr,"Argument to argv of %D is out of range\n"
143 			,errdata.longdat);
144 		return(errdata.longdat);
145 	case EPACK:
146 		fprintf(stderr,"i = %D: Bad i to pack(a,i,z)\n"
147 			,errdata.longdat);
148 		return(errdata.longdat);
149 	case EUNPACK:
150 		fprintf(stderr,"i = %D: Bad i to unpack(z,a,i)\n"
151 			,errdata.longdat);
152 		return(errdata.longdat);
153 	case ERANGE:
154 		fprintf(stderr,"Value of %D is out of range\n",errdata.longdat);
155 		return(errdata.longdat);
156 	case ESUBSC:
157 		fprintf(stderr,"Subscript value of %D is out of range\n"
158 			,errdata.longdat);
159 		return(errdata.longdat);
160 	case EASRT:
161 		fprintf(stderr,"Assertion failed: %s\n",errdata.strngdat);
162 		return(0);
163 	case ESTLIM:
164 		fprintf(stderr,
165 			"Statement count limit exceeded, %D statements executed\n",
166 			errdata.longdat);
167 		return(errdata.longdat);
168 	default:
169 		fputs("Panic: unknown error\n",stderr);
170 		return(0);
171 	}
172 }
173