File: postexit.x

package info (click to toggle)
iraf 2.18.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,000 kB
  • sloc: ansic: 115,890; fortran: 74,576; lisp: 18,888; yacc: 5,642; sh: 961; lex: 596; makefile: 509; asm: 159; csh: 54; xml: 33; sed: 4
file content (52 lines) | stat: -rw-r--r-- 1,592 bytes parent folder | download | duplicates (5)
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