Deleted Added
full compact
error.c (18018) error.c (20425)
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 19 unchanged lines hidden (view full) ---

28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kenneth Almquist.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 19 unchanged lines hidden (view full) ---

28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * $Id: error.c,v 1.4 1996/09/01 10:19:53 peter Exp $
36 * $Id: error.c,v 1.5 1996/09/03 14:15:46 peter Exp $
37 */
38
39#ifndef lint
37 */
38
39#ifndef lint
40static char sccsid[] = "@(#)error.c 8.2 (Berkeley) 5/4/95";
40static char const sccsid[] = "@(#)error.c 8.2 (Berkeley) 5/4/95";
41#endif /* not lint */
42
43/*
44 * Errors and exceptions.
45 */
46
47#include "shell.h"
48#include "main.h"

--- 12 unchanged lines hidden (view full) ---

61
62struct jmploc *handler;
63int exception;
64volatile int suppressint;
65volatile int intpending;
66char *commandname;
67
68
41#endif /* not lint */
42
43/*
44 * Errors and exceptions.
45 */
46
47#include "shell.h"
48#include "main.h"

--- 12 unchanged lines hidden (view full) ---

61
62struct jmploc *handler;
63int exception;
64volatile int suppressint;
65volatile int intpending;
66char *commandname;
67
68
69static void exverror __P((int, char *, va_list));
70
69/*
70 * Called to raise an exception. Since C doesn't include exceptions, we
71 * just do a longjmp to the exception handler. The type of exception is
72 * stored in the global variable "exception".
73 */
74
75void
71/*
72 * Called to raise an exception. Since C doesn't include exceptions, we
73 * just do a longjmp to the exception handler. The type of exception is
74 * stored in the global variable "exception".
75 */
76
77void
76exraise(e)
78exraise(e)
77 int e;
78{
79 if (handler == NULL)
80 abort();
81 exception = e;
82 longjmp(handler->loc, 1);
83}
84

--- 14 unchanged lines hidden (view full) ---

99
100 if (suppressint) {
101 intpending++;
102 return;
103 }
104 intpending = 0;
105 sigemptyset(&sigset);
106 sigprocmask(SIG_SETMASK, &sigset, NULL);
79 int e;
80{
81 if (handler == NULL)
82 abort();
83 exception = e;
84 longjmp(handler->loc, 1);
85}
86

--- 14 unchanged lines hidden (view full) ---

101
102 if (suppressint) {
103 intpending++;
104 return;
105 }
106 intpending = 0;
107 sigemptyset(&sigset);
108 sigprocmask(SIG_SETMASK, &sigset, NULL);
109 out2str("\n");
107 if (rootshell && iflag)
108 exraise(EXINT);
109 else
110 _exit(128 + SIGINT);
111}
112
113
110 if (rootshell && iflag)
111 exraise(EXINT);
112 else
113 _exit(128 + SIGINT);
114}
115
116
114
115/*
117/*
116 * Error is called to raise the error exception. If the first argument
118 * Exverror is called to raise the error exception. If the first argument
117 * is not NULL then error prints an error message using printf style
118 * formatting. It then raises the error exception.
119 */
119 * is not NULL then error prints an error message using printf style
120 * formatting. It then raises the error exception.
121 */
122static void
123exverror(cond, msg, ap)
124 int cond;
125 char *msg;
126 va_list ap;
127{
128 CLEAR_PENDING_INT;
129 INTOFF;
120
130
131#ifdef DEBUG
132 if (msg)
133 TRACE(("exverror(%d, \"%s\") pid=%d\n", cond, msg, getpid()));
134 else
135 TRACE(("exverror(%d, NULL) pid=%d\n", cond, getpid()));
136#endif
137 if (msg) {
138 if (commandname)
139 outfmt(&errout, "%s: ", commandname);
140 doformat(&errout, msg, ap);
141 out2c('\n');
142 }
143 flushall();
144 exraise(cond);
145}
146
147
121#if __STDC__
122void
123error(char *msg, ...)
124#else
125void
126error(va_alist)
127 va_dcl
128#endif
129{
130#if !__STDC__
131 char *msg;
132#endif
133 va_list ap;
148#if __STDC__
149void
150error(char *msg, ...)
151#else
152void
153error(va_alist)
154 va_dcl
155#endif
156{
157#if !__STDC__
158 char *msg;
159#endif
160 va_list ap;
134 CLEAR_PENDING_INT;
135 INTOFF;
136
137#if __STDC__
138 va_start(ap, msg);
139#else
140 va_start(ap);
141 msg = va_arg(ap, char *);
142#endif
161#if __STDC__
162 va_start(ap, msg);
163#else
164 va_start(ap);
165 msg = va_arg(ap, char *);
166#endif
143#ifdef DEBUG
144 if (msg)
145 TRACE(("error(\"%s\") pid=%d\n", msg, getpid()));
146 else
147 TRACE(("error(NULL) pid=%d\n", getpid()));
167 exverror(EXERROR, msg, ap);
168 va_end(ap);
169}
170
171
172#if __STDC__
173void
174exerror(int cond, char *msg, ...)
175#else
176void
177exerror(va_alist)
178 va_dcl
148#endif
179#endif
149 if (msg) {
150 if (commandname)
151 outfmt(&errout, "%s: ", commandname);
152 doformat(&errout, msg, ap);
153 out2c('\n');
154 }
180{
181#if !__STDC__
182 int cond;
183 char *msg;
184#endif
185 va_list ap;
186#if __STDC__
187 va_start(ap, msg);
188#else
189 va_start(ap);
190 cond = va_arg(ap, int);
191 msg = va_arg(ap, char *);
192#endif
193 exverror(cond, msg, ap);
155 va_end(ap);
194 va_end(ap);
156 flushall();
157 exraise(EXERROR);
158}
159
160
161
162/*
163 * Table of error messages.
164 */
165

--- 63 unchanged lines hidden (view full) ---

229
230/*
231 * Return a string describing an error. The returned string may be a
232 * pointer to a static buffer that will be overwritten on the next call.
233 * Action describes the operation that got the error.
234 */
235
236char *
195}
196
197
198
199/*
200 * Table of error messages.
201 */
202

--- 63 unchanged lines hidden (view full) ---

266
267/*
268 * Return a string describing an error. The returned string may be a
269 * pointer to a static buffer that will be overwritten on the next call.
270 * Action describes the operation that got the error.
271 */
272
273char *
237errmsg(e, action)
274errmsg(e, action)
238 int e;
239 int action;
240{
241 struct errname const *ep;
242 static char buf[12];
243
244 for (ep = errormsg ; ep->errcode ; ep++) {
245 if (ep->errcode == e && (ep->action & action) != 0)
246 return ep->msg;
247 }
248 fmtstr(buf, sizeof buf, "error %d", e);
249 return buf;
250}
275 int e;
276 int action;
277{
278 struct errname const *ep;
279 static char buf[12];
280
281 for (ep = errormsg ; ep->errcode ; ep++) {
282 if (ep->errcode == e && (ep->action & action) != 0)
283 return ep->msg;
284 }
285 fmtstr(buf, sizeof buf, "error %d", e);
286 return buf;
287}