aboutsummaryrefslogtreecommitdiff
path: root/noao/digiphot/apphot/aputil/apgscur.x
blob: 5cc8a6df25940d63982c16989790daa6ab81f675 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
include <gset.h>
include <fset.h>

# APGSCUR -- Read the x and y coordinates of an object from a file and move
# the cursor to those coordinates.

int procedure apgscur (sl, gd, xcur, ycur, prev_num, req_num, num)

int	sl		# coordinate file descriptor
pointer	gd		# pointer to graphics stream
real	xcur, ycur	# x cur and y cur
int	prev_num	# previous number
int	req_num		# requested number
int	num		# list number

int	stdin, nskip, ncount
pointer	sp, fname
int	fscan(), nscan(), strncmp()
errchk	greactivate, gdeactivate, gscur

begin
	if (sl == NULL)
	    return (EOF)

	call smark (sp)
	call salloc (fname, SZ_FNAME, TY_CHAR)

	# Find the number of objects to be skipped.
	call fstats (sl, F_FILENAME, Memc[fname], SZ_FNAME)
	if (strncmp ("STDIN", Memc[fname], 5) == 0) {
	    stdin = YES
	    nskip = 1
	} else {
	    stdin = NO
	    if (req_num <= prev_num) {
		call seek (sl, BOF)
		nskip = req_num
	    } else
		nskip = req_num - prev_num
	}

	# Initialize.
	ncount = 0
	num = prev_num

	# Read the coordinates and write the cursor.
	repeat {

	    # Print the prompt if file is STDIN.
	    if (stdin == YES) {
		call printf ("Type object x and y coordinates: ")
		call flush (STDOUT)
	    }

	    # Fetch the coordinates.
	    if (fscan (sl) != EOF) {
		call gargr (xcur)
		call gargr (ycur)
		if (nscan () == 2) {
		    ncount = ncount + 1
		    num = num + 1
		}
	    } else 
		ncount = EOF

	    # Move the cursor.
	    if (gd != NULL && (ncount == nskip || ncount == EOF)) {
		iferr {
		    call greactivate (gd, 0)
	            call gscur (gd, xcur, ycur)
		    call gdeactivate (gd, 0)
		} then
		    ;
	    }

	} until (ncount == EOF || ncount == nskip)

	call sfree (sp)

	if (ncount == EOF) {
	    return (EOF)
	} else if (nskip == req_num) {
	    num = ncount
	    return (ncount)
	} else {
	    return (num)
	}
end