#include <data/case-source.h>
#include <data/case.h>
#include <data/dictionary.h>
+#include <data/procedure.h>
#include <data/settings.h>
#include <data/value.h>
#include <data/variable.h>
#include <language/command.h>
#include <language/lexer/lexer.h>
+#include <language/lexer/variable-parser.h>
#include <libpspp/alloc.h>
#include <libpspp/array.h>
+#include <libpspp/assertion.h>
#include <libpspp/message.h>
#include <libpspp/message.h>
#include <libpspp/misc.h>
#include <libpspp/pool.h>
#include <libpspp/str.h>
-#include <procedure.h>
#include "intprops.h"
cmd_flip (void)
{
struct flip_pgm *flip;
+ struct case_sink *sink;
bool ok;
- if (temporary != 0)
- {
- msg (SW, _("FLIP ignores TEMPORARY. "
- "Temporary transformations will be made permanent."));
- cancel_temporary ();
- }
+ if (proc_make_temporary_transformations_permanent (current_dataset))
+ msg (SW, _("FLIP ignores TEMPORARY. "
+ "Temporary transformations will be made permanent."));
flip = pool_create_container (struct flip_pgm, pool);
flip->var = NULL;
- flip->idx_to_fv = dict_get_compacted_idx_to_fv (default_dict);
+ flip->idx_to_fv = dict_get_compacted_idx_to_fv (dataset_dict (current_dataset));
pool_register (flip->pool, free, flip->idx_to_fv);
flip->var_cnt = 0;
flip->case_cnt = 0;
if (lex_match_id ("VARIABLES"))
{
lex_match ('=');
- if (!parse_variables (default_dict, &flip->var, &flip->var_cnt,
+ if (!parse_variables (dataset_dict (current_dataset), &flip->var, &flip->var_cnt,
PV_NO_DUPLICATE))
goto error;
lex_match ('/');
}
else
- dict_get_vars (default_dict, &flip->var, &flip->var_cnt, 1u << DC_SYSTEM);
+ dict_get_vars (dataset_dict (current_dataset), &flip->var, &flip->var_cnt, 1u << DC_SYSTEM);
pool_register (flip->pool, free, flip->var);
lex_match ('/');
goto error;
}
else
- flip->new_names = dict_lookup_var (default_dict, "CASE_LBL");
+ flip->new_names = dict_lookup_var (dataset_dict (current_dataset), "CASE_LBL");
if (flip->new_names)
{
/* Read the active file into a flip_sink. */
flip->case_cnt = 0;
- temp_trns = temporary = 0;
- vfm_sink = flip_sink_create (flip);
- if (vfm_sink == NULL)
+ proc_make_temporary_transformations_permanent (current_dataset);
+ sink = flip_sink_create (flip);
+ if (sink == NULL)
goto error;
+ proc_set_sink (current_dataset, sink);
flip->new_names_tail = NULL;
- ok = procedure (NULL, NULL);
+ ok = procedure (current_dataset,NULL, NULL);
/* Flip the data we read. */
if (!flip_file (flip))
{
- discard_variables ();
+ discard_variables (current_dataset);
goto error;
}
/* Flip the dictionary. */
- dict_clear (default_dict);
+ dict_clear (dataset_dict (current_dataset));
if (!build_dictionary (flip))
{
- discard_variables ();
+ discard_variables (current_dataset);
goto error;
}
- flip->case_size = dict_get_case_size (default_dict);
+ flip->case_size = dict_get_case_size (dataset_dict (current_dataset));
/* Set up flipped data for reading. */
- vfm_source = flip_source_create (flip);
+ proc_set_source (current_dataset, flip_source_create (flip));
return ok ? lex_end_of_command () : CMD_CASCADING_FAILURE;
*cp = '\0';
str_uppercase (name);
- if (dict_create_var (default_dict, name, 0))
+ if (dict_create_var (dataset_dict (current_dataset), name, 0))
return 1;
/* Add numeric extensions until acceptable. */
memcpy (n, name, ofs);
sprintf (&n[ofs], "%d", i);
- if (dict_create_var (default_dict, n, 0))
+ if (dict_create_var (dataset_dict (current_dataset), n, 0))
return 1;
}
}
static int
build_dictionary (struct flip_pgm *flip)
{
- dict_create_var_assert (default_dict, "CASE_LBL", 8);
+ dict_create_var_assert (dataset_dict (current_dataset), "CASE_LBL", 8);
if (flip->new_names_head == NULL)
{
char s[SHORT_NAME_LEN + 1];
sprintf (s, "VAR%03d", i);
- v = dict_create_var_assert (default_dict, s, 0);
+ v = dict_create_var_assert (dataset_dict (current_dataset), s, 0);
}
}
else
flip->case_cnt = 1;
- return create_case_sink (&flip_sink_class, default_dict, flip);
+ return create_case_sink (&flip_sink_class, dataset_dict (current_dataset), flip);
}
/* Writes case C to the FLIP sink.
case_idx += read_cases;
}
- pool_fclose (flip->pool, input_file);
+ if (pool_fclose (flip->pool, input_file) == EOF)
+ {
+ msg (SE, _("Error closing FLIP source file: %s."), strerror (errno));
+ return false;
+ }
pool_unregister (flip->pool, input_buf);
free (input_buf);
else if (feof (flip->file))
msg (SE, _("Unexpected end of file reading FLIP temporary file."));
else
- abort ();
+ NOT_REACHED ();
ok = false;
break;
}