+ /* Save old variable names for use as values of CASE_LBL
+ variable in flipped file. */
+ for (i = 0; i < flip->n_vars; i++)
+ var_names_add (flip->pool, &flip->old_names,
+ pool_strdup (flip->pool, var_get_name (vars[i])));
+
+ /* Read the active dataset into a flip_sink. */
+ proc_discard_output (ds);
+
+ /* Save old dictionary. */
+ new_dict = dict_clone (old_dict);
+ flip->encoding = dict_get_encoding (new_dict);
+ dict_clear (new_dict);
+
+ input = proc_open_filtering (ds, false);
+ while ((c = casereader_read (input)) != NULL)
+ {
+ flip->n_cases++;
+ for (i = 0; i < flip->n_vars; i++)
+ {
+ const struct variable *v = vars[i];
+ double out = var_is_numeric (v) ? case_num (c, v) : SYSMIS;
+ fwrite (&out, sizeof out, 1, flip->file);
+ }
+ if (flip->new_names_var != NULL)
+ {
+ const union value *value = case_data (c, flip->new_names_var);
+ const char *name;
+ if (var_is_numeric (flip->new_names_var))
+ {
+ double f = value->f;
+ name = (f == SYSMIS ? "VSYSMIS"
+ : f < INT_MIN ? "VNEGINF"
+ : f > INT_MAX ? "VPOSINF"
+ : pool_asprintf (flip->pool, "V%d", (int) f));
+ }
+ else
+ {
+ name = data_out_pool (value, dict_get_encoding (old_dict),
+ var_get_write_format (flip->new_names_var),
+ settings_get_fmt_settings (), flip->pool);
+ }
+ var_names_add (flip->pool, &flip->new_names, name);
+ }
+ case_unref (c);
+ }
+ ok = casereader_destroy (input);
+ ok = proc_commit (ds) && ok;
+
+ /* Flip the data we read. */
+ if (!ok || !flip_file (flip))