projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Handle case of a lookup table as the active file.
[pspp]
/
src
/
loop.c
diff --git
a/src/loop.c
b/src/loop.c
index 7a31234c4f681629c7f9baf37abafc9618a9c9d1..b6df5c2d6263aac1e4d81532a582448f17b6fe60 100644
(file)
--- a/
src/loop.c
+++ b/
src/loop.c
@@
-14,16
+14,18
@@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
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., 5
9 Temple Place - Suite 330
, Boston, MA
- 0211
1-1307
, USA. */
+ Foundation, Inc., 5
1 Franklin Street, Fifth Floor
, Boston, MA
+ 0211
0-1301
, USA. */
#include <config.h>
#include <config.h>
-#include
<assert.h>
+#include
"error.h"
#include "alloc.h"
#include "alloc.h"
+#include "case.h"
#include "command.h"
#include "command.h"
+#include "dictionary.h"
#include "do-ifP.h"
#include "error.h"
#include "do-ifP.h"
#include "error.h"
-#include "expr.h"
+#include "expr
essions/public
.h"
#include "lexer.h"
#include "misc.h"
#include "settings.h"
#include "lexer.h"
#include "misc.h"
#include "settings.h"
@@
-164,9
+166,7
@@
static int
internal_cmd_loop (void)
{
/* Name of indexing variable if applicable. */
internal_cmd_loop (void)
{
/* Name of indexing variable if applicable. */
- char name[9];
-
- lex_match_id ("LOOP");
+ char name[LONG_NAME_LEN + 1];
/* Create and initialize transformations to facilitate
error-handling. */
/* Create and initialize transformations to facilitate
error-handling. */
@@
-200,7
+200,7
@@
internal_cmd_loop (void)
assert (token == '=');
lex_get ();
assert (token == '=');
lex_get ();
- one->init = expr_parse (
PXP_NUMERIC
);
+ one->init = expr_parse (
default_dict, EXPR_NUMBER
);
if (!one->init)
return 0;
if (!one->init)
return 0;
@@
-209,7
+209,7
@@
internal_cmd_loop (void)
expr_free (one->init);
return 0;
}
expr_free (one->init);
return 0;
}
- one->term = expr_parse (
PXP_NUMERIC
);
+ one->term = expr_parse (
default_dict, EXPR_NUMBER
);
if (!one->term)
{
expr_free (one->init);
if (!one->term)
{
expr_free (one->init);
@@
-218,20
+218,20
@@
internal_cmd_loop (void)
if (lex_match (T_BY))
{
if (lex_match (T_BY))
{
- one->incr = expr_parse (
PXP_NUMERIC
);
+ one->incr = expr_parse (
default_dict, EXPR_NUMBER
);
if (!one->incr)
return 0;
}
}
else
if (!one->incr)
return 0;
}
}
else
- name[0] =
0
;
+ name[0] =
'\0'
;
/* Parse IF clause. */
if (lex_match_id ("IF"))
{
two->flags |= LPC_COND;
/* Parse IF clause. */
if (lex_match_id ("IF"))
{
two->flags |= LPC_COND;
- two->cond = expr_parse (
PXP
_BOOLEAN);
+ two->cond = expr_parse (
default_dict, EXPR
_BOOLEAN);
if (!two->cond)
return 0;
}
if (!two->cond)
return 0;
}
@@
-243,7
+243,7
@@
internal_cmd_loop (void)
}
/* Find variable; create if necessary. */
}
/* Find variable; create if necessary. */
- if (name[0])
+ if (name[0]
!= '\0'
)
{
two->index = dict_lookup_var (default_dict, name);
if (!two->index)
{
two->index = dict_lookup_var (default_dict, name);
if (!two->index)
@@
-261,15
+261,6
@@
internal_cmd_loop (void)
add_transformation ((struct trns_header *) one);
add_transformation ((struct trns_header *) two);
add_transformation ((struct trns_header *) one);
add_transformation ((struct trns_header *) two);
-#if DEBUGGING
- printf ("LOOP");
- if (two->flags & LPC_INDEX)
- printf ("(INDEX)");
- if (two->flags & LPC_COND)
- printf ("(IF)");
- printf ("\n");
-#endif
-
return 1;
}
return 1;
}
@@
-315,7
+306,7
@@
internal_cmd_end_loop (void)
/* Parse the expression if any. */
if (lex_match_id ("IF"))
{
/* Parse the expression if any. */
if (lex_match_id ("IF"))
{
- thr->cond = expr_parse (
PXP
_BOOLEAN);
+ thr->cond = expr_parse (
default_dict, EXPR
_BOOLEAN);
if (!thr->cond)
return 0;
}
if (!thr->cond)
return 0;
}
@@
-330,13
+321,6
@@
internal_cmd_end_loop (void)
/* Pop off the top of stack. */
ctl_stack = ctl_stack->down;
/* Pop off the top of stack. */
ctl_stack = ctl_stack->down;
-#if DEBUGGING
- printf ("END LOOP");
- if (thr->cond)
- printf ("(IF)");
- printf ("\n");
-#endif
-
return 1;
}
return 1;
}
@@
-351,31
+335,31
@@
loop_1_trns_proc (struct trns_header * trns, struct ccase * c,
two->pass = -1;
if (two->flags & LPC_INDEX)
{
two->pass = -1;
if (two->flags & LPC_INDEX)
{
-
union valu
e t1, t2, t3;
+
doubl
e t1, t2, t3;
-
expr_evaluate (one->init, c, case_num, &t1
);
+
t1 = expr_evaluate_num (one->init, c, case_num
);
if (one->incr)
if (one->incr)
-
expr_evaluate (one->incr, c, case_num, &t2
);
+
t2 = expr_evaluate_num (one->incr, c, case_num
);
else
else
- t2
.f
= 1.0;
-
expr_evaluate (one->term, c, case_num, &t3
);
+ t2 = 1.0;
+
t3 = expr_evaluate_num (one->term, c, case_num
);
/* Even if the loop is never entered, force the index variable
to assume the initial value. */
/* Even if the loop is never entered, force the index variable
to assume the initial value. */
- c
->data[two->index->fv].f = t1.f
;
+ c
ase_data_rw (c, two->index->fv)->f = t1
;
/* Throw out various pathological cases. */
/* Throw out various pathological cases. */
- if (!finite (t1
.f) || !finite (t2.f) || !finite (t3.f) || t2.f
== 0.0)
+ if (!finite (t1
) || !finite (t2) || !finite (t3) || t2
== 0.0)
return two->loop_term;
debug_printf (("LOOP %s=%g TO %g BY %g.\n", two->index->name,
return two->loop_term;
debug_printf (("LOOP %s=%g TO %g BY %g.\n", two->index->name,
- t1
.f, t3.f, t2.f
));
- if (t2
.f
> 0.0)
+ t1
, t3, t2
));
+ if (t2 > 0.0)
{
/* Loop counts upward: I=1 TO 5 BY 1. */
two->flags &= ~LPC_RINDEX;
/* incr>0 but init>term */
{
/* Loop counts upward: I=1 TO 5 BY 1. */
two->flags &= ~LPC_RINDEX;
/* incr>0 but init>term */
- if (t1
.f > t3.f
)
+ if (t1
> t3
)
return two->loop_term;
}
else
return two->loop_term;
}
else
@@
-384,13
+368,13
@@
loop_1_trns_proc (struct trns_header * trns, struct ccase * c,
two->flags |= LPC_RINDEX;
/* incr<0 but init<term */
two->flags |= LPC_RINDEX;
/* incr<0 but init<term */
- if (t1
.f < t3.f
)
+ if (t1
< t3
)
return two->loop_term;
}
return two->loop_term;
}
- two->curr = t1
.f
;
- two->incr = t2
.f
;
- two->term = t3
.f
;
+ two->curr = t1;
+ two->incr = t2;
+ two->term = t3;
}
return -1;
}
return -1;
@@
-430,7
+414,7
@@
loop_2_trns_proc (struct trns_header * trns, struct ccase * c,
return two->loop_term;
/* Set the current value into the case. */
return two->loop_term;
/* Set the current value into the case. */
- c
->data[two->index->fv].
f = two->curr;
+ c
ase_data_rw (c, two->index->fv)->
f = two->curr;
/* Decrement the current value. */
two->curr += two->incr;
/* Decrement the current value. */
two->curr += two->incr;
@@
-443,7
+427,7
@@
loop_2_trns_proc (struct trns_header * trns, struct ccase * c,
return two->loop_term;
/* Set the current value into the case. */
return two->loop_term;
/* Set the current value into the case. */
- c
->data[two->index->fv].
f = two->curr;
+ c
ase_data_rw (c, two->index->fv)->
f = two->curr;
/* Increment the current value. */
two->curr += two->incr;
/* Increment the current value. */
two->curr += two->incr;
@@
-451,7
+435,7
@@
loop_2_trns_proc (struct trns_header * trns, struct ccase * c,
/* Conditional clause limiter. */
if ((two->flags & LPC_COND)
/* Conditional clause limiter. */
if ((two->flags & LPC_COND)
- && expr_evaluate
(two->cond, c, case_num, NULL
) != 1.0)
+ && expr_evaluate
_num (two->cond, c, case_num
) != 1.0)
return two->loop_term;
return -1;
return two->loop_term;
return -1;
@@
-475,7
+459,7
@@
loop_3_trns_proc (struct trns_header * trns, struct ccase * c,
/* Note that it breaks out of the loop if the expression is true *or
missing*. This is conformant. */
/* Note that it breaks out of the loop if the expression is true *or
missing*. This is conformant. */
- if (thr->cond && expr_evaluate
(two->cond, c, case_num, NULL
) != 0.0)
+ if (thr->cond && expr_evaluate
_num (two->cond, c, case_num
) != 0.0)
return -1;
return thr->loop_start;
return -1;
return thr->loop_start;
@@
-502,8
+486,6
@@
cmd_break (void)
/* New transformation. */
struct break_trns *t;
/* New transformation. */
struct break_trns *t;
- lex_match_id ("BREAK");
-
for (loop = ctl_stack; loop; loop = loop->down)
if (loop->type == CST_LOOP)
break;
for (loop = ctl_stack; loop; loop = loop->down)
if (loop->type == CST_LOOP)
break;