projects
/
pspp-builds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
More constness
[pspp-builds.git]
/
src
/
language
/
stats
/
flip.c
diff --git
a/src/language/stats/flip.c
b/src/language/stats/flip.c
index f2c0290c0b31cf3823e2438cfd4793ae34645261..8a6128bc88936b1eb3d5af6d0675cdf4de429645 100644
(file)
--- a/
src/language/stats/flip.c
+++ b/
src/language/stats/flip.c
@@
-18,31
+18,37
@@
02110-1301, USA. */
#include "config.h"
02110-1301, USA. */
#include "config.h"
-#include <libpspp/message.h>
+
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <stdlib.h>
-#include <libpspp/array.h>
-#include <libpspp/alloc.h>
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#include <data/case-sink.h>
+#include <data/case-source.h>
#include <data/case.h>
#include <data/case.h>
-#include <language/command.h>
#include <data/dictionary.h>
#include <data/dictionary.h>
-#include <libpspp/message.h>
-#include "intprops.h"
+#include <data/procedure.h>
+#include <data/settings.h>
+#include <data/value.h>
+#include <data/variable.h>
+#include <language/command.h>
#include <language/lexer/lexer.h>
#include <language/lexer/lexer.h>
+#include <language/lexer/variable-parser.h>
+#include <libpspp/alloc.h>
+#include <libpspp/array.h>
+#include <libpspp/assertion.h>
+#include <libpspp/message.h>
+#include <libpspp/message.h>
#include <libpspp/misc.h>
#include <libpspp/pool.h>
#include <libpspp/misc.h>
#include <libpspp/pool.h>
-#include <data/settings.h>
#include <libpspp/str.h>
#include <libpspp/str.h>
-#include <data/value.h>
-#include <data/variable.h>
-#include <procedure.h>
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
+#include "intprops.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
#include "gettext.h"
#define _(msgid) gettext (msgid)
@@
-74,31
+80,30
@@
struct flip_pgm
};
static void destroy_flip_pgm (struct flip_pgm *);
};
static void destroy_flip_pgm (struct flip_pgm *);
-static struct case_sink *flip_sink_create (struct flip_pgm *);
+static struct case_sink *flip_sink_create (struct
dictionary *d, struct
flip_pgm *);
static struct case_source *flip_source_create (struct flip_pgm *);
static bool flip_file (struct flip_pgm *);
static struct case_source *flip_source_create (struct flip_pgm *);
static bool flip_file (struct flip_pgm *);
-static int build_dictionary (struct flip_pgm *);
+static int build_dictionary (struct
dictionary *, struct
flip_pgm *);
static const struct case_source_class flip_source_class;
static const struct case_sink_class flip_sink_class;
/* Parses and executes FLIP. */
int
static const struct case_source_class flip_source_class;
static const struct case_sink_class flip_sink_class;
/* Parses and executes FLIP. */
int
-cmd_flip (
void
)
+cmd_flip (
struct dataset *ds
)
{
struct flip_pgm *flip;
{
struct flip_pgm *flip;
+ struct case_sink *sink;
+ struct dictionary *dict = dataset_dict (ds);
bool ok;
bool ok;
- if (temporary != 0)
- {
- msg (SW, _("FLIP ignores TEMPORARY. "
- "Temporary transformations will be made permanent."));
- cancel_temporary ();
- }
+ if (proc_make_temporary_transformations_permanent (ds))
+ msg (SW, _("FLIP ignores TEMPORARY. "
+ "Temporary transformations will be made permanent."));
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 (d
efault_d
ict);
+ flip->idx_to_fv = dict_get_compacted_idx_to_fv (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;
@@
-111,25
+116,25
@@
cmd_flip (void)
if (lex_match_id ("VARIABLES"))
{
lex_match ('=');
if (lex_match_id ("VARIABLES"))
{
lex_match ('=');
- if (!parse_variables (d
efault_d
ict, &flip->var, &flip->var_cnt,
+ if (!parse_variables (dict, &flip->var, &flip->var_cnt,
PV_NO_DUPLICATE))
goto error;
lex_match ('/');
}
else
PV_NO_DUPLICATE))
goto error;
lex_match ('/');
}
else
- dict_get_vars (d
efault_d
ict, &flip->var, &flip->var_cnt, 1u << DC_SYSTEM);
+ 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 ('=');
pool_register (flip->pool, free, flip->var);
lex_match ('/');
if (lex_match_id ("NEWNAMES"))
{
lex_match ('=');
- flip->new_names = parse_variable ();
+ flip->new_names = parse_variable (
dict
);
if (!flip->new_names)
goto error;
}
else
if (!flip->new_names)
goto error;
}
else
- flip->new_names = dict_lookup_var (d
efault_d
ict, "CASE_LBL");
+ flip->new_names = dict_lookup_var (dict, "CASE_LBL");
if (flip->new_names)
{
if (flip->new_names)
{
@@
-146,31
+151,32
@@
cmd_flip (void)
/* Read the active file into a flip_sink. */
flip->case_cnt = 0;
/* Read the active file into a flip_sink. */
flip->case_cnt = 0;
-
temp_trns = temporary = 0
;
-
vfm_sink = flip_sink_create (
flip);
- if (
vfm_
sink == NULL)
+
proc_make_temporary_transformations_permanent (ds)
;
+
sink = flip_sink_create (dict,
flip);
+ if (sink == NULL)
goto error;
goto error;
+ proc_set_sink (ds, sink);
flip->new_names_tail = NULL;
flip->new_names_tail = NULL;
- ok = procedure (NULL, NULL);
+ ok = procedure (
ds,
NULL, NULL);
/* Flip the data we read. */
if (!flip_file (flip))
{
/* Flip the data we read. */
if (!flip_file (flip))
{
- discard_variables ();
+ discard_variables (
ds
);
goto error;
}
/* Flip the dictionary. */
goto error;
}
/* Flip the dictionary. */
- dict_clear (d
efault_d
ict);
- if (!build_dictionary (flip))
+ dict_clear (dict);
+ if (!build_dictionary (
dict,
flip))
{
{
- discard_variables ();
+ discard_variables (
ds
);
goto error;
}
goto error;
}
- flip->case_size = dict_get_case_size (d
efault_d
ict);
+ flip->case_size = dict_get_case_size (dict);
/* Set up flipped data for reading. */
/* Set up flipped data for reading. */
-
vfm_source = flip_source_create (flip
);
+
proc_set_source (ds, flip_source_create (flip)
);
return ok ? lex_end_of_command () : CMD_CASCADING_FAILURE;
return ok ? lex_end_of_command () : CMD_CASCADING_FAILURE;
@@
-190,7
+196,7
@@
destroy_flip_pgm (struct flip_pgm *flip)
/* Make a new variable with base name NAME, which is bowdlerized and
mangled until acceptable, and returns success. */
static int
/* Make a new variable with base name NAME, which is bowdlerized and
mangled until acceptable, and returns success. */
static int
-make_new_var (char name[])
+make_new_var (
struct dictionary *dict,
char name[])
{
char *cp;
{
char *cp;
@@
-214,7
+220,7
@@
make_new_var (char name[])
*cp = '\0';
str_uppercase (name);
*cp = '\0';
str_uppercase (name);
- if (dict_create_var (d
efault_d
ict, name, 0))
+ if (dict_create_var (dict, name, 0))
return 1;
/* Add numeric extensions until acceptable. */
return 1;
/* Add numeric extensions until acceptable. */
@@
-229,7
+235,7
@@
make_new_var (char name[])
memcpy (n, name, ofs);
sprintf (&n[ofs], "%d", i);
memcpy (n, name, ofs);
sprintf (&n[ofs], "%d", i);
- if (dict_create_var (d
efault_d
ict, n, 0))
+ if (dict_create_var (dict, n, 0))
return 1;
}
}
return 1;
}
}
@@
-240,9
+246,9
@@
make_new_var (char name[])
/* Make a new dictionary for all the new variable names. */
static int
/* Make a new dictionary for all the new variable names. */
static int
-build_dictionary (struct flip_pgm *flip)
+build_dictionary (struct
dictionary *dict, struct
flip_pgm *flip)
{
{
- dict_create_var_assert (d
efault_d
ict, "CASE_LBL", 8);
+ dict_create_var_assert (dict, "CASE_LBL", 8);
if (flip->new_names_head == NULL)
{
if (flip->new_names_head == NULL)
{
@@
-260,7
+266,7
@@
build_dictionary (struct flip_pgm *flip)
char s[SHORT_NAME_LEN + 1];
sprintf (s, "VAR%03d", i);
char s[SHORT_NAME_LEN + 1];
sprintf (s, "VAR%03d", i);
- v = dict_create_var_assert (d
efault_d
ict, s, 0);
+ v = dict_create_var_assert (dict, s, 0);
}
}
else
}
}
else
@@
-268,7
+274,7
@@
build_dictionary (struct flip_pgm *flip)
struct varname *v;
for (v = flip->new_names_head; v; v = v->next)
struct varname *v;
for (v = flip->new_names_head; v; v = v->next)
- if (!make_new_var (v->name))
+ if (!make_new_var (
dict,
v->name))
return 0;
}
return 0;
}
@@
-277,7
+283,7
@@
build_dictionary (struct flip_pgm *flip)
/* Creates a flip sink based on FLIP. */
static struct case_sink *
/* Creates a flip sink based on FLIP. */
static struct case_sink *
-flip_sink_create (struct flip_pgm *flip)
+flip_sink_create (struct
dictionary *dict, struct
flip_pgm *flip)
{
size_t i;
{
size_t i;
@@
-304,7
+310,7
@@
flip_sink_create (struct flip_pgm *flip)
flip->case_cnt = 1;
flip->case_cnt = 1;
- return create_case_sink (&flip_sink_class, d
efault_d
ict, flip);
+ return create_case_sink (&flip_sink_class, dict, flip);
}
/* Writes case C to the FLIP sink.
}
/* Writes case C to the FLIP sink.
@@
-331,12
+337,8
@@
flip_sink_write (struct case_sink *sink, const struct ccase *c)
strcpy (v->name, "VNEGINF");
else if (f > INT_MAX)
strcpy (v->name, "VPOSINF");
strcpy (v->name, "VNEGINF");
else if (f > INT_MAX)
strcpy (v->name, "VPOSINF");
- else
- {
- char name[INT_STRLEN_BOUND (int) + 2];
- sprintf (name, "V%d", (int) f);
- str_copy_trunc (v->name, sizeof v->name, name);
- }
+ else
+ snprintf (v->name, sizeof v->name, "V%d", (int) f);
}
else
{
}
else
{
@@
-475,7
+477,11
@@
flip_file (struct flip_pgm *flip)
case_idx += read_cases;
}
case_idx += read_cases;
}
- pool_fclose (flip->pool, input_file);
+ if (pool_fclose (flip->pool, input_file) == EOF)
+ {
+ msg (SE, _("Error closing FLIP source file: %s."), strerror (errno));
+ return false;
+ }
pool_unregister (flip->pool, input_buf);
free (input_buf);
pool_unregister (flip->pool, input_buf);
free (input_buf);
@@
-534,7
+540,7
@@
flip_source_read (struct case_source *source,
else if (feof (flip->file))
msg (SE, _("Unexpected end of file reading FLIP temporary file."));
else
else if (feof (flip->file))
msg (SE, _("Unexpected end of file reading FLIP temporary file."));
else
-
abort
();
+
NOT_REACHED
();
ok = false;
break;
}
ok = false;
break;
}