+/* Creates and returns a new dataset that has the same data and dictionary as
+ OLD named NAME, adds it to the same session as OLD, and returns the new
+ dataset. If SESSION already contains a dataset named NAME, it is deleted
+ and replaced.
+
+ OLD must not have any active transformations or temporary state and must
+ not be in the middle of a procedure.
+
+ Callbacks are not cloned. */
+struct dataset *
+dataset_clone (struct dataset *old, const char *name)
+{
+ struct dataset *new;
+
+ assert (old->proc_state == PROC_COMMITTED);
+ assert (trns_chain_is_empty (old->permanent_trns_chain));
+ assert (old->permanent_dict == NULL);
+ assert (old->sink == NULL);
+ assert (old->temporary_trns_chain == NULL);
+
+ new = xzalloc (sizeof *new);
+ new->name = xstrdup (name);
+ new->display = DATASET_FRONT;
+ new->source = casereader_clone (old->source);
+ new->dict = dict_clone (old->dict);
+ new->caseinit = caseinit_clone (old->caseinit);
+ new->last_proc_invocation = old->last_proc_invocation;
+ new->ok = old->ok;
+
+ dataset_create_finish__ (new, old->session);
+
+ return new;
+}
+