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

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

# GRC_READ -- Fill the frame buffer from a metacode spool file and redraw
# the screen.  The contents of the frame buffer are overwritten.

procedure grc_read (tr, stream, fname)

pointer	tr			# graphics descriptor
int	stream			# graphics stream
char	fname[ARB]		# metacode file

pointer	sp, lbuf, op
int 	fd, nchars, filelen
long	fstatl()
pointer	gtr_writep()
int	open(), read()
errchk	read
define	err_ 91

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

	iferr (fd = open (fname, READ_ONLY, BINARY_FILE)) {
	    call grc_message (stream, " - cannot open file")
	    call sfree (sp)
	    return
	}

	filelen = fstatl (fd, F_FILESIZE)
	call sprintf (Memc[lbuf], SZ_LINE, " - file size %d chars")
	    call pargi (filelen)
	call grc_message (stream, Memc[lbuf])

	# Discard the current frame.
	call gtr_frame (tr, TR_FRAMEBUF(tr), stream)

	# Read new frame buffer.
	nchars = filelen
	if (nchars <= 0)
	    goto err_
	op = gtr_writep (stream, nchars)
	if (read (fd, Mems[op], nchars) < nchars)
	    goto err_

	# Redraw the new frame buffer.
	call gtr_redraw (stream)

	call close (fd)
	call sfree (sp)
	return
err_
	call close (fd)
	call grc_message (stream, " [READ ERROR]")
	call sfree (sp)
end