X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fflip.c;h=b4f908dfb7ccdaaf3c591b3321ed8cc6c101c830;hb=b321086267ad1014dc5d09886396cde30f094437;hp=7bf59104f7fca2fe5da4abb137c48ffa435e2a8d;hpb=37597beca4a11edba50b847932fdfeca3a648fa2;p=pspp diff --git a/src/flip.c b/src/flip.c index 7bf59104f7..b4f908dfb7 100644 --- a/src/flip.c +++ b/src/flip.c @@ -18,14 +18,16 @@ 02111-1307, USA. */ #include -#include +#include "error.h" #include #include #include #include #include #include "alloc.h" +#include "case.h" #include "command.h" +#include "dictionary.h" #include "error.h" #include "lexer.h" #include "misc.h" @@ -71,6 +73,13 @@ cmd_flip (void) { struct flip_pgm *flip; + if (temporary != 0) + { + msg (SM, _("FLIP ignores TEMPORARY. " + "Temporary transformations will be made permanent.")); + cancel_temporary (); + } + flip = xmalloc (sizeof *flip); flip->var = NULL; flip->var_cnt = 0; @@ -80,7 +89,6 @@ cmd_flip (void) flip->new_names_tail = NULL; flip->file = NULL; - lex_match_id ("FLIP"); lex_match ('/'); if (lex_match_id ("VARIABLES")) { @@ -121,7 +129,7 @@ cmd_flip (void) temp_trns = temporary = 0; vfm_sink = flip_sink_create (flip); flip->new_names_tail = NULL; - procedure (NULL, NULL, NULL, NULL); + procedure (NULL, NULL); /* Flip the data we read. */ flip_file (flip); @@ -278,7 +286,7 @@ flip_sink_create (struct flip_pgm *flip) flip->case_cnt = 1; - return create_case_sink (&flip_sink_class, info); + return create_case_sink (&flip_sink_class, default_dict, info); } /* Writes case C to the FLIP sink. */ @@ -297,7 +305,7 @@ flip_sink_write (struct case_sink *sink, const struct ccase *c) v->next = NULL; if (flip->new_names->type == NUMERIC) { - double f = c->data[flip->new_names->fv].f; + double f = case_num (c, sink->idx_to_fv[flip->new_names->index]); if (f == SYSMIS) strcpy (v->name, "VSYSMIS"); @@ -316,7 +324,8 @@ flip_sink_write (struct case_sink *sink, const struct ccase *c) else { int width = min (flip->new_names->width, 8); - memcpy (v->name, c->data[flip->new_names->fv].s, width); + memcpy (v->name, case_str (c, sink->idx_to_fv[flip->new_names->index]), + width); v->name[width] = 0; } @@ -329,10 +338,15 @@ flip_sink_write (struct case_sink *sink, const struct ccase *c) /* Write to external file. */ for (i = 0; i < flip->var_cnt; i++) - if (flip->var[i]->type == NUMERIC) - info->output_buf[i].f = c->data[flip->var[i]->fv].f; - else - info->output_buf[i].f = SYSMIS; + { + double out; + + if (flip->var[i]->type == NUMERIC) + out = case_num (c, sink->idx_to_fv[flip->var[i]->index]); + else + out = SYSMIS; + info->output_buf[i].f = out; + } if (fwrite (info->output_buf, sizeof *info->output_buf, flip->var_cnt, flip->file) != (size_t) flip->var_cnt) @@ -351,7 +365,7 @@ flip_file (struct flip_pgm *flip) /* Allocate memory for many cases. */ case_bytes = flip->var_cnt * sizeof *input_buf; - case_capacity = set_max_workspace / case_bytes; + case_capacity = get_max_workspace() / case_bytes; if (case_capacity > flip->case_cnt * 2) case_capacity = flip->case_cnt * 2; if (case_capacity < 2) @@ -400,9 +414,14 @@ flip_file (struct flip_pgm *flip) for (j = 0; j < read_cases; j++) output_buf[j] = input_buf[i + j * flip->var_cnt]; - if (fseek (output_file, - sizeof *input_buf * (case_idx + i * flip->case_cnt), - SEEK_SET) != 0) +#ifndef HAVE_FSEEKO +#define fseeko fseek +#endif + + if (fseeko (output_file, + sizeof *input_buf * (case_idx + + (off_t) i * flip->case_cnt), + SEEK_SET) != 0) msg (FE, _("Error seeking FLIP source file: %s."), strerror (errno)); @@ -459,11 +478,15 @@ flip_source_read (struct case_source *source, write_case_func *write_case, write_case_data wc_data) { struct flip_pgm *flip = source->aux; + union value *input_buf; int i; + input_buf = xmalloc (sizeof *input_buf * flip->case_cnt); for (i = 0; i < flip->var_cnt; i++) { - if (fread (c->data, sizeof *c->data, flip->case_cnt, + size_t j; + + if (fread (input_buf, sizeof *input_buf, flip->case_cnt, flip->file) != flip->case_cnt) { if (ferror (flip->file)) @@ -476,9 +499,12 @@ flip_source_read (struct case_source *source, break; } + for (j = 0; j < flip->case_cnt; j++) + case_data_rw (c, j)->f = input_buf[j].f; if (!write_case (wc_data)) break; } + free (input_buf); } /* Destroy internal data in SOURCE. */