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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <syserr.h>
include <ctype.h>
include <mach.h>
include "qpoe.h"
include "qpex.h"
include "qpio.h"
# QPIO_PARSE -- Parse the QPIO expression operand input to qpio_open or
# qpio_setfilter. This consists of a comma delimited list of keyword=value
# terms. We factor out those which are QPIO related and deal with these
# directly, concatenating the remaining terms to be passed on to QPEX.
# The output filter buffer is resized as needed to hold the filter expr.
# ERR is returned as the function value if an error occurs while compiling
# the expression.
int procedure qpio_parse (io, expr, filter, sz_filter, mask, sz_mask)
pointer io #I QPIO descriptor
char expr[ARB] #I expression to be parsed
pointer filter #U filter buffer
int sz_filter #U allocated buffer size
char mask[sz_mask] #O new mask name (not reallocatable)
int sz_mask #I max chars out
real rval
pointer qp, sp, keyword, vp, in
int assignop, byte_offset, sz_field
int level, zlevel, status, start, value, token, op, kw, tokno
pointer qp_opentext()
int qp_gettok(), gstrcpy(), strlen(), strdic(), ctoi(), ctor()
errchk qp_opentext, malloc, realloc, qp_gettok, qp_ungettok, syserrs
define F Memc[filter+($1)-1]
define noval_ 91
define badval_ 92
define badkey_ 93
begin
call smark (sp)
call salloc (keyword, SZ_FNAME, TY_CHAR)
qp = IO_QP(io)
# Open the input expression for macro expanded token input.
in = qp_opentext (qp, expr)
# Extract and process a series of "param[=expr]" terms, where
# the expr may be any series of tokens, delimited by an
# unparenthesized comma.
op = 1
tokno = 0
F(op) = EOS
mask[1] = EOS
status = OK
level = 0
repeat {
start = op
# Advance to the next keyword.
token = qp_gettok (in, F(op), SZ_TOKBUF)
tokno = tokno + 1
switch (token) {
case EOF:
break
case '(', '[', '{':
level = level + 1
next
case ')', ']', '}':
level = level - 1
next
case '!':
if (tokno <= 2) {
IO_NODEFFILT(io) = YES
IO_NODEFMASK(io) = YES
tokno = 1
}
next
case TOK_IDENTIFIER:
op = op + strlen (F(op))
if (op + SZ_TOKBUF > sz_filter) {
sz_filter = sz_filter + INC_SZEXPRBUF
call realloc (filter, sz_filter, TY_CHAR)
}
call strcpy (F(start), Memc[keyword], SZ_FNAME)
call strlwr (Memc[keyword])
default:
if (token != ',') {
call eprintf ("QPIO: unexpected token `%s'\n")
call pargstr (F(op))
status = ERR
}
next
}
value = NULL
token = qp_gettok (in, F(op), SZ_TOKBUF)
if (token == '=' ||
token == TOK_PLUSEQUALS || token == TOK_COLONEQUALS) {
# Accumulate the expression.
zlevel = level
assignop = token
op = op + strlen (F(op))
value = op
repeat {
# Peek at the next token to see if it terminates the
# expression. An unparenthesized comma or unmatched
# right brace, bracket, or parenthesis is part of the
# next statement and terminates the expression.
token = qp_gettok (in, F(op), SZ_TOKBUF)
switch (token) {
case EOF:
break
case '(', '[', '{':
level = level + 1
case ')', ']', '}':
if (level <= zlevel) {
call qp_ungettok (in, F(op))
F(op) = EOS
break
} else
level = level - 1
case ',':
if (level <= zlevel) {
call qp_ungettok (in, F(op))
F(op) = EOS
break
}
}
# Accept token as data.
op = op + strlen (F(op))
if (op + SZ_TOKBUF + 1 > sz_filter) {
sz_filter = sz_filter + INC_SZEXPRBUF
call realloc (filter, sz_filter, TY_CHAR)
}
F(op) = ' '; op = op + 1
F(op) = EOS
}
}
# Process the keywords known to QPIO and pass anything else on
# to the output filter buffer.
kw = strdic (Memc[keyword], Memc[keyword], SZ_FNAME, KEYWORDS)
vp = filter + value - 1
switch (kw) {
case KW_BLOCK:
# Set the XY blocking factor for pixelation.
if (value == NULL)
goto noval_
else if (ctor (Memc, vp, rval) <= 0)
goto badval_
IO_XBLOCK(io) = rval
IO_YBLOCK(io) = rval
op = start
case KW_XBLOCK:
# Set the X blocking factor for pixelation.
if (value == NULL)
goto noval_
else if (ctor (Memc, vp, rval) <= 0)
goto badval_
IO_XBLOCK(io) = rval
op = start
case KW_YBLOCK:
# Set the Y blocking factor for pixelation.
if (value == NULL)
goto noval_
else if (ctor (Memc, vp, rval) <= 0)
goto badval_
IO_YBLOCK(io) = rval
op = start
case KW_DEBUG:
# Set the debug level, default 1 if no argument.
if (value == NULL)
IO_DEBUG(io) = 1
else if (ctoi (Memc, vp, IO_DEBUG(io)) <= 0) {
IO_DEBUG(io) = QP_DEBUG(qp)
badval_ call eprintf ("QPIO: cannot convert `%s' to integer\n")
call pargstr (Memc[vp])
}
op = start
case KW_FILTER:
# A term such as "filter=(...)". Keep the (...).
if (value == NULL)
goto noval_
else {
# Accumulate expression term.
op = start + gstrcpy (Memc[vp], F(start), ARB)
F(op) = ','; op = op + 1
F(op) = EOS
}
case KW_KEY:
# Set the offsets of the event attribute fields to be used
# for the event coordinates during extraction. The typical
# syntax of the key value is, e.g., key=(s10,s8). Fields
# used for event coordinate keys must be a numeric type.
call strlwr (Memc[vp])
while (Memc[vp] == ' ' || Memc[vp] == '(')
vp = vp + 1
# Get the X field offset and type.
switch (Memc[vp]) {
case 's':
IO_EVXTYPE(io) = TY_SHORT
sz_field = SZ_SHORT
case 'i':
IO_EVXTYPE(io) = TY_INT
sz_field = SZ_INT
case 'l':
IO_EVXTYPE(io) = TY_LONG
sz_field = SZ_LONG
case 'r':
IO_EVXTYPE(io) = TY_REAL
sz_field = SZ_REAL
case 'd':
IO_EVXTYPE(io) = TY_DOUBLE
sz_field = SZ_DOUBLE
default:
goto badkey_
}
vp = vp + 1
if (ctoi (Memc, vp, byte_offset) <= 0)
goto badkey_
else
IO_EVXOFF(io) = byte_offset / (sz_field * SZB_CHAR)
while (Memc[vp] == ' ' || Memc[vp] == ',')
vp = vp + 1
# Get the Y field offset.
switch (Memc[vp]) {
case 's':
IO_EVYTYPE(io) = TY_SHORT
sz_field = SZ_SHORT
case 'i':
IO_EVYTYPE(io) = TY_INT
sz_field = SZ_INT
case 'l':
IO_EVYTYPE(io) = TY_LONG
sz_field = SZ_LONG
case 'r':
IO_EVYTYPE(io) = TY_REAL
sz_field = SZ_REAL
case 'd':
IO_EVYTYPE(io) = TY_DOUBLE
sz_field = SZ_DOUBLE
default:
goto badkey_
}
vp = vp + 1
if (ctoi (Memc, vp, byte_offset) <= 0) {
badkey_ call eprintf ("QPIO: bad key value `%s'\n")
call pargstr (F(value))
status = ERR
} else
IO_EVYOFF(io) = byte_offset / (sz_field * SZB_CHAR)
op = start
case KW_NOINDEX:
# Disable use of the index for extraction (for testing).
IO_NOINDEX(io) = YES
op = start
case KW_PARAM, KW_MASK:
# Set a string valued option.
if (value == NULL) {
noval_ call eprintf ("QPIO: kewyord `%s' requires an argument\n")
call pargstr (Memc[keyword])
status = ERR
} else {
# Kill space added at end of token.
op = op - 1
F(op) = EOS
# Output the string.
if (kw == KW_PARAM) {
# Set the name of the event list parameter.
call strcpy (Memc[vp], Memc[IO_PARAM(io)], SZ_FNAME)
} else {
# Set the name of the region mask.
call strcpy (Memc[vp], mask, sz_mask)
if (assignop == TOK_COLONEQUALS)
IO_NODEFMASK(io) = YES
}
}
op = start
case KW_RECT:
# Set the source rect or "bounding box" for i/o. The syntax
# is somewhat flexible, i.e., "*", ":N", "N:", "M:N" are
# all accepted ways of expressing the range for an axis.
IO_VSDEF(io,1) = 1; IO_VSDEF(io,2) = 1
IO_VEDEF(io,1) = IO_NCOLS(io); IO_VEDEF(io,2) = IO_NLINES(io)
if (Memc[vp] == '[' || Memc[vp] == '(') # ])
vp = vp + 1
while (Memc[vp] == ' ')
vp = vp + 1
# Get range in X.
if (Memc[vp] == '*')
vp = vp + 1
else {
if (ctoi (Memc, vp, IO_VSDEF(io,1)) <= 0)
IO_VSDEF(io,1) = 1
while (IS_WHITE(Memc[vp]) || Memc[vp] == ':')
vp = vp + 1
if (ctoi (Memc, vp, IO_VEDEF(io,1)) <= 0)
IO_VEDEF(io,1) = IO_NCOLS(io)
}
while (IS_WHITE(Memc[vp]) || Memc[vp] == ',')
vp = vp + 1
# Get range in Y.
if (Memc[vp] == '*')
vp = vp + 1
else {
if (ctoi (Memc, vp, IO_VSDEF(io,2)) <= 0)
IO_VSDEF(io,2) = 1
while (IS_WHITE(Memc[vp]) || Memc[vp] == ':')
vp = vp + 1
if (ctoi (Memc, vp, IO_VEDEF(io,2)) <= 0)
IO_VEDEF(io,2) = IO_NLINES(io)
}
IO_BBUSED(io) = YES
op = start
default:
# Accumulate EAF expression term.
F(op) = ','; op = op + 1
F(op) = ' '; op = op + 1
F(op) = EOS
}
}
# Verify that the parens etc. match.
if (level != 0)
call syserrs (SYS_QPIOSYN, QP_DFNAME(qp))
F(op) = EOS
sz_filter = op
call realloc (filter, sz_filter, TY_CHAR)
call qp_closetext (in)
call sfree (sp)
return (status)
end
|