+/* Destroys DS. */
+void
+dataset_destroy (struct dataset *ds)
+{
+ if (ds != NULL)
+ {
+ dataset_clear (ds);
+ dict_destroy (ds->dict);
+ caseinit_destroy (ds->caseinit);
+ trns_chain_destroy (ds->permanent_trns_chain);
+
+ if ( ds->xform_callback)
+ ds->xform_callback (false, ds->xform_callback_aux);
+ free (ds->syntax_encoding);
+ free (ds);
+ }
+}
+
+/* Discards the active file dictionary, data, and transformations. */
+void
+dataset_clear (struct dataset *ds)
+{
+ assert (ds->proc_state == PROC_COMMITTED);
+
+ dict_clear (ds->dict);
+ fh_set_default_handle (NULL);
+
+ ds->n_lag = 0;
+
+ casereader_destroy (ds->source);
+ ds->source = NULL;
+
+ proc_cancel_all_transformations (ds);
+}
+
+/* Returns the dictionary within DS. This is always nonnull, although it
+ might not contain any variables. */
+struct dictionary *
+dataset_dict (const struct dataset *ds)
+{
+ return ds->dict;
+}
+
+/* Replaces DS's dictionary by DICT, discarding any source and
+ transformations. */
+void
+dataset_set_dict (struct dataset *ds, struct dictionary *dict)
+{
+ assert (ds->proc_state == PROC_COMMITTED);
+ assert (ds->dict != dict);
+
+ dataset_clear (ds);
+
+ dict_destroy (ds->dict);
+ ds->dict = dict;
+ dict_set_change_callback (ds->dict, dict_callback, ds);
+}
+
+/* Returns the casereader that will be read when a procedure is executed on
+ DS. This can be NULL if none has been set up yet. */
+const struct casereader *
+dataset_source (const struct dataset *ds)
+{
+ return ds->source;
+}
+
+/* Returns true if DS has a data source, false otherwise. */
+bool
+dataset_has_source (const struct dataset *ds)
+{
+ return dataset_source (ds) != NULL;
+}
+
+/* Replaces the active file's data by READER. READER's cases must have an
+ appropriate format for DS's dictionary. */
+bool
+dataset_set_source (struct dataset *ds, struct casereader *reader)
+{
+ casereader_destroy (ds->source);
+ ds->source = reader;
+
+ caseinit_clear (ds->caseinit);
+ caseinit_mark_as_preinited (ds->caseinit, ds->dict);
+
+ return reader == NULL || !casereader_error (reader);
+}
+
+/* Returns the data source from DS and removes it from DS. Returns a null
+ pointer if DS has no data source. */
+struct casereader *
+dataset_steal_source (struct dataset *ds)
+{
+ struct casereader *reader = ds->source;
+ ds->source = NULL;
+
+ return reader;
+}
+\f