projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Made src/language into one big library. Closes patch #5633
[pspp]
/
src
/
language
/
stats
/
flip.c
diff --git
a/src/language/stats/flip.c
b/src/language/stats/flip.c
index 8a6128bc88936b1eb3d5af6d0675cdf4de429645..c28de4600ac055247c9dcd58ea0859ef8e642dc5 100644
(file)
--- a/
src/language/stats/flip.c
+++ b/
src/language/stats/flip.c
@@
-49,6
+49,7
@@
#include <libpspp/str.h>
#include "intprops.h"
#include <libpspp/str.h>
#include "intprops.h"
+#include "minmax.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
#include "gettext.h"
#define _(msgid) gettext (msgid)
@@
-90,7
+91,7
@@
static const struct case_sink_class flip_sink_class;
/* Parses and executes FLIP. */
int
/* Parses and executes FLIP. */
int
-cmd_flip (struct dataset *ds)
+cmd_flip (struct
lexer *lexer, struct
dataset *ds)
{
struct flip_pgm *flip;
struct case_sink *sink;
{
struct flip_pgm *flip;
struct case_sink *sink;
@@
-103,7
+104,7
@@
cmd_flip (struct dataset *ds)
flip = pool_create_container (struct flip_pgm, pool);
flip->var = NULL;
flip = pool_create_container (struct flip_pgm, pool);
flip->var = NULL;
- flip->idx_to_fv = dict_get_compacted_
idx_to_fv
(dict);
+ flip->idx_to_fv = dict_get_compacted_
dict_index_to_case_index
(dict);
pool_register (flip->pool, free, flip->idx_to_fv);
flip->var_cnt = 0;
flip->case_cnt = 0;
pool_register (flip->pool, free, flip->idx_to_fv);
flip->var_cnt = 0;
flip->case_cnt = 0;
@@
-112,24
+113,24
@@
cmd_flip (struct dataset *ds)
flip->new_names_tail = NULL;
flip->file = NULL;
flip->new_names_tail = NULL;
flip->file = NULL;
- lex_match ('/');
- if (lex_match_id ("VARIABLES"))
+ lex_match (
lexer,
'/');
+ if (lex_match_id (
lexer,
"VARIABLES"))
{
{
- lex_match ('=');
- if (!parse_variables (dict, &flip->var, &flip->var_cnt,
+ lex_match (
lexer,
'=');
+ if (!parse_variables (
lexer,
dict, &flip->var, &flip->var_cnt,
PV_NO_DUPLICATE))
goto error;
PV_NO_DUPLICATE))
goto error;
- lex_match ('/');
+ lex_match (
lexer,
'/');
}
else
dict_get_vars (dict, &flip->var, &flip->var_cnt, 1u << DC_SYSTEM);
pool_register (flip->pool, free, flip->var);
}
else
dict_get_vars (dict, &flip->var, &flip->var_cnt, 1u << DC_SYSTEM);
pool_register (flip->pool, free, flip->var);
- lex_match ('/');
- if (lex_match_id ("NEWNAMES"))
+ lex_match (
lexer,
'/');
+ if (lex_match_id (
lexer,
"NEWNAMES"))
{
{
- lex_match ('=');
- flip->new_names = parse_variable (dict);
+ lex_match (
lexer,
'=');
+ flip->new_names = parse_variable (
lexer,
dict);
if (!flip->new_names)
goto error;
}
if (!flip->new_names)
goto error;
}
@@
-178,7
+179,7
@@
cmd_flip (struct dataset *ds)
/* Set up flipped data for reading. */
proc_set_source (ds, flip_source_create (flip));
/* Set up flipped data for reading. */
proc_set_source (ds, flip_source_create (flip));
- return ok ? lex_end_of_command () : CMD_CASCADING_FAILURE;
+ return ok ? lex_end_of_command (
lexer
) : CMD_CASCADING_FAILURE;
error:
destroy_flip_pgm (flip);
error:
destroy_flip_pgm (flip);
@@
-231,7
+232,7
@@
make_new_var (struct dictionary *dict, char name[])
for (i = 1; i < 10000000; i++)
{
for (i = 1; i < 10000000; i++)
{
- int ofs =
min
(7 - intlog10 (i), len);
+ int ofs =
MIN
(7 - intlog10 (i), len);
memcpy (n, name, ofs);
sprintf (&n[ofs], "%d", i);
memcpy (n, name, ofs);
sprintf (&n[ofs], "%d", i);
@@
-300,7
+301,7
@@
flip_sink_create (struct dictionary *dict, struct flip_pgm *flip)
/* Write variable names as first case. */
for (i = 0; i < flip->var_cnt; i++)
buf_copy_str_rpad (flip->output_buf[i].s, MAX_SHORT_STRING,
/* Write variable names as first case. */
for (i = 0; i < flip->var_cnt; i++)
buf_copy_str_rpad (flip->output_buf[i].s, MAX_SHORT_STRING,
-
flip->var[i]->name
);
+
var_get_name (flip->var[i])
);
if (fwrite (flip->output_buf, sizeof *flip->output_buf,
flip->var_cnt, flip->file) != (size_t) flip->var_cnt)
{
if (fwrite (flip->output_buf, sizeof *flip->output_buf,
flip->var_cnt, flip->file) != (size_t) flip->var_cnt)
{
@@
-326,10
+327,11
@@
flip_sink_write (struct case_sink *sink, const struct ccase *c)
if (flip->new_names != NULL)
{
struct varname *v = pool_alloc (flip->pool, sizeof *v);
if (flip->new_names != NULL)
{
struct varname *v = pool_alloc (flip->pool, sizeof *v);
+ int fv = flip->idx_to_fv[var_get_dict_index (flip->new_names)];
v->next = NULL;
v->next = NULL;
- if (
flip->new_names->type == NUMERIC)
+ if (
var_is_numeric (flip->new_names))
{
{
- double f = case_num
(c, flip->idx_to_fv[flip->new_names->index]
);
+ double f = case_num
_idx (c, fv
);
if (f == SYSMIS)
strcpy (v->name, "VSYSMIS");
if (f == SYSMIS)
strcpy (v->name, "VSYSMIS");
@@
-342,9
+344,8
@@
flip_sink_write (struct case_sink *sink, const struct ccase *c)
}
else
{
}
else
{
- int width = min (flip->new_names->width, MAX_SHORT_STRING);
- memcpy (v->name, case_str (c, flip->idx_to_fv[flip->new_names->index]),
- width);
+ int width = MIN (var_get_width (flip->new_names), MAX_SHORT_STRING);
+ memcpy (v->name, case_str_idx (c, fv), width);
v->name[width] = 0;
}
v->name[width] = 0;
}
@@
-360,8
+361,11
@@
flip_sink_write (struct case_sink *sink, const struct ccase *c)
{
double out;
{
double out;
- if (flip->var[i]->type == NUMERIC)
- out = case_num (c, flip->idx_to_fv[flip->var[i]->index]);
+ if (var_is_numeric (flip->var[i]))
+ {
+ int fv = flip->idx_to_fv[var_get_dict_index (flip->var[i])];
+ out = case_num_idx (c, fv);
+ }
else
out = SYSMIS;
flip->output_buf[i].f = out;
else
out = SYSMIS;
flip->output_buf[i].f = out;
@@
-430,7
+434,7
@@
flip_file (struct flip_pgm *flip)
for (case_idx = 0; case_idx < flip->case_cnt; )
{
for (case_idx = 0; case_idx < flip->case_cnt; )
{
- unsigned long read_cases =
min
(flip->case_cnt - case_idx,
+ unsigned long read_cases =
MIN
(flip->case_cnt - case_idx,
case_capacity);
size_t i;
case_capacity);
size_t i;
@@
-546,7
+550,7
@@
flip_source_read (struct case_source *source,
}
for (j = 0; j < flip->case_cnt; j++)
}
for (j = 0; j < flip->case_cnt; j++)
- case_data_rw (c, j)->f = input_buf[j].f;
+ case_data_rw
_idx
(c, j)->f = input_buf[j].f;
ok = write_case (wc_data);
}
free (input_buf);
ok = write_case (wc_data);
}
free (input_buf);