aboutsummaryrefslogtreecommitdiff
path: root/sys/etc/maideh.x
blob: d0850deb2d11b9d1e752f62547ce2e761943726d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<xwhen.h>
include	<syserr.h>
include	<fset.h>

define	SZ_ERRMSG	SZ_LINE

# MA_IDEH -- Iraf Main routine which installs the default exception handler.
# A single handler processes all exceptions.

procedure ma_ideh()

extern	xstdexh()
int	junk, i, epa_standard_handler
int	exception[4]
data	exception /X_ACV, X_INT, X_ARITH, X_IPC/

begin
	call zlocpr (xstdexh, epa_standard_handler)
	do i = 1, 4
	    call xwhen (exception[i], epa_standard_handler, junk)

	# Initialize the critical section protection stack.
	call intr_reset()
end


# XSTDEXH -- Standard exception handler.  Unless the user code posts a handler
# for a particular exception, this handler will gain control.

procedure xstdexh (exception, next_handler)

int	exception			# code for exception
int	next_handler			# EPA of next handler to be called

char	os_errmsg[SZ_ERRMSG]
int	os_errcode

begin
	# Get OS description of the exception.
	call zxgmes (os_errcode, os_errmsg, SZ_ERRMSG)
	call strupk (os_errmsg, os_errmsg, SZ_ERRMSG)

	# Cancel any output and resync awaits.
	call fseti (STDOUT, F_CANCEL, OK)
	call fseti (CLOUT, F_CANCEL, OK)
	call fseti (CLIN, F_CANCEL, OK)

	# Set this here as error() will return immediately if it comes back.
	next_handler = X_IGNORE

	# Take error action.
	switch (exception) {
	case X_ACV:
	    if (os_errcode > 0)
		call fatal (SYS_XACV, os_errmsg)
	    else
		call fatal (SYS_XACV, "Access violation")
	case X_ARITH:
	    if (os_errcode > 0)
		call fatal (SYS_XARITH, os_errmsg)
	    else
		call fatal (SYS_XARITH, "Arithmetic exception")
	case X_INT:
	    if (os_errcode > 0)
		call fatal (SYS_XINT, os_errmsg)
	    else
		call fatal (SYS_XINT, "Keyboard interrupt")
	case X_IPC:
	    call fatal (SYS_XIPC, "Write to IPC with no reader")

	default:
	    call fatal (ERR, "Unknown exception")
	}
end