25 |
#include "command.h" |
#include "command.h" |
26 |
#include "dictionary.h" |
#include "dictionary.h" |
27 |
#include "error.h" |
#include "error.h" |
28 |
#include "expr.h" |
#include "expressions/public.h" |
29 |
#include "lexer.h" |
#include "lexer.h" |
30 |
#include "misc.h" |
#include "misc.h" |
31 |
#include "str.h" |
#include "str.h" |
112 |
struct compute_trns *compute = (struct compute_trns *) compute_; |
struct compute_trns *compute = (struct compute_trns *) compute_; |
113 |
|
|
114 |
if (compute->test == NULL |
if (compute->test == NULL |
115 |
|| expr_evaluate (compute->test, c, case_num, NULL) == 1.0) |
|| expr_evaluate_num (compute->test, c, case_num) == 1.0) |
116 |
{ |
case_data_rw (c, compute->fv)->f = expr_evaluate_num (compute->rvalue, c, |
117 |
expr_evaluate (compute->rvalue, c, case_num, |
case_num); |
|
case_data_rw (c, compute->fv)); |
|
|
} |
|
118 |
|
|
119 |
return -1; |
return -1; |
120 |
} |
} |
128 |
struct compute_trns *compute = (struct compute_trns *) compute_; |
struct compute_trns *compute = (struct compute_trns *) compute_; |
129 |
|
|
130 |
if (compute->test == NULL |
if (compute->test == NULL |
131 |
|| expr_evaluate (compute->test, c, case_num, NULL) == 1.0) |
|| expr_evaluate_num (compute->test, c, case_num) == 1.0) |
132 |
{ |
{ |
133 |
/* Index into the vector. */ |
double index; /* Index into the vector. */ |
134 |
union value index; |
int rindx; /* Rounded index value. */ |
135 |
|
|
136 |
/* Rounded index value. */ |
index = expr_evaluate_num (compute->element, c, case_num); |
137 |
int rindx; |
rindx = floor (index + EPSILON); |
138 |
|
if (index == SYSMIS || rindx < 1 || rindx > compute->vector->cnt) |
|
expr_evaluate (compute->element, c, case_num, &index); |
|
|
rindx = floor (index.f + EPSILON); |
|
|
if (index.f == SYSMIS || rindx < 1 || rindx > compute->vector->cnt) |
|
139 |
{ |
{ |
140 |
if (index.f == SYSMIS) |
if (index == SYSMIS) |
141 |
msg (SW, _("When executing COMPUTE: SYSMIS is not a valid value as " |
msg (SW, _("When executing COMPUTE: SYSMIS is not a valid value as " |
142 |
"an index into vector %s."), compute->vector->name); |
"an index into vector %s."), compute->vector->name); |
143 |
else |
else |
144 |
msg (SW, _("When executing COMPUTE: %g is not a valid value as " |
msg (SW, _("When executing COMPUTE: %g is not a valid value as " |
145 |
"an index into vector %s."), |
"an index into vector %s."), |
146 |
index.f, compute->vector->name); |
index, compute->vector->name); |
147 |
return -1; |
return -1; |
148 |
} |
} |
149 |
expr_evaluate (compute->rvalue, c, case_num, |
case_data_rw (c, compute->vector->var[rindx - 1]->fv)->f |
150 |
case_data_rw (c, compute->vector->var[rindx - 1]->fv)); |
= expr_evaluate_num (compute->rvalue, c, case_num); |
151 |
} |
} |
152 |
|
|
153 |
return -1; |
return -1; |
161 |
struct compute_trns *compute = (struct compute_trns *) compute_; |
struct compute_trns *compute = (struct compute_trns *) compute_; |
162 |
|
|
163 |
if (compute->test == NULL |
if (compute->test == NULL |
164 |
|| expr_evaluate (compute->test, c, case_num, NULL) == 1.0) |
|| expr_evaluate_num (compute->test, c, case_num) == 1.0) |
165 |
{ |
expr_evaluate_str (compute->rvalue, c, case_num, |
166 |
/* Temporary storage for string expression return value. */ |
case_data_rw (c, compute->fv)->s, compute->width); |
|
union value v; |
|
|
|
|
|
expr_evaluate (compute->rvalue, c, case_num, &v); |
|
|
st_bare_pad_len_copy (case_data_rw (c, compute->fv)->s, |
|
|
&v.c[1], compute->width, v.c[0]); |
|
|
} |
|
167 |
|
|
168 |
return -1; |
return -1; |
169 |
} |
} |
177 |
struct compute_trns *compute = (struct compute_trns *) compute_; |
struct compute_trns *compute = (struct compute_trns *) compute_; |
178 |
|
|
179 |
if (compute->test == NULL |
if (compute->test == NULL |
180 |
|| expr_evaluate (compute->test, c, case_num, NULL) == 1.0) |
|| expr_evaluate_num (compute->test, c, case_num) == 1.0) |
181 |
{ |
{ |
182 |
/* Temporary storage for string expression return value. */ |
double index; /* Index into the vector. */ |
183 |
union value v; |
int rindx; /* Rounded index value. */ |
184 |
|
struct variable *vr; /* Variable reference by indexed vector. */ |
185 |
/* Index into the vector. */ |
|
186 |
union value index; |
index = expr_evaluate_num (compute->element, c, case_num); |
187 |
|
rindx = floor (index + EPSILON); |
188 |
/* Rounded index value. */ |
if (index == SYSMIS) |
|
int rindx; |
|
|
|
|
|
/* Variable reference by indexed vector. */ |
|
|
struct variable *vr; |
|
|
|
|
|
expr_evaluate (compute->element, c, case_num, &index); |
|
|
rindx = floor (index.f + EPSILON); |
|
|
if (index.f == SYSMIS || rindx < 1 || rindx > compute->vector->cnt) |
|
189 |
{ |
{ |
190 |
if (index.f == SYSMIS) |
msg (SW, _("When executing COMPUTE: SYSMIS is not a valid " |
191 |
msg (SW, _("When executing COMPUTE: SYSMIS is not a valid " |
"value as an index into vector %s."), |
192 |
"value as an index into vector %s."), |
compute->vector->name); |
193 |
compute->vector->name); |
return -1; |
194 |
else |
} |
195 |
msg (SW, _("When executing COMPUTE: %g is not a valid value as " |
else if (rindx < 1 || rindx > compute->vector->cnt) |
196 |
"an index into vector %s."), |
{ |
197 |
index.f, compute->vector->name); |
msg (SW, _("When executing COMPUTE: %g is not a valid value as " |
198 |
|
"an index into vector %s."), |
199 |
|
index, compute->vector->name); |
200 |
return -1; |
return -1; |
201 |
} |
} |
202 |
|
|
|
expr_evaluate (compute->rvalue, c, case_num, &v); |
|
203 |
vr = compute->vector->var[rindx - 1]; |
vr = compute->vector->var[rindx - 1]; |
204 |
st_bare_pad_len_copy (case_data_rw (c, vr->fv)->s, |
expr_evaluate_str (compute->rvalue, c, case_num, |
205 |
&v.c[1], vr->width, v.c[0]); |
case_data_rw (c, vr->fv)->s, vr->width); |
206 |
} |
} |
207 |
|
|
208 |
return -1; |
return -1; |
219 |
compute = compute_trns_create (); |
compute = compute_trns_create (); |
220 |
|
|
221 |
/* Test expression. */ |
/* Test expression. */ |
222 |
compute->test = expr_parse (EXPR_BOOLEAN); |
compute->test = expr_parse (default_dict, EXPR_BOOLEAN); |
223 |
if (compute->test == NULL) |
if (compute->test == NULL) |
224 |
goto fail; |
goto fail; |
225 |
|
|
262 |
|
|
263 |
assert (type == NUMERIC || type == ALPHA); |
assert (type == NUMERIC || type == ALPHA); |
264 |
|
|
265 |
compute->rvalue = expr_parse (type == ALPHA ? EXPR_STRING : EXPR_NUMERIC); |
compute->rvalue = expr_parse (default_dict, |
266 |
|
type == ALPHA ? EXPR_STRING : EXPR_NUMBER); |
267 |
if (compute->rvalue == NULL) |
if (compute->rvalue == NULL) |
268 |
return 0; |
return 0; |
269 |
|
|
344 |
lex_get (); |
lex_get (); |
345 |
if (!lex_force_match ('(')) |
if (!lex_force_match ('(')) |
346 |
goto lossage; |
goto lossage; |
347 |
lvalue->element = expr_parse (EXPR_NUMERIC); |
lvalue->element = expr_parse (default_dict, EXPR_NUMBER); |
348 |
if (lvalue->element == NULL) |
if (lvalue->element == NULL) |
349 |
goto lossage; |
goto lossage; |
350 |
if (!lex_force_match (')')) |
if (!lex_force_match (')')) |