aboutsummaryrefslogtreecommitdiff
path: root/sys/gio/gclose.x
blob: a6802a0a4e4934720ae1d019cef5b75abbfc22b6 (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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<gio.h>

# GCLOSE -- Close a graphics stream previously opened with GOPEN.  Flush any
# buffered polyline output, output the close worstation metacode instruction,
# close the output stream, close the graphcap descriptor, and return all
# buffer space.

procedure gclose (gp)

pointer	gp			# graphics descriptor

int	fd
int	and()

begin
	fd = GP_FD(gp)

	if (and (GP_GFLAGS(gp), GF_WSOPEN) != 0) {
	    call gflush (gp)
	    call gki_closews (fd, GP_DEVNAME(gp))

	    # If the output stream is a file rather than a standard graphics
	    # stream, write a WCS savefile to permit restoration of the WCS if
	    # the device is subsequently opened in APPEND mode.

	    if (fd > STDPLOT)
		call gwrwcs (GP_DEVNAME(gp),
		    Memi[GP_WCSPTR(gp,1)], LEN_WCSARRAY)

	    # If the output file was opened by GOPEN (as indicated by the
	    # CLOSEFD flag), close the file.

	    if (and (GP_GFLAGS(gp), GF_CLOSEFD) != 0)
		call close (fd)
	    else
		call flush (fd)
	}

	call ttycdes (GP_TTY(gp))
	call mfree (gp, TY_STRUCT)
	call gki_redir (fd, NULL, NULL, NULL)
	call gexfls_clear (fd)
end