struct save_file
{
struct file_handle *file;
+ struct dataset *dataset;
/* Parameters from parsing the first SAVE command for 'file'. */
struct string_array variables;
struct matrix_expr *names;
struct stringi_set strings;
- /* Results from the first attempt to open this save_file. */
+ /* Results from the first (only) attempt to open this save_file. */
bool error;
struct casewriter *writer;
+ struct dictionary *dict;
};
struct matrix_state
struct save_file *sf = xmalloc (sizeof *sf);
*sf = (struct save_file) {
.file = fh,
+ .dataset = s->dataset,
.variables = *variables,
.names = names,
.strings = STRINGI_SET_INITIALIZER (sf->strings),
msg (ME, _("The first SAVE to %s within this matrix program "
"had %zu columns, so a %zuĂ—%zu matrix cannot be "
"saved to it."),
- fh_get_name (sf->file), n_variables, m->size1, m->size2);
+ sf->file == fh_inline_file () ? "*" : fh_get_name (sf->file),
+ n_variables, m->size1, m->size2);
return NULL;
}
}
return NULL;
}
- sf->writer = any_writer_open (sf->file, dict);
- dict_unref (dict);
- if (!sf->writer)
+ if (sf->file == fh_inline_file ())
+ sf->writer = autopaging_writer_create (dict_get_proto (dict));
+ else
+ sf->writer = any_writer_open (sf->file, dict);
+ if (sf->writer)
+ sf->dict = dict;
+ else
{
+ dict_unref (dict);
sf->error = true;
- return NULL;
}
return sf->writer;
}
{
if (sf)
{
+ if (sf->file == fh_inline_file () && sf->writer && sf->dict)
+ {
+ dataset_set_dict (sf->dataset, sf->dict);
+ dataset_set_source (sf->dataset, casewriter_make_reader (sf->writer));
+ sf->dict = NULL;
+ sf->writer = NULL;
+ }
+
fh_unref (sf->file);
string_array_destroy (&sf->variables);
matrix_expr_destroy (sf->names);
stringi_set_destroy (&sf->strings);
casewriter_destroy (sf->writer);
+ dict_unref (sf->dict);
free (sf);
}
}
1,abcd,3
4,xyzw,6
])
+AT_CLEANUP
+
+AT_SETUP([MATRIX - SAVE - inline])
+AT_DATA([matrix.sps], [dnl
+MATRIX.
+SAVE {1,2,3; 4,5,6}/OUTFILE=*.
+SAVE {7,8,9}/VARIABLES=a b c d.
+END MATRIX.
+LIST.
+
+MATRIX.
+SAVE {1,2,3}/OUTFILE=*/VARIABLES=v01 TO v03.
+SAVE {4,5,6}/NAMES={'x', 'y', 'z', 'w'}.
+END MATRIX.
+LIST.
+
+MATRIX.
+SAVE {1,'abcd',3}/OUTFILE=*/NAMES={'a', 'b', 'c'}/STRINGS=b.
+SAVE {4,'xyzw',6}/STRINGS=a, b.
+END MATRIX.
+LIST.
+])
+AT_CHECK([pspp matrix.sps -O format=csv], [0], [dnl
+Table: Data List
+COL1,COL2,COL3
+1.00,2.00,3.00
+4.00,5.00,6.00
+7.00,8.00,9.00
+
+Table: Data List
+v01,v02,v03
+1.00,2.00,3.00
+4.00,5.00,6.00
+
+Table: Data List
+a,b,c
+1.00,abcd,3.00
+4.00,xyzw,6.00
+])
AT_CLEANUP
\ No newline at end of file