From: John Darrington Date: Fri, 9 Dec 2011 10:24:56 +0000 (+0100) Subject: Added a function to clone an interaction. X-Git-Tag: v0.7.9~63 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75e7e4241ba2424c3803548bcf2da0382faf7349;p=pspp-builds.git Added a function to clone an interaction. --- diff --git a/src/math/interaction.c b/src/math/interaction.c index 269aa7e9..4e4134f0 100644 --- a/src/math/interaction.c +++ b/src/math/interaction.c @@ -42,7 +42,6 @@ */ - struct interaction * interaction_create (const struct variable *v) { @@ -57,6 +56,24 @@ interaction_create (const struct variable *v) return i; } +/* Deep copy an interaction */ +struct interaction * +interaction_clone (const struct interaction *iact) +{ + int v; + struct interaction *i = xmalloc (sizeof *i); + i->vars = xcalloc (iact->n_vars, sizeof *i->vars); + i->n_vars = iact->n_vars; + + for (v = 0; v < iact->n_vars; ++v) + { + i->vars[v] = iact->vars[v]; + } + + return i; +} + + void interaction_destroy (struct interaction *i) { diff --git a/src/math/interaction.h b/src/math/interaction.h index ccd6706f..23bd4f21 100644 --- a/src/math/interaction.h +++ b/src/math/interaction.h @@ -33,6 +33,7 @@ struct interaction }; struct interaction * interaction_create (const struct variable *); +struct interaction * interaction_clone (const struct interaction *); void interaction_destroy (struct interaction *); void interaction_add_variable (struct interaction *, const struct variable *); void interaction_dump (const struct interaction *);