180 |
write_case_data wc_data) |
write_case_data wc_data) |
181 |
{ |
{ |
182 |
struct input_program_pgm *inp = source->aux; |
struct input_program_pgm *inp = source->aux; |
183 |
int i; |
size_t i; |
184 |
|
|
185 |
/* Nonzero if there were any END CASE commands in the set of |
/* Nonzero if there were any END CASE commands in the set of |
186 |
transformations. If so, we don't automatically write out |
transformations. If so, we don't automatically write out |
197 |
|
|
198 |
/* Figure end_case. */ |
/* Figure end_case. */ |
199 |
for (i = 0; i < f_trns; i++) |
for (i = 0; i < f_trns; i++) |
200 |
if (t_trns[i]->proc == end_case_trns_proc) |
if (t_trns[i].proc == end_case_trns_proc) |
201 |
end_case = 1; |
end_case = 1; |
202 |
|
|
203 |
/* FIXME: This is an ugly kluge. */ |
/* FIXME: This is an ugly kluge. */ |
204 |
for (i = 0; i < f_trns; i++) |
for (i = 0; i < f_trns; i++) |
205 |
if (t_trns[i]->proc == repeating_data_trns_proc) |
if (t_trns[i].proc == repeating_data_trns_proc) |
206 |
repeating_data_set_write_case (t_trns[i], write_case, wc_data); |
repeating_data_set_write_case (t_trns[i].private, write_case, wc_data); |
207 |
|
|
208 |
init_case (inp, c); |
init_case (inp, c); |
209 |
for (;;) |
for (;;) |
213 |
{ |
{ |
214 |
int code; /* Return value of last-called transformation. */ |
int code; /* Return value of last-called transformation. */ |
215 |
|
|
216 |
if (t_trns[i]->proc == end_case_trns_proc) |
if (t_trns[i].proc == end_case_trns_proc) |
217 |
{ |
{ |
218 |
cases_written++; |
cases_written++; |
219 |
if (!write_case (wc_data)) |
if (!write_case (wc_data)) |
223 |
continue; |
continue; |
224 |
} |
} |
225 |
|
|
226 |
code = t_trns[i]->proc (t_trns[i], c, cases_written + 1); |
code = t_trns[i].proc (t_trns[i].private, c, cases_written + 1); |
227 |
switch (code) |
switch (code) |
228 |
{ |
{ |
229 |
case -1: |
case -1: |
280 |
int |
int |
281 |
cmd_end_case (void) |
cmd_end_case (void) |
282 |
{ |
{ |
|
struct trns_header *t; |
|
|
|
|
283 |
if (!case_source_is_class (vfm_source, &input_program_source_class)) |
if (!case_source_is_class (vfm_source, &input_program_source_class)) |
284 |
{ |
{ |
285 |
msg (SE, _("This command may only be executed between INPUT PROGRAM " |
msg (SE, _("This command may only be executed between INPUT PROGRAM " |
287 |
return CMD_FAILURE; |
return CMD_FAILURE; |
288 |
} |
} |
289 |
|
|
290 |
t = xmalloc (sizeof *t); |
add_transformation (end_case_trns_proc, NULL, NULL); |
|
t->proc = end_case_trns_proc; |
|
|
t->free = NULL; |
|
|
add_transformation ((struct trns_header *) t); |
|
291 |
|
|
292 |
return lex_end_of_command (); |
return lex_end_of_command (); |
293 |
} |
} |
295 |
/* Should never be called, because this is handled in |
/* Should never be called, because this is handled in |
296 |
input_program_source_read(). */ |
input_program_source_read(). */ |
297 |
int |
int |
298 |
end_case_trns_proc (struct trns_header *t UNUSED, struct ccase * c UNUSED, |
end_case_trns_proc (void *trns_ UNUSED, struct ccase *c UNUSED, |
299 |
int case_num UNUSED) |
int case_num UNUSED) |
300 |
{ |
{ |
301 |
assert (0); |
assert (0); |
305 |
/* REREAD transformation. */ |
/* REREAD transformation. */ |
306 |
struct reread_trns |
struct reread_trns |
307 |
{ |
{ |
|
struct trns_header h; |
|
|
|
|
308 |
struct dfm_reader *reader; /* File to move file pointer back on. */ |
struct dfm_reader *reader; /* File to move file pointer back on. */ |
309 |
struct expression *column; /* Column to reset file pointer to. */ |
struct expression *column; /* Column to reset file pointer to. */ |
310 |
}; |
}; |
355 |
} |
} |
356 |
|
|
357 |
t = xmalloc (sizeof *t); |
t = xmalloc (sizeof *t); |
|
t->h.proc = reread_trns_proc; |
|
|
t->h.free = reread_trns_free; |
|
358 |
t->reader = dfm_open_reader (fh); |
t->reader = dfm_open_reader (fh); |
359 |
t->column = e; |
t->column = e; |
360 |
add_transformation ((struct trns_header *) t); |
add_transformation (reread_trns_proc, reread_trns_free, t); |
361 |
|
|
362 |
return CMD_SUCCESS; |
return CMD_SUCCESS; |
363 |
} |
} |
364 |
|
|
365 |
/* Executes a REREAD transformation. */ |
/* Executes a REREAD transformation. */ |
366 |
static int |
static int |
367 |
reread_trns_proc (struct trns_header * pt, struct ccase * c, |
reread_trns_proc (void *t_, struct ccase *c, int case_num) |
|
int case_num) |
|
368 |
{ |
{ |
369 |
struct reread_trns *t = (struct reread_trns *) pt; |
struct reread_trns *t = t_; |
370 |
|
|
371 |
if (t->column == NULL) |
if (t->column == NULL) |
372 |
dfm_reread_record (t->reader, 1); |
dfm_reread_record (t->reader, 1); |
387 |
|
|
388 |
/* Frees a REREAD transformation. */ |
/* Frees a REREAD transformation. */ |
389 |
static void |
static void |
390 |
reread_trns_free (struct trns_header *t_) |
reread_trns_free (void *t_) |
391 |
{ |
{ |
392 |
struct reread_trns *t = (struct reread_trns *) t_; |
struct reread_trns *t = t_; |
393 |
expr_free (t->column); |
expr_free (t->column); |
394 |
dfm_close_reader (t->reader); |
dfm_close_reader (t->reader); |
395 |
} |
} |
398 |
int |
int |
399 |
cmd_end_file (void) |
cmd_end_file (void) |
400 |
{ |
{ |
|
struct trns_header *t; |
|
|
|
|
401 |
if (!case_source_is_class (vfm_source, &input_program_source_class)) |
if (!case_source_is_class (vfm_source, &input_program_source_class)) |
402 |
{ |
{ |
403 |
msg (SE, _("This command may only be executed between INPUT PROGRAM " |
msg (SE, _("This command may only be executed between INPUT PROGRAM " |
405 |
return CMD_FAILURE; |
return CMD_FAILURE; |
406 |
} |
} |
407 |
|
|
408 |
t = xmalloc (sizeof *t); |
add_transformation (end_file_trns_proc, NULL, NULL); |
|
t->proc = end_file_trns_proc; |
|
|
t->free = NULL; |
|
|
add_transformation ((struct trns_header *) t); |
|
409 |
|
|
410 |
return lex_end_of_command (); |
return lex_end_of_command (); |
411 |
} |
} |
412 |
|
|
413 |
/* Executes an END FILE transformation. */ |
/* Executes an END FILE transformation. */ |
414 |
static int |
static int |
415 |
end_file_trns_proc (struct trns_header * t UNUSED, struct ccase * c UNUSED, |
end_file_trns_proc (void *trns_ UNUSED, struct ccase *c UNUSED, |
416 |
int case_num UNUSED) |
int case_num UNUSED) |
417 |
{ |
{ |
418 |
return -2; |
return -2; |