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

include	<fset.h>
include	<gio.h>
include	"gtr.h"
include	"grc.h"

# GRC_WRITE -- Write the contents of the frame buffer to a file, with or
# without applying the workstation transformation, optionally clobbering
# any existing file of the same name.

procedure grc_write (tr, stream, fname, clobber, fullframe)

pointer	tr			# graphics stream descriptor
int	stream			# graphics stream
char	fname[ARB]		# file name
bool	clobber			# clobber existing file
bool	fullframe		# write full frame (no workstation transform)

pointer	sp, lbuf
long	size1, size2
int	save1, save2, fd, nchars
long	fstatl()
int	open()
errchk	write, gtr_redraw

begin
	call smark (sp)
	call salloc (lbuf, SZ_LINE, TY_CHAR)

	# Delete existing file if clobber requested.
	if (clobber)
	    iferr (call delete (fname))
		;

	# Open metacode spool file for appending.
	iferr (fd = open (fname, APPEND, BINARY_FILE)) {
	    call grc_message (stream, " - cannot open file for appending")
	    call sfree (sp)
	    return
	}

	# Write either the full frame or the displayed frame into spool file.

	size1 = fstatl (fd, F_FILESIZE)
	if (fullframe) {
	    nchars = (TR_OP(tr) - TR_FRAMEBUF(tr)) * SZ_SHORT
	    call write (fd, Mems[TR_FRAMEBUF(tr)], nchars)
	} else {
	    call gki_redir  (stream, fd, save1, save2)
	    call gtr_redraw (stream)
	    call gki_redir  (stream,  0, save1, save2)
	}

	size2 = fstatl (fd, F_FILESIZE)
	call sprintf (Memc[lbuf], SZ_LINE, " - %d chars %s")
	    call pargi (size2 - size1)
	if (size1 > 0)
	    call pargstr ("appended")
	else
	    call pargstr ("")
	call grc_message (stream, Memc[lbuf])

	call close (fd)
	call sfree (sp)
end