#include "data/format.h"
#include "data/variable.h"
-#include "language/command.h"
#include "language/lexer/lexer.h"
#include "language/lexer/variable-parser.h"
-#include "libpspp/hmap.h"
-#include "libpspp/bt.h"
-#include "libpspp/misc.h"
#include "libpspp/pool.h"
#include "means.h"
parse_means_table_syntax (struct lexer *lexer, const struct means *cmd,
struct mtable *table)
{
- table->n_layers = 0;
- table->layers = NULL;
+ memset (table, 0, sizeof *table);
/* Dependent variable (s) */
if (!parse_variables_const_pool (lexer, cmd->pool, cmd->dict,
PV_NO_DUPLICATE | PV_NUMERIC))
return false;
-
/* Factor variable (s) */
while (lex_match (lexer, T_BY))
{
- struct layer *layer = xzalloc (sizeof *layer);
- hmap_init (&layer->instances.map);
+ struct layer *layer = pool_zalloc (cmd->pool, sizeof *layer);
+ table->layers =
+ pool_nrealloc (cmd->pool, table->layers, table->n_layers + 1,
+ sizeof *table->layers);
+ table->layers[table->n_layers] = layer;
table->n_layers++;
- table->layers = xrealloc (table->layers,
- table->n_layers * sizeof *table->layers);
-
- table->layers[table->n_layers - 1] = layer;
if (!parse_variables_const_pool
(lexer, cmd->pool, cmd->dict,
tstr = lex_next_tokcstr (lexer, n);
- if (NULL == dict_lookup_var (dict, tstr) )
+ if (NULL == dict_lookup_var (dict, tstr))
return false;
return true;
}
-static bool
+bool
means_parse (struct lexer *lexer, struct means *means)
{
/* Optional TABLES = */
/* Parse the "tables" */
while (more_tables)
{
- means->n_tables ++;
- means->table = pool_realloc (means->pool, means->table, means->n_tables * sizeof (*means->table));
+ means->table = pool_realloc (means->pool, means->table,
+ (means->n_tables + 1) * sizeof (*means->table));
if (! parse_means_table_syntax (lexer, means,
- &means->table[means->n_tables - 1]))
+ &means->table[means->n_tables]))
{
return false;
}
+ means->n_tables ++;
/* Look ahead to see if there are more tables to be parsed */
more_tables = false;
- if ( T_SLASH == lex_next_token (lexer, 0) )
+ if (T_SLASH == lex_next_token (lexer, 0))
{
- if (lex_is_variable (lexer, means->dict, 1) )
+ if (lex_is_variable (lexer, means->dict, 1))
{
more_tables = true;
lex_match (lexer, T_SLASH);
values in the analysis.
*/
- means->exclude = MV_SYSTEM;
+ means->ctrl_exclude = MV_SYSTEM;
means->dep_exclude = MV_SYSTEM;
}
- else if (lex_match_id (lexer, "TABLE"))
- /*
- This is the default. (I think).
- Every case containing a complete set of variables for a given
- table. If any variable, categorical or dependent for in a table
- is missing (as defined by what?), then that variable will
- be dropped FOR THAT TABLE ONLY.
- */
- {
- means->listwise_exclude = true;
- }
else if (lex_match_id (lexer, "DEPENDENT"))
/*
Use the command "/MISSING=DEPENDENT" to
*/
{
means->dep_exclude = MV_ANY;
- means->exclude = MV_SYSTEM;
+ means->ctrl_exclude = MV_SYSTEM;
}
else
{
/* The default values become overwritten */
means->n_statistics = 0;
- free (means->statistics);
+ pool_free (means->pool, means->statistics);
means->statistics = 0;
while (lex_token (lexer) != T_ENDCMD
&& lex_token (lexer) != T_SLASH)
{
if (lex_match (lexer, T_ALL))
{
- free (means->statistics);
- means->statistics = xcalloc (n_MEANS_STATISTICS, sizeof (*means->statistics));
+ pool_free (means->pool, means->statistics);
+ means->statistics = pool_calloc (means->pool,
+ n_MEANS_STATISTICS,
+ sizeof (*means->statistics));
means->n_statistics = n_MEANS_STATISTICS;
int i;
for (i = 0; i < n_MEANS_STATISTICS; ++i)
else if (lex_match_id (lexer, "NONE"))
{
means->n_statistics = 0;
- free (means->statistics);
+ pool_free (means->pool, means->statistics);
means->statistics = 0;
}
else if (lex_match_id (lexer, "DEFAULT"))
{
- means->n_statistics = 3;
- means->statistics = xcalloc (3, sizeof *means->statistics);
+ pool_free (means->pool, means->statistics);
+ means->statistics = pool_calloc (means->pool,
+ 3,
+ sizeof *means->statistics);
means->statistics[0] = MEANS_MEAN;
means->statistics[1] = MEANS_N;
means->statistics[2] = MEANS_STDDEV;
if (lex_match_id (lexer, cs->keyword))
{
means->statistics
- = xrealloc (means->statistics,
- (means->n_statistics + 1)
- * sizeof (*means->statistics));
+ = pool_realloc (means->pool,
+ means->statistics,
+ (means->n_statistics + 1)
+ * sizeof (*means->statistics));
means->statistics[means->n_statistics] = i;
means->n_statistics++;
}
return true;
}
-
-int
-cmd_means (struct lexer *lexer, struct dataset *ds)
-{
- struct means means;
- means.pool = pool_create ();
-
- means.exclude = MV_ANY;
- means.dep_exclude = MV_ANY;
- means.listwise_exclude = false;
- means.table = NULL;
- means.n_tables = 0;
-
- means.dict = dataset_dict (ds);
-
- means.n_statistics = 3;
- means.statistics = xcalloc (3, sizeof *means.statistics);
- means.statistics[0] = MEANS_MEAN;
- means.statistics[1] = MEANS_N;
- means.statistics[2] = MEANS_STDDEV;
-
- if (! means_parse (lexer, &means))
- goto error;
-
- {
- struct casegrouper *grouper;
- struct casereader *group;
- bool ok;
-
- grouper = casegrouper_create_splits (proc_open (ds), means.dict);
- while (casegrouper_get_next_group (grouper, &group))
- {
- run_means (&means, group, ds);
- }
- ok = casegrouper_destroy (grouper);
- ok = proc_commit (ds) && ok;
- }
-
- for (int t = 0; t < means.n_tables; ++t)
- {
- const struct mtable *table = means.table + t;
- means_shipout (table, &means);
- }
-
- return CMD_SUCCESS;
-
- error:
-
- return CMD_FAILURE;
-}
-
-
-\f
-
-