aboutsummaryrefslogtreecommitdiff
path: root/pkg/xtools/catquery/cqgrecords.x
blob: f7debe942dd5587ff961a196741a8f00385d02ad (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
include "cqdef.h"
include "cq.h"


# CQ_GNRECORD -- Get next record from the results descriptor.

int procedure cq_gnrecord (res, buf, maxch, recptr)

pointer	res			#I the results descriptor
char	buf[ARB]		#O the output record buffer
int	maxch			#I the maximum buffer size 
int	recptr			#U the current record pointer

int	nchars
int	getline()

begin
	# The record is outside the record data range.
	if (recptr < 0)
	    return (BOF)
	if (recptr >= CQ_RNRECS(res))
	    return (EOF)

	# Use file mechanism to extract record. Could also use buffer pointer
	# and offsets 

	switch (CQ_RTYPE(res)) {

	# Don't worry about maxch at the moment. Just assume that the
	# buffer is at least SZ_LINE long. Can use recsize to return
	# a buffer, SZ_LINE is the default. May need to use getlline 
	# in future.

	case CQ_STEXT, CQ_BTEXT:
	    call seek (CQ_RFD(res), Meml[CQ_RINDEX(res)+recptr])
	    nchars = getline (CQ_RFD(res), buf)
	    recptr = recptr + 1
	    return (nchars)

	default:
	    return (EOF)
	}
end


# CQ_GRECORD -- Get a specified record from the results descriptor.

int procedure cq_grecord (res, buf, maxch, recptr)

pointer	res			#I the results descriptor
char	buf[ARB]		#O the output record buffer
int	maxch			#I the maximum buffer size 
int	recptr			#I the record to be extracted

int	nchars
int	getline()

begin
	# Check for out-of-bounds record requests.
	if (recptr < 1)
	    return (BOF)
	if (recptr > CQ_RNRECS(res))
	    return (EOF)

	# Use file mechanism to extract record. Could also use buffer pointer
	# and offsets 

	switch (CQ_RTYPE(res)) {

	# Don't worry about maxch at the moment. Just assume that the
	# buffer is at least SZ_LINE long. Can use recsize to return
	# a buffer, SZ_LINE is the default. May need to use getlline
	# in future.

	case CQ_STEXT, CQ_BTEXT:
	    call seek (CQ_RFD(res), Meml[CQ_RINDEX(res)+recptr-1])
	    nchars = getline (CQ_RFD(res), buf)
	    return (nchars)

	default:
	    return (EOF)
	}
end