X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=inline;f=src%2Fdata%2Fcaseinit.c;h=69a0f01869fb7a66c97522d0a86243b9f523dfaf;hb=32897a3d95b7772d44ddd14e2ac8bc154cfe4542;hp=496ea9b2ce29d26c8fa3a3a3ce304dc0fec6b2fc;hpb=5da5a98055ad574120c3e3922af097411a0dcf3a;p=pspp
diff --git a/src/data/caseinit.c b/src/data/caseinit.c
index 496ea9b2ce..69a0f01869 100644
--- a/src/data/caseinit.c
+++ b/src/data/caseinit.c
@@ -1,38 +1,36 @@
-/* PSPP - computes sample statistics.
- Copyright (C) 2007 Free Software Foundation, Inc.
+/* PSPP - a program for statistical analysis.
+ Copyright (C) 2007, 2009, 2011 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
+ along with this program. If not, see . */
#include
-#include
+#include "data/caseinit.h"
#include
#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include "data/case.h"
+#include "data/dictionary.h"
+#include "data/value.h"
+#include "data/variable.h"
+#include "libpspp/array.h"
+#include "libpspp/assertion.h"
+#include "libpspp/compiler.h"
-#include "xalloc.h"
+#include "gl/xalloc.h"
/* Initializer list: a set of values to write to locations within
a case. */
@@ -40,8 +38,9 @@
/* Binds a value with a place to put it. */
struct init_value
{
- union value value;
size_t case_index;
+ int width;
+ union value value;
};
/* A set of values to initialize in a case. */
@@ -70,6 +69,10 @@ init_list_create (struct init_list *list)
static void
init_list_destroy (struct init_list *list)
{
+ struct init_value *iv;
+
+ for (iv = &list->values[0]; iv < &list->values[list->cnt]; iv++)
+ value_destroy (&iv->value, iv->width);
free (list->values);
}
@@ -113,14 +116,13 @@ init_list_mark (struct init_list *list, const struct init_list *exclude,
size_t i;
assert (list != exclude);
- list->values = xnrealloc (list->values,
- list->cnt + dict_get_next_value_idx (d),
+ list->values = xnrealloc (list->values, list->cnt + dict_get_var_cnt (d),
sizeof *list->values);
for (i = 0; i < var_cnt; i++)
{
struct variable *v = dict_get_var (d, i);
size_t case_index = var_get_case_index (v);
- int offset;
+ struct init_value *iv;
/* Only include the correct class. */
if (!(include & (var_get_leave (v) ? LEAVE_LEFT : LEAVE_REINIT)))
@@ -130,19 +132,14 @@ init_list_mark (struct init_list *list, const struct init_list *exclude,
if (exclude != NULL && init_list_includes (exclude, case_index))
continue;
- offset = 0;
- do
- {
- struct init_value *iv = &list->values[list->cnt++];
- iv->case_index = case_index++;
- if (var_is_numeric (v))
- iv->value.f = var_get_leave (v) ? 0 : SYSMIS;
- else
- memset (iv->value.s, ' ', sizeof iv->value.s);
-
- offset += sizeof iv->value.s;
- }
- while (offset < var_get_width (v));
+ iv = &list->values[list->cnt++];
+ iv->case_index = case_index;
+ iv->width = var_get_width (v);
+ value_init (&iv->value, iv->width);
+ if (var_is_numeric (v) && var_get_leave (v))
+ iv->value.f = 0;
+ else
+ value_set_missing (&iv->value, iv->width);
}
/* Drop duplicates. */
@@ -155,13 +152,10 @@ init_list_mark (struct init_list *list, const struct init_list *exclude,
static void
init_list_init (const struct init_list *list, struct ccase *c)
{
- size_t i;
+ const struct init_value *iv;
- for (i = 0; i < list->cnt; i++)
- {
- const struct init_value *value = &list->values[i];
- *case_data_rw_idx (c, value->case_index) = value->value;
- }
+ for (iv = &list->values[0]; iv < &list->values[list->cnt]; iv++)
+ value_copy (case_data_rw_idx (c, iv->case_index), &iv->value, iv->width);
}
/* Updates the values in the initializer LIST from the data in
@@ -169,13 +163,10 @@ init_list_init (const struct init_list *list, struct ccase *c)
static void
init_list_update (const struct init_list *list, const struct ccase *c)
{
- size_t i;
+ struct init_value *iv;
- for (i = 0; i < list->cnt; i++)
- {
- struct init_value *value = &list->values[i];
- value->value = *case_data_idx (c, value->case_index);
- }
+ for (iv = &list->values[0]; iv < &list->values[list->cnt]; iv++)
+ value_copy (&iv->value, case_data_idx (c, iv->case_index), iv->width);
}
/* A case initializer. */
@@ -249,7 +240,8 @@ caseinit_mark_for_init (struct caseinit *ci, const struct dictionary *d)
init_list_mark (&ci->left_values, &ci->preinited_values, LEAVE_LEFT, d);
}
-/* Initializes variables in C as described by CI. */
+/* Initializes variables in *C as described by CI.
+ C must not be shared. */
void
caseinit_init_vars (const struct caseinit *ci, struct ccase *c)
{