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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
include <pkg/cq.h>
# AT_WNOFILRECS -- Write out the catalog header and records without filtering.
procedure at_wnofilrecs (fd, res, standard)
int fd #I the output file descriptor
pointer res #I the results descriptor
bool standard #I write a standard catalog header.
int nlines, nrecs
int at_wcathdr(), at_wcatrecs()
begin
# Write out the catalog header.
if (standard)
nlines = at_wcathdr (fd, res)
# Write out the records.
nrecs = at_wcatrecs (fd, res)
end
# AT_WCATHDR -- Write out a catalog header.
int procedure at_wcathdr (fd, res)
int fd #I the output file descriptor
pointer res #I the results descriptor
pointer sp, catname, qpnames, qpvalues, qpunits, fname, fvalue, funits, ffmts
int i, nlines, nfields, fsize, foffset, ftype
int at_wrdstr(), cq_rstati(), cq_hinfon(), cq_finfon()
char cq_itype()
begin
nlines = 0
# Allocate working space.
call smark (sp)
call salloc (catname, SZ_FNAME, TY_CHAR)
call salloc (fname, max (CQ_SZ_QPNAME, CQ_SZ_FNAME), TY_CHAR)
call salloc (fvalue, CQ_SZ_QPVALUE, TY_CHAR)
call salloc (funits, max (CQ_SZ_QPUNITS, CQ_SZ_FUNITS), TY_CHAR)
call salloc (ffmts, CQ_SZ_FFMTS, TY_CHAR)
call salloc (qpnames, SZ_LINE, TY_CHAR)
call salloc (qpvalues, SZ_LINE, TY_CHAR)
call salloc (qpunits, SZ_LINE, TY_CHAR)
# Write the header banner.
call fprintf (fd, "# BEGIN CATALOG HEADER\n")
nlines = nlines + 1
# Write the catalog database and id.
call cq_rstats (res, CQRCATDB, Memc[catname], SZ_FNAME)
call fprintf (fd, "# catdb %s\n")
call pargstr (Memc[catname])
nlines = nlines + 1
call cq_rstats (res, CQRCATNAME, Memc[catname], SZ_FNAME)
call fprintf (fd, "# catname %s\n")
call pargstr (Memc[catname])
nlines = nlines + 1
# Write out the query parameter names, values, and units used
# to generate the catalog.
call cq_rstats (res, CQRQPNAMES, Memc[qpnames], SZ_LINE)
call cq_rstats (res, CQRQPVALUES, Memc[qpvalues], SZ_LINE)
call cq_rstats (res, CQRQPUNITS, Memc[qpunits], SZ_LINE)
nfields = cq_rstati (res, CQRNQPARS)
call fprintf (fd, "# nquery %d\n")
call pargi (nfields)
nlines = nlines + 1
do i = 1, nfields {
if (at_wrdstr (i, Memc[fname], CQ_SZ_QPNAME, Memc[qpnames]) != i)
;
if (at_wrdstr (i, Memc[fvalue], CQ_SZ_QPVALUE, Memc[qpvalues]) != i)
;
if (at_wrdstr (i, Memc[funits], CQ_SZ_QPUNITS, Memc[qpunits]) != i)
;
call fprintf (fd, "# %s %s %s\n")
call pargstr (Memc[fname])
call pargstr (Memc[fvalue])
call pargstr (Memc[funits])
nlines = nlines + 1
}
# Write out the results format type.
if (at_wrdstr (cq_rstati(res, CQRTYPE), Memc[fvalue], CQ_SZ_QPVALUE,
CQ_RTYPESTR) <= 0)
call strcpy ("stext", Memc[fvalue], CQ_SZ_QPVALUE)
call fprintf (fd, "# type %s\n")
call pargstr (Memc[fvalue])
nlines = nlines + 1
# Write out the header parameters,
nfields = cq_rstati (res, CQNHEADER)
call fprintf (fd, "# nheader %d\n")
call pargi (nfields)
nlines = nlines + 1
do i = 1, nfields {
if (cq_hinfon (res, i, Memc[fname], CQ_SZ_QPNAME, Memc[fvalue],
CQ_SZ_QPVALUE) != i)
next
call fprintf (fd, "# %s %s\n")
call pargstr (Memc[fname])
call pargstr (Memc[fvalue])
nlines = nlines + 1
}
# Write out the field parameters.
nfields = cq_rstati (res, CQNFIELDS)
call fprintf (fd, "# nfields %d\n")
call pargi (nfields)
do i = 1, nfields {
if (cq_finfon (res, i, Memc[fname], CQ_SZ_FNAME, foffset, fsize,
ftype, Memc[funits], CQ_SZ_FUNITS, Memc[ffmts],
CQ_SZ_FFMTS) != i)
next
call fprintf (fd, "# %s %d %d %c %s %s\n")
call pargstr (Memc[fname])
call pargi (foffset)
call pargi (fsize)
call pargc (cq_itype (ftype))
call pargstr (Memc[funits])
call pargstr (Memc[ffmts])
nlines = nlines + 1
}
# Write the header trailer.
call fprintf (fd, "# END CATALOG HEADER\n#\n")
nlines = nlines + 1
call sfree (sp)
return (nlines)
end
# AT_WCATRECS -- Write out the catalog records without modification, except
# for the builtin trim parameters.
int procedure at_wcatrecs (fd, res)
int fd #I the output file descriptor
pointer res #I the results descriptor
pointer sp, record
int sz_rec, nrec, recptr, nchars
int cq_rstati(), cq_gnrecord()
begin
# Allocate space for the record. For now SZ_LINE is the default.
if (cq_rstati(res, CQRECSIZE) > 0)
sz_rec = max (SZ_LINE, cq_rstati (res, CQRECSIZE))
else
sz_rec = SZ_LINE
nrec = cq_rstati (res, CQRNRECS)
# Allocate working space.
call smark (sp)
call salloc (record, sz_rec, TY_CHAR)
# For the moment assume that the simple and blocked text file records
# are newline delimited, and that the simple text file fields are
# whitespace delimited.
# Write the records.
switch (cq_rstati (res, CQRTYPE)) {
case CQ_STEXT:
recptr = 0
while (recptr < nrec) {
nchars = cq_gnrecord (res, Memc[record], sz_rec, recptr)
if (nchars == EOF)
break
call fprintf (fd, "%s")
call pargstr (Memc[record])
}
case CQ_BTEXT:
recptr = 0
while (recptr < nrec) {
nchars = cq_gnrecord (res, Memc[record], sz_rec, recptr)
if (nchars == EOF)
break
call fprintf (fd, "%s")
call pargstr (Memc[record])
}
default:
;
}
call sfree (sp)
return (recptr)
end
|