-/* PSPP - computes sample statistics.
- Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+/* PSPP - a program for statistical analysis.
+ Copyright (C) 1997-9, 2000, 2009 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 <http://www.gnu.org/licenses/>. */
#include <config.h>
+#include <stdint.h>
#include <stdlib.h>
#include <data/case.h>
#include <language/command.h>
#include <language/expressions/public.h>
#include <language/lexer/lexer.h>
-#include <libpspp/alloc.h>
-#include <libpspp/message.h>
#include <libpspp/message.h>
#include <libpspp/misc.h>
#include <libpspp/str.h>
+#include "xalloc.h"
+
#include "gettext.h"
#define _(msgid) gettext (msgid)
/* Handle COMPUTE or IF with numeric target variable. */
static int
-compute_num (void *compute_, struct ccase *c, casenumber case_num)
+compute_num (void *compute_, struct ccase **c, casenumber case_num)
{
struct compute_trns *compute = compute_;
if (compute->test == NULL
- || expr_evaluate_num (compute->test, c, case_num) == 1.0)
- case_data_rw (c, compute->variable)->f
- = expr_evaluate_num (compute->rvalue, c, case_num);
+ || expr_evaluate_num (compute->test, *c, case_num) == 1.0)
+ {
+ *c = case_unshare (*c);
+ case_data_rw (*c, compute->variable)->f
+ = expr_evaluate_num (compute->rvalue, *c, case_num);
+ }
return TRNS_CONTINUE;
}
/* Handle COMPUTE or IF with numeric vector element target
variable. */
static int
-compute_num_vec (void *compute_, struct ccase *c, casenumber case_num)
+compute_num_vec (void *compute_, struct ccase **c, casenumber case_num)
{
struct compute_trns *compute = compute_;
if (compute->test == NULL
- || expr_evaluate_num (compute->test, c, case_num) == 1.0)
+ || expr_evaluate_num (compute->test, *c, case_num) == 1.0)
{
double index; /* Index into the vector. */
int rindx; /* Rounded index value. */
- index = expr_evaluate_num (compute->element, c, case_num);
+ index = expr_evaluate_num (compute->element, *c, case_num);
rindx = floor (index + EPSILON);
if (index == SYSMIS
|| rindx < 1 || rindx > vector_get_var_cnt (compute->vector))
index, vector_get_name (compute->vector));
return TRNS_CONTINUE;
}
- case_data_rw (c, vector_get_var (compute->vector, rindx - 1))->f
- = expr_evaluate_num (compute->rvalue, c, case_num);
+
+ *c = case_unshare (*c);
+ case_data_rw (*c, vector_get_var (compute->vector, rindx - 1))->f
+ = expr_evaluate_num (compute->rvalue, *c, case_num);
}
return TRNS_CONTINUE;
/* Handle COMPUTE or IF with string target variable. */
static int
-compute_str (void *compute_, struct ccase *c, casenumber case_num)
+compute_str (void *compute_, struct ccase **c, casenumber case_num)
{
struct compute_trns *compute = compute_;
if (compute->test == NULL
- || expr_evaluate_num (compute->test, c, case_num) == 1.0)
- expr_evaluate_str (compute->rvalue, c, case_num,
- case_data_rw (c, compute->variable)->s, compute->width);
+ || expr_evaluate_num (compute->test, *c, case_num) == 1.0)
+ {
+ *c = case_unshare (*c);
+ expr_evaluate_str (compute->rvalue, *c, case_num,
+ case_data_rw (*c, compute->variable)->s,
+ compute->width);
+ }
return TRNS_CONTINUE;
}
/* Handle COMPUTE or IF with string vector element target
variable. */
static int
-compute_str_vec (void *compute_, struct ccase *c, casenumber case_num)
+compute_str_vec (void *compute_, struct ccase **c, casenumber case_num)
{
struct compute_trns *compute = compute_;
if (compute->test == NULL
- || expr_evaluate_num (compute->test, c, case_num) == 1.0)
+ || expr_evaluate_num (compute->test, *c, case_num) == 1.0)
{
double index; /* Index into the vector. */
int rindx; /* Rounded index value. */
struct variable *vr; /* Variable reference by indexed vector. */
- index = expr_evaluate_num (compute->element, c, case_num);
+ index = expr_evaluate_num (compute->element, *c, case_num);
rindx = floor (index + EPSILON);
if (index == SYSMIS)
{
}
vr = vector_get_var (compute->vector, rindx - 1);
- expr_evaluate_str (compute->rvalue, c, case_num,
- case_data_rw (c, vr)->s,
+ *c = case_unshare (*c);
+ expr_evaluate_str (compute->rvalue, *c, case_num,
+ case_data_rw (*c, vr)->s,
var_get_width (vr));
}
static trns_proc_func *
get_proc_func (const struct lvalue *lvalue)
{
- bool is_numeric = lvalue_get_type (lvalue) == VAR_NUMERIC;
+ bool is_numeric = lvalue_get_type (lvalue) == VAL_NUMERIC;
bool is_vector = lvalue_is_vector (lvalue);
return (is_numeric
parse_rvalue (struct lexer *lexer,
const struct lvalue *lvalue, struct dataset *ds)
{
- bool is_numeric = lvalue_get_type (lvalue) == VAR_NUMERIC;
+ bool is_numeric = lvalue_get_type (lvalue) == VAL_NUMERIC;
return expr_parse (lexer, ds, is_numeric ? EXPR_NUMBER : EXPR_STRING);
}