aboutsummaryrefslogtreecommitdiff
path: root/pkg/utilities/nttools/stxtools/postexit.x
blob: ebad32f909d72741ba56eff0a9ffd4e0c466ffbf (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
include <clset.h>

# POST_EXIT_HANDLER -- Post an error handler that exits with an error code

# The standard behavior of an iraf program is to exit with an error code
# of zero regardless of whether program execution is halted with an error.
# This behavior complicates control of tasks by user scripts. To change this
# behavor, this procedure posts an error handler that exits the program with
# its error code set to the value passed to the error procedure. The exit
# procedure is only called of the program terminates with a non-zero error
# status and the program is being run at the host level. The latter 
# restriction is in place because exiting a program running under the iraf
# command language (cl) hangs the command language. Since error handlers
# a run in the order that they are posted, this procedure should be called
# after any other error handlers you may have in your program.
#
# Nelson Zarate		30-Nov-95	original

procedure post_exit_handler ()

#--
extern 	exit_handler()
int 	clstati()

begin
	# Only post the exit handler if the task is being run in host mode

	if (clstati(CL_PRTYPE) == PR_HOST)
	    call onerror(exit_handler)
end

# EXIT_HANDLER -- Error handler that exits the program, setting the error code

procedure exit_handler (status)

int	status		# i: program exit status
#--

begin
	# Only take exit if error status is non-zero (not OK)

	if (status != OK) {
	    # Must clean up file i/o first
	    # The OK flag flushes the buffers

	    call fio_cleanup (OK)

	    # Take the error exit with the specified status

	    call errxit (status)
	}
end