add manual page, cleanup
[unix-history] / usr / src / old / sh / error.c
CommitLineData
f6227721
SL
1#ifndef lint
2static char sccsid[] = "@(#)error.c 4.2 %G%";
3#endif
9def2197
KM
4
5#
6/*
7 * UNIX shell
8 *
9 * S. R. Bourne
10 * Bell Telephone Laboratories
11 *
12 */
13
14#include "defs.h"
15
16
17/* ======== error handling ======== */
18
19exitset()
20{
21 assnum(&exitadr,exitval);
22}
23
24sigchk()
25{
26 /* Find out if it is time to go away.
27 * `trapnote' is set to SIGSET when fault is seen and
28 * no trap has been set.
29 */
30 IF trapnote&SIGSET
31 THEN exitsh(SIGFAIL);
32 FI
33}
34
35failed(s1,s2)
36 STRING s1, s2;
37{
38 prp(); prs(s1);
39 IF s2
40 THEN prs(colon); prs(s2);
41 FI
42 newline(); exitsh(ERROR);
43}
44
45error(s)
46 STRING s;
47{
48 failed(s,NIL);
49}
50
51exitsh(xno)
52 INT xno;
53{
54 /* Arrive here from `FATAL' errors
55 * a) exit command,
56 * b) default trap,
57 * c) fault with no trap set.
58 *
59 * Action is to return to command level or exit.
60 */
61 exitval=xno;
62 IF (flags & (forked|errflg|ttyflg)) != ttyflg
63 THEN done();
64 ELSE clearup();
65 longjmp(errshell,1);
66 FI
67}
68
69done()
70{
71 REG STRING t;
72 IF t=trapcom[0]
73 THEN trapcom[0]=0; /*should free but not long */
74 execexp(t,0);
75 FI
76 rmtemp(0);
77 exit(exitval);
78}
79
80rmtemp(base)
81 IOPTR base;
82{
83 WHILE iotemp>base
84 DO unlink(iotemp->ioname);
85 iotemp=iotemp->iolst;
86 OD
87}