The dataset is now owned by main, and passed around by pointer.
/* Deletes variable V from dictionary D and frees V.
This is a very bad idea if there might be any pointers to V
- from outside D. In general, no variable in current_dataset->dict
- should be deleted when any transformations are active, because
+ from outside D. In general, no variable in should be deleted when
+ any transformations are active on the dictionary's dataset, because
those transformations might reference the deleted variable.
The safest time to delete a variable is just after a procedure
has been executed, as done by MODIFY VARS.
struct write_case_data
{
/* Function to call for each case. */
- case_func_t case_func;
+ case_func *proc;
void *aux;
struct dataset *dataset; /* The dataset concerned */
}; /* struct dataset */
-struct dataset *current_dataset;
-
static void add_case_limit_trns (struct dataset *ds);
static void add_filter_trns (struct dataset *ds);
-static bool internal_procedure (struct dataset *ds, case_func_t,
- bool (*end_func) (void *),
+static bool internal_procedure (struct dataset *ds, case_func *,
+ end_func *,
void *aux);
static void update_last_proc_invocation (struct dataset *ds);
static void create_trns_case (struct ccase *, struct dictionary *);
Returns true if successful, false if an I/O error occurred. */
bool
-procedure (struct dataset *ds, case_func_t cf, void *aux)
+procedure (struct dataset *ds, case_func *cf, void *aux)
{
return internal_procedure (ds, cf, NULL, aux);
}
/* Case processing function for multipass_procedure(). */
static bool
-multipass_case_func (const struct ccase *c, void *aux_data_)
+multipass_case_func (const struct ccase *c, void *aux_data_, const struct dataset *ds UNUSED)
{
struct multipass_aux_data *aux_data = aux_data_;
return casefile_append (aux_data->casefile, c);
/* End-of-file function for multipass_procedure(). */
static bool
-multipass_end_func (void *aux_data_)
+multipass_end_func (void *aux_data_, const struct dataset *ds UNUSED)
{
struct multipass_aux_data *aux_data = aux_data_;
return (aux_data->proc_func == NULL
The entire active file is passed to PROC_FUNC, with the given
AUX as auxiliary data, as a unit. */
bool
-multipass_procedure (struct dataset *ds, casefile_func_t proc_func, void *aux)
+multipass_procedure (struct dataset *ds, casefile_func *proc_func, void *aux)
{
struct multipass_aux_data aux_data;
bool ok;
Returns true if successful, false if an I/O error occurred (or
if CASE_FUNC or END_FUNC ever returned false). */
static bool
-internal_procedure (struct dataset *ds, case_func_t case_func,
- bool (*end_func) (void *),
+internal_procedure (struct dataset *ds, case_func *proc,
+ end_func *end,
void *aux)
{
struct write_case_data wc_data;
/* Optimize the trivial case where we're not going to do
anything with the data, by not reading the data at all. */
- if (case_func == NULL && end_func == NULL
+ if (proc == NULL && end == NULL
&& case_source_is_class (ds->proc_source, &storage_source_class)
&& ds->proc_sink == NULL
&& (ds->temporary_trns_chain == NULL
open_active_file (ds);
- wc_data.case_func = case_func;
+ wc_data.proc = proc;
wc_data.aux = aux;
wc_data.dataset = ds;
create_trns_case (&wc_data.trns_case, ds->dict);
ok = ds->proc_source->class->read (ds->proc_source,
&wc_data.trns_case,
write_case, &wc_data) && ok;
- if (end_func != NULL)
- ok = end_func (aux) && ok;
+ if (end != NULL)
+ ok = end (aux, ds) && ok;
case_destroy (&wc_data.sink_case);
case_destroy (&wc_data.trns_case);
}
/* Pass case to procedure. */
- if (wc_data->case_func != NULL)
- if (!wc_data->case_func (&wc_data->trns_case, wc_data->aux))
+ if (wc_data->proc != NULL)
+ if (!wc_data->proc (&wc_data->trns_case, wc_data->aux, ds))
retval = TRNS_ERROR;
done:
struct ccase prev_case; /* Data in previous case. */
/* Callback functions. */
- begin_func_t begin_func ;
- case_func_t proc_func ;
- void (*end_func) (void *);
+ begin_func *begin;
+ case_func *proc;
+ end_func *end;
void *func_aux;
};
static int equal_splits (const struct ccase *, const struct ccase *, const struct dataset *ds);
-static bool split_procedure_case_func (const struct ccase *c, void *);
-static bool split_procedure_end_func (void *);
+static bool split_procedure_case_func (const struct ccase *c, void *, const struct dataset *);
+static bool split_procedure_end_func (void *, const struct dataset *);
/* Like procedure(), but it automatically breaks the case stream
into SPLIT FILE break groups. Before each group of cases with
Returns true if successful, false if an I/O error occurred. */
bool
procedure_with_splits (struct dataset *ds,
- begin_func_t begin_func,
- case_func_t proc_func,
- void (*end_func) (void *aux),
+ begin_func begin,
+ case_func *proc,
+ end_func *end,
void *func_aux)
{
struct split_aux_data split_aux;
bool ok;
case_nullify (&split_aux.prev_case);
- split_aux.begin_func = begin_func;
- split_aux.proc_func = proc_func;
- split_aux.end_func = end_func;
+ split_aux.begin = begin;
+ split_aux.proc = proc;
+ split_aux.end = end;
split_aux.func_aux = func_aux;
split_aux.dataset = ds;
/* Case callback used by procedure_with_splits(). */
static bool
-split_procedure_case_func (const struct ccase *c, void *split_aux_)
+split_procedure_case_func (const struct ccase *c, void *split_aux_, const struct dataset *ds)
{
struct split_aux_data *split_aux = split_aux_;
if (case_is_null (&split_aux->prev_case)
|| !equal_splits (c, &split_aux->prev_case, split_aux->dataset))
{
- if (!case_is_null (&split_aux->prev_case) && split_aux->end_func != NULL)
- split_aux->end_func (split_aux->func_aux);
+ if (!case_is_null (&split_aux->prev_case) && split_aux->end != NULL)
+ split_aux->end (split_aux->func_aux, ds);
case_destroy (&split_aux->prev_case);
case_clone (&split_aux->prev_case, c);
- if (split_aux->begin_func != NULL)
- split_aux->begin_func (&split_aux->prev_case, split_aux->func_aux);
-
+ if (split_aux->begin != NULL)
+ split_aux->begin (&split_aux->prev_case, split_aux->func_aux, ds);
}
- return (split_aux->proc_func == NULL
- || split_aux->proc_func (c, split_aux->func_aux));
+ return (split_aux->proc == NULL
+ || split_aux->proc (c, split_aux->func_aux, ds));
}
/* End-of-file callback used by procedure_with_splits(). */
static bool
-split_procedure_end_func (void *split_aux_)
+split_procedure_end_func (void *split_aux_, const struct dataset *ds)
{
struct split_aux_data *split_aux = split_aux_;
- if (!case_is_null (&split_aux->prev_case) && split_aux->end_func != NULL)
- split_aux->end_func (split_aux->func_aux);
+ if (!case_is_null (&split_aux->prev_case) && split_aux->end != NULL)
+ split_aux->end (split_aux->func_aux, ds);
return true;
}
struct dataset *dataset; /* The dataset of the split */
struct ccase prev_case; /* Data in previous case. */
struct casefile *casefile; /* Accumulates data for a split. */
-
- /* Function to call with the accumulated data. */
- bool (*split_func) (const struct ccase *first, const struct casefile *,
- void *);
- void *func_aux; /* Auxiliary data. */
+ split_func *split; /* Function to call with the accumulated
+ data. */
+ void *func_aux; /* Auxiliary data. */
};
-static bool multipass_split_case_func (const struct ccase *c, void *aux_);
-static bool multipass_split_end_func (void *aux_);
-static bool multipass_split_output (struct multipass_split_aux_data *);
+static bool multipass_split_case_func (const struct ccase *c, void *aux_, const struct dataset *);
+static bool multipass_split_end_func (void *aux_, const struct dataset *ds);
+static bool multipass_split_output (struct multipass_split_aux_data *, const struct dataset *ds);
/* Returns true if successful, false if an I/O error occurred. */
bool
multipass_procedure_with_splits (struct dataset *ds,
- bool (*split_func) (const struct ccase *first,
- const struct casefile *,
- void *aux),
+ split_func *split,
void *func_aux)
{
struct multipass_split_aux_data aux;
case_nullify (&aux.prev_case);
aux.casefile = NULL;
- aux.split_func = split_func;
+ aux.split = split;
aux.func_aux = func_aux;
aux.dataset = ds;
/* Case callback used by multipass_procedure_with_splits(). */
static bool
-multipass_split_case_func (const struct ccase *c, void *aux_)
+multipass_split_case_func (const struct ccase *c, void *aux_, const struct dataset *ds)
{
struct multipass_split_aux_data *aux = aux_;
- struct dataset *ds = aux->dataset;
bool ok = true;
/* Start a new series if needed. */
/* Pass any cases to split_func. */
if (aux->casefile != NULL)
- ok = multipass_split_output (aux);
+ ok = multipass_split_output (aux, ds);
/* Start a new casefile. */
aux->casefile =
/* End-of-file callback used by multipass_procedure_with_splits(). */
static bool
-multipass_split_end_func (void *aux_)
+multipass_split_end_func (void *aux_, const struct dataset *ds)
{
struct multipass_split_aux_data *aux = aux_;
- return (aux->casefile == NULL || multipass_split_output (aux));
+ return (aux->casefile == NULL || multipass_split_output (aux, ds));
}
static bool
-multipass_split_output (struct multipass_split_aux_data *aux)
+multipass_split_output (struct multipass_split_aux_data *aux, const struct dataset *ds)
{
bool ok;
assert (aux->casefile != NULL);
- ok = aux->split_func (&aux->prev_case, aux->casefile, aux->func_aux);
+ ok = aux->split (&aux->prev_case, aux->casefile, aux->func_aux, ds);
casefile_destroy (aux->casefile);
aux->casefile = NULL;
{
discard_variables (ds);
dict_destroy (ds->dict);
+ trns_chain_destroy (ds->permanent_trns_chain);
free (ds);
}
*CASES_REMAINING. */
static int
case_limit_trns_proc (void *cases_remaining_,
- struct ccase *c UNUSED, casenum_t case_nr UNUSED)
+ struct ccase *c UNUSED, casenumber case_nr UNUSED)
{
size_t *cases_remaining = cases_remaining_;
if (*cases_remaining > 0)
/* FILTER transformation. */
static int
filter_trns_proc (void *filter_var_,
- struct ccase *c UNUSED, casenum_t case_nr UNUSED)
+ struct ccase *c UNUSED, casenumber case_nr UNUSED)
{
struct variable *filter_var = filter_var_;
void proc_set_sink (struct dataset *ds, struct case_sink *);
struct casefile *proc_capture_output (struct dataset *ds);
-typedef bool (*casefile_func_t) (const struct casefile *, void *);
-typedef bool (*case_func_t) (const struct ccase *, void *);
-typedef void (*begin_func_t) (const struct ccase *, void *);
+typedef bool casefile_func (const struct casefile *, void *);
+typedef bool case_func (const struct ccase *, void *, const struct dataset *);
+typedef void begin_func (const struct ccase *, void *, const struct dataset*);
+typedef bool end_func (void *, const struct dataset *);
+typedef bool split_func (const struct ccase *, const struct casefile *,
+ void *, const struct dataset *);
-bool procedure (struct dataset *ds, case_func_t, void *aux) WARN_UNUSED_RESULT;
+
+
+bool procedure (struct dataset *ds, case_func *, void *aux) WARN_UNUSED_RESULT;
bool procedure_with_splits (struct dataset *ds,
- begin_func_t begin_func,
- case_func_t proc_func,
- void (*end_func) (void *),
+ begin_func *,
+ case_func *,
+ end_func *,
void *aux)
WARN_UNUSED_RESULT;
-bool multipass_procedure (struct dataset *ds, casefile_func_t, void *aux)
+bool multipass_procedure (struct dataset *ds, casefile_func *, void *aux)
WARN_UNUSED_RESULT;
bool multipass_procedure_with_splits (struct dataset *ds,
- bool (*) (const struct ccase *,
- const struct casefile *,
- void *),
+ split_func *,
void *aux)
WARN_UNUSED_RESULT;
struct ccase *lagged_case (const struct dataset *ds, int n_before);
-extern struct dataset *current_dataset;
-
inline struct dictionary *dataset_dict (const struct dataset *ds);
inline void dataset_set_dict ( struct dataset *ds, struct dictionary *dict);
#include <stdbool.h>
#include <stddef.h>
-typedef unsigned long casenum_t ;
+typedef unsigned long casenumber ;
/* trns_proc_func return values. */
enum trns_result
struct ccase;
typedef void trns_finalize_func (void *);
-typedef int trns_proc_func (void *, struct ccase *, casenum_t);
+typedef int trns_proc_func (void *, struct ccase *, casenumber);
typedef bool trns_free_func (void *);
\f
/* Transformation chains. */
enum states states; /* States in which command is allowed. */
enum flags flags; /* Other command requirements. */
const char *name; /* Command name. */
- int (*function) (void); /* Function to call. */
+ int (*function) (struct dataset *); /* Function to call. */
};
/* Define the command array. */
/* Command parser. */
static const struct command *parse_command_name (void);
-static enum cmd_result do_parse_command (enum cmd_state);
+static enum cmd_result do_parse_command (struct dataset *ds, enum cmd_state);
/* Parses an entire command, from command name to terminating
dot. On failure, skips to the terminating dot.
Returns the command's success or failure result. */
enum cmd_result
-cmd_parse (enum cmd_state state)
+cmd_parse (struct dataset *ds, enum cmd_state state)
{
int result;
som_new_series ();
- result = do_parse_command (state);
+ result = do_parse_command (ds, state);
if (cmd_result_is_failure (result))
lex_discard_rest_of_command ();
unset_cmd_algorithm ();
- dict_clear_aux (dataset_dict (current_dataset));
+ dict_clear_aux (dataset_dict (ds));
return result;
}
/* Parses an entire command, from command name to terminating
dot. */
static enum cmd_result
-do_parse_command (enum cmd_state state)
+do_parse_command (struct dataset *ds, enum cmd_state state)
{
const struct command *command;
enum cmd_result result;
/* Execute command. */
msg_set_command_name (command->name);
tab_set_command_name (command->name);
- result = command->function ();
+ result = command->function (ds);
tab_set_command_name (NULL);
msg_set_command_name (NULL);
/* Parse and execute FINISH command. */
int
-cmd_finish (void)
+cmd_finish (struct dataset *ds UNUSED)
{
return CMD_FINISH;
}
/* Parses the N command. */
int
-cmd_n_of_cases (void)
+cmd_n_of_cases (struct dataset *ds)
{
/* Value for N. */
int x;
x = lex_integer ();
lex_get ();
if (!lex_match_id ("ESTIMATED"))
- dict_set_case_limit (dataset_dict (current_dataset), x);
+ dict_set_case_limit (dataset_dict (ds), x);
return lex_end_of_command ();
}
/* Parses, performs the EXECUTE procedure. */
int
-cmd_execute (void)
+cmd_execute (struct dataset *ds)
{
- if (!procedure (current_dataset,NULL, NULL))
+ if (!procedure (ds, NULL, NULL))
return CMD_CASCADING_FAILURE;
return lex_end_of_command ();
}
/* Parses, performs the ERASE command. */
int
-cmd_erase (void)
+cmd_erase (struct dataset *ds UNUSED)
{
if (get_safer_mode ())
{
/* Parses, performs the HOST command. */
int
-cmd_host (void)
+cmd_host (struct dataset *ds UNUSED)
{
int code;
/* Parses, performs the NEW FILE command. */
int
-cmd_new_file (void)
+cmd_new_file (struct dataset *ds)
{
- discard_variables (current_dataset);
+ discard_variables (ds);
return lex_end_of_command ();
}
/* Parses a comment. */
int
-cmd_comment (void)
+cmd_comment (struct dataset *ds UNUSED)
{
lex_skip_comment ();
return CMD_SUCCESS;
CMD_STATE_FILE_TYPE /* Inside FILE TYPE. */
};
-enum cmd_result cmd_parse (enum cmd_state);
+struct dataset;
+enum cmd_result cmd_parse (struct dataset *ds, enum cmd_state);
struct command;
const char *cmd_complete (const char *, const struct command **);
+struct dataset;
+
/* Prototype all the command functions. */
-#define DEF_CMD(STATES, FLAGS, NAME, FUNCTION) int FUNCTION (void);
+#define DEF_CMD(STATES, FLAGS, NAME, FUNCTION) int FUNCTION (struct dataset *);
#define UNIMPL_CMD(NAME, DESCRIPTION)
#include "command.def"
#undef DEF_CMD
}
void
-ctl_stack_pop (void *private UNUSED)
+ctl_stack_pop (void *private)
{
struct ctl_struct *top = ctl_stack;
/* DO IF transformation. */
struct do_if_trns
{
+ struct dataset *ds; /* The dataset */
struct clause *clauses; /* Clauses. */
size_t clause_cnt; /* Number of clauses. */
int past_END_IF_index; /* Transformation just past last clause. */
static const struct ctl_class do_if_class;
-static int parse_clause (struct do_if_trns *);
+static int parse_clause (struct do_if_trns *, struct dataset *ds);
static void add_clause (struct do_if_trns *,
struct expression *condition, int target_index);
static void add_else (struct do_if_trns *);
/* Parse DO IF. */
int
-cmd_do_if (void)
+cmd_do_if (struct dataset *ds)
{
struct do_if_trns *do_if = xmalloc (sizeof *do_if);
do_if->clauses = NULL;
do_if->clause_cnt = 0;
+ do_if->ds = ds;
ctl_stack_push (&do_if_class, do_if);
- add_transformation_with_finalizer (current_dataset, do_if_finalize_func,
+ add_transformation_with_finalizer (ds, do_if_finalize_func,
do_if_trns_proc, do_if_trns_free, do_if);
- return parse_clause (do_if);
+ return parse_clause (do_if, ds);
}
/* Parse ELSE IF. */
int
-cmd_else_if (void)
+cmd_else_if (struct dataset *ds)
{
struct do_if_trns *do_if = ctl_stack_top (&do_if_class);
if (do_if == NULL || !must_not_have_else (do_if))
return CMD_CASCADING_FAILURE;
- return parse_clause (do_if);
+ return parse_clause (do_if, ds);
}
/* Parse ELSE. */
int
-cmd_else (void)
+cmd_else (struct dataset *ds)
{
struct do_if_trns *do_if = ctl_stack_top (&do_if_class);
+ assert (ds == do_if->ds);
if (do_if == NULL || !must_not_have_else (do_if))
return CMD_CASCADING_FAILURE;
add_else (do_if);
/* Parse END IF. */
int
-cmd_end_if (void)
+cmd_end_if (struct dataset *ds)
{
struct do_if_trns *do_if = ctl_stack_top (&do_if_class);
+ assert (ds == do_if->ds);
+
if (do_if == NULL)
return CMD_CASCADING_FAILURE;
/* Closes out DO_IF, by adding a sentinel ELSE clause if
necessary and setting past_END_IF_index. */
static void
-close_do_if (void *do_if_)
+close_do_if (void *do_if_)
{
struct do_if_trns *do_if = do_if_;
if (!has_else (do_if))
add_else (do_if);
- do_if->past_END_IF_index = next_transformation (current_dataset);
+ do_if->past_END_IF_index = next_transformation (do_if->ds);
}
/* Adds an ELSE clause to DO_IF pointing to the next
add_else (struct do_if_trns *do_if)
{
assert (!has_else (do_if));
- add_clause (do_if, NULL, next_transformation (current_dataset));
+ add_clause (do_if, NULL, next_transformation (do_if->ds));
}
/* Returns true if DO_IF does not yet have an ELSE clause.
corresponding clause to DO_IF. Checks for end of command and
returns a command return code. */
static int
-parse_clause (struct do_if_trns *do_if)
+parse_clause (struct do_if_trns *do_if, struct dataset *ds)
{
struct expression *condition;
- condition = expr_parse (dataset_dict (current_dataset), EXPR_BOOLEAN);
+ condition = expr_parse (ds, EXPR_BOOLEAN);
if (condition == NULL)
return CMD_CASCADING_FAILURE;
- add_clause (do_if, condition, next_transformation (current_dataset));
+ add_clause (do_if, condition, next_transformation (ds));
return lex_end_of_command ();
}
struct clause *clause;
if (do_if->clause_cnt > 0)
- add_transformation (current_dataset, break_trns_proc, NULL, do_if);
+ add_transformation (do_if->ds, break_trns_proc, NULL, do_if);
do_if->clauses = xnrealloc (do_if->clauses,
do_if->clause_cnt + 1, sizeof *do_if->clauses);
Checks each clause and jumps to the appropriate
transformation. */
static int
-do_if_trns_proc (void *do_if_, struct ccase *c, casenum_t case_num UNUSED)
+do_if_trns_proc (void *do_if_, struct ccase *c, casenumber case_num UNUSED)
{
struct do_if_trns *do_if = do_if_;
struct clause *clause;
/* Breaks out of a DO IF construct. */
static int
-break_trns_proc (void *do_if_, struct ccase *c UNUSED, casenum_t case_num UNUSED)
+break_trns_proc (void *do_if_, struct ccase *c UNUSED, casenumber case_num UNUSED)
{
struct do_if_trns *do_if = do_if_;
struct loop_trns
{
struct pool *pool;
+ struct dataset *ds;
/* Iteration limit. */
int max_pass_count; /* Maximum number of passes (-1=unlimited). */
static trns_proc_func loop_trns_proc, end_loop_trns_proc, break_trns_proc;
static trns_free_func loop_trns_free;
-static struct loop_trns *create_loop_trns (void);
+static struct loop_trns *create_loop_trns (struct dataset *);
static bool parse_if_clause (struct loop_trns *, struct expression **);
static bool parse_index_clause (struct loop_trns *, char index_var_name[]);
static void close_loop (void *);
/* Parses LOOP. */
int
-cmd_loop (void)
+cmd_loop (struct dataset *ds)
{
struct loop_trns *loop;
char index_var_name[LONG_NAME_LEN + 1];
bool ok = true;
- loop = create_loop_trns ();
+ loop = create_loop_trns (ds);
while (token != '.' && ok)
{
if (lex_match_id ("IF"))
/* Find index variable and create if necessary. */
if (ok && index_var_name[0] != '\0')
{
- loop->index_var = dict_lookup_var (dataset_dict (current_dataset), index_var_name);
+ loop->index_var = dict_lookup_var (dataset_dict (ds), index_var_name);
if (loop->index_var == NULL)
- loop->index_var = dict_create_var (dataset_dict (current_dataset), index_var_name, 0);
+ loop->index_var = dict_create_var (dataset_dict (ds),
+ index_var_name, 0);
}
if (!ok)
/* Parses END LOOP. */
int
-cmd_end_loop (void)
+cmd_end_loop (struct dataset *ds)
{
struct loop_trns *loop;
bool ok = true;
loop = ctl_stack_top (&loop_class);
if (loop == NULL)
return CMD_CASCADING_FAILURE;
+
+ assert (loop->ds == ds);
/* Parse syntax. */
if (lex_match_id ("IF"))
/* Parses BREAK. */
int
-cmd_break (void)
+cmd_break (struct dataset *ds)
{
struct ctl_stmt *loop = ctl_stack_search (&loop_class);
if (loop == NULL)
return CMD_CASCADING_FAILURE;
- add_transformation (current_dataset, break_trns_proc, NULL, loop);
+ add_transformation (ds, break_trns_proc, NULL, loop);
return lex_end_of_command ();
}
{
struct loop_trns *loop = loop_;
- add_transformation (current_dataset, end_loop_trns_proc, NULL, loop);
- loop->past_END_LOOP_index = next_transformation (current_dataset);
+ add_transformation (loop->ds, end_loop_trns_proc, NULL, loop);
+ loop->past_END_LOOP_index = next_transformation (loop->ds);
/* If there's nothing else limiting the number of loops, use
MXLOOPS as a limit. */
static bool
parse_if_clause (struct loop_trns *loop, struct expression **condition)
{
- *condition = expr_parse_pool (loop->pool, dataset_dict (current_dataset), EXPR_BOOLEAN);
+ *condition = expr_parse_pool (loop->pool, loop->ds, EXPR_BOOLEAN);
return *condition != NULL;
}
if (!lex_force_match ('='))
return false;
- loop->first_expr = expr_parse_pool (loop->pool, dataset_dict (current_dataset), EXPR_NUMBER);
+ loop->first_expr = expr_parse_pool (loop->pool, loop->ds, EXPR_NUMBER);
if (loop->first_expr == NULL)
return false;
lex_sbc_only_once (e == &loop->last_expr ? "TO" : "BY");
return false;
}
- *e = expr_parse_pool (loop->pool, dataset_dict (current_dataset), EXPR_NUMBER);
+ *e = expr_parse_pool (loop->pool, loop->ds, EXPR_NUMBER);
if (*e == NULL)
return false;
}
/* Creates, initializes, and returns a new loop_trns. */
static struct loop_trns *
-create_loop_trns (void)
+create_loop_trns (struct dataset *ds)
{
struct loop_trns *loop = pool_create_container (struct loop_trns, pool);
loop->max_pass_count = -1;
loop->index_var = NULL;
loop->first_expr = loop->by_expr = loop->last_expr = NULL;
loop->loop_condition = loop->end_loop_condition = NULL;
+ loop->ds = ds;
- add_transformation_with_finalizer (current_dataset, loop_trns_finalize,
+ add_transformation_with_finalizer (ds, loop_trns_finalize,
loop_trns_proc, loop_trns_free, loop);
- loop->past_LOOP_index = next_transformation (current_dataset);
+ loop->past_LOOP_index = next_transformation (ds);
ctl_stack_push (&loop_class, loop);
/* Sets up LOOP for the first pass. */
static int
-loop_trns_proc (void *loop_, struct ccase *c, casenum_t case_num)
+loop_trns_proc (void *loop_, struct ccase *c, casenumber case_num)
{
struct loop_trns *loop = loop_;
/* Finishes a pass through the loop and starts the next. */
static int
-end_loop_trns_proc (void *loop_, struct ccase *c, casenum_t case_num UNUSED)
+end_loop_trns_proc (void *loop_, struct ccase *c, casenumber case_num UNUSED)
{
struct loop_trns *loop = loop_;
/* Executes BREAK. */
static int
-break_trns_proc (void *loop_, struct ccase *c UNUSED, casenum_t case_num UNUSED)
+break_trns_proc (void *loop_, struct ccase *c UNUSED, casenumber case_num UNUSED)
{
struct loop_trns *loop = loop_;
struct repeat_block
{
struct pool *pool; /* Pool used for storage. */
+ struct dataset *ds; /* The dataset for this block */
struct line_list *first_line; /* First line in line buffer. */
struct line_list *cur_line; /* Current line in line buffer. */
int loop_cnt; /* Number of loops. */
static bool parse_lines (struct repeat_block *);
static void create_vars (struct repeat_block *);
-static int parse_ids (struct repeat_entry *, struct pool *);
+static int parse_ids (const struct dictionary *dict, struct repeat_entry *, struct pool *);
static int parse_numbers (struct repeat_entry *, struct pool *);
static int parse_strings (struct repeat_entry *, struct pool *);
static void do_repeat_close (void *block);
int
-cmd_do_repeat (void)
+cmd_do_repeat (struct dataset *ds)
{
struct repeat_block *block;
block = pool_create_container (struct repeat_block, pool);
+ block->ds = ds;
if (!parse_specification (block) || !parse_lines (block))
goto error;
{
struct repeat_entry *e;
struct repeat_entry *iter;
+ struct dictionary *dict = dataset_dict (block->ds);
int count;
/* Get a stand-in variable name and make sure it's unique. */
if (!lex_force_id ())
return false;
- if (dict_lookup_var (dataset_dict (current_dataset), tokid))
+ if (dict_lookup_var (dict, tokid))
msg (SW, _("Dummy variable name \"%s\" hides dictionary "
"variable \"%s\"."),
tokid, tokid);
/* Get the details of the variable's possible values. */
if (token == T_ID)
- count = parse_ids (e, block->pool);
+ count = parse_ids (dict, e, block->pool);
else if (lex_is_number ())
count = parse_numbers (e, block->pool);
else if (token == T_STRING)
{
/* Ignore return value: if the variable already
exists there is no harm done. */
- dict_create_var (dataset_dict (current_dataset), iter->replacement[i], 0);
+ dict_create_var (dataset_dict (block->ds), iter->replacement[i], 0);
}
}
}
/* Parses a set of ids for DO REPEAT. */
static int
-parse_ids (struct repeat_entry *e, struct pool *pool)
+parse_ids (const struct dictionary *dict, struct repeat_entry *e, struct pool *pool)
{
size_t n = 0;
e->type = VAR_NAMES;
- return parse_mixed_vars_pool (pool, &e->replacement, &n, PV_NONE) ? n : 0;
+ return parse_mixed_vars_pool (dict, pool, &e->replacement, &n, PV_NONE) ? n : 0;
}
/* Adds STRING to E's list of replacements, which has *USED
}
\f
int
-cmd_end_repeat (void)
+cmd_end_repeat (struct dataset *ds UNUSED)
{
msg (SE, _("No matching DO REPEAT."));
return CMD_CASCADING_FAILURE;
/* Parses the TEMPORARY command. */
int
-cmd_temporary (void)
+cmd_temporary (struct dataset *ds)
{
- if (!proc_in_temporary_transformations (current_dataset))
- proc_start_temporary_transformations (current_dataset);
+ if (!proc_in_temporary_transformations (ds))
+ proc_start_temporary_transformations (ds);
else
msg (SE, _("This command may only appear once between "
"procedures and procedure-like commands."));
static const struct case_source_class data_list_source_class;
-static bool parse_fixed (struct pool *tmp_pool, struct data_list_pgm *);
-static bool parse_free (struct pool *tmp_pool, struct data_list_pgm *);
+static bool parse_fixed (struct dictionary *dict,
+ struct pool *tmp_pool, struct data_list_pgm *);
+static bool parse_free (struct dictionary *dict,
+ struct pool *tmp_pool, struct data_list_pgm *);
static void dump_fixed_table (const struct ll_list *,
const struct file_handle *, int record_cnt);
static void dump_free_table (const struct data_list_pgm *,
static trns_proc_func data_list_trns_proc;
int
-cmd_data_list (void)
+cmd_data_list (struct dataset *ds)
{
+ struct dictionary *dict = dataset_dict (ds);
struct data_list_pgm *dls;
int table = -1; /* Print table if nonzero, -1=undecided. */
struct file_handle *fh = fh_inline_file ();
bool ok;
if (!in_input_program ())
- discard_variables (current_dataset);
+ discard_variables (ds);
dls = pool_create_container (struct data_list_pgm, pool);
ll_init (&dls->specs);
lex_match ('=');
if (!lex_force_id ())
goto error;
- dls->end = dict_lookup_var (dataset_dict (current_dataset), tokid);
+ dls->end = dict_lookup_var (dataset_dict (ds), tokid);
if (!dls->end)
- dls->end = dict_create_var_assert (dataset_dict (current_dataset), tokid, 0);
+ dls->end = dict_create_var_assert (dataset_dict (ds), tokid, 0);
lex_get ();
}
else if (token == T_ID)
if (table == -1)
table = dls->type != DLS_FREE;
- ok = (dls->type == DLS_FIXED ? parse_fixed : parse_free) (tmp_pool, dls);
+ ok = (dls->type == DLS_FIXED ? parse_fixed : parse_free) (dict, tmp_pool, dls);
if (!ok)
goto error;
goto error;
if (in_input_program ())
- add_transformation (current_dataset, data_list_trns_proc, data_list_trns_free, dls);
+ add_transformation (ds, data_list_trns_proc, data_list_trns_free, dls);
else
- proc_set_source (current_dataset,
- create_case_source (&data_list_source_class, dls));
+ proc_set_source (ds, create_case_source (&data_list_source_class, dls));
pool_destroy (tmp_pool);
needed once parsing is complete. Returns true only if
successful. */
static bool
-parse_fixed (struct pool *tmp_pool, struct data_list_pgm *dls)
+parse_fixed (struct dictionary *dict,
+ struct pool *tmp_pool, struct data_list_pgm *dls)
{
int last_nonempty_record;
int record = 0;
/* Create variable. */
width = get_format_var_width (f);
- v = dict_create_var (dataset_dict (current_dataset), name, width);
+ v = dict_create_var (dict, name, width);
if (v != NULL)
{
/* Success. */
return false;
}
- v = dict_lookup_var_assert (dataset_dict (current_dataset), name);
+ v = dict_lookup_var_assert (dict, name);
if ((width != 0) != (v->width != 0))
{
msg (SE, _("There is already a variable %s of a "
them to DLS. Uses TMP_POOL for data that is not needed once
parsing is complete. Returns true only if successful. */
static bool
-parse_free (struct pool *tmp_pool, struct data_list_pgm *dls)
+parse_free (struct dictionary *dict, struct pool *tmp_pool, struct data_list_pgm *dls)
{
lex_get ();
while (token != '.')
struct dls_var_spec *spec;
struct variable *v;
- v = dict_create_var (dataset_dict (current_dataset), name[i],
+ v = dict_create_var (dict, name[i],
get_format_var_width (&input));
if (v == NULL)
{
/* Handle DATA LIST transformation DLS, parsing data into C. */
static int
-data_list_trns_proc (void *dls_, struct ccase *c, casenum_t case_num UNUSED)
+data_list_trns_proc (void *dls_, struct ccase *c, casenumber case_num UNUSED)
{
struct data_list_pgm *dls = dls_;
int retval;
/* Perform BEGIN DATA...END DATA as a procedure in itself. */
int
-cmd_begin_data (void)
+cmd_begin_data (struct dataset *ds)
{
struct dfm_reader *r;
bool ok;
/* Input procedure reads from inline file. */
getl_set_prompt_style (GETL_PROMPT_DATA);
- ok = procedure (current_dataset,NULL, NULL);
+ ok = procedure (ds, NULL, NULL);
dfm_close_reader (r);
/* (functions) */
int
-cmd_file_handle (void)
+cmd_file_handle (struct dataset *ds)
{
char handle_name[LONG_NAME_LEN + 1];
struct fh_properties properties = *fh_default_properties ();
if (!lex_force_match ('/'))
return CMD_CASCADING_FAILURE;
- if (!parse_file_handle (&cmd, NULL))
+ if (!parse_file_handle (ds, &cmd, NULL))
return CMD_CASCADING_FAILURE;
if (lex_end_of_command () != CMD_SUCCESS)
}
int
-cmd_close_file_handle (void)
+cmd_close_file_handle (struct dataset *ds UNUSED)
{
struct file_handle *handle;
/* Parses a GET or IMPORT command. */
static int
-parse_read_command (enum reader_command type)
+parse_read_command (struct dataset *ds, enum reader_command type)
{
struct case_reader_pgm *pgm = NULL;
struct file_handle *fh = NULL;
goto error;
}
- discard_variables (current_dataset);
+ discard_variables (ds);
pgm = xmalloc (sizeof *pgm);
pgm->reader = any_reader_open (fh, &dict);
pgm->map = finish_case_map (dict);
- dict_destroy (dataset_dict (current_dataset));
- dataset_set_dict (current_dataset, dict);
+ dict_destroy (dataset_dict (ds));
+ dataset_set_dict (ds, dict);
- proc_set_source (current_dataset,
+ proc_set_source (ds,
create_case_source (&case_reader_source_class, pgm));
return CMD_SUCCESS;
\f
/* GET. */
int
-cmd_get (void)
+cmd_get (struct dataset *ds)
{
- return parse_read_command (GET_CMD);
+ return parse_read_command (ds, GET_CMD);
}
/* IMPORT. */
int
-cmd_import (void)
+cmd_import (struct dataset *ds)
{
- return parse_read_command (IMPORT_CMD);
+ return parse_read_command (ds, IMPORT_CMD);
}
\f
/* Writing system and portable files. */
On failure, returns a null pointer. */
static struct case_writer *
-parse_write_command (enum writer_type writer_type,
+parse_write_command (struct dataset *ds,
+ enum writer_type writer_type,
enum command_type command_type,
bool *retain_unselected)
{
*retain_unselected = true;
handle = NULL;
- dict = dict_clone (dataset_dict (current_dataset));
+ dict = dict_clone (dataset_dict (ds));
aw = xmalloc (sizeof *aw);
aw->writer = NULL;
aw->map = NULL;
\f
/* SAVE and EXPORT. */
-static bool output_proc (const struct ccase *, void *);
+static bool output_proc (const struct ccase *, void *, const struct dataset *);
/* Parses and performs the SAVE or EXPORT procedure. */
static int
-parse_output_proc (enum writer_type writer_type)
+parse_output_proc (struct dataset *ds, enum writer_type writer_type)
{
bool retain_unselected;
struct variable *saved_filter_variable;
struct case_writer *aw;
bool ok;
- aw = parse_write_command (writer_type, PROC_CMD, &retain_unselected);
+ aw = parse_write_command (ds, writer_type, PROC_CMD, &retain_unselected);
if (aw == NULL)
return CMD_CASCADING_FAILURE;
- saved_filter_variable = dict_get_filter (dataset_dict (current_dataset));
+ saved_filter_variable = dict_get_filter (dataset_dict (ds));
if (retain_unselected)
- dict_set_filter (dataset_dict (current_dataset), NULL);
- ok = procedure (current_dataset,output_proc, aw);
- dict_set_filter (dataset_dict (current_dataset), saved_filter_variable);
+ dict_set_filter (dataset_dict (ds), NULL);
+ ok = procedure (ds, output_proc, aw);
+ dict_set_filter (dataset_dict (ds), saved_filter_variable);
case_writer_destroy (aw);
return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
/* Writes case C to file. */
static bool
-output_proc (const struct ccase *c, void *aw_)
+output_proc (const struct ccase *c, void *aw_, const struct dataset *ds UNUSED)
{
struct case_writer *aw = aw_;
return case_writer_write_case (aw, c);
}
int
-cmd_save (void)
+cmd_save (struct dataset *ds)
{
- return parse_output_proc (SYSFILE_WRITER);
+ return parse_output_proc (ds, SYSFILE_WRITER);
}
int
-cmd_export (void)
+cmd_export (struct dataset *ds)
{
- return parse_output_proc (PORFILE_WRITER);
+ return parse_output_proc (ds, PORFILE_WRITER);
}
\f
/* XSAVE and XEXPORT. */
/* Parses the XSAVE or XEXPORT transformation command. */
static int
-parse_output_trns (enum writer_type writer_type)
+parse_output_trns (struct dataset *ds, enum writer_type writer_type)
{
struct output_trns *t = xmalloc (sizeof *t);
- t->aw = parse_write_command (writer_type, XFORM_CMD, NULL);
+ t->aw = parse_write_command (ds, writer_type, XFORM_CMD, NULL);
if (t->aw == NULL)
{
free (t);
return CMD_CASCADING_FAILURE;
}
- add_transformation (current_dataset, output_trns_proc, output_trns_free, t);
+ add_transformation (ds, output_trns_proc, output_trns_free, t);
return CMD_SUCCESS;
}
/* Writes case C to the system file specified on XSAVE or XEXPORT. */
static int
-output_trns_proc (void *trns_, struct ccase *c, casenum_t case_num UNUSED)
+output_trns_proc (void *trns_, struct ccase *c, casenumber case_num UNUSED)
{
struct output_trns *t = trns_;
case_writer_write_case (t->aw, c);
/* XSAVE command. */
int
-cmd_xsave (void)
+cmd_xsave (struct dataset *ds)
{
- return parse_output_trns (SYSFILE_WRITER);
+ return parse_output_trns (ds, SYSFILE_WRITER);
}
/* XEXPORT command. */
int
-cmd_xexport (void)
+cmd_xexport (struct dataset *ds)
{
- return parse_output_trns (PORFILE_WRITER);
+ return parse_output_trns (ds, PORFILE_WRITER);
}
\f
static bool rename_variables (struct dictionary *dict);
{
struct variable *v;
- v = parse_dict_variable (dict);
+ v = parse_variable (dict);
if (v == NULL)
return 0;
if (!lex_force_match ('=')
static bool mtf_delete_file_in_place (struct mtf_proc *, struct mtf_file **);
static bool mtf_read_nonactive_records (void *);
-static bool mtf_processing_finish (void *);
-static bool mtf_processing (const struct ccase *, void *);
+static bool mtf_processing_finish (void *, const struct dataset *);
+static bool mtf_processing (const struct ccase *, void *, const struct dataset *);
static char *var_type_description (struct variable *);
/* Parse and execute the MATCH FILES command. */
int
-cmd_match_files (void)
+cmd_match_files (struct dataset *ds)
{
struct mtf_proc mtf;
struct mtf_file *first_table = NULL;
case_nullify (&mtf.mtf_case);
mtf.seq_num = 0;
mtf.seq_nums = NULL;
- dict_set_case_limit (mtf.dict, dict_get_case_limit (dataset_dict (current_dataset)));
+ dict_set_case_limit (mtf.dict, dict_get_case_limit (dataset_dict (ds)));
lex_match ('/');
while (token == T_ID
}
used_active_file = true;
- if (!proc_has_source (current_dataset))
+ if (!proc_has_source (ds))
{
msg (SE, _("Cannot specify the active file since no active "
"file has been defined."));
goto error;
}
- if (proc_make_temporary_transformations_permanent (current_dataset))
+ if (proc_make_temporary_transformations_permanent (ds))
msg (SE,
_("MATCH FILES may not be used after TEMPORARY when "
"the active file is an input source. "
"Temporary transformations will be made permanent."));
- file->dict = dataset_dict (current_dataset);
+ file->dict = dataset_dict (ds);
}
else
{
values. */
if (!used_active_file)
- discard_variables (current_dataset);
+ discard_variables (ds);
dict_compact_values (mtf.dict);
mtf.output = fastfile_create (dict_get_next_value_idx (mtf.dict));
if (used_active_file)
{
- proc_set_sink (current_dataset,
+ proc_set_sink (ds,
create_case_sink (&null_sink_class,
- dataset_dict (current_dataset), NULL));
- ok = procedure (current_dataset,mtf_processing, &mtf) && mtf_processing_finish (&mtf);
+ dataset_dict (ds), NULL));
+ ok =
+ ( procedure (ds, mtf_processing, &mtf) &&
+ mtf_processing_finish (&mtf, ds) );
}
else
- ok = mtf_processing_finish (&mtf);
+ ok = mtf_processing_finish (&mtf, ds);
- discard_variables (current_dataset);
+ discard_variables (ds);
- dict_destroy (dataset_dict (current_dataset));
- dataset_set_dict (current_dataset, mtf.dict);
+ dict_destroy (dataset_dict (ds));
+ dataset_set_dict (ds, mtf.dict);
mtf.dict = NULL;
- proc_set_source (current_dataset, storage_source_create (mtf.output));
+ proc_set_source (ds, storage_source_create (mtf.output));
mtf.output = NULL;
if (!mtf_free (&mtf))
/* Repeats 2...7 an arbitrary number of times. */
static bool
-mtf_processing_finish (void *mtf_)
+mtf_processing_finish (void *mtf_, const struct dataset *ds)
{
struct mtf_proc *mtf = mtf_;
struct mtf_file *iter;
}
while (mtf->head && mtf->head->type == MTF_FILE)
- if (!mtf_processing (NULL, mtf))
+ if (!mtf_processing (NULL, mtf, ds))
return false;
return true;
/* Perform one iteration of steps 3...7 above.
Returns true if successful, false if an I/O error occurred. */
static bool
-mtf_processing (const struct ccase *c, void *mtf_)
+mtf_processing (const struct ccase *c, void *mtf_, const struct dataset *ds UNUSED)
{
struct mtf_proc *mtf = mtf_;
/* Emits an END CASE transformation for INP. */
static void
-emit_END_CASE (struct input_program_pgm *inp)
+emit_END_CASE (struct dataset *ds, struct input_program_pgm *inp)
{
- add_transformation (current_dataset, end_case_trns_proc, NULL, inp);
+ add_transformation (ds, end_case_trns_proc, NULL, inp);
}
int
-cmd_input_program (void)
+cmd_input_program (struct dataset *ds)
{
struct input_program_pgm *inp;
size_t i;
bool saw_END_CASE = false;
- discard_variables (current_dataset);
+ discard_variables (ds);
if (token != '.')
return lex_end_of_command ();
inside_input_program = true;
for (;;)
{
- enum cmd_result result = cmd_parse (CMD_STATE_INPUT_PROGRAM);
+ enum cmd_result result = cmd_parse (ds, CMD_STATE_INPUT_PROGRAM);
if (result == CMD_END_INPUT_PROGRAM)
break;
else if (result == CMD_END_CASE)
{
- emit_END_CASE (inp);
+ emit_END_CASE (ds, inp);
saw_END_CASE = true;
}
else if (cmd_result_is_failure (result) && result != CMD_FAILURE)
if (result == CMD_EOF)
msg (SE, _("Unexpected end-of-file within INPUT PROGRAM."));
inside_input_program = false;
- discard_variables (current_dataset);
+ discard_variables (ds);
destroy_input_program (inp);
return result;
}
}
if (!saw_END_CASE)
- emit_END_CASE (inp);
+ emit_END_CASE (ds, inp);
inside_input_program = false;
- if (dict_get_next_value_idx (dataset_dict (current_dataset)) == 0)
+ if (dict_get_next_value_idx (dataset_dict (ds)) == 0)
{
msg (SE, _("Input program did not create any variables."));
- discard_variables (current_dataset);
+ discard_variables (ds);
destroy_input_program (inp);
return CMD_FAILURE;
}
- inp->trns_chain = proc_capture_transformations (current_dataset);
+ inp->trns_chain = proc_capture_transformations (ds);
trns_chain_finalize (inp->trns_chain);
/* Figure out how to initialize each input case. */
- inp->init_cnt = dict_get_next_value_idx (dataset_dict (current_dataset));
+ inp->init_cnt = dict_get_next_value_idx (dataset_dict (ds));
inp->init = xnmalloc (inp->init_cnt, sizeof *inp->init);
for (i = 0; i < inp->init_cnt; i++)
inp->init[i] = -1;
- for (i = 0; i < dict_get_var_cnt (dataset_dict (current_dataset)); i++)
+ for (i = 0; i < dict_get_var_cnt (dataset_dict (ds)); i++)
{
- struct variable *var = dict_get_var (dataset_dict (current_dataset), i);
+ struct variable *var = dict_get_var (dataset_dict (ds), i);
enum value_init_type value_init;
size_t j;
}
for (i = 0; i < inp->init_cnt; i++)
assert (inp->init[i] != -1);
- inp->case_size = dict_get_case_size (dataset_dict (current_dataset));
+ inp->case_size = dict_get_case_size (dataset_dict (ds));
- proc_set_source (current_dataset,
+ proc_set_source (ds,
create_case_source (&input_program_source_class, inp));
return CMD_SUCCESS;
}
int
-cmd_end_input_program (void)
+cmd_end_input_program (struct dataset *ds UNUSED)
{
assert (in_input_program ());
return CMD_END_INPUT_PROGRAM;
};
\f
int
-cmd_end_case (void)
+cmd_end_case (struct dataset *ds UNUSED)
{
assert (in_input_program ());
if (token == '.')
/* Sends the current case as the source's output. */
int
-end_case_trns_proc (void *inp_, struct ccase *c, casenum_t case_nr UNUSED)
+end_case_trns_proc (void *inp_, struct ccase *c, casenumber case_nr UNUSED)
{
struct input_program_pgm *inp = inp_;
/* Parses REREAD command. */
int
-cmd_reread (void)
+cmd_reread (struct dataset *ds)
{
struct file_handle *fh; /* File to be re-read. */
struct expression *e; /* Expression for column to set. */
return CMD_CASCADING_FAILURE;
}
- e = expr_parse (dataset_dict (current_dataset), EXPR_NUMBER);
+ e = expr_parse (ds, EXPR_NUMBER);
if (!e)
return CMD_CASCADING_FAILURE;
}
t = xmalloc (sizeof *t);
t->reader = dfm_open_reader (fh);
t->column = e;
- add_transformation (current_dataset, reread_trns_proc, reread_trns_free, t);
+ add_transformation (ds, reread_trns_proc, reread_trns_free, t);
return CMD_SUCCESS;
}
/* Executes a REREAD transformation. */
static int
-reread_trns_proc (void *t_, struct ccase *c, casenum_t case_num)
+reread_trns_proc (void *t_, struct ccase *c, casenumber case_num)
{
struct reread_trns *t = t_;
/* Parses END FILE command. */
int
-cmd_end_file (void)
+cmd_end_file (struct dataset *ds)
{
assert (in_input_program ());
- add_transformation (current_dataset, end_file_trns_proc, NULL, NULL);
+ add_transformation (ds, end_file_trns_proc, NULL, NULL);
return lex_end_of_command ();
}
/* Executes an END FILE transformation. */
static int
end_file_trns_proc (void *trns_ UNUSED, struct ccase *c UNUSED,
- casenum_t case_num UNUSED)
+ casenumber case_num UNUSED)
{
return TRNS_END_FILE;
}
static void write_line (struct outp_driver *d, const char *s);
/* Other functions. */
-static bool list_cases (const struct ccase *, void *);
+static bool list_cases (const struct ccase *, void *, const struct dataset *);
static void determine_layout (void);
static void clean_up (void);
static void write_header (struct outp_driver *);
-static void write_all_headers (const struct ccase *, void *);
+static void write_all_headers (const struct ccase *, void *, const struct dataset*);
/* Returns the number of text lines that can fit on the remainder of
the page. */
/* Parses and executes the LIST procedure. */
int
-cmd_list (void)
+cmd_list (struct dataset *ds)
{
struct variable casenum_var;
bool ok;
- if (!parse_list (&cmd, NULL))
+ if (!parse_list (ds, &cmd, NULL))
return CMD_FAILURE;
/* Fill in defaults. */
if (cmd.last == NOT_LONG)
cmd.last = LONG_MAX;
if (!cmd.sbc_variables)
- dict_get_vars (dataset_dict (current_dataset), &cmd.v_variables, &cmd.n_variables,
+ dict_get_vars (dataset_dict (ds), &cmd.v_variables, &cmd.n_variables,
(1u << DC_SYSTEM) | (1u << DC_SCRATCH));
if (cmd.n_variables == 0)
{
/* Weighting variable. */
if (cmd.weight == LST_WEIGHT)
{
- if (dict_get_weight (dataset_dict (current_dataset)) != NULL)
+ if (dict_get_weight (dataset_dict (ds)) != NULL)
{
size_t i;
for (i = 0; i < cmd.n_variables; i++)
- if (cmd.v_variables[i] == dict_get_weight (dataset_dict (current_dataset)))
+ if (cmd.v_variables[i] == dict_get_weight (dataset_dict (ds)))
break;
if (i >= cmd.n_variables)
{
cmd.v_variables = xnrealloc (cmd.v_variables, cmd.n_variables,
sizeof *cmd.v_variables);
cmd.v_variables[cmd.n_variables - 1]
- = dict_get_weight (dataset_dict (current_dataset));
+ = dict_get_weight (dataset_dict (ds));
}
}
else
determine_layout ();
case_idx = 0;
- ok = procedure_with_splits (current_dataset, write_all_headers, list_cases, NULL, NULL);
+ ok = procedure_with_splits (ds, write_all_headers, list_cases, NULL, NULL);
ds_destroy(&line_buffer);
clean_up ();
/* Writes headers to all devices. This is done at the beginning of
each SPLIT FILE group. */
static void
-write_all_headers (const struct ccase *c, void *aux UNUSED)
+write_all_headers (const struct ccase *c, void *aux UNUSED, const struct dataset *ds)
{
struct outp_driver *d;
- output_split_file_values (c);
+ output_split_file_values (ds, c);
for (d = outp_drivers (NULL); d; d = outp_drivers (d))
{
if (!d->class->special)
/* Writes case C to output. */
static bool
-list_cases (const struct ccase *c, void *aux UNUSED)
+list_cases (const struct ccase *c, void *aux UNUSED, const struct dataset *ds UNUSED)
{
struct outp_driver *d;
/* Continuous variables. */
int n_continuous; /* Number of continuous variables. */
- int first_continuous; /* Index into dataset_dict (current_dataset).var of
+ int first_continuous; /* Index into dictionary of
first continuous variable. */
};
static int compare_variables_by_mxd_var_type (const void *pa,
const void *pb);
-static bool read_matrices_without_rowtype (struct matrix_data_pgm *);
-static bool read_matrices_with_rowtype (struct matrix_data_pgm *);
+static bool read_matrices_without_rowtype (struct dataset *ds, struct matrix_data_pgm *);
+static bool read_matrices_with_rowtype (struct dataset *ds, struct matrix_data_pgm *);
static int string_to_content_type (char *, int *);
static void attach_mxd_aux (struct variable *, int var_type, int sub_type);
int
-cmd_matrix_data (void)
+cmd_matrix_data (struct dataset *ds)
{
struct pool *pool;
struct matrix_data_pgm *mx;
unsigned seen = 0;
- discard_variables (current_dataset);
+ discard_variables (ds);
pool = pool_create ();
mx = pool_alloc (pool, sizeof *mx);
if (strcasecmp (v[i], "ROWTYPE_"))
{
- new_var = dict_create_var_assert (dataset_dict (current_dataset), v[i], 0);
+ new_var = dict_create_var_assert (dataset_dict (ds), v[i], 0);
attach_mxd_aux (new_var, MXD_CONTINUOUS, i);
}
else
free (v);
}
- mx->rowtype_ = dict_create_var_assert (dataset_dict (current_dataset),
+ mx->rowtype_ = dict_create_var_assert (dataset_dict (ds),
"ROWTYPE_", 8);
attach_mxd_aux (mx->rowtype_, MXD_ROWTYPE, 0);
}
goto lossage;
}
- if (dict_lookup_var (dataset_dict (current_dataset), tokid) == NULL
+ if (dict_lookup_var (dataset_dict (ds), tokid) == NULL
&& (lex_look_ahead () == '.' || lex_look_ahead () == '/'))
{
if (!strcasecmp (tokid, "ROWTYPE_")
goto lossage;
}
- mx->single_split = dict_create_var_assert (dataset_dict (current_dataset),
+ mx->single_split = dict_create_var_assert (dataset_dict (ds),
tokid, 0);
attach_mxd_aux (mx->single_split, MXD_CONTINUOUS, 0);
lex_get ();
- dict_set_split_vars (dataset_dict (current_dataset), &mx->single_split, 1);
+ dict_set_split_vars (dataset_dict (ds), &mx->single_split, 1);
}
else
{
struct variable **split;
size_t n;
- if (!parse_variables (dataset_dict (current_dataset), &split, &n, PV_NO_DUPLICATE))
+ if (!parse_variables (dataset_dict (ds), &split, &n, PV_NO_DUPLICATE))
goto lossage;
- dict_set_split_vars (dataset_dict (current_dataset), split, n);
+ dict_set_split_vars (dataset_dict (ds), split, n);
}
{
- struct variable *const *split = dict_get_split_vars (dataset_dict (current_dataset));
- size_t split_cnt = dict_get_split_cnt (dataset_dict (current_dataset));
+ struct variable *const *split = dict_get_split_vars (dataset_dict (ds));
+ size_t split_cnt = dict_get_split_cnt (dataset_dict (ds));
int i;
for (i = 0; i < split_cnt; i++)
}
seen |= 4;
- if (!parse_variables (dataset_dict (current_dataset), &mx->factors, &mx->n_factors,
+ if (!parse_variables (dataset_dict (ds), &mx->factors, &mx->n_factors,
PV_NONE))
goto lossage;
}
/* Create VARNAME_. */
- mx->varname_ = dict_create_var_assert (dataset_dict (current_dataset), "VARNAME_", 8);
+ mx->varname_ = dict_create_var_assert (dataset_dict (ds), "VARNAME_", 8);
attach_mxd_aux (mx->varname_, MXD_VARNAME, 0);
/* Sort the dictionary variables into the desired order for the
struct variable **v;
size_t nv;
- dict_get_vars (dataset_dict (current_dataset), &v, &nv, 0);
+ dict_get_vars (dataset_dict (ds), &v, &nv, 0);
qsort (v, nv, sizeof *v, compare_variables_by_mxd_var_type);
- dict_reorder_vars (dataset_dict (current_dataset), v, nv);
+ dict_reorder_vars (dataset_dict (ds), v, nv);
free (v);
}
int i;
mx->first_continuous = -1;
- for (i = 0; i < dict_get_var_cnt (dataset_dict (current_dataset)); i++)
+ for (i = 0; i < dict_get_var_cnt (dataset_dict (ds)); i++)
{
- struct variable *v = dict_get_var (dataset_dict (current_dataset), i);
+ struct variable *v = dict_get_var (dataset_dict (ds), i);
struct mxd_var *mv = v->aux;
int type = mv->var_type;
goto lossage;
if (mx->explicit_rowtype)
- ok = read_matrices_with_rowtype (mx);
+ ok = read_matrices_with_rowtype (ds, mx);
else
- ok = read_matrices_without_rowtype (mx);
+ ok = read_matrices_without_rowtype (ds, mx);
dfm_close_reader (mx->reader);
return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
lossage:
- discard_variables (current_dataset);
+ discard_variables (ds);
free (mx->factors);
pool_destroy (mx->container);
return CMD_CASCADING_FAILURE;
struct nr_aux_data
{
+ const struct dictionary *dict; /* The dictionary */
struct matrix_data_pgm *mx; /* MATRIX DATA program. */
double ***data; /* MATRIX DATA data. */
double *factor_values; /* Factor values. */
/* Read from the data file and write it to the active file.
Returns true if successful, false if an I/O error occurred. */
static bool
-read_matrices_without_rowtype (struct matrix_data_pgm *mx)
+read_matrices_without_rowtype (struct dataset *ds, struct matrix_data_pgm *mx)
{
struct nr_aux_data nr;
bool ok;
mx->cells = 1;
nr.mx = mx;
+ nr.dict = dataset_dict (ds);
nr.data = NULL;
nr.factor_values = xnmalloc (mx->n_factors * mx->cells,
sizeof *nr.factor_values);
nr.max_cell_idx = 0;
- nr.split_values = xnmalloc (dict_get_split_cnt (dataset_dict (current_dataset)),
+ nr.split_values = xnmalloc (dict_get_split_cnt (dataset_dict (ds)),
sizeof *nr.split_values);
- proc_set_source (current_dataset, create_case_source (
+ proc_set_source (ds, create_case_source (
&matrix_data_without_rowtype_source_class, &nr));
- ok = procedure (current_dataset,NULL, NULL);
+ ok = procedure (ds, NULL, NULL);
free (nr.split_values);
free (nr.factor_values);
if (token.type != MNUM)
{
msg (SE, _("expecting value for %s %s"),
- dict_get_var (dataset_dict (current_dataset), j)->name,
+ dict_get_var (nr->dict, j)->name,
context (mx->reader));
return 0;
}
if (!nr_output_data (nr, c, write_case, wc_data))
return false;
- if (dict_get_split_cnt (dataset_dict (current_dataset)) == 0
+ if (dict_get_split_cnt (nr->dict) == 0
|| !another_token (mx->reader))
return true;
}
return true;
}
- if (dict_get_split_vars (dataset_dict (current_dataset)) == NULL)
+ if (dict_get_split_vars (nr->dict) == NULL)
return true;
if (mx->single_split)
{
if (!compare)
{
- struct mxd_var *mv = dict_get_split_vars (dataset_dict (current_dataset))[0]->aux;
+ struct mxd_var *mv = dict_get_split_vars (nr->dict)[0]->aux;
nr->split_values[0] = ++mv->sub_type;
}
return true;
if (!compare)
just_read = 1;
- split_cnt = dict_get_split_cnt (dataset_dict (current_dataset));
+ split_cnt = dict_get_split_cnt (nr->dict);
for (i = 0; i < split_cnt; i++)
{
struct matrix_token token;
{
msg (SE, _("Expecting value %g for %s."),
nr->split_values[i],
- dict_get_split_vars (dataset_dict (current_dataset))[i]->name);
+ dict_get_split_vars (nr->dict)[i]->name);
return false;
}
}
CP to the active file.
Returns true if successful, false if an I/O error occurred. */
static bool
-dump_cell_content (struct matrix_data_pgm *mx, int content, double *cp,
+dump_cell_content (const struct dictionary *dict,
+ struct matrix_data_pgm *mx, int content, double *cp,
struct ccase *c,
write_case_func *write_case, write_case_data wc_data)
{
for (j = 0; j < mx->n_continuous; j++)
{
- int fv = dict_get_var (dataset_dict (current_dataset), mx->first_continuous + j)->fv;
+ int fv = dict_get_var (dict, mx->first_continuous + j)->fv;
case_data_rw (c, fv)->f = *cp;
cp++;
}
if (type == 1)
buf_copy_str_rpad (case_data_rw (c, mx->varname_->fv)->s, 8,
- dict_get_var (dataset_dict (current_dataset),
+ dict_get_var (dict,
mx->first_continuous + i)->name);
if (!write_case (wc_data))
return false;
size_t split_cnt;
size_t i;
- split_cnt = dict_get_split_cnt (dataset_dict (current_dataset));
- split = dict_get_split_vars (dataset_dict (current_dataset));
+ split_cnt = dict_get_split_cnt (nr->dict);
+ split = dict_get_split_vars (nr->dict);
for (i = 0; i < split_cnt; i++)
case_data_rw (c, split[i]->fv)->f = nr->split_values[i];
}
assert (nr->data[content] != NULL
&& nr->data[content][cell] != NULL);
- if (!dump_cell_content (mx, content, nr->data[content][cell],
+ if (!dump_cell_content (nr->dict, mx,
+ content, nr->data[content][cell],
c, write_case, wc_data))
return false;
}
for (content = 0; content <= PROX; content++)
if (!mx->is_per_factor[content] && nr->data[content] != NULL)
{
- if (!dump_cell_content (mx, content, nr->data[content][0],
+ if (!dump_cell_content (nr->dict, mx, content, nr->data[content][0],
c, write_case, wc_data))
return false;
}
/* With ROWTYPE_ auxiliary data. */
struct wr_aux_data
{
+ const struct dictionary *dict; /* The dictionary */
struct matrix_data_pgm *mx; /* MATRIX DATA program. */
int content; /* Type of current row. */
double *split_values; /* SPLIT FILE variable values. */
them to the output file.
Returns true if successful, false if an I/O error occurred. */
static bool
-read_matrices_with_rowtype (struct matrix_data_pgm *mx)
+read_matrices_with_rowtype (struct dataset *ds, struct matrix_data_pgm *mx)
{
struct wr_aux_data wr;
bool ok;
wr.split_values = NULL;
wr.data = NULL;
wr.current = NULL;
+ wr.dict = dataset_dict (ds);
mx->cells = 0;
- proc_set_source (current_dataset,
+ proc_set_source (ds,
create_case_source (&matrix_data_with_rowtype_source_class,
&wr));
- ok = procedure (current_dataset,NULL, NULL);
+ ok = procedure (ds, NULL, NULL);
free (wr.split_values);
return ok;
bool compare;
size_t split_cnt;
- split_cnt = dict_get_split_cnt (dataset_dict (current_dataset));
+ split_cnt = dict_get_split_cnt (wr->dict);
if (split_cnt == 0)
return true;
size_t split_cnt;
size_t i;
- split_cnt = dict_get_split_cnt (dataset_dict (current_dataset));
- split = dict_get_split_vars (dataset_dict (current_dataset));
+ split_cnt = dict_get_split_cnt (wr->dict);
+ split = dict_get_split_vars (wr->dict);
for (i = 0; i < split_cnt; i++)
case_data_rw (c, split[i]->fv)->f = wr->split_values[i];
}
fill_matrix (mx, content, iter->data[content]);
- ok = dump_cell_content (mx, content, iter->data[content],
+ ok = dump_cell_content (wr->dict, mx, content,
+ iter->data[content],
c, write_case, wc_data);
if (!ok)
break;
if (token.type != MNUM)
{
msg (SE, _("Syntax error expecting value for %s %s."),
- dict_get_var (dataset_dict (current_dataset), mx->first_continuous + j)->name,
+ dict_get_var (wr->dict, mx->first_continuous + j)->name,
context (mx->reader));
return false;
}
static trns_free_func print_space_trns_free;
int
-cmd_print_space (void)
+cmd_print_space (struct dataset *ds)
{
struct print_space_trns *trns;
struct file_handle *handle;
if (token != '.')
{
- expr = expr_parse (dataset_dict (current_dataset), EXPR_NUMBER);
+ expr = expr_parse (ds, EXPR_NUMBER);
if (token != '.')
{
expr_free (expr);
trns->writer = writer;
trns->expr = expr;
- add_transformation (current_dataset,
+ add_transformation (ds,
print_space_trns_proc, print_space_trns_free, trns);
return CMD_SUCCESS;
}
/* Executes a PRINT SPACE transformation. */
static int
print_space_trns_proc (void *t_, struct ccase *c,
- casenum_t case_num UNUSED)
+ casenumber case_num UNUSED)
{
struct print_space_trns *trns = t_;
int n;
WRITE
};
-static int internal_cmd_print (enum which_formats, bool eject);
+static int internal_cmd_print (struct dataset *ds,
+ enum which_formats, bool eject);
static trns_proc_func print_trns_proc;
static trns_free_func print_trns_free;
static bool parse_specs (struct pool *tmp_pool, struct print_trns *,
- enum which_formats);
+ struct dictionary *dict, enum which_formats);
static void dump_table (struct print_trns *, const struct file_handle *);
\f
/* Basic parsing. */
/* Parses PRINT command. */
int
-cmd_print (void)
+cmd_print (struct dataset *ds)
{
- return internal_cmd_print (PRINT, false);
+ return internal_cmd_print (ds, PRINT, false);
}
/* Parses PRINT EJECT command. */
int
-cmd_print_eject (void)
+cmd_print_eject (struct dataset *ds)
{
- return internal_cmd_print (PRINT, true);
+ return internal_cmd_print (ds, PRINT, true);
}
/* Parses WRITE command. */
int
-cmd_write (void)
+cmd_write (struct dataset *ds)
{
- return internal_cmd_print (WRITE, false);
+ return internal_cmd_print (ds, WRITE, false);
}
/* Parses the output commands. */
static int
-internal_cmd_print (enum which_formats which_formats, bool eject)
+internal_cmd_print (struct dataset *ds,
+ enum which_formats which_formats, bool eject)
{
bool print_table = 0;
struct print_trns *trns;
}
/* Parse variables and strings. */
- if (!parse_specs (tmp_pool, trns, which_formats))
+ if (!parse_specs (tmp_pool, trns, dataset_dict (ds), which_formats))
goto error;
if (lex_end_of_command () != CMD_SUCCESS)
dump_table (trns, fh);
/* Put the transformation in the queue. */
- add_transformation (current_dataset, print_trns_proc, print_trns_free, trns);
+ add_transformation (ds, print_trns_proc, print_trns_free, trns);
pool_destroy (tmp_pool);
\f
static bool parse_string_argument (struct print_trns *,
int record, int *column);
-static bool parse_variable_argument (struct print_trns *,
+static bool parse_variable_argument (const struct dictionary *,
+ struct print_trns *,
struct pool *tmp_pool,
int *record, int *column,
enum which_formats);
Returns success. */
static bool
parse_specs (struct pool *tmp_pool, struct print_trns *trns,
+ struct dictionary *dict,
enum which_formats which_formats)
{
int record = 0;
if (token == T_STRING)
ok = parse_string_argument (trns, record, &column);
else
- ok = parse_variable_argument (trns, tmp_pool, &record, &column,
+ ok = parse_variable_argument (dict, trns, tmp_pool, &record, &column,
which_formats);
if (!ok)
return 0;
to fixed_parse_compatible() or fixed_parse_fortran() as appropriate.
Returns success. */
static bool
-parse_variable_argument (struct print_trns *trns, struct pool *tmp_pool,
+parse_variable_argument (const struct dictionary *dict,
+ struct print_trns *trns, struct pool *tmp_pool,
int *record, int *column,
enum which_formats which_formats)
{
size_t format_cnt;
bool add_space;
- if (!parse_variables_pool (tmp_pool,
- dataset_dict (current_dataset), &vars, &var_cnt, PV_DUPLICATE))
+ if (!parse_variables_pool (tmp_pool, dict, &vars, &var_cnt, PV_DUPLICATE))
return false;
if (lex_is_number () || token == '(')
/* Performs the transformation inside print_trns T on case C. */
static int
-print_trns_proc (void *trns_, struct ccase *c, casenum_t case_num UNUSED)
+print_trns_proc (void *trns_, struct ccase *c, casenumber case_num UNUSED)
{
struct print_trns *trns = trns_;
struct prt_out_spec *spec;
/* Parses and executes APPLY DICTIONARY. */
int
-cmd_apply_dictionary (void)
+cmd_apply_dictionary (struct dataset *ds)
{
struct file_handle *handle;
struct any_reader *reader;
for (i = 0; i < dict_get_var_cnt (dict); i++)
{
struct variable *s = dict_get_var (dict, i);
- struct variable *t = dict_lookup_var (dataset_dict (current_dataset), s->name);
+ struct variable *t = dict_lookup_var (dataset_dict (ds), s->name);
if (t == NULL)
continue;
if (dict_get_weight (dict) != NULL)
{
struct variable *new_weight
- = dict_lookup_var (dataset_dict (current_dataset), dict_get_weight (dict)->name);
+ = dict_lookup_var (dataset_dict (ds), dict_get_weight (dict)->name);
if (new_weight != NULL)
- dict_set_weight (dataset_dict (current_dataset), new_weight);
+ dict_set_weight (dataset_dict (ds), new_weight);
}
any_reader_close (reader);
FORMATS_WRITE = 002
};
-static int internal_cmd_formats (int);
+static int internal_cmd_formats (struct dataset *ds, int);
int
-cmd_print_formats (void)
+cmd_print_formats (struct dataset *ds)
{
- return internal_cmd_formats (FORMATS_PRINT);
+ return internal_cmd_formats (ds, FORMATS_PRINT);
}
int
-cmd_write_formats (void)
+cmd_write_formats (struct dataset *ds)
{
- return internal_cmd_formats (FORMATS_WRITE);
+ return internal_cmd_formats (ds, FORMATS_WRITE);
}
int
-cmd_formats (void)
+cmd_formats (struct dataset *ds)
{
- return internal_cmd_formats (FORMATS_PRINT | FORMATS_WRITE);
+ return internal_cmd_formats (ds, FORMATS_PRINT | FORMATS_WRITE);
}
-int
-internal_cmd_formats (int which)
+static int
+internal_cmd_formats (struct dataset *ds, int which)
{
/* Variables. */
struct variable **v;
if (token == '.')
break;
- if (!parse_variables (dataset_dict (current_dataset), &v, &cv, PV_NUMERIC))
+ if (!parse_variables (dataset_dict (ds), &v, &cv, PV_NUMERIC))
return CMD_FAILURE;
type = v[0]->type;
#define _(msgid) gettext (msgid)
int
-cmd_missing_values (void)
+cmd_missing_values (struct dataset *ds)
{
struct variable **v;
size_t nv;
{
size_t i;
- if (!parse_variables (dataset_dict (current_dataset), &v, &nv, PV_NONE))
+ if (!parse_variables (dataset_dict (ds), &v, &nv, PV_NONE))
goto done;
if (!lex_match ('('))
/* Performs MODIFY VARS command. */
int
-cmd_modify_vars (void)
+cmd_modify_vars (struct dataset *ds)
{
/* Bits indicated whether we've already encountered a subcommand of
this type. */
size_t i;
- if (proc_make_temporary_transformations_permanent (current_dataset))
+ if (proc_make_temporary_transformations_permanent (ds))
msg (SE, _("MODIFY VARS may not be used after TEMPORARY. "
"Temporary transformations will be made permanent."));
"of variables."));
goto done;
}
- dict_get_vars (dataset_dict (current_dataset), &v, &nv, 1u << DC_SYSTEM);
+ dict_get_vars (dataset_dict (ds), &v, &nv, 1u << DC_SYSTEM);
}
else
{
free (v);
goto done;
}
- if (!parse_variables (dataset_dict (current_dataset), &v, &nv,
+ if (!parse_variables (dataset_dict (ds), &v, &nv,
PV_APPEND | PV_NO_DUPLICATE))
{
free (v);
msg (SE, _("`(' expected on RENAME subcommand."));
goto done;
}
- if (!parse_variables (dataset_dict (current_dataset), &vm.rename_vars, &vm.rename_cnt,
+ if (!parse_variables (dataset_dict (ds), &vm.rename_vars, &vm.rename_cnt,
PV_APPEND | PV_NO_DUPLICATE))
goto done;
if (!lex_match ('='))
already_encountered |= 4;
lex_match ('=');
- if (!parse_variables (dataset_dict (current_dataset), &keep_vars, &keep_cnt, PV_NONE))
+ if (!parse_variables (dataset_dict (ds), &keep_vars, &keep_cnt, PV_NONE))
goto done;
/* Transform the list of variables to keep into a list of
sort (keep_vars, keep_cnt, sizeof *keep_vars,
compare_variables_given_ordering, &forward_positional_ordering);
- dict_get_vars (dataset_dict (current_dataset), &all_vars, &all_cnt, 0);
+ dict_get_vars (dataset_dict (ds), &all_vars, &all_cnt, 0);
assert (all_cnt >= keep_cnt);
drop_cnt = all_cnt - keep_cnt;
already_encountered |= 4;
lex_match ('=');
- if (!parse_variables (dataset_dict (current_dataset), &drop_vars, &drop_cnt, PV_NONE))
+ if (!parse_variables (dataset_dict (ds), &drop_vars, &drop_cnt, PV_NONE))
goto done;
vm.drop_vars = drop_vars;
vm.drop_cnt = drop_cnt;
}
else if (lex_match_id ("MAP"))
{
- struct dictionary *temp = dict_clone (dataset_dict (current_dataset));
+ struct dictionary *temp = dict_clone (dataset_dict (ds));
int success = rearrange_dict (temp, &vm);
if (success)
{
if (already_encountered & (1 | 4))
{
/* Read the data. */
- if (!procedure (current_dataset,NULL, NULL))
+ if (!procedure (ds,NULL, NULL))
goto done;
}
- if (!rearrange_dict (dataset_dict (current_dataset), &vm))
+ if (!rearrange_dict (dataset_dict (ds), &vm))
goto done;
ret_code = CMD_SUCCESS;
/* Parses the NUMERIC command. */
int
-cmd_numeric (void)
+cmd_numeric (struct dataset *ds)
{
size_t i;
/* Create each variable. */
for (i = 0; i < nv; i++)
{
- struct variable *new_var = dict_create_var (dataset_dict (current_dataset), v[i], 0);
+ struct variable *new_var = dict_create_var (dataset_dict (ds), v[i], 0);
if (!new_var)
msg (SE, _("There is already a variable named %s."), v[i]);
else
/* Parses the STRING command. */
int
-cmd_string (void)
+cmd_string (struct dataset *ds)
{
size_t i;
/* Create each variable. */
for (i = 0; i < nv; i++)
{
- struct variable *new_var = dict_create_var (dataset_dict (current_dataset), v[i],
+ struct variable *new_var = dict_create_var (dataset_dict (ds), v[i],
width);
if (!new_var)
msg (SE, _("There is already a variable named %s."), v[i]);
/* Parses the LEAVE command. */
int
-cmd_leave (void)
+cmd_leave (struct dataset *ds)
{
struct variable **v;
size_t nv;
size_t i;
- if (!parse_variables (dataset_dict (current_dataset), &v, &nv, PV_NONE))
+ if (!parse_variables (dataset_dict (ds), &v, &nv, PV_NONE))
return CMD_CASCADING_FAILURE;
for (i = 0; i < nv; i++)
v[i]->leave = true;
/* The code for this function is very similar to the code for the
RENAME subcommand of MODIFY VARS. */
int
-cmd_rename_variables (void)
+cmd_rename_variables (struct dataset *ds)
{
struct variable **rename_vars = NULL;
char **rename_new_names = NULL;
int status = CMD_CASCADING_FAILURE;
- if (proc_make_temporary_transformations_permanent (current_dataset))
+ if (proc_make_temporary_transformations_permanent (ds))
msg (SE, _("RENAME VARS may not be used after TEMPORARY. "
"Temporary transformations will be made permanent."));
msg (SE, _("`(' expected."));
goto lossage;
}
- if (!parse_variables (dataset_dict (current_dataset), &rename_vars, &rename_cnt,
+ if (!parse_variables (dataset_dict (ds), &rename_vars, &rename_cnt,
PV_APPEND | PV_NO_DUPLICATE))
goto lossage;
if (!lex_match ('='))
}
while (token != '.');
- if (!dict_rename_vars (dataset_dict (current_dataset),
+ if (!dict_rename_vars (dataset_dict (ds),
rename_vars, rename_new_names, rename_cnt,
&err_name))
{
#define _(msgid) gettext (msgid)
int
-cmd_split_file (void)
+cmd_split_file (struct dataset *ds)
{
if (lex_match_id ("OFF"))
- dict_set_split_vars (dataset_dict (current_dataset), NULL, 0);
+ dict_set_split_vars (dataset_dict (ds), NULL, 0);
else
{
struct variable **v;
(void) ( lex_match_id ("SEPARATE") || lex_match_id ("LAYERED") );
lex_match (T_BY);
- if (!parse_variables (dataset_dict (current_dataset), &v, &n, PV_NO_DUPLICATE))
+ if (!parse_variables (dataset_dict (ds), &v, &n, PV_NO_DUPLICATE))
return CMD_CASCADING_FAILURE;
- dict_set_split_vars (dataset_dict (current_dataset), v, n);
+ dict_set_split_vars (dataset_dict (ds), v, n);
free (v);
}
/* Dumps out the values of all the split variables for the case C. */
void
-output_split_file_values (const struct ccase *c)
+output_split_file_values (const struct dataset *ds, const struct ccase *c)
{
+ const struct dictionary *dict = dataset_dict (ds);
struct variable *const *split;
struct tab_table *t;
size_t split_cnt;
int i;
- split_cnt = dict_get_split_cnt (dataset_dict (current_dataset));
+ split_cnt = dict_get_split_cnt (dict);
if (split_cnt == 0)
return;
tab_text (t, 0, 0, TAB_NONE, _("Variable"));
tab_text (t, 1, 0, TAB_LEFT, _("Value"));
tab_text (t, 2, 0, TAB_LEFT, _("Label"));
- split = dict_get_split_vars (dataset_dict (current_dataset));
+ split = dict_get_split_vars (dict);
for (i = 0; i < split_cnt; i++)
{
struct variable *v = split[i];
#ifndef SPLIT_FILE_H
#define SPLIT_FILE_H 1
-void output_split_file_values (const struct ccase *);
+void output_split_file_values (const struct dataset *ds, const struct ccase *);
#endif /* split-file.h */
/* SYSFILE INFO utility. */
int
-cmd_sysfile_info (void)
+cmd_sysfile_info (struct dataset *ds UNUSED)
{
struct file_handle *h;
struct dictionary *d;
/* DISPLAY utility. */
static void display_macros (void);
-static void display_documents (void);
+static void display_documents (const struct dictionary *dict);
static void display_variables (struct variable **, size_t, int);
-static void display_vectors (int sorted);
+static void display_vectors (const struct dictionary *dict, int sorted);
int
-cmd_display (void)
+cmd_display (struct dataset *ds)
{
/* Whether to sort the list of variables alphabetically. */
int sorted;
if (lex_match_id ("MACROS"))
display_macros ();
else if (lex_match_id ("DOCUMENTS"))
- display_documents ();
+ display_documents (dataset_dict (ds));
else if (lex_match_id ("FILE"))
{
som_blank_line ();
if (!lex_force_match_id ("LABEL"))
return CMD_FAILURE;
- if (dict_get_label (dataset_dict (current_dataset)) == NULL)
+ if (dict_get_label (dataset_dict (ds)) == NULL)
tab_output_text (TAB_LEFT,
_("The active file does not have a file label."));
else
{
tab_output_text (TAB_LEFT | TAT_TITLE, _("File label:"));
- tab_output_text (TAB_LEFT | TAB_FIX, dict_get_label (dataset_dict (current_dataset)));
+ tab_output_text (TAB_LEFT | TAB_FIX, dict_get_label (dataset_dict (ds)));
}
}
else
if (as == AS_VECTOR)
{
- display_vectors (sorted);
+ display_vectors (dataset_dict(ds), sorted);
return CMD_SUCCESS;
}
if (token != '.')
{
- if (!parse_variables (dataset_dict (current_dataset), &vl, &n, PV_NONE))
+ if (!parse_variables (dataset_dict (ds), &vl, &n, PV_NONE))
{
free (vl);
return CMD_FAILURE;
as = AS_DICTIONARY;
}
else
- dict_get_vars (dataset_dict (current_dataset), &vl, &n, 0);
+ dict_get_vars (dataset_dict (ds), &vl, &n, 0);
if (as == AS_SCRATCH)
{
}
static void
-display_documents (void)
+display_documents (const struct dictionary *dict)
{
- const char *documents = dict_get_documents (dataset_dict (current_dataset));
+ const char *documents = dict_get_documents (dict);
som_blank_line ();
if (documents == NULL)
/* Display a list of vectors. If SORTED is nonzero then they are
sorted alphabetically. */
static void
-display_vectors (int sorted)
+display_vectors (const struct dictionary *dict, int sorted)
{
const struct vector **vl;
int i;
struct tab_table *t;
size_t nvec;
- nvec = dict_get_vector_cnt (dataset_dict (current_dataset));
+ nvec = dict_get_vector_cnt (dict);
if (nvec == 0)
{
msg (SW, _("No vectors defined."));
vl = xnmalloc (nvec, sizeof *vl);
for (i = 0; i < nvec; i++)
- vl[i] = dict_get_vector (dataset_dict (current_dataset), i);
+ vl[i] = dict_get_vector (dict, i);
if (sorted)
qsort (vl, nvec, sizeof *vl, compare_vectors_by_name);
\f
/* Declarations. */
-static int do_value_labels (int);
+static int do_value_labels (const struct dictionary *dict, int);
static int verify_val_labs (struct variable **vars, size_t var_cnt);
static void erase_labels (struct variable **vars, size_t var_cnt);
static int get_label (struct variable **vars, size_t var_cnt);
/* Stubs. */
int
-cmd_value_labels (void)
+cmd_value_labels (struct dataset *ds)
{
- return do_value_labels (1);
+ return do_value_labels (dataset_dict (ds), 1);
}
int
-cmd_add_value_labels (void)
+cmd_add_value_labels (struct dataset *ds)
{
- return do_value_labels (0);
+ return do_value_labels (dataset_dict (ds), 0);
}
\f
/* Do it. */
static int
-do_value_labels (int erase)
+do_value_labels (const struct dictionary *dict, int erase)
{
struct variable **vars; /* Variable list. */
size_t var_cnt; /* Number of variables. */
while (token != '.')
{
- parse_err = !parse_variables (dataset_dict (current_dataset), &vars, &var_cnt,
+ parse_err = !parse_variables (dict, &vars, &var_cnt,
PV_SAME_TYPE) ;
if (var_cnt < 1)
{
It affects nothing but GUIs
*/
int
-cmd_variable_alignment (void)
+cmd_variable_alignment (struct dataset *ds)
{
do
{
size_t i;
enum alignment align;
- if (!parse_variables (dataset_dict (current_dataset), &v, &nv, PV_NONE))
+ if (!parse_variables (dataset_dict (ds), &v, &nv, PV_NONE))
return CMD_FAILURE;
if ( lex_force_match('(') )
It affects nothing but GUIs
*/
int
-cmd_variable_width (void)
+cmd_variable_width (struct dataset *ds)
{
do
{
size_t nv;
size_t i;
- if (!parse_variables (dataset_dict (current_dataset), &v, &nv, PV_NONE))
+ if (!parse_variables (dataset_dict (ds), &v, &nv, PV_NONE))
return CMD_FAILURE;
if ( lex_force_match('(') )
/* Set variables' measurement level */
int
-cmd_variable_level (void)
+cmd_variable_level (struct dataset *ds)
{
do
{
enum measure level;
size_t i;
- if (!parse_variables (dataset_dict (current_dataset), &v, &nv, PV_NONE))
+ if (!parse_variables (dataset_dict (ds), &v, &nv, PV_NONE))
return CMD_FAILURE;
if ( lex_force_match('(') )
#define _(msgid) gettext (msgid)
int
-cmd_variable_labels (void)
+cmd_variable_labels (struct dataset *ds)
{
do
{
size_t i;
- if (!parse_variables (dataset_dict (current_dataset), &v, &nv, PV_NONE))
+ if (!parse_variables (dataset_dict (ds), &v, &nv, PV_NONE))
return CMD_FAILURE;
if (token != T_STRING)
#define _(msgid) gettext (msgid)
int
-cmd_vector (void)
+cmd_vector (struct dataset *ds)
{
/* Just to be different, points to a set of null terminated strings
containing the names of the vectors to be created. The list
/* Maximum allocated position for vecnames, plus one position. */
char *endp = NULL;
+ struct dictionary *dict = dataset_dict (ds);
+
cp = vecnames = xmalloc (256);
endp = &vecnames[256];
do
goto fail;
}
- if (dict_lookup_vector (dataset_dict (current_dataset), tokid))
+ if (dict_lookup_vector (dict, tokid))
{
msg (SE, _("There is already a vector with name %s."), tokid);
goto fail;
goto fail;
}
- if (!parse_variables (dataset_dict (current_dataset), &v, &nv,
+ if (!parse_variables (dict, &v, &nv,
PV_SAME_TYPE | PV_DUPLICATE))
goto fail;
- dict_create_vector (dataset_dict (current_dataset), vecnames, v, nv);
+ dict_create_vector (dict, vecnames, v, nv);
free (v);
}
else if (lex_match ('('))
for (i = 0; i < nv; i++)
{
sprintf (name, "%s%d", cp, i + 1);
- if (dict_lookup_var (dataset_dict (current_dataset), name))
+ if (dict_lookup_var (dict, name))
{
msg (SE, _("There is already a variable named %s."),
name);
for (i = 0; i < nv; i++)
{
sprintf (name, "%s%d", cp, i + 1);
- v[i] = dict_create_var_assert (dataset_dict (current_dataset), name, 0);
+ v[i] = dict_create_var_assert (dict, name, 0);
}
- if (!dict_create_vector (dataset_dict (current_dataset), cp, v, nv))
+ if (!dict_create_vector (dict, cp, v, nv))
NOT_REACHED ();
cp += strlen (cp) + 1;
}
#define _(msgid) gettext (msgid)
int
-cmd_weight (void)
+cmd_weight (struct dataset *ds)
{
+ struct dictionary *dict = dataset_dict (ds);
if (lex_match_id ("OFF"))
- dict_set_weight (dataset_dict (current_dataset), NULL);
+ dict_set_weight (dataset_dict (ds), NULL);
else
{
struct variable *v;
lex_match (T_BY);
- v = parse_variable ();
+ v = parse_variable (dict);
if (!v)
return CMD_CASCADING_FAILURE;
if (v->type == ALPHA)
return CMD_CASCADING_FAILURE;
}
- dict_set_weight (dataset_dict (current_dataset), v);
+ dict_set_weight (dict, v);
}
return lex_end_of_command ();
expr_evaluate (struct expression *e, const struct ccase *c, int case_idx,
void *result)
{
+ struct dataset *ds = e->ds;
union operation_data *op = e->ops;
double *ns = e->number_stack;
struct substring *ss = e->string_stack;
- assert ((c != NULL) == (e->dict != NULL));
+ /* Without a dictionary/dataset, the expression can't refer to variables,
+ and you don't need to specify a case when you evaluate the
+ expression. With a dictionary/dataset, the expression can refer
+ to variables, so you must specify a case when you evaluate the
+ expression. */
+ assert ((c != NULL) == (e->ds != NULL));
+
pool_clear (e->eval_pool);
for (;;)
#include <language/command.h>
int
-cmd_debug_evaluate (void)
+cmd_debug_evaluate (struct dataset *dsother UNUSED)
{
bool optimize = true;
int retval = CMD_FAILURE;
bool dump_postfix = false;
- struct dictionary *d = NULL;
+
struct ccase *c = NULL;
+ struct dataset *ds = NULL;
+
struct expression *expr;
for (;;)
{
+ struct dictionary *d = NULL;
if (lex_match_id ("NOOPTIMIZE"))
optimize = 0;
else if (lex_match_id ("POSTFIX"))
lex_error (_("expecting number or string"));
goto done;
}
-
- if (d == NULL)
- d = dict_create ();
+
+ if ( ds == NULL )
+ {
+ ds = create_dataset ();
+ d = dataset_dict (ds);
+ }
old_value_cnt = dict_get_next_value_idx (d);
v = dict_create_var (d, name, width);
lex_force_match ('/');
goto done;
}
- if (d != NULL)
- fprintf (stderr, "; ");
+
+ if ( ds != NULL )
+ fprintf(stderr, "; ");
fprintf (stderr, "%s => ", lex_rest_of_line (NULL));
lex_get ();
- expr = expr_parse_any (d, optimize);
+ expr = expr_parse_any (ds, optimize);
if (!expr || lex_end_of_command () != CMD_SUCCESS)
{
if (expr != NULL)
retval = CMD_SUCCESS;
done:
+ if (ds)
+ destroy_dataset (ds);
+
if (c != NULL)
{
case_destroy (c);
free (c);
}
- dict_destroy (d);
+
return retval;
}
FIXED_VALUE => 'c');
init_type ('case_idx', 'fixed', C_TYPE => 'size_t',
FIXED_VALUE => 'case_idx');
+ init_type ('dataset', 'fixed', C_TYPE => 'struct dataset *',
+ FIXED_VALUE => 'ds');
# One of these is emitted at the end of each expression as a sentinel
# that tells expr_evaluate() to return the value on the stack.
}
no_opt perm_only function LAG (num_var v, pos_int n_before)
+ dataset ds;
{
- struct ccase *c = lagged_case (current_dataset, n_before);
+ struct ccase *c = lagged_case (ds, n_before);
if (c != NULL)
{
double x = case_num (c, v->fv);
}
no_opt perm_only function LAG (num_var v)
+ dataset ds;
{
- struct ccase *c = lagged_case (current_dataset, 1);
+ struct ccase *c = lagged_case (ds, 1);
if (c != NULL)
{
double x = case_num (c, v->fv);
no_opt perm_only string function LAG (str_var v, pos_int n_before)
expression e;
+ dataset ds;
{
- struct ccase *c = lagged_case (current_dataset, n_before);
+ struct ccase *c = lagged_case (ds, n_before);
if (c != NULL)
return copy_string (e, case_str (c, v->fv), v->width);
else
no_opt perm_only string function LAG (str_var v)
expression e;
+ dataset ds;
{
- struct ccase *c = lagged_case (current_dataset, 1);
+ struct ccase *c = lagged_case (ds, 1);
if (c != NULL)
return copy_string (e, case_str (c, v->fv), v->width);
else
static parse_recursively_func parse_vector_element, parse_function;
/* Utility functions. */
-static struct expression *expr_create (struct dictionary *);
+static struct expression *expr_create (struct dataset *ds);
atom_type expr_node_returns (const union any_node *);
static const char *atom_type_name (atom_type);
Returns the new expression if successful or a null pointer
otherwise. */
struct expression *
-expr_parse (struct dictionary *dict, enum expr_type type)
+expr_parse (struct dataset *ds, enum expr_type type)
{
union any_node *n;
struct expression *e;
assert (type == EXPR_NUMBER || type == EXPR_STRING || type == EXPR_BOOLEAN);
- e = expr_create (dict);
+ e = expr_create (ds);
n = parse_or (e);
if (n != NULL && type_check (e, &n, type))
return finish_expression (expr_optimize (n, e), e);
the expression as well. */
struct expression *
expr_parse_pool (struct pool *pool,
- struct dictionary *dict, enum expr_type type)
+ struct dataset *ds,
+ enum expr_type type)
{
- struct expression *e = expr_parse (dict, type);
+ struct expression *e = expr_parse (ds, type);
if (e != NULL)
pool_add_subpool (pool, e->expr_pool);
return e;
}
struct expression *
-expr_parse_any (struct dictionary *dict, bool optimize)
+expr_parse_any (struct dataset *ds, bool optimize)
{
union any_node *n;
struct expression *e;
- e = expr_create (dict);
+ e = expr_create (ds);
n = parse_or (e);
if (n == NULL)
{
"JUL", "AUG", "SEP", "OCT", "NOV", "DEC",
};
- time_t last_proc_time = time_of_last_procedure (current_dataset);
+ time_t last_proc_time = time_of_last_procedure (e->ds);
struct tm *time;
char temp_buf[10];
return expr_allocate_number (e, SYSMIS);
else if (lex_match_id ("$JDATE"))
{
- time_t time = time_of_last_procedure (current_dataset);
+ time_t time = time_of_last_procedure (e->ds);
struct tm *tm = localtime (&time);
return expr_allocate_number (e, expr_ymd_to_ofs (tm->tm_year + 1900,
tm->tm_mon + 1,
}
else if (lex_match_id ("$TIME"))
{
- time_t time = time_of_last_procedure (current_dataset);
+ time_t time = time_of_last_procedure (e->ds);
struct tm *tm = localtime (&time);
return expr_allocate_number (e,
expr_ymd_to_date (tm->tm_year + 1900,
/* An identifier followed by a left parenthesis may be
a vector element reference. If not, it's a function
call. */
- if (e->dict != NULL && dict_lookup_vector (e->dict, tokid) != NULL)
+ if (e->ds != NULL && dict_lookup_vector (dataset_dict (e->ds), tokid) != NULL)
return parse_vector_element (e);
else
return parse_function (e);
/* $ at the beginning indicates a system variable. */
return parse_sysvar (e);
}
- else if (e->dict != NULL && dict_lookup_var (e->dict, tokid))
+ else if (e->ds != NULL && dict_lookup_var (dataset_dict (e->ds), tokid))
{
/* It looks like a user variable.
(It could be a format specifier, but we'll assume
it's a variable unless proven otherwise. */
- return allocate_unary_variable (e, parse_dict_variable (e->dict));
+ return allocate_unary_variable (e, parse_variable (dataset_dict (e->ds)));
}
else
{
/* Find vector, skip token.
The caller must already have verified that the current token
is the name of a vector. */
- vector = dict_lookup_vector (dataset_dict (current_dataset), tokid);
+ vector = dict_lookup_vector (dataset_dict (e->ds), tokid);
assert (vector != NULL);
lex_get ();
size_t var_cnt;
size_t i;
- if (!parse_variables (dataset_dict (current_dataset), &vars, &var_cnt, PV_SINGLE))
+ if (!parse_variables (dataset_dict (e->ds), &vars, &var_cnt, PV_SINGLE))
goto fail;
for (i = 0; i < var_cnt; i++)
add_arg (&args, &arg_cnt, &arg_cap,
goto fail;
}
if ((f->flags & OPF_PERM_ONLY) &&
- proc_in_temporary_transformations (current_dataset))
+ proc_in_temporary_transformations (e->ds))
{
msg (SE, _("%s may not appear after TEMPORARY."), f->prototype);
goto fail;
if (n->type == OP_LAG_Vn || n->type == OP_LAG_Vs)
{
- if (dataset_n_lag (current_dataset) < 1)
- dataset_set_n_lag (current_dataset, 1);
+ if (dataset_n_lag (e->ds) < 1)
+ dataset_set_n_lag (e->ds, 1);
}
else if (n->type == OP_LAG_Vnn || n->type == OP_LAG_Vsn)
{
assert (n->composite.arg_cnt == 2);
assert (n->composite.args[1]->type == OP_pos_int);
n_before = n->composite.args[1]->integer.i;
- if ( dataset_n_lag (current_dataset) < n_before)
- dataset_set_n_lag (current_dataset, n_before);
+ if ( dataset_n_lag (e->ds) < n_before)
+ dataset_set_n_lag (e->ds, n_before);
}
free (args);
/* Utility functions. */
static struct expression *
-expr_create (struct dictionary *dict)
+expr_create (struct dataset *ds)
{
struct pool *pool = pool_create ();
struct expression *e = pool_alloc (pool, sizeof *e);
e->expr_pool = pool;
- e->dict = dict;
+ e->ds = ds;
e->eval_pool = pool_create_subpool (e->expr_pool);
e->ops = NULL;
e->op_types = NULL;
struct expression
{
struct pool *expr_pool; /* Pool for expression static data. */
- struct dictionary *dict; /* Dictionary for variables, vectors. */
+ struct dataset *ds ; /* The dataset */
atom_type type; /* Type of expression result. */
union operation_data *ops; /* Expression data. */
struct pool *eval_pool; /* Pool for evaluation temporaries. */
};
-struct expression *expr_parse_any (struct dictionary *, bool optimize);
+struct expression *expr_parse_any (struct dataset *, bool optimize);
void expr_debug_print_postfix (const struct expression *);
union any_node *expr_optimize (union any_node *, struct expression *);
struct ccase;
struct pool;
union value;
+struct dataset ;
-struct expression *expr_parse (struct dictionary *, enum expr_type);
+struct expression *expr_parse (struct dataset *, enum expr_type);
struct expression *expr_parse_pool (struct pool *,
- struct dictionary *, enum expr_type);
+ struct dataset *,
+ enum expr_type);
void expr_free (struct expression *);
+struct dataset;
double expr_evaluate_num (struct expression *, const struct ccase *,
int case_idx);
void expr_evaluate_str (struct expression *, const struct ccase *,
dump (0, "/* Prototype for custom subcommands of %s. */",
cmdname);
}
- dump (0, "static int %scustom_%s (struct cmd_%s *, void *);",
+ dump (0, "static int %scustom_%s (struct dataset *, struct cmd_%s *, void *);",
st_lower (prefix), st_lower (sbc->name),
make_identifier (cmdname));
}
/* Prototypes for parsing and freeing functions. */
{
dump (0, "/* Command parsing functions. */");
- dump (0, "static int parse_%s (struct cmd_%s *, void *);",
+ dump (0, "static int parse_%s (struct dataset *, struct cmd_%s *, void *);",
make_identifier (cmdname), make_identifier (cmdname));
dump (0, "static void free_%s (struct cmd_%s *);",
make_identifier (cmdname), make_identifier (cmdname));
}
else if (sbc->type == SBC_VARLIST)
{
- dump (1, "if (!parse_variables (dataset_dict (current_dataset), &p->%sv_%s, &p->%sn_%s, "
+ dump (1, "if (!parse_variables (dataset_dict (ds), &p->%sv_%s, &p->%sn_%s, "
"PV_APPEND%s%s))",
st_lower (sbc->prefix), st_lower (sbc->name),
st_lower (sbc->prefix), st_lower (sbc->name),
}
else if (sbc->type == SBC_VAR)
{
- dump (0, "p->%sv_%s = parse_variable ();",
+ dump (0, "p->%sv_%s = parse_variable (dataset_dict (ds));",
st_lower (sbc->prefix), st_lower (sbc->name));
dump (1, "if (!p->%sv_%s)",
st_lower (sbc->prefix), st_lower (sbc->name));
}
else if (sbc->type == SBC_CUSTOM)
{
- dump (1, "switch (%scustom_%s (p, aux))",
+ dump (1, "switch (%scustom_%s (ds, p, aux))",
st_lower (prefix), st_lower (sbc->name));
dump (0, "{");
dump (1, "case 0:");
indent = 0;
dump (0, "static int");
- dump (0, "parse_%s (struct cmd_%s *p, void *aux UNUSED)",
+ dump (0, "parse_%s (struct dataset *ds%s, struct cmd_%s *p, void *aux UNUSED)",
make_identifier (cmdname),
+ (def && ( def->type == SBC_VARLIST && def->type == SBC_CUSTOM))?"":" UNUSED",
make_identifier (cmdname));
dump (1, "{");
{
if (def->type == SBC_VARLIST)
dump (1, "if (token == T_ID "
- "&& dict_lookup_var (dataset_dict (current_dataset), tokid) != NULL "
+ "&& dict_lookup_var (dataset_dict (ds), tokid) != NULL "
"&& lex_look_ahead () != '=')");
else
{
dump (0, "if ((token == T_ID "
- "&& dict_lookup_var (dataset_dict (current_dataset), tokid) "
+ "&& dict_lookup_var (dataset_dict (ds), tokid) "
"&& lex_look_ahead () != '=')");
dump (1, " || token == T_ALL)");
}
dump (1, "{");
dump (0, "p->sbc_%s++;", st_lower (def->name));
- dump (1, "if (!parse_variables (dataset_dict (current_dataset), &p->%sv_%s, &p->%sn_%s, "
+ dump (1, "if (!parse_variables (dataset_dict (ds), &p->%sv_%s, &p->%sn_%s, "
"PV_APPEND))",
st_lower (def->prefix), st_lower (def->name),
st_lower (def->prefix), st_lower (def->name));
}
else if (def && def->type == SBC_CUSTOM)
{
- dump (1, "switch (%scustom_%s (p, aux))",
+ dump (1, "switch (%scustom_%s (ds, p, aux))",
st_lower (prefix), st_lower (def->name));
dump (0, "{");
dump (1, "case 0:");
dump (0, "#line %d \"%s\"", ln + 1, ifn);
}
-
-
return EXIT_SUCCESS;
}
variable if successful. On failure emits an error message and
returns a null pointer. */
struct variable *
-parse_dict_variable (const struct dictionary *d)
+parse_variable (const struct dictionary *d)
{
struct var_set *vs = var_set_create_from_dict (d);
struct variable *var = parse_vs_variable (vs);
return var;
}
-/* Parses a variable name in dataset_dict (current_dataset) and returns the
- variable if successful. On failure emits an error message and
- returns a null pointer. */
-struct variable *
-parse_variable (void)
-{
- return parse_dict_variable (dataset_dict (current_dataset));
-}
-
-
/* Parses a set of variables from dictionary D given options
OPTS. Resulting list of variables stored in *VAR and the
number of variables into *CNT. Returns true only if
existing and the rest are to be created. Same args as
parse_DATA_LIST_vars(). */
bool
-parse_mixed_vars (char ***names, size_t *nnames, int pv_opts)
+parse_mixed_vars (const struct dictionary *dict,
+ char ***names, size_t *nnames, int pv_opts)
{
size_t i;
}
while (token == T_ID || token == T_ALL)
{
- if (token == T_ALL || dict_lookup_var (dataset_dict (current_dataset), tokid) != NULL)
+ if (token == T_ALL || dict_lookup_var (dict, tokid) != NULL)
{
struct variable **v;
size_t nv;
- if (!parse_variables (dataset_dict (current_dataset), &v, &nv, PV_NONE))
+ if (!parse_variables (dict, &v, &nv, PV_NONE))
goto fail;
*names = xnrealloc (*names, *nnames + nv, sizeof **names);
for (i = 0; i < nv; i++)
parse_mixed_vars(), except that all allocations are taken
from the given POOL. */
bool
-parse_mixed_vars_pool (struct pool *pool,
+parse_mixed_vars_pool (const struct dictionary *dict, struct pool *pool,
char ***names, size_t *nnames, int pv_opts)
{
int retval;
re-free it later. */
assert (!(pv_opts & PV_APPEND));
- retval = parse_mixed_vars (names, nnames, pv_opts);
+ retval = parse_mixed_vars (dict, names, nnames, pv_opts);
if (retval)
register_vars_pool (pool, *names, *nnames);
return retval;
PV_NO_SCRATCH = 00200 /* Disallow scratch variables. */
};
-struct variable *parse_variable (void);
-struct variable *parse_dict_variable (const struct dictionary *);
+struct variable *parse_variable (const struct dictionary *);
bool parse_variables (const struct dictionary *, struct variable ***, size_t *,
int opts);
bool parse_variables_pool (struct pool *, const struct dictionary *,
bool parse_DATA_LIST_vars (char ***names, size_t *cnt, int opts);
bool parse_DATA_LIST_vars_pool (struct pool *,
char ***names, size_t *cnt, int opts);
-bool parse_mixed_vars (char ***names, size_t *cnt, int opts);
-bool parse_mixed_vars_pool (struct pool *,
+bool parse_mixed_vars (const struct dictionary *dict,
+ char ***names, size_t *cnt, int opts);
+bool parse_mixed_vars_pool (const struct dictionary *dict,
+ struct pool *,
char ***names, size_t *cnt, int opts);
#endif /* variable-parser.h */
enum missing_treatment missing; /* How to treat missing values. */
struct agr_var *agr_vars; /* First aggregate variable. */
struct dictionary *dict; /* Aggregate dictionary. */
+ const struct dictionary *src_dict; /* Dict of the source */
int case_cnt; /* Counts aggregated cases. */
struct ccase agr_case; /* Aggregate case for output. */
};
const struct ccase *);
/* Prototypes. */
-static bool parse_aggregate_functions (struct agr_proc *);
+static bool parse_aggregate_functions (const struct dictionary *,
+ struct agr_proc *);
static void agr_destroy (struct agr_proc *);
static bool aggregate_single_case (struct agr_proc *agr,
- const struct ccase *input,
- struct ccase *output);
+ const struct ccase *input,
+ struct ccase *output);
static void dump_aggregate_info (struct agr_proc *agr, struct ccase *output);
/* Aggregating to the active file. */
-static bool agr_to_active_file (const struct ccase *, void *aux);
+static bool agr_to_active_file (const struct ccase *, void *aux, const struct dataset *);
/* Aggregating to a system file. */
-static bool presorted_agr_to_sysfile (const struct ccase *, void *aux);
+static bool presorted_agr_to_sysfile (const struct ccase *, void *aux, const struct dataset *);
\f
/* Parsing. */
/* Parses and executes the AGGREGATE procedure. */
int
-cmd_aggregate (void)
+cmd_aggregate (struct dataset *ds)
{
+ struct dictionary *dict = dataset_dict (ds);
struct agr_proc agr;
struct file_handle *out_file = NULL;
case_nullify (&agr.break_case);
agr.dict = dict_create ();
- dict_set_label (agr.dict, dict_get_label (dataset_dict (current_dataset)));
- dict_set_documents (agr.dict, dict_get_documents (dataset_dict (current_dataset)));
+ agr.src_dict = dict;
+ dict_set_label (agr.dict, dict_get_label (dict));
+ dict_set_documents (agr.dict, dict_get_documents (dict));
/* OUTFILE subcommand must be first. */
if (!lex_force_match_id ("OUTFILE"))
int i;
lex_match ('=');
- agr.sort = sort_parse_criteria (dataset_dict (current_dataset),
+ agr.sort = sort_parse_criteria (dict,
&agr.break_vars, &agr.break_var_cnt,
&saw_direction, NULL);
if (agr.sort == NULL)
/* Read in the aggregate functions. */
lex_match ('/');
- if (!parse_aggregate_functions (&agr))
+ if (!parse_aggregate_functions (dict, &agr))
goto error;
/* Delete documents. */
{
/* The active file will be replaced by the aggregated data,
so TEMPORARY is moot. */
- proc_cancel_temporary_transformations (current_dataset);
+ proc_cancel_temporary_transformations (ds);
if (agr.sort != NULL && !presorted)
{
- if (!sort_active_file_in_place (agr.sort))
+ if (!sort_active_file_in_place (ds, agr.sort))
goto error;
}
agr.sink = create_case_sink (&storage_sink_class, agr.dict, NULL);
if (agr.sink->class->open != NULL)
agr.sink->class->open (agr.sink);
- proc_set_sink (current_dataset,
+ proc_set_sink (ds,
create_case_sink (&null_sink_class,
- dataset_dict (current_dataset), NULL));
- if (!procedure (current_dataset,agr_to_active_file, &agr))
+ dict, NULL));
+ if (!procedure (ds, agr_to_active_file, &agr))
goto error;
if (agr.case_cnt > 0)
{
if (!agr.sink->class->write (agr.sink, &agr.agr_case))
goto error;
}
- discard_variables (current_dataset);
- dict_destroy (dataset_dict (current_dataset));
- dataset_set_dict (current_dataset, agr.dict);
+ discard_variables (ds);
+ dict_destroy (dict);
+ dataset_set_dict (ds, agr.dict);
agr.dict = NULL;
- proc_set_source (current_dataset,
+ proc_set_source (ds,
agr.sink->class->make_source (agr.sink));
free_case_sink (agr.sink);
}
struct ccase c;
bool ok = true;
- dst = sort_active_file_to_casefile (agr.sort);
+ dst = sort_active_file_to_casefile (ds, agr.sort);
if (dst == NULL)
goto error;
reader = casefile_get_destructive_reader (dst);
else
{
/* Active file is already sorted. */
- if (!procedure (current_dataset,presorted_agr_to_sysfile, &agr))
+ if (!procedure (ds, presorted_agr_to_sysfile, &agr))
goto error;
}
/* Parse all the aggregate functions. */
static bool
-parse_aggregate_functions (struct agr_proc *agr)
+parse_aggregate_functions (const struct dictionary *dict, struct agr_proc *agr)
{
struct agr_var *tail; /* Tail of linked list starting at agr->vars. */
else if (function->n_args)
pv_opts |= PV_SAME_TYPE;
- if (!parse_variables (dataset_dict (current_dataset), &src, &n_src, pv_opts))
+ if (!parse_variables (dict, &src, &n_src, pv_opts))
goto error;
}
if (destvar != NULL)
{
if ((func_index == N || func_index == NMISS)
- && dict_get_weight (dataset_dict (current_dataset)) != NULL)
+ && dict_get_weight (dict) != NULL)
destvar->print = destvar->write = f8_2;
else
destvar->print = destvar->write = function->format;
v->src = NULL;
destvar = dict_create_var (agr->dict, dest[i], 0);
if (func_index == N_NO_VARS
- && dict_get_weight (dataset_dict (current_dataset)) != NULL)
+ && dict_get_weight (dict) != NULL)
destvar->print = destvar->write = f8_2;
else
destvar->print = destvar->write = function->format;
double weight;
bool bad_warn = true;
- weight = dict_get_case_weight (dataset_dict (current_dataset), input, &bad_warn);
+ weight = dict_get_case_weight (agr->src_dict, input, &bad_warn);
for (iter = agr->agr_vars; iter; iter = iter->next)
if (iter->src)
are dropped.
Returns true if successful, false if an I/O error occurred. */
static bool
-agr_to_active_file (const struct ccase *c, void *agr_)
+agr_to_active_file (const struct ccase *c, void *agr_, const struct dataset *ds UNUSED)
{
struct agr_proc *agr = agr_;
/* Aggregate the current case and output it if we passed a
breakpoint. */
static bool
-presorted_agr_to_sysfile (const struct ccase *c, void *agr_)
+presorted_agr_to_sysfile (const struct ccase *c, void *agr_, const struct dataset *ds UNUSED)
{
struct agr_proc *agr = agr_;
static trns_proc_func autorecode_trns_proc;
static trns_free_func autorecode_trns_free;
-static bool autorecode_proc_func (const struct ccase *, void *);
+static bool autorecode_proc_func (const struct ccase *, void *, const struct dataset *);
static hsh_compare_func compare_alpha_value, compare_numeric_value;
static hsh_hash_func hash_alpha_value, hash_numeric_value;
-static void recode (const struct autorecode_pgm *);
+static void recode (struct dataset *, const struct autorecode_pgm *);
static void arc_free (struct autorecode_pgm *);
/* Performs the AUTORECODE procedure. */
int
-cmd_autorecode (void)
+cmd_autorecode (struct dataset *ds)
{
struct autorecode_pgm arc;
size_t dst_cnt;
lex_match_id ("VARIABLES");
lex_match ('=');
- if (!parse_variables (dataset_dict (current_dataset), &arc.src_vars, &arc.var_cnt,
+ if (!parse_variables (dataset_dict (ds), &arc.src_vars, &arc.var_cnt,
PV_NO_DUPLICATE))
goto lossage;
if (!lex_force_match_id ("INTO"))
{
int j;
- if (dict_lookup_var (dataset_dict (current_dataset), arc.dst_names[i]) != NULL)
+ if (dict_lookup_var (dataset_dict (ds), arc.dst_names[i]) != NULL)
{
msg (SE, _("Target variable %s duplicates existing variable %s."),
arc.dst_names[i], arc.dst_names[i]);
arc.src_values[i] = hsh_create (10, compare_numeric_value,
hash_numeric_value, NULL, NULL);
- ok = procedure (current_dataset,autorecode_proc_func, &arc);
+ ok = procedure (ds, autorecode_proc_func, &arc);
for (i = 0; i < arc.var_cnt; i++)
- arc.dst_vars[i] = dict_create_var_assert (dataset_dict (current_dataset),
+ arc.dst_vars[i] = dict_create_var_assert (dataset_dict (ds),
arc.dst_names[i], 0);
- recode (&arc);
+ recode (ds, &arc);
arc_free (&arc);
return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
/* AUTORECODE transformation. */
static void
-recode (const struct autorecode_pgm *arc)
+recode (struct dataset *ds, const struct autorecode_pgm *arc)
{
struct autorecode_trns *trns;
size_t i;
hsh_force_insert (spec->items, item);
}
}
- add_transformation (current_dataset,
+ add_transformation (ds,
autorecode_trns_proc, autorecode_trns_free, trns);
}
/* Executes an AUTORECODE transformation. */
static int
-autorecode_trns_proc (void *trns_, struct ccase *c, casenum_t case_idx UNUSED)
+autorecode_trns_proc (void *trns_, struct ccase *c, casenumber case_idx UNUSED)
{
struct autorecode_trns *trns = trns_;
size_t i;
}
static bool
-autorecode_proc_func (const struct ccase *c, void *arc_)
+autorecode_proc_func (const struct ccase *c, void *arc_, const struct dataset *ds UNUSED)
{
struct autorecode_pgm *arc = arc_;
size_t i;
static struct file_handle *matrix_file;
static void free_correlations_state (void);
-static int internal_cmd_correlations (void);
+static int internal_cmd_correlations (struct dataset *ds);
int
-cmd_correlations (void)
+cmd_correlations (struct dataset *ds)
{
- int result = internal_cmd_correlations ();
+ int result = internal_cmd_correlations (ds);
free_correlations_state ();
return result;
}
/* (functions) */
int
-internal_cmd_correlations (void)
+internal_cmd_correlations (struct dataset *ds)
{
struct cmd_correlations cmd;
cor_list = cor_last = NULL;
matrix_file = NULL;
- if (!parse_correlations (&cmd, NULL))
+ if (!parse_correlations (ds, &cmd, NULL))
return CMD_FAILURE;
+
free_correlations (&cmd);
return CMD_SUCCESS;
}
static int
-cor_custom_variables (struct cmd_correlations *cmd UNUSED, void *aux UNUSED)
+cor_custom_variables (struct dataset *ds, struct cmd_correlations *cmd UNUSED, void *aux UNUSED)
{
struct variable **v1, **v2;
size_t nv1, nv2;
/* Ensure that this is a VARIABLES subcommand. */
if (!lex_match_id ("VARIABLES")
- && (token != T_ID || dict_lookup_var (dataset_dict (current_dataset), tokid) != NULL)
+ && (token != T_ID || dict_lookup_var (dataset_dict (ds), tokid) != NULL)
&& token != T_ALL)
return 2;
lex_match ('=');
- if (!parse_variables (dataset_dict (current_dataset), &v1, &nv1,
+ if (!parse_variables (dataset_dict (ds), &v1, &nv1,
PV_NO_DUPLICATE | PV_NUMERIC))
return 0;
if (lex_match (T_WITH))
{
- if (!parse_variables (dataset_dict (current_dataset), &v2, &nv2,
+ if (!parse_variables (dataset_dict (ds), &v2, &nv2,
PV_NO_DUPLICATE | PV_NUMERIC))
{
free (v1);
}
static int
-cor_custom_matrix (struct cmd_correlations *cmd UNUSED, void *aux UNUSED)
+cor_custom_matrix (struct dataset *ds UNUSED, struct cmd_correlations *cmd UNUSED, void *aux UNUSED)
{
if (!lex_force_match ('('))
return 0;
static struct pool *pl_tc; /* For table cells. */
static struct pool *pl_col; /* For column data. */
-static int internal_cmd_crosstabs (void);
-static void precalc (const struct ccase *, void *);
-static bool calc_general (const struct ccase *, void *);
-static bool calc_integer (const struct ccase *, void *);
-static void postcalc (void *);
+static int internal_cmd_crosstabs (struct dataset *ds);
+static void precalc (const struct ccase *, void *, const struct dataset *);
+static bool calc_general (const struct ccase *, void *, const struct dataset *);
+static bool calc_integer (const struct ccase *, void *, const struct dataset *);
+static bool postcalc (void *, const struct dataset *);
static void submit (struct tab_table *);
static void format_short (char *s, const struct fmt_spec *fp,
/* Parse and execute CROSSTABS, then clean up. */
int
-cmd_crosstabs (void)
+cmd_crosstabs (struct dataset *ds)
{
- int result = internal_cmd_crosstabs ();
+ int result = internal_cmd_crosstabs (ds);
free (variables);
pool_destroy (pl_tc);
/* Parses and executes the CROSSTABS procedure. */
static int
-internal_cmd_crosstabs (void)
+internal_cmd_crosstabs (struct dataset *ds)
{
int i;
bool ok;
pl_tc = pool_create ();
pl_col = pool_create ();
- if (!parse_crosstabs (&cmd, NULL))
+ if (!parse_crosstabs (ds, &cmd, NULL))
return CMD_FAILURE;
mode = variables ? INTEGER : GENERAL;
else
write = CRS_WR_NONE;
- ok = procedure_with_splits (current_dataset, precalc,
+ ok = procedure_with_splits (ds, precalc,
mode == GENERAL ? calc_general : calc_integer,
postcalc, NULL);
/* Parses the TABLES subcommand. */
static int
-crs_custom_tables (struct cmd_crosstabs *cmd UNUSED, void *aux UNUSED)
+crs_custom_tables (struct dataset *ds, struct cmd_crosstabs *cmd UNUSED, void *aux UNUSED)
{
struct var_set *var_set;
int n_by;
/* Ensure that this is a TABLES subcommand. */
if (!lex_match_id ("TABLES")
- && (token != T_ID || dict_lookup_var (dataset_dict (current_dataset), tokid) == NULL)
+ && (token != T_ID || dict_lookup_var (dataset_dict (ds), tokid) == NULL)
&& token != T_ALL)
return 2;
lex_match ('=');
if (variables != NULL)
var_set = var_set_create_from_array (variables, variables_cnt);
else
- var_set = var_set_create_from_dict (dataset_dict (current_dataset));
+ var_set = var_set_create_from_dict (dataset_dict (ds));
assert (var_set != NULL);
for (n_by = 0; ;)
/* Parses the VARIABLES subcommand. */
static int
-crs_custom_variables (struct cmd_crosstabs *cmd UNUSED, void *aux UNUSED)
+crs_custom_variables (struct dataset *ds, struct cmd_crosstabs *cmd UNUSED, void *aux UNUSED)
{
if (nxtab)
{
long min, max;
- if (!parse_variables (dataset_dict (current_dataset), &variables, &variables_cnt,
+ if (!parse_variables (dataset_dict (ds), &variables, &variables_cnt,
(PV_APPEND | PV_NUMERIC
| PV_NO_DUPLICATE | PV_NO_SCRATCH)))
return 0;
/* Set up the crosstabulation tables for processing. */
static void
-precalc (const struct ccase *first, void *aux UNUSED)
+precalc (const struct ccase *first, void *aux UNUSED, const struct dataset *ds)
{
- output_split_file_values (first);
+ output_split_file_values (ds, first);
if (mode == GENERAL)
{
gen_tab = hsh_create (512, compare_table_entry, hash_table_entry,
/* Form crosstabulations for general mode. */
static bool
-calc_general (const struct ccase *c, void *aux UNUSED)
+calc_general (const struct ccase *c, void *aux UNUSED, const struct dataset *ds)
{
bool bad_warn = true;
/* Case weight. */
- double weight = dict_get_case_weight (dataset_dict (current_dataset), c, &bad_warn);
+ double weight = dict_get_case_weight (dataset_dict (ds), c, &bad_warn);
/* Flattened current table index. */
int t;
}
static bool
-calc_integer (const struct ccase *c, void *aux UNUSED)
+calc_integer (const struct ccase *c, void *aux UNUSED, const struct dataset *ds)
{
bool bad_warn = true;
/* Case weight. */
- double weight = dict_get_case_weight (dataset_dict (current_dataset), c, &bad_warn);
+ double weight = dict_get_case_weight (dataset_dict (ds), c, &bad_warn);
/* Flattened current table index. */
int t;
int *, int *, int *);
static void make_summary_table (void);
-static void
-postcalc (void *aux UNUSED)
+static bool
+postcalc (void *aux UNUSED, const struct dataset *ds UNUSED)
{
if (mode == GENERAL)
{
}
hsh_destroy (gen_tab);
+
+ return true;
}
static void insert_summary (struct tab_table *, int tab_index, double valid);
static void free_dsc_proc (struct dsc_proc *);
/* Z-score functions. */
-static bool try_name (struct dsc_proc *dsc, char *name);
-static bool generate_z_varname (struct dsc_proc *dsc, char *z_name,
- const char *name, size_t *z_cnt);
+static bool try_name (const struct dictionary *dict,
+ struct dsc_proc *dsc, char *name);
+static bool generate_z_varname (const struct dictionary *dict,
+ struct dsc_proc *dsc, char *z_name,
+ const char *name, size_t *z_cnt);
static void dump_z_table (struct dsc_proc *);
-static void setup_z_trns (struct dsc_proc *);
+static void setup_z_trns (struct dsc_proc *, struct dataset *);
/* Procedure execution functions. */
static bool calc_descriptives (const struct ccase *first,
- const struct casefile *, void *dsc_);
+ const struct casefile *, void *dsc_,
+ const struct dataset *);
static void display (struct dsc_proc *dsc);
\f
/* Parser and outline. */
/* Handles DESCRIPTIVES. */
int
-cmd_descriptives (void)
+cmd_descriptives (struct dataset *ds)
{
+ struct dictionary *dict = dataset_dict (ds);
struct dsc_proc *dsc;
struct variable **vars = NULL;
size_t var_cnt = 0;
{
int i;
- if (!parse_variables (dataset_dict (current_dataset), &vars, &var_cnt,
+ if (!parse_variables (dataset_dict (ds), &vars, &var_cnt,
PV_APPEND | PV_NO_DUPLICATE | PV_NUMERIC))
goto error;
lex_error (NULL);
goto error;
}
- if (try_name (dsc, tokid))
+ if (try_name (dict, dsc, tokid))
{
strcpy (dsc->vars[dsc->var_cnt - 1].z_name, tokid);
z_cnt++;
for (i = 0; i < dsc->var_cnt; i++)
if (dsc->vars[i].z_name[0] == 0)
{
- if (!generate_z_varname (dsc, dsc->vars[i].z_name,
+ if (!generate_z_varname (dict, dsc, dsc->vars[i].z_name,
dsc->vars[i].v->name, &gen_cnt))
goto error;
z_cnt++;
dsc->vars[i].moments = moments_create (dsc->max_moment);
/* Data pass. */
- ok = multipass_procedure_with_splits (current_dataset, calc_descriptives, dsc);
+ ok = multipass_procedure_with_splits (ds, calc_descriptives, dsc);
/* Z-scoring! */
if (ok && z_cnt)
- setup_z_trns (dsc);
+ setup_z_trns (dsc, ds);
/* Done. */
free (vars);
/* Returns false if NAME is a duplicate of any existing variable name or
of any previously-declared z-var name; otherwise returns true. */
static bool
-try_name (struct dsc_proc *dsc, char *name)
+try_name (const struct dictionary *dict, struct dsc_proc *dsc, char *name)
{
size_t i;
- if (dict_lookup_var (dataset_dict (current_dataset), name) != NULL)
+ if (dict_lookup_var (dict, name) != NULL)
return false;
for (i = 0; i < dsc->var_cnt; i++)
if (!strcasecmp (dsc->vars[i].z_name, name))
known to already exist. If successful, returns true and
copies the new name into Z_NAME. On failure, returns false. */
static bool
-generate_z_varname (struct dsc_proc *dsc, char *z_name,
+generate_z_varname (const struct dictionary *dict, struct dsc_proc *dsc, char *z_name,
const char *var_name, size_t *z_cnt)
{
char name[LONG_NAME_LEN + 1];
/* Try a name based on the original variable name. */
name[0] = 'Z';
str_copy_trunc (name + 1, sizeof name - 1, var_name);
- if (try_name (dsc, name))
+ if (try_name (dict, dsc, name))
{
strcpy (z_name, name);
return true;
return false;
}
- if (try_name (dsc, name))
+ if (try_name (dict, dsc, name))
{
strcpy (z_name, name);
return true;
*/
static int
descriptives_trns_proc (void *trns_, struct ccase * c,
- casenum_t case_idx UNUSED)
+ casenumber case_idx UNUSED)
{
struct dsc_trns *t = trns_;
struct dsc_z_score *z;
/* Sets up a transformation to calculate Z scores. */
static void
-setup_z_trns (struct dsc_proc *dsc)
+setup_z_trns (struct dsc_proc *dsc, struct dataset *ds)
{
struct dsc_trns *t;
size_t cnt, i;
char *cp;
struct variable *dst_var;
- dst_var = dict_create_var_assert (dataset_dict (current_dataset), dv->z_name, 0);
+ dst_var = dict_create_var_assert (dataset_dict (ds), dv->z_name, 0);
if (dv->v->label)
{
dst_var->label = xmalloc (strlen (dv->v->label) + 12);
}
}
- add_transformation (current_dataset,
+ add_transformation (ds,
descriptives_trns_proc, descriptives_trns_free, t);
}
\f
in CF. */
static bool
calc_descriptives (const struct ccase *first,
- const struct casefile *cf, void *dsc_)
+ const struct casefile *cf, void *dsc_,
+ const struct dataset *ds)
{
struct dsc_proc *dsc = dsc_;
struct casereader *reader;
struct ccase c;
size_t i;
- output_split_file_values (first);
+ output_split_file_values (ds, first);
for (i = 0; i < dsc->var_cnt; i++)
{
casereader_read (reader, &c);
case_destroy (&c))
{
- double weight = dict_get_case_weight (dataset_dict (current_dataset), &c, &dsc->bad_warn);
+ double weight = dict_get_case_weight (dataset_dict (ds), &c, &dsc->bad_warn);
if (weight <= 0.0)
continue;
casereader_read (reader, &c);
case_destroy (&c))
{
- double weight = dict_get_case_weight (dataset_dict (current_dataset), &c,
+ double weight = dict_get_case_weight (dataset_dict (ds), &c,
&dsc->bad_warn);
if (weight <= 0.0)
continue;
static struct metrics *totals=0;
/* Parse the clause specifying the factors */
-static int examine_parse_independent_vars(struct cmd_examine *cmd);
+static int examine_parse_independent_vars (const struct dictionary *dict, struct cmd_examine *cmd);
/* Per Split function */
-static bool run_examine(const struct ccase *,
- const struct casefile *cf, void *cmd_);
+static bool run_examine (const struct ccase *,
+ const struct casefile *cf, void *cmd_, const struct dataset *);
static void output_examine(void);
int
-cmd_examine(void)
+cmd_examine (struct dataset *ds)
{
bool ok;
subc_list_double_create(&percentile_list);
percentile_algorithm = PC_HAVERAGE;
- if ( !parse_examine(&cmd, NULL) )
+ if ( !parse_examine (ds, &cmd, NULL) )
return CMD_FAILURE;
/* If /MISSING=INCLUDE is set, then user missing values are ignored */
subc_list_double_push(&percentile_list, 75);
}
- ok = multipass_procedure_with_splits (current_dataset, run_examine, &cmd);
+ ok = multipass_procedure_with_splits (ds, run_examine, &cmd);
if ( totals )
{
/* Parse the PERCENTILES subcommand */
static int
-xmn_custom_percentiles(struct cmd_examine *p UNUSED, void *aux UNUSED)
+xmn_custom_percentiles(struct dataset *ds UNUSED,
+ struct cmd_examine *p UNUSED, void *aux UNUSED)
{
sbc_percentile = 1;
while ( lex_is_number() )
{
- subc_list_double_push(&percentile_list,lex_number());
+ subc_list_double_push (&percentile_list, lex_number());
lex_get();
if ( 0 == subc_list_double_count(&percentile_list))
{
- subc_list_double_push(&percentile_list, 5);
- subc_list_double_push(&percentile_list, 10);
- subc_list_double_push(&percentile_list, 25);
- subc_list_double_push(&percentile_list, 50);
- subc_list_double_push(&percentile_list, 75);
- subc_list_double_push(&percentile_list, 90);
- subc_list_double_push(&percentile_list, 95);
+ subc_list_double_push (&percentile_list, 5);
+ subc_list_double_push (&percentile_list, 10);
+ subc_list_double_push (&percentile_list, 25);
+ subc_list_double_push (&percentile_list, 50);
+ subc_list_double_push (&percentile_list, 75);
+ subc_list_double_push (&percentile_list, 90);
+ subc_list_double_push (&percentile_list, 95);
}
return 1;
/* TOTAL and NOTOTAL are simple, mutually exclusive flags */
static int
-xmn_custom_total(struct cmd_examine *p, void *aux UNUSED)
+xmn_custom_total (struct dataset *ds UNUSED, struct cmd_examine *p, void *aux UNUSED)
{
if ( p->sbc_nototal )
{
}
static int
-xmn_custom_nototal(struct cmd_examine *p, void *aux UNUSED)
+xmn_custom_nototal (struct dataset *ds UNUSED,
+ struct cmd_examine *p, void *aux UNUSED)
{
if ( p->sbc_total )
{
/* Parser for the variables sub command
Returns 1 on success */
static int
-xmn_custom_variables(struct cmd_examine *cmd, void *aux UNUSED)
+xmn_custom_variables(struct dataset *ds, struct cmd_examine *cmd, void *aux UNUSED)
{
+ const struct dictionary *dict = dataset_dict (ds);
lex_match('=');
- if ((token != T_ID || dict_lookup_var (dataset_dict (current_dataset), tokid) == NULL)
+ if ((token != T_ID || dict_lookup_var (dict, tokid) == NULL)
&& token != T_ALL)
{
return 2;
}
- if (!parse_variables (dataset_dict (current_dataset), &dependent_vars, &n_dependent_vars,
+ if (!parse_variables (dict, &dependent_vars, &n_dependent_vars,
PV_NO_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH) )
{
free (dependent_vars);
if ( lex_match(T_BY))
{
int success ;
- success = examine_parse_independent_vars(cmd);
+ success = examine_parse_independent_vars (dict, cmd);
if ( success != 1 ) {
free (dependent_vars);
free (totals) ;
/* Parse the clause specifying the factors */
static int
-examine_parse_independent_vars(struct cmd_examine *cmd)
+examine_parse_independent_vars (const struct dictionary *dict, struct cmd_examine *cmd)
{
int success;
struct factor *sf = xmalloc (sizeof *sf);
- if ((token != T_ID || dict_lookup_var (dataset_dict (current_dataset), tokid) == NULL)
+ if ((token != T_ID || dict_lookup_var (dict, tokid) == NULL)
&& token != T_ALL)
{
free ( sf ) ;
}
- sf->indep_var[0] = parse_variable();
+ sf->indep_var[0] = parse_variable (dict);
sf->indep_var[1] = 0;
if ( token == T_BY )
lex_match(T_BY);
- if ((token != T_ID || dict_lookup_var (dataset_dict (current_dataset), tokid) == NULL)
+ if ((token != T_ID || dict_lookup_var (dict, tokid) == NULL)
&& token != T_ALL)
{
free ( sf ) ;
return 2;
}
- sf->indep_var[1] = parse_variable();
+ sf->indep_var[1] = parse_variable (dict);
}
if ( token == '.' || token == '/' )
return 1;
- success = examine_parse_independent_vars(cmd);
+ success = examine_parse_independent_vars (dict, cmd);
if ( success != 1 )
free ( sf ) ;
}
static bool
-run_examine(const struct ccase *first, const struct casefile *cf, void *cmd_ )
+run_examine(const struct ccase *first, const struct casefile *cf,
+ void *cmd_, const struct dataset *ds)
{
+ struct dictionary *dict = dataset_dict (ds);
struct casereader *r;
struct ccase c;
int v;
struct factor *fctr;
- output_split_file_values (first);
+ output_split_file_values (ds, first);
/* Make sure we haven't got rubbish left over from a
previous split */
fctr = next;
}
-
-
for ( v = 0 ; v < n_dependent_vars ; ++v )
metrics_precalc(&totals[v]);
const int case_no = casereader_cnum(r);
const double weight =
- dict_get_case_weight(dataset_dict (current_dataset), &c, &bad_weight_warn);
+ dict_get_case_weight(dict, &c, &bad_weight_warn);
if ( cmd->miss == XMN_LISTWISE )
{
};
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 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
-cmd_flip (void)
+cmd_flip (struct dataset *ds)
{
struct flip_pgm *flip;
struct case_sink *sink;
+ struct dictionary *dict = dataset_dict (ds);
bool ok;
- if (proc_make_temporary_transformations_permanent (current_dataset))
+ 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->idx_to_fv = dict_get_compacted_idx_to_fv (dataset_dict (current_dataset));
+ 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;
if (lex_match_id ("VARIABLES"))
{
lex_match ('=');
- if (!parse_variables (dataset_dict (current_dataset), &flip->var, &flip->var_cnt,
+ if (!parse_variables (dict, &flip->var, &flip->var_cnt,
PV_NO_DUPLICATE))
goto error;
lex_match ('/');
}
else
- dict_get_vars (dataset_dict (current_dataset), &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 ('=');
- flip->new_names = parse_variable ();
+ flip->new_names = parse_variable (dict);
if (!flip->new_names)
goto error;
}
else
- flip->new_names = dict_lookup_var (dataset_dict (current_dataset), "CASE_LBL");
+ flip->new_names = dict_lookup_var (dict, "CASE_LBL");
if (flip->new_names)
{
/* Read the active file into a flip_sink. */
flip->case_cnt = 0;
- proc_make_temporary_transformations_permanent (current_dataset);
- sink = flip_sink_create (flip);
+ proc_make_temporary_transformations_permanent (ds);
+ sink = flip_sink_create (dict, flip);
if (sink == NULL)
goto error;
- proc_set_sink (current_dataset, sink);
+ proc_set_sink (ds, sink);
flip->new_names_tail = NULL;
- ok = procedure (current_dataset,NULL, NULL);
+ ok = procedure (ds,NULL, NULL);
/* Flip the data we read. */
if (!flip_file (flip))
{
- discard_variables (current_dataset);
+ discard_variables (ds);
goto error;
}
/* Flip the dictionary. */
- dict_clear (dataset_dict (current_dataset));
- if (!build_dictionary (flip))
+ dict_clear (dict);
+ if (!build_dictionary (dict, flip))
{
- discard_variables (current_dataset);
+ discard_variables (ds);
goto error;
}
- flip->case_size = dict_get_case_size (dataset_dict (current_dataset));
+ flip->case_size = dict_get_case_size (dict);
/* Set up flipped data for reading. */
- proc_set_source (current_dataset, flip_source_create (flip));
+ proc_set_source (ds, flip_source_create (flip));
return ok ? lex_end_of_command () : CMD_CASCADING_FAILURE;
/* 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;
*cp = '\0';
str_uppercase (name);
- if (dict_create_var (dataset_dict (current_dataset), name, 0))
+ if (dict_create_var (dict, name, 0))
return 1;
/* Add numeric extensions until acceptable. */
memcpy (n, name, ofs);
sprintf (&n[ofs], "%d", i);
- if (dict_create_var (dataset_dict (current_dataset), n, 0))
+ if (dict_create_var (dict, n, 0))
return 1;
}
}
/* 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 (dataset_dict (current_dataset), "CASE_LBL", 8);
+ dict_create_var_assert (dict, "CASE_LBL", 8);
if (flip->new_names_head == NULL)
{
char s[SHORT_NAME_LEN + 1];
sprintf (s, "VAR%03d", i);
- v = dict_create_var_assert (dataset_dict (current_dataset), s, 0);
+ v = dict_create_var_assert (dict, s, 0);
}
}
else
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;
}
/* 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;
flip->case_cnt = 1;
- return create_case_sink (&flip_sink_class, dataset_dict (current_dataset), flip);
+ return create_case_sink (&flip_sink_class, dict, flip);
}
/* Writes case C to the FLIP sink.
static void calc_stats (struct variable *v, double d[frq_n_stats]);
-static void precalc (const struct ccase *, void *);
-static bool calc (const struct ccase *, void *);
-static void postcalc (void *);
+static void precalc (const struct ccase *, void *, const struct dataset *);
+static bool calc (const struct ccase *, void *, const struct dataset *);
+static bool postcalc (void *, const struct dataset *);
static void postprocess_freq_tab (struct variable *);
static void dump_full (struct variable *);
\f
/* Parser and outline. */
-static int internal_cmd_frequencies (void);
+static int internal_cmd_frequencies (struct dataset *ds);
int
-cmd_frequencies (void)
+cmd_frequencies (struct dataset *ds)
{
int result;
int_pool = pool_create ();
- result = internal_cmd_frequencies ();
+ result = internal_cmd_frequencies (ds);
pool_destroy (int_pool);
int_pool=0;
pool_destroy (gen_pool);
}
static int
-internal_cmd_frequencies (void)
+internal_cmd_frequencies (struct dataset *ds)
{
int i;
bool ok;
n_variables = 0;
v_variables = NULL;
- if (!parse_frequencies (&cmd, NULL))
+ if (!parse_frequencies (ds, &cmd, NULL))
return CMD_FAILURE;
if (cmd.onepage_limit == NOT_LONG)
/* Do it! */
- ok = procedure_with_splits (current_dataset, precalc, calc, postcalc, NULL);
+ ok = procedure_with_splits (ds, precalc, calc, postcalc, NULL);
free_frequencies(&cmd);
/* Add data from case C to the frequency table. */
static bool
-calc (const struct ccase *c, void *aux UNUSED)
+calc (const struct ccase *c, void *aux UNUSED, const struct dataset *ds)
{
double weight;
size_t i;
bool bad_warn = true;
- weight = dict_get_case_weight (dataset_dict (current_dataset), c, &bad_warn);
+ weight = dict_get_case_weight (dataset_dict (ds), c, &bad_warn);
for (i = 0; i < n_variables; i++)
{
/* Prepares each variable that is the target of FREQUENCIES by setting
up its hash table. */
static void
-precalc (const struct ccase *first, void *aux UNUSED)
+precalc (const struct ccase *first, void *aux UNUSED, const struct dataset *ds)
{
size_t i;
- output_split_file_values (first);
+ output_split_file_values (ds, first);
pool_destroy (gen_pool);
gen_pool = pool_create ();
/* Finishes up with the variables after frequencies have been
calculated. Displays statistics, percentiles, ... */
-static void
-postcalc (void *aux UNUSED)
+static bool
+postcalc (void *aux UNUSED, const struct dataset *ds UNUSED)
{
size_t i;
cleanup_freq_tab (v);
}
+
+ return true;
}
/* Returns the comparison function that should be used for
/* Parses the VARIABLES subcommand, adding to
{n_variables,v_variables}. */
static int
-frq_custom_variables (struct cmd_frequencies *cmd UNUSED, void *aux UNUSED)
+frq_custom_variables (struct dataset *ds, struct cmd_frequencies *cmd UNUSED, void *aux UNUSED)
{
int mode;
int min = 0, max = 0;
lex_match ('=');
if (token != T_ALL && (token != T_ID
- || dict_lookup_var (dataset_dict (current_dataset), tokid) == NULL))
+ || dict_lookup_var (dataset_dict (ds), tokid) == NULL))
return 2;
- if (!parse_variables (dataset_dict (current_dataset), &v_variables, &n_variables,
+ if (!parse_variables (dataset_dict (ds), &v_variables, &n_variables,
PV_APPEND | PV_NO_SCRATCH))
return 0;
/* Parses the GROUPED subcommand, setting the n_grouped, grouped
fields of specified variables. */
static int
-frq_custom_grouped (struct cmd_frequencies *cmd UNUSED, void *aux UNUSED)
+frq_custom_grouped (struct dataset *ds, struct cmd_frequencies *cmd UNUSED, void *aux UNUSED)
{
lex_match ('=');
- if ((token == T_ID && dict_lookup_var (dataset_dict (current_dataset), tokid) != NULL)
+ if ((token == T_ID && dict_lookup_var (dataset_dict (ds), tokid) != NULL)
|| token == T_ID)
for (;;)
{
size_t n;
struct variable **v;
- if (!parse_variables (dataset_dict (current_dataset), &v, &n,
+ if (!parse_variables (dataset_dict (ds), &v, &n,
PV_NO_DUPLICATE | PV_NUMERIC))
return 0;
if (lex_match ('('))
free (v);
if (!lex_match ('/'))
break;
- if ((token != T_ID || dict_lookup_var (dataset_dict (current_dataset), tokid) != NULL)
+ if ((token != T_ID || dict_lookup_var (dataset_dict (ds), tokid) != NULL)
&& token != T_ALL)
{
lex_put_back ('/');
/* Parses and executes the T-TEST procedure. */
int
-cmd_means (void)
+cmd_means (struct dataset *ds)
{
struct cmd_means cmd;
int success = CMD_FAILURE;
v_dim = NULL;
v_var = NULL;
- if (!parse_means (&cmd, NULL))
+ if (!parse_means (ds, &cmd, NULL))
goto free;
if (cmd.sbc_cells)
/* Parses the TABLES subcommand. */
static int
-mns_custom_tables (struct cmd_means *cmd, void *aux UNUSED)
+mns_custom_tables (struct dataset *ds, struct cmd_means *cmd, void *aux UNUSED)
{
struct var_set *var_set;
if (!lex_match_id ("TABLES")
- && (token != T_ID || dict_lookup_var (dataset_dict (current_dataset), tokid) == NULL)
+ && (token != T_ID || dict_lookup_var (dataset_dict (ds), tokid) == NULL)
&& token != T_ALL)
return 2;
lex_match ('=');
return 0;
}
- var_set = var_set_create_from_dict (dataset_dict (current_dataset));
+ var_set = var_set_create_from_dict (dataset_dict (ds));
assert (var_set != NULL);
do
static bool run_oneway(const struct ccase *first,
- const struct casefile *cf, void *_mode);
+ const struct casefile *cf, void *_mode, const struct dataset *);
/* Routines to show the output tables */
int
-cmd_oneway(void)
+cmd_oneway (struct dataset *ds)
{
int i;
bool ok;
- if ( !parse_oneway(&cmd, NULL) )
+ if ( !parse_oneway (ds, &cmd, NULL) )
return CMD_FAILURE;
/* If /MISSING=INCLUDE is set, then user missing values are ignored */
}
}
- ok = multipass_procedure_with_splits (current_dataset, run_oneway, &cmd);
+ ok = multipass_procedure_with_splits (ds, run_oneway, &cmd);
free (vars);
free_oneway (&cmd);
/* Parser for the variables sub command */
static int
-oneway_custom_variables(struct cmd_oneway *cmd UNUSED, void *aux UNUSED)
+oneway_custom_variables(struct dataset *ds, struct cmd_oneway *cmd UNUSED, void *aux UNUSED)
{
+ struct dictionary *dict = dataset_dict (ds);
lex_match('=');
- if ((token != T_ID || dict_lookup_var (dataset_dict (current_dataset), tokid) == NULL)
+ if ((token != T_ID || dict_lookup_var (dict, tokid) == NULL)
&& token != T_ALL)
return 2;
-
- if (!parse_variables (dataset_dict (current_dataset), &vars, &n_vars,
+ if (!parse_variables (dict, &vars, &n_vars,
PV_DUPLICATE
| PV_NUMERIC | PV_NO_SCRATCH) )
{
if ( ! lex_match(T_BY))
return 2;
-
- indep_var = parse_variable();
+ indep_var = parse_variable (dict);
if ( !indep_var )
{
return 0;
}
-
return 1;
}
static bool
-run_oneway(const struct ccase *first, const struct casefile *cf, void *cmd_)
+run_oneway(const struct ccase *first, const struct casefile *cf, void *cmd_, const struct dataset *ds)
{
struct casereader *r;
struct ccase c;
struct cmd_oneway *cmd = (struct cmd_oneway *) cmd_;
- output_split_file_values (first);
+ output_split_file_values (ds, first);
global_group_hash = hsh_create(4,
(hsh_compare_func *) compare_values,
size_t i;
const double weight =
- dict_get_case_weight (dataset_dict (current_dataset), &c, &bad_weight_warn);
+ dict_get_case_weight (dataset_dict (ds), &c, &bad_weight_warn);
const union value *indep_val = case_data (&c, indep_var->fv);
if ( stat_tables & STAT_HOMO )
- levene(cf, indep_var, n_vars, vars,
+ levene (dataset_dict (ds), cf, indep_var, n_vars, vars,
(cmd->miss == ONEWAY_LISTWISE) ? LEV_LISTWISE : LEV_ANALYSIS ,
value_is_missing);
static struct casefile *rank_sorted_casefile (struct casefile *cf,
const struct sort_criteria *,
+ const struct dictionary *,
const struct rank_spec *rs,
int n_rank_specs,
int idx,
static bool
-rank_cmd (const struct sort_criteria *sc,
- const struct rank_spec *rank_specs, int n_rank_specs)
+rank_cmd (struct dataset *ds, const struct sort_criteria *sc,
+ const struct rank_spec *rank_specs, int n_rank_specs)
{
struct sort_criteria criteria;
bool result = true;
int i;
- const int n_splits = dict_get_split_cnt (dataset_dict (current_dataset));
+ const int n_splits = dict_get_split_cnt (dataset_dict (ds));
criteria.crit_cnt = n_splits + n_group_vars + 1;
criteria.crits = xnmalloc (criteria.crit_cnt, sizeof *criteria.crits);
for (i = 0; i < n_splits ; i++)
{
- struct variable *v = dict_get_split_vars (dataset_dict (current_dataset))[i];
+ struct variable *v = dict_get_split_vars (dataset_dict (ds))[i];
criteria.crits[i].fv = v->fv;
criteria.crits[i].width = v->width;
criteria.crits[i].dir = SRT_ASCEND;
struct casefile *sorted_cf ;
/* Obtain active file in CF. */
- if (!procedure (current_dataset, NULL, NULL))
+ if (!procedure (ds, NULL, NULL))
goto error;
- cf = proc_capture_output (current_dataset);
+ cf = proc_capture_output (ds);
/* Sort CF into SORTED_CF. */
reader = casefile_get_destructive_reader (cf) ;
casefile_destroy (cf);
out = rank_sorted_casefile (sorted_cf, &criteria,
+ dataset_dict (ds),
rank_specs, n_rank_specs,
i, &src_vars[i]->miss) ;
if ( NULL == out )
continue ;
}
- proc_set_source (current_dataset, storage_source_create (out));
+ proc_set_source (ds, storage_source_create (out));
}
free (criteria.crits);
static void
rank_cases (struct casereader *cr,
unsigned long end,
+ const struct dictionary *dict,
const struct sort_criterion *criterion,
const struct missing_values *mv,
double w,
break;
this_value = case_data (&this_case, fv);
- c = dict_get_case_weight (dataset_dict (current_dataset), &this_case, &warn);
+ c = dict_get_case_weight (dict, &this_case, &warn);
lookahead = casereader_clone (cr);
n = 0;
break;
}
- c += dict_get_case_weight (dataset_dict (current_dataset), &lookahead_case, &warn);
+ c += dict_get_case_weight (dict, &lookahead_case, &warn);
case_destroy (&lookahead_case);
n++;
}
static struct casefile *
rank_sorted_casefile (struct casefile *cf,
const struct sort_criteria *crit,
+ const struct dictionary *dict,
const struct rank_spec *rs,
int n_rank_specs,
int dest_idx,
this_value = case_data( &group_case, ultimate_crit->fv);
if ( !value_is_missing(mv, this_value) )
- w = dict_get_case_weight (dataset_dict (current_dataset), &group_case, &warn);
+ w = dict_get_case_weight (dict, &group_case, &warn);
while (casereader_read (lookahead, &this_case))
{
const union value *this_value =
case_data(&this_case, ultimate_crit->fv);
- double c = dict_get_case_weight (dataset_dict (current_dataset), &this_case, &warn);
+ double c = dict_get_case_weight (dict, &this_case, &warn);
if (!same_group (&group_case, &this_case, crit))
{
rank_cases (pos, casereader_cnum (lookahead) - 1,
+ dict,
ultimate_crit,
mv, w,
rs, n_rank_specs,
case_destroy (&this_case);
}
case_destroy (&group_case);
- rank_cases (pos, ULONG_MAX, ultimate_crit, mv, w,
+ rank_cases (pos, ULONG_MAX, dict, ultimate_crit, mv, w,
rs, n_rank_specs, dest_idx, dest);
}
If VNAME is NULL, then a name will be automatically chosen.
*/
static struct variable *
-create_rank_variable (enum RANK_FUNC f,
+create_rank_variable (struct dictionary *dict, enum RANK_FUNC f,
const struct variable *src_var,
const char *vname)
{
char name[SHORT_NAME_LEN + 1];
if ( vname )
- var = dict_create_var(dataset_dict (current_dataset), vname, 0);
+ var = dict_create_var(dict, vname, 0);
if ( NULL == var )
{
snprintf(name, SHORT_NAME_LEN + 1, "%c%s",
function_name[f][0], src_var->name);
- var = dict_create_var(dataset_dict (current_dataset), name, 0);
+ var = dict_create_var(dict, name, 0);
}
i = 1;
snprintf(name, SHORT_NAME_LEN + 1, "%s%03d", func_abb,
i);
- var = dict_create_var(dataset_dict (current_dataset), name, 0);
+ var = dict_create_var(dict, name, 0);
if (i++ >= 999)
break;
}
snprintf(name, SHORT_NAME_LEN + 1,
"RNK%s%02d", func_abb, i);
- var = dict_create_var(dataset_dict (current_dataset), name, 0);
+ var = dict_create_var(dict, name, 0);
if ( i++ >= 99 )
break;
}
return var;
}
-int cmd_rank(void);
+int cmd_rank(struct dataset *ds);
static void
rank_cleanup(void)
}
int
-cmd_rank(void)
+cmd_rank (struct dataset *ds)
{
bool result;
struct variable *order;
size_t i;
n_rank_specs = 0;
- if ( !parse_rank(&cmd, NULL) )
+ if ( !parse_rank (ds, &cmd, NULL) )
{
rank_cleanup ();
return CMD_FAILURE;
if ( rank_specs[i].destvars[v] == NULL )
{
rank_specs[i].destvars[v] =
- create_rank_variable (rank_specs[i].rfunc, src_vars[v], NULL);
+ create_rank_variable (dataset_dict(ds), rank_specs[i].rfunc, src_vars[v], NULL);
}
create_var_label ( rank_specs[i].destvars[v],
/* Add a variable which we can sort by to get back the original
order */
- order = dict_create_var_assert (dataset_dict (current_dataset), "$ORDER_", 0);
+ order = dict_create_var_assert (dataset_dict (ds), "$ORDER_", 0);
- add_transformation (current_dataset, create_resort_key, 0, order);
+ add_transformation (ds, create_resort_key, 0, order);
/* Do the ranking */
- result = rank_cmd (sc, rank_specs, n_rank_specs);
+ result = rank_cmd (ds, sc, rank_specs, n_rank_specs);
/* Put the active file back in its original order */
{
criteria.crits = &restore_criterion;
criteria.crit_cnt = 1;
- sort_active_file_in_place (&criteria);
+ sort_active_file_in_place (ds, &criteria);
}
/* ... and we don't need our sort key anymore. So delete it */
- dict_delete_var (dataset_dict (current_dataset), order);
+ dict_delete_var (dataset_dict (ds), order);
rank_cleanup();
/* Parser for the variables sub command
Returns 1 on success */
static int
-rank_custom_variables(struct cmd_rank *cmd UNUSED, void *aux UNUSED)
+rank_custom_variables (struct dataset *ds, struct cmd_rank *cmd UNUSED, void *aux UNUSED)
{
static const int terminators[2] = {T_BY, 0};
lex_match('=');
- if ((token != T_ID || dict_lookup_var (dataset_dict (current_dataset), tokid) == NULL)
+ if ((token != T_ID || dict_lookup_var (dataset_dict (ds), tokid) == NULL)
&& token != T_ALL)
return 2;
- sc = sort_parse_criteria (dataset_dict (current_dataset),
+ sc = sort_parse_criteria (dataset_dict (ds),
&src_vars, &n_src_vars, 0, terminators);
if ( lex_match(T_BY) )
{
- if ((token != T_ID || dict_lookup_var (dataset_dict (current_dataset), tokid) == NULL))
+ if ((token != T_ID || dict_lookup_var (dataset_dict (ds), tokid) == NULL))
{
return 2;
}
- if (!parse_variables (dataset_dict (current_dataset), &group_vars, &n_group_vars,
+ if (!parse_variables (dataset_dict (ds), &group_vars, &n_group_vars,
PV_NO_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH) )
{
free (group_vars);
/* Parse the [/rank INTO var1 var2 ... varN ] clause */
static int
-parse_rank_function(struct cmd_rank *cmd UNUSED, enum RANK_FUNC f)
+parse_rank_function(struct dictionary *dict, struct cmd_rank *cmd UNUSED, enum RANK_FUNC f)
{
int var_count = 0;
while( token == T_ID )
{
- if ( dict_lookup_var (dataset_dict (current_dataset), tokid) != NULL )
+ if ( dict_lookup_var (dict, tokid) != NULL )
{
msg(SE, _("Variable %s already exists."), tokid);
return 0;
return 0;
}
- destvar = create_rank_variable (f, src_vars[var_count], tokid);
+ destvar = create_rank_variable (dict, f, src_vars[var_count], tokid);
rank_specs[n_rank_specs - 1].destvars[var_count] = destvar ;
lex_get();
static int
-rank_custom_rank(struct cmd_rank *cmd, void *aux UNUSED )
+rank_custom_rank(struct dataset *ds, struct cmd_rank *cmd, void *aux UNUSED )
{
- return parse_rank_function(cmd, RANK);
+ struct dictionary *dict = dataset_dict (ds);
+
+ return parse_rank_function (dict, cmd, RANK);
}
static int
-rank_custom_normal(struct cmd_rank *cmd, void *aux UNUSED )
+rank_custom_normal(struct dataset *ds, struct cmd_rank *cmd, void *aux UNUSED )
{
- return parse_rank_function(cmd, NORMAL);
+ struct dictionary *dict = dataset_dict (ds);
+
+ return parse_rank_function (dict, cmd, NORMAL);
}
static int
-rank_custom_percent(struct cmd_rank *cmd, void *aux UNUSED )
+rank_custom_percent(struct dataset *ds, struct cmd_rank *cmd, void *aux UNUSED )
{
- return parse_rank_function (cmd, PERCENT);
+ struct dictionary *dict = dataset_dict (ds);
+
+ return parse_rank_function (dict, cmd, PERCENT);
}
static int
-rank_custom_rfraction(struct cmd_rank *cmd, void *aux UNUSED )
+rank_custom_rfraction(struct dataset *ds, struct cmd_rank *cmd, void *aux UNUSED )
{
- return parse_rank_function(cmd, RFRACTION);
+ struct dictionary *dict = dataset_dict (ds);
+
+ return parse_rank_function (dict, cmd, RFRACTION);
}
static int
-rank_custom_proportion(struct cmd_rank *cmd, void *aux UNUSED )
+rank_custom_proportion(struct dataset *ds, struct cmd_rank *cmd, void *aux UNUSED )
{
- return parse_rank_function(cmd, PROPORTION);
+ struct dictionary *dict = dataset_dict (ds);
+
+ return parse_rank_function (dict, cmd, PROPORTION);
}
static int
-rank_custom_n(struct cmd_rank *cmd, void *aux UNUSED )
+rank_custom_n (struct dataset *ds, struct cmd_rank *cmd, void *aux UNUSED )
{
- return parse_rank_function(cmd, N);
+ struct dictionary *dict = dataset_dict (ds);
+
+ return parse_rank_function (dict, cmd, N);
}
static int
-rank_custom_savage(struct cmd_rank *cmd, void *aux UNUSED )
+rank_custom_savage(struct dataset *ds, struct cmd_rank *cmd, void *aux UNUSED )
{
- return parse_rank_function(cmd, SAVAGE);
+ struct dictionary *dict = dataset_dict (ds);
+
+ return parse_rank_function (dict, cmd, SAVAGE);
}
static int
-rank_custom_ntiles(struct cmd_rank *cmd, void *aux UNUSED )
+rank_custom_ntiles (struct dataset *ds, struct cmd_rank *cmd, void *aux UNUSED )
{
+ struct dictionary *dict = dataset_dict (ds);
+
if ( lex_force_match('(') )
{
if ( lex_force_int() )
else
return 0;
- return parse_rank_function(cmd, NTILES);
+ return parse_rank_function(dict, cmd, NTILES);
}
static int pspp_reg_rc = CMD_SUCCESS;
static bool run_regression (const struct ccase *,
- const struct casefile *, void *);
+ const struct casefile *, void *,
+ const struct dataset *);
/*
STATISTICS subcommand output functions.
}
/*
- Returns 0 if NAME is a duplicate of any existing variable name.
+ Returns false if NAME is a duplicate of any existing variable name.
*/
-static int
-try_name (char *name)
+static bool
+try_name (const struct dictionary *dict, const char *name)
{
- if (dict_lookup_var (dataset_dict (current_dataset), name) != NULL)
- return 0;
+ if (dict_lookup_var (dict, name) != NULL)
+ return false;
- return 1;
+ return true;
}
+
static void
-reg_get_name (char name[LONG_NAME_LEN], const char prefix[LONG_NAME_LEN])
+reg_get_name (const struct dictionary *dict, char name[LONG_NAME_LEN], const char prefix[LONG_NAME_LEN])
{
int i = 1;
snprintf (name, LONG_NAME_LEN, "%s%d", prefix, i);
- while (!try_name (name))
+ while (!try_name (dict, name))
{
i++;
snprintf (name, LONG_NAME_LEN, "%s%d", prefix, i);
}
}
+
static void
-reg_save_var (const char *prefix, trns_proc_func * f,
+reg_save_var (struct dataset *ds, const char *prefix, trns_proc_func * f,
pspp_linreg_cache * c, struct variable **v, int n_trns)
{
+ struct dictionary *dict = dataset_dict (ds);
static int trns_index = 1;
char name[LONG_NAME_LEN];
struct variable *new_var;
t->trns_id = trns_index;
t->n_trns = n_trns;
t->c = c;
- reg_get_name (name, prefix);
- new_var = dict_create_var (dataset_dict (current_dataset), name, 0);
+ reg_get_name (dict, name, prefix);
+ new_var = dict_create_var (dict, name, 0);
assert (new_var != NULL);
*v = new_var;
- add_transformation (current_dataset, f, regression_trns_free, t);
+ add_transformation (ds, f, regression_trns_free, t);
trns_index++;
}
+
static void
-subcommand_save (int save, pspp_linreg_cache ** models)
+subcommand_save (struct dataset *ds, int save, pspp_linreg_cache ** models)
{
pspp_linreg_cache **lc;
int n_trns = 0;
assert ((*lc)->depvar != NULL);
if (cmd.a_save[REGRESSION_SV_RESID])
{
- reg_save_var ("RES", regression_trns_resid_proc, *lc,
+ reg_save_var (ds, "RES", regression_trns_resid_proc, *lc,
&(*lc)->resid, n_trns);
}
if (cmd.a_save[REGRESSION_SV_PRED])
{
- reg_save_var ("PRED", regression_trns_pred_proc, *lc,
+ reg_save_var (ds, "PRED", regression_trns_pred_proc, *lc,
&(*lc)->pred, n_trns);
}
}
}
}
}
+
static int
reg_inserted (const struct variable *v, struct variable **varlist, int n_vars)
{
}
return 0;
}
+
static void
reg_print_categorical_encoding (FILE * fp, pspp_linreg_cache * c)
{
fclose (fp);
}
}
+
static int
-regression_custom_export (struct cmd_regression *cmd UNUSED, void *aux UNUSED)
+regression_custom_export (struct dataset *ds UNUSED, struct cmd_regression *cmd UNUSED, void *aux UNUSED)
{
/* 0 on failure, 1 on success, 2 on failure that should result in syntax error */
if (!lex_force_match ('('))
}
int
-cmd_regression (void)
+cmd_regression (struct dataset *ds)
{
- if (!parse_regression (&cmd, NULL))
+ if (!parse_regression (ds, &cmd, NULL))
return CMD_FAILURE;
models = xnmalloc (cmd.n_dependent, sizeof *models);
- if (!multipass_procedure_with_splits (current_dataset, run_regression, &cmd))
+ if (!multipass_procedure_with_splits (ds, run_regression, &cmd))
return CMD_CASCADING_FAILURE;
- subcommand_save (cmd.sbc_save, models);
+ subcommand_save (ds, cmd.sbc_save, models);
free (v_variables);
free (models);
return pspp_reg_rc;
/* Parser for the variables sub command */
static int
-regression_custom_variables (struct cmd_regression *cmd UNUSED,
+regression_custom_variables (struct dataset *ds,
+ struct cmd_regression *cmd UNUSED,
void *aux UNUSED)
{
+ const struct dictionary *dict = dataset_dict (ds);
lex_match ('=');
- if ((token != T_ID || dict_lookup_var (dataset_dict (current_dataset), tokid) == NULL)
+ if ((token != T_ID || dict_lookup_var (dict, tokid) == NULL)
&& token != T_ALL)
return 2;
- if (!parse_variables (dataset_dict (current_dataset), &v_variables, &n_variables, PV_NONE))
+ if (!parse_variables (dict, &v_variables, &n_variables, PV_NONE))
{
free (v_variables);
return 0;
static bool
run_regression (const struct ccase *first,
- const struct casefile *cf, void *cmd_ UNUSED)
+ const struct casefile *cf, void *cmd_ UNUSED, const struct dataset *ds)
{
size_t i;
size_t n_data = 0; /* Number of valide cases. */
assert (models != NULL);
- output_split_file_values (first);
+ output_split_file_values (ds, first);
if (!v_variables)
{
- dict_get_vars (dataset_dict (current_dataset), &v_variables, &n_variables,
+ dict_get_vars (dataset_dict (ds), &v_variables, &n_variables,
1u << DC_SYSTEM);
}
/* Performs the SORT CASES procedures. */
int
-cmd_sort_cases (void)
+cmd_sort_cases (struct dataset *ds)
{
struct sort_criteria *criteria;
bool success = false;
lex_match (T_BY);
- criteria = sort_parse_criteria (dataset_dict (current_dataset), NULL, NULL, NULL, NULL);
+ criteria = sort_parse_criteria (dataset_dict (ds), NULL, NULL, NULL, NULL);
if (criteria == NULL)
return CMD_CASCADING_FAILURE;
lex_get ();
}
- success = sort_active_file_in_place (criteria);
+ success = sort_active_file_in_place (ds, criteria);
done:
min_buffers = 64;
};
-static int common_calc (const struct ccase *, void *);
+static int common_calc (const struct dictionary *dict,
+ const struct ccase *, void *);
static void common_precalc (struct cmd_t_test *);
static void common_postcalc (struct cmd_t_test *);
-static int one_sample_calc (const struct ccase *, void *);
+static int one_sample_calc (const struct dictionary *dict, const struct ccase *, void *);
static void one_sample_precalc (struct cmd_t_test *);
static void one_sample_postcalc (struct cmd_t_test *);
-static int paired_calc (const struct ccase *, void *);
+static int paired_calc (const struct dictionary *dict, const struct ccase *, void *);
static void paired_precalc (struct cmd_t_test *);
static void paired_postcalc (struct cmd_t_test *);
static void group_precalc (struct cmd_t_test *);
-static int group_calc (const struct ccase *, struct cmd_t_test *);
+static int group_calc (const struct dictionary *dict, const struct ccase *, struct cmd_t_test *);
static void group_postcalc (struct cmd_t_test *);
static bool calculate(const struct ccase *first,
- const struct casefile *cf, void *_mode);
+ const struct casefile *cf, void *_mode,
+ const struct dataset *ds);
static int mode;
int
-cmd_t_test(void)
+cmd_t_test (struct dataset *ds)
{
bool ok;
- if ( !parse_t_test(&cmd, NULL) )
+ if ( !parse_t_test (ds, &cmd, NULL) )
return CMD_FAILURE;
if (! cmd.sbc_criteria)
bad_weight_warn = true;
- ok = multipass_procedure_with_splits (current_dataset, calculate, &cmd);
+ ok = multipass_procedure_with_splits (ds, calculate, &cmd);
n_pairs=0;
free(pairs);
}
static int
-tts_custom_groups (struct cmd_t_test *cmd UNUSED, void *aux UNUSED)
+tts_custom_groups (struct dataset *ds, struct cmd_t_test *cmd UNUSED, void *aux UNUSED)
{
int n_group_values=0;
lex_match('=');
- indep_var = parse_variable ();
+ indep_var = parse_variable (dataset_dict (ds));
if (!indep_var)
{
lex_error ("expecting variable name in GROUPS subcommand");
static int
-tts_custom_pairs (struct cmd_t_test *cmd UNUSED, void *aux UNUSED)
+tts_custom_pairs (struct dataset *ds, struct cmd_t_test *cmd UNUSED, void *aux UNUSED)
{
struct variable **vars;
size_t n_vars;
lex_match('=');
n_vars=0;
- if (!parse_variables (dataset_dict (current_dataset), &vars, &n_vars,
+ if (!parse_variables (dataset_dict (ds), &vars, &n_vars,
PV_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH))
{
free (vars);
if (lex_match (T_WITH))
{
n_before_WITH = n_vars;
- if (!parse_variables (dataset_dict (current_dataset), &vars, &n_vars,
+ if (!parse_variables (dataset_dict (ds), &vars, &n_vars,
PV_DUPLICATE | PV_APPEND
| PV_NUMERIC | PV_NO_SCRATCH))
{
/* Per case calculations common to all variants of the T test */
static int
-common_calc (const struct ccase *c, void *_cmd)
+common_calc (const struct dictionary *dict, const struct ccase *c, void *_cmd)
{
int i;
struct cmd_t_test *cmd = (struct cmd_t_test *)_cmd;
- double weight = dict_get_case_weight (dataset_dict (current_dataset), c, &bad_weight_warn);
+ double weight = dict_get_case_weight (dict, c, &bad_weight_warn);
/* Skip the entire case if /MISSING=LISTWISE is set */
/* Per case calculations for one sample t test */
static int
-one_sample_calc (const struct ccase *c, void *cmd_)
+one_sample_calc (const struct dictionary *dict,
+ const struct ccase *c, void *cmd_)
{
int i;
struct cmd_t_test *cmd = (struct cmd_t_test *)cmd_;
- double weight = dict_get_case_weight (dataset_dict (current_dataset), c, &bad_weight_warn);
+ double weight = dict_get_case_weight (dict, c, &bad_weight_warn);
/* Skip the entire case if /MISSING=LISTWISE is set */
if ( cmd->miss == TTS_LISTWISE )
static int
-paired_calc (const struct ccase *c, void *cmd_)
+paired_calc (const struct dictionary *dict, const struct ccase *c, void *cmd_)
{
int i;
struct cmd_t_test *cmd = (struct cmd_t_test *) cmd_;
- double weight = dict_get_case_weight (dataset_dict (current_dataset), c, &bad_weight_warn);
+ double weight = dict_get_case_weight (dict, c, &bad_weight_warn);
/* Skip the entire case if /MISSING=LISTWISE is set ,
AND one member of a pair is missing */
}
static int
-group_calc (const struct ccase *c, struct cmd_t_test *cmd)
+group_calc (const struct dictionary *dict,
+ const struct ccase *c, struct cmd_t_test *cmd)
{
int i;
const union value *gv = case_data (c, indep_var->fv);
const double weight =
- dict_get_case_weight (dataset_dict (current_dataset), c, &bad_weight_warn);
+ dict_get_case_weight (dict, c, &bad_weight_warn);
if ( value_is_missing(&indep_var->miss, gv) )
{
static bool
-calculate(const struct ccase *first, const struct casefile *cf, void *cmd_)
+calculate(const struct ccase *first, const struct casefile *cf,
+ void *cmd_, const struct dataset *ds)
{
+ const struct dictionary *dict = dataset_dict (ds);
struct ssbox stat_summary_box;
struct trbox test_results_box;
struct cmd_t_test *cmd = (struct cmd_t_test *) cmd_;
- output_split_file_values (first);
+ output_split_file_values (ds, first);
common_precalc(cmd);
for(r = casefile_get_reader (cf);
casereader_read (r, &c) ;
case_destroy (&c))
{
- common_calc(&c,cmd);
+ common_calc(dict, &c,cmd);
}
casereader_destroy (r);
common_postcalc(cmd);
casereader_read (r, &c) ;
case_destroy (&c))
{
- one_sample_calc(&c,cmd);
+ one_sample_calc (dict, &c,cmd);
}
casereader_destroy (r);
one_sample_postcalc(cmd);
casereader_read (r, &c) ;
case_destroy (&c))
{
- paired_calc(&c,cmd);
+ paired_calc (dict, &c,cmd);
}
casereader_destroy (r);
- paired_postcalc(cmd);
+ paired_postcalc (cmd);
break;
case T_IND_SAMPLES:
casereader_read (r, &c) ;
case_destroy (&c))
{
- group_calc(&c,cmd);
+ group_calc (dict, &c, cmd);
}
casereader_destroy (r);
group_postcalc(cmd);
- levene(cf, indep_var, cmd->n_variables, cmd->v_variables,
+ levene (dict, cf, indep_var, cmd->n_variables, cmd->v_variables,
(cmd->miss == TTS_LISTWISE)?LEV_LISTWISE:LEV_ANALYSIS ,
value_is_missing);
break;
static void fail_test (const char *message, ...);
int
-cmd_debug_casefile (void)
+cmd_debug_casefile (struct dataset *ds UNUSED)
{
static const size_t sizes[] =
{
#include <math.h>
#include <stdlib.h>
#include "xalloc.h"
+#include <libpspp/compiler.h>
#define _(msgid) gettext (msgid)
}
int
-cmd_debug_moments (void)
+cmd_debug_moments (struct dataset *ds UNUSED)
{
int retval = CMD_FAILURE;
double *values = NULL;
/* Self-test routine.
This is not exhaustive, but it can be useful. */
int
-cmd_debug_pool (void)
+cmd_debug_pool (struct dataset *ds UNUSED)
{
int seed = time (0) * 257 % 32768;
/* Stub for USE command. */
int
-cmd_use (void)
+cmd_use (struct dataset *ds UNUSED)
{
if (lex_match (T_ALL))
return lex_end_of_command ();
/* Echos a string to the output stream */
int
-cmd_echo(void)
+cmd_echo (struct dataset *ds UNUSED)
{
struct tab_table *tab;
#define _(msgid) gettext (msgid)
int
-cmd_include (void)
+cmd_include (struct dataset *ds UNUSED)
{
/* Skip optional FILE=. */
if (lex_match_id ("FILE"))
/* Parses the PERMISSIONS command. */
int
-cmd_permissions (void)
+cmd_permissions (struct dataset *ds UNUSED)
{
char *fn = 0;
static bool do_cc (const char *cc_string, int idx);
int
-cmd_set (void)
+cmd_set (struct dataset *ds)
{
struct cmd_set cmd;
bool ok = true;
- if (!parse_set (&cmd, NULL))
+ if (!parse_set (ds, &cmd, NULL))
return CMD_FAILURE;
if (cmd.sbc_cca)
completely blank fields in numeric data imply. X, Wnd: Syntax is
SYSMIS or a numeric value. */
static int
-stc_custom_blanks (struct cmd_set *cmd UNUSED, void *aux UNUSED)
+stc_custom_blanks (struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
{
lex_match ('=');
if ((token == T_ID && lex_id_match ("SYSMIS", tokid)))
/* Parses the EPOCH subcommand, which controls the epoch used for
parsing 2-digit years. */
static int
-stc_custom_epoch (struct cmd_set *cmd UNUSED, void *aux UNUSED)
+stc_custom_epoch (struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
{
lex_match ('=');
if (lex_match_id ("AUTOMATIC"))
}
static int
-stc_custom_length (struct cmd_set *cmd UNUSED, void *aux UNUSED)
+stc_custom_length (struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
{
int page_length;
}
static int
-stc_custom_seed (struct cmd_set *cmd UNUSED, void *aux UNUSED)
+stc_custom_seed (struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
{
lex_match ('=');
if (lex_match_id ("RANDOM"))
}
static int
-stc_custom_width (struct cmd_set *cmd UNUSED, void *aux UNUSED)
+stc_custom_width (struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
{
lex_match ('=');
if (lex_match_id ("NARROW"))
/* Parses FORMAT subcommand, which consists of a numeric format
specifier. */
static int
-stc_custom_format (struct cmd_set *cmd UNUSED, void *aux UNUSED)
+stc_custom_format (struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
{
struct fmt_spec fmt;
}
static int
-stc_custom_journal (struct cmd_set *cmd UNUSED, void *aux UNUSED)
+stc_custom_journal (struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
{
lex_match ('=');
if (!lex_match_id ("ON") && !lex_match_id ("OFF"))
}
static int
-stc_custom_listing (struct cmd_set *cmd UNUSED, void *aux UNUSED)
+stc_custom_listing (struct dataset *ds UNUSED, struct cmd_set *cmd UNUSED, void *aux UNUSED)
{
bool listing;
}
static int
-stc_custom_disk (struct cmd_set *cmd UNUSED, void *aux)
+stc_custom_disk (struct dataset *ds, struct cmd_set *cmd UNUSED, void *aux)
{
- return stc_custom_listing (cmd, aux);
+ return stc_custom_listing (ds, cmd, aux);
}
\f
static void
-show_blanks (void)
+show_blanks (const struct dataset *ds UNUSED)
{
if (get_blanks () == SYSMIS)
msg (SN, _("BLANKS is SYSMIS."));
static void
-show_cca (void)
+show_cca (const struct dataset *ds UNUSED)
{
show_cc (0);
}
static void
-show_ccb (void)
+show_ccb (const struct dataset *ds UNUSED)
{
show_cc (1);
}
static void
-show_ccc (void)
+show_ccc (const struct dataset *ds UNUSED)
{
show_cc (2);
}
static void
-show_ccd (void)
+show_ccd (const struct dataset *ds UNUSED)
{
show_cc (3);
}
static void
-show_cce (void)
+show_cce (const struct dataset *ds UNUSED)
{
show_cc (4);
}
static void
-show_decimals (void)
+show_decimals (const struct dataset *ds UNUSED)
{
msg (SN, _("DECIMAL is \"%c\"."), get_decimal ());
}
static void
-show_endcmd (void)
+show_endcmd (const struct dataset *ds UNUSED)
{
msg (SN, _("ENDCMD is \"%c\"."), get_endcmd ());
}
static void
-show_format (void)
+show_format (const struct dataset *ds UNUSED)
{
msg (SN, _("FORMAT is %s."), fmt_to_string (get_format ()));
}
static void
-show_length (void)
+show_length (const struct dataset *ds UNUSED)
{
msg (SN, _("LENGTH is %d."), get_viewlength ());
}
static void
-show_mxerrs (void)
+show_mxerrs (const struct dataset *ds UNUSED)
{
msg (SN, _("MXERRS is %d."), get_mxerrs ());
}
static void
-show_mxloops (void)
+show_mxloops (const struct dataset *ds UNUSED)
{
msg (SN, _("MXLOOPS is %d."), get_mxloops ());
}
static void
-show_mxwarns (void)
+show_mxwarns (const struct dataset *ds UNUSED)
{
msg (SN, _("MXWARNS is %d."), get_mxwarns ());
}
static void
-show_scompression (void)
+show_scompression (const struct dataset *ds UNUSED)
{
if (get_scompression ())
msg (SN, _("SCOMPRESSION is ON."));
}
static void
-show_undefined (void)
+show_undefined (const struct dataset *ds UNUSED)
{
if (get_undefined ())
msg (SN, _("UNDEFINED is WARN."));
}
static void
-show_weight (void)
+show_weight (const struct dataset *ds)
{
- struct variable *var = dict_get_weight (dataset_dict (current_dataset));
+ struct variable *var = dict_get_weight (dataset_dict (ds));
if (var == NULL)
msg (SN, _("WEIGHT is off."));
else
}
static void
-show_width (void)
+show_width (const struct dataset *ds UNUSED)
{
msg (SN, _("WIDTH is %d."), get_viewwidth ());
}
struct show_sbc
{
const char *name;
- void (*function) (void);
+ void (*function) (const struct dataset *);
};
const struct show_sbc show_table[] =
};
static void
-show_all (void)
+show_all (const struct dataset *ds)
{
size_t i;
for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
- show_table[i].function ();
+ show_table[i].function (ds);
}
static void
}
static void
-show_warranty (void)
+show_warranty (const struct dataset *ds UNUSED)
{
msg (MN, lack_of_warranty);
}
static void
-show_copying (void)
+show_copying (const struct dataset *ds UNUSED)
{
msg (MN, copyleft);
}
int
-cmd_show (void)
+cmd_show (struct dataset *ds)
{
if (token == '.')
{
- show_all ();
+ show_all (ds);
return CMD_SUCCESS;
}
do
{
if (lex_match (T_ALL))
- show_all ();
+ show_all (ds);
else if (lex_match_id ("CC"))
show_all_cc ();
else if (lex_match_id ("WARRANTY"))
- show_warranty ();
+ show_warranty (ds);
else if (lex_match_id ("COPYING"))
- show_copying ();
+ show_copying (ds);
else if (token == T_ID)
{
int i;
for (i = 0; i < sizeof show_table / sizeof *show_table; i++)
if (lex_match_id (show_table[i].name))
{
- show_table[i].function ();
+ show_table[i].function (ds);
goto found;
}
lex_error (NULL);
static int get_title (const char *cmd, char **title);
int
-cmd_title (void)
+cmd_title (struct dataset *ds UNUSED)
{
return get_title ("TITLE", &outp_title);
}
int
-cmd_subtitle (void)
+cmd_subtitle (struct dataset *ds UNUSED)
{
return get_title ("SUBTITLE", &outp_subtitle);
}
/* Performs the FILE LABEL command. */
int
-cmd_file_label (void)
+cmd_file_label (struct dataset *ds)
{
const char *label;
while (isspace ((unsigned char) *label))
label++;
- dict_set_label (dataset_dict (current_dataset), label);
+ dict_set_label (dataset_dict (ds), label);
token = '.';
return CMD_SUCCESS;
}
-/* Add LINE as a line of document information to dataset_dict (current_dataset),
+/* Add LINE as a line of document information to dictionary
indented by INDENT spaces. */
static void
-add_document_line (const char *line, int indent)
+add_document_line (struct dictionary *dict, const char *line, int indent)
{
const char *old_documents;
size_t old_len;
char *new_documents;
- old_documents = dict_get_documents (dataset_dict (current_dataset));
+ old_documents = dict_get_documents (dict);
old_len = old_documents != NULL ? strlen (old_documents) : 0;
new_documents = xmalloc (old_len + 81);
buf_copy_str_rpad (new_documents + old_len + indent, 80 - indent, line);
new_documents[old_len + 80] = '\0';
- dict_set_documents (dataset_dict (current_dataset), new_documents);
+ dict_set_documents (dict, new_documents);
free (new_documents);
}
/* Performs the DOCUMENT command. */
int
-cmd_document (void)
+cmd_document (struct dataset *ds)
{
+ struct dictionary *dict = dataset_dict (ds);
/* Add a few header lines for reference. */
{
char buf[256];
- if (dict_get_documents (dataset_dict (current_dataset)) != NULL)
- add_document_line ("", 0);
+ if (dict && dict_get_documents (dict))
+ add_document_line (dict, "", 0);
sprintf (buf, _("Document entered %s by %s:"), get_start_date (), version);
- add_document_line (buf, 1);
+ add_document_line (dict, buf, 1);
}
for (;;)
if (had_dot)
strcat (copy_line, ".");
- add_document_line (copy_line, 3);
+ add_document_line (dict, copy_line, 3);
free (copy_line);
lex_get_line ();
/* Performs the DROP DOCUMENTS command. */
int
-cmd_drop_documents (void)
+cmd_drop_documents (struct dataset *ds)
{
- dict_set_documents (dataset_dict (current_dataset), NULL);
+ dict_set_documents (dataset_dict (ds), NULL);
return lex_end_of_command ();
}
/* Target of a COMPUTE or IF assignment, either a variable or a
vector element. */
-static struct lvalue *lvalue_parse (void);
-static int lvalue_get_type (const struct lvalue *);
+static struct lvalue *lvalue_parse (struct dataset *);
+static int lvalue_get_type (const struct lvalue *, const struct dictionary *);
static bool lvalue_is_vector (const struct lvalue *);
static void lvalue_finalize (struct lvalue *,
- struct compute_trns *);
+ struct compute_trns *, struct dictionary *);
static void lvalue_destroy (struct lvalue *);
/* COMPUTE and IF transformation. */
struct expression *rvalue; /* Rvalue expression. */
};
-static struct expression *parse_rvalue (const struct lvalue *);
+static struct expression *parse_rvalue (const struct lvalue *, struct dataset *);
static struct compute_trns *compute_trns_create (void);
-static trns_proc_func *get_proc_func (const struct lvalue *);
+static trns_proc_func *get_proc_func (const struct lvalue *, const struct dictionary *);
static trns_free_func compute_trns_free;
\f
/* COMPUTE. */
int
-cmd_compute (void)
+cmd_compute (struct dataset *ds)
{
+ struct dictionary *dict = dataset_dict (ds);
struct lvalue *lvalue = NULL;
struct compute_trns *compute = NULL;
compute = compute_trns_create ();
- lvalue = lvalue_parse ();
+ lvalue = lvalue_parse (ds);
if (lvalue == NULL)
goto fail;
if (!lex_force_match ('='))
goto fail;
- compute->rvalue = parse_rvalue (lvalue);
+ compute->rvalue = parse_rvalue (lvalue, ds);
if (compute->rvalue == NULL)
goto fail;
- add_transformation (current_dataset,
- get_proc_func (lvalue), compute_trns_free, compute);
+ add_transformation (ds, get_proc_func (lvalue, dict),
+ compute_trns_free, compute);
- lvalue_finalize (lvalue, compute);
+ lvalue_finalize (lvalue, compute, dict);
return lex_end_of_command ();
/* Handle COMPUTE or IF with numeric target variable. */
static int
-compute_num (void *compute_, struct ccase *c, casenum_t case_num)
+compute_num (void *compute_, struct ccase *c, casenumber case_num)
{
struct compute_trns *compute = compute_;
/* Handle COMPUTE or IF with numeric vector element target
variable. */
static int
-compute_num_vec (void *compute_, struct ccase *c, casenum_t case_num)
+compute_num_vec (void *compute_, struct ccase *c, casenumber case_num)
{
struct compute_trns *compute = compute_;
/* Handle COMPUTE or IF with string target variable. */
static int
-compute_str (void *compute_, struct ccase *c, casenum_t case_num)
+compute_str (void *compute_, struct ccase *c, casenumber case_num)
{
struct compute_trns *compute = compute_;
/* Handle COMPUTE or IF with string vector element target
variable. */
static int
-compute_str_vec (void *compute_, struct ccase *c, casenum_t case_num)
+compute_str_vec (void *compute_, struct ccase *c, casenumber case_num)
{
struct compute_trns *compute = compute_;
/* IF. */
int
-cmd_if (void)
+cmd_if (struct dataset *ds)
{
+ struct dictionary *dict = dataset_dict (ds);
struct compute_trns *compute = NULL;
struct lvalue *lvalue = NULL;
compute = compute_trns_create ();
/* Test expression. */
- compute->test = expr_parse (dataset_dict (current_dataset), EXPR_BOOLEAN);
+ compute->test = expr_parse (ds, EXPR_BOOLEAN);
if (compute->test == NULL)
goto fail;
/* Lvalue variable. */
- lvalue = lvalue_parse ();
+ lvalue = lvalue_parse (ds);
if (lvalue == NULL)
goto fail;
/* Rvalue expression. */
if (!lex_force_match ('='))
goto fail;
- compute->rvalue = parse_rvalue (lvalue);
+ compute->rvalue = parse_rvalue (lvalue, ds);
if (compute->rvalue == NULL)
goto fail;
- add_transformation (current_dataset,
- get_proc_func (lvalue), compute_trns_free, compute);
+ add_transformation (ds, get_proc_func (lvalue, dict),
+ compute_trns_free, compute);
- lvalue_finalize (lvalue, compute);
+ lvalue_finalize (lvalue, compute, dict);
return lex_end_of_command ();
/* Code common to COMPUTE and IF. */
static trns_proc_func *
-get_proc_func (const struct lvalue *lvalue)
+get_proc_func (const struct lvalue *lvalue, const struct dictionary *dict)
{
- bool is_numeric = lvalue_get_type (lvalue) == NUMERIC;
+ bool is_numeric = lvalue_get_type (lvalue, dict) == NUMERIC;
bool is_vector = lvalue_is_vector (lvalue);
return (is_numeric
/* Parses and returns an rvalue expression of the same type as
LVALUE, or a null pointer on failure. */
static struct expression *
-parse_rvalue (const struct lvalue *lvalue)
+parse_rvalue (const struct lvalue *lvalue, struct dataset *ds)
{
- bool is_numeric = lvalue_get_type (lvalue) == NUMERIC;
+ const struct dictionary *dict = dataset_dict (ds);
+ bool is_numeric = lvalue_get_type (lvalue, dict) == NUMERIC;
- return expr_parse (dataset_dict (current_dataset), is_numeric ? EXPR_NUMBER : EXPR_STRING);
+ return expr_parse (ds, is_numeric ? EXPR_NUMBER : EXPR_STRING);
}
/* Returns a new struct compute_trns after initializing its fields. */
/* Parses the target variable or vector element into a new
`struct lvalue', which is returned. */
static struct lvalue *
-lvalue_parse (void)
+lvalue_parse (struct dataset *ds)
{
struct lvalue *lvalue;
if (lex_look_ahead () == '(')
{
/* Vector. */
- lvalue->vector = dict_lookup_vector (dataset_dict (current_dataset), tokid);
+ lvalue->vector = dict_lookup_vector (dataset_dict (ds), tokid);
if (lvalue->vector == NULL)
{
msg (SE, _("There is no vector named %s."), tokid);
lex_get ();
if (!lex_force_match ('('))
goto lossage;
- lvalue->element = expr_parse (dataset_dict (current_dataset), EXPR_NUMBER);
+ lvalue->element = expr_parse (ds, EXPR_NUMBER);
if (lvalue->element == NULL)
goto lossage;
if (!lex_force_match (')'))
/* Returns the type (NUMERIC or ALPHA) of the target variable or
vector in LVALUE. */
static int
-lvalue_get_type (const struct lvalue *lvalue)
+lvalue_get_type (const struct lvalue *lvalue, const struct dictionary *dict)
{
if (lvalue->vector == NULL)
{
- struct variable *var = dict_lookup_var (dataset_dict (current_dataset), lvalue->var_name);
+ struct variable *var = dict_lookup_var (dict, lvalue->var_name);
if (var == NULL)
return NUMERIC;
else
/* Finalizes making LVALUE the target of COMPUTE, by creating the
target variable if necessary and setting fields in COMPUTE. */
static void
-lvalue_finalize (struct lvalue *lvalue, struct compute_trns *compute)
+lvalue_finalize (struct lvalue *lvalue,
+ struct compute_trns *compute,
+ struct dictionary *dict)
{
if (lvalue->vector == NULL)
{
- compute->variable = dict_lookup_var (dataset_dict (current_dataset), lvalue->var_name);
+ compute->variable = dict_lookup_var (dict, lvalue->var_name);
if (compute->variable == NULL)
- compute->variable = dict_create_var_assert (dataset_dict (current_dataset),
- lvalue->var_name, 0);
+ compute->variable = dict_create_var_assert (dict, lvalue->var_name, 0);
compute->fv = compute->variable->fv;
compute->width = compute->variable->width;
static bool parse_string_criteria (struct pool *, struct criteria *);
\f
int
-cmd_count (void)
+cmd_count (struct dataset *ds)
{
struct dst_var *dv; /* Destination var being parsed. */
struct count_trns *trns; /* Transformation. */
/* Get destination variable, or at least its name. */
if (!lex_force_id ())
goto fail;
- dv->var = dict_lookup_var (dataset_dict (current_dataset), tokid);
+ dv->var = dict_lookup_var (dataset_dict (ds), tokid);
if (dv->var != NULL)
{
if (dv->var->type == ALPHA)
crit->next = NULL;
crit->vars = NULL;
- if (!parse_variables (dataset_dict (current_dataset), &crit->vars, &crit->var_cnt,
+ if (!parse_variables (dataset_dict (ds), &crit->vars, &crit->var_cnt,
PV_DUPLICATE | PV_SAME_TYPE))
goto fail;
pool_register (trns->pool, free, crit->vars);
{
/* It's valid, though motivationally questionable, to count to
the same dest var more than once. */
- dv->var = dict_lookup_var (dataset_dict (current_dataset), dv->name);
+ dv->var = dict_lookup_var (dataset_dict (ds), dv->name);
if (dv->var == NULL)
- dv->var = dict_create_var_assert (dataset_dict (current_dataset), dv->name, 0);
+ dv->var = dict_create_var_assert (dataset_dict (ds), dv->name, 0);
}
- add_transformation (current_dataset, count_trns_proc, count_trns_free, trns);
+ add_transformation (ds, count_trns_proc, count_trns_free, trns);
return CMD_SUCCESS;
fail:
/* Performs the COUNT transformation T on case C. */
static int
count_trns_proc (void *trns_, struct ccase *c,
- casenum_t case_num UNUSED)
+ casenumber case_num UNUSED)
{
struct count_trns *trns = trns_;
struct dst_var *dv;
#include <language/command.h>
#include <language/lexer/lexer.h>
-static int trns_fail (void *x, struct ccase *c, casenum_t n);
+static int trns_fail (void *x, struct ccase *c, casenumber n);
\f
static int
trns_fail (void *x UNUSED, struct ccase *c UNUSED,
- casenum_t n UNUSED)
+ casenumber n UNUSED)
{
return TRNS_ERROR;
}
int
-cmd_debug_xform_fail (void)
+cmd_debug_xform_fail (struct dataset *ds)
{
- add_transformation (current_dataset, trns_fail, NULL, NULL);
+ add_transformation (ds, trns_fail, NULL, NULL);
return lex_end_of_command ();
}
size_t map_cnt; /* Number of mappings. */
};
-static bool parse_src_vars (struct recode_trns *);
+static bool parse_src_vars (struct recode_trns *, const struct dictionary *dict);
static bool parse_mappings (struct recode_trns *);
-static bool parse_dst_vars (struct recode_trns *);
+static bool parse_dst_vars (struct recode_trns *, const struct dictionary *dict);
static void add_mapping (struct recode_trns *,
size_t *map_allocated, const struct map_in *);
const struct string *);
static void enlarge_dst_widths (struct recode_trns *);
-static void create_dst_vars (struct recode_trns *);
+static void create_dst_vars (struct recode_trns *, struct dictionary *);
static trns_proc_func recode_trns_proc;
static trns_free_func recode_trns_free;
/* Parses the RECODE transformation. */
int
-cmd_recode (void)
+cmd_recode (struct dataset *ds)
{
do
{
/* Parse source variable names,
then input to output mappings,
then destintation variable names. */
- if (!parse_src_vars (trns)
+ if (!parse_src_vars (trns, dataset_dict (ds) )
|| !parse_mappings (trns)
- || !parse_dst_vars (trns))
+ || !parse_dst_vars (trns, dataset_dict (ds)))
{
recode_trns_free (trns);
return CMD_FAILURE;
This must be the final step; otherwise we'd have to
delete destination variables on failure. */
if (trns->src_vars != trns->dst_vars)
- create_dst_vars (trns);
+ create_dst_vars (trns, dataset_dict (ds));
/* Done. */
- add_transformation (current_dataset,
+ add_transformation (ds,
recode_trns_proc, recode_trns_free, trns);
}
while (lex_match ('/'));
TRNS->var_cnt. Sets TRNS->src_type. Returns true if
successful, false on parse error. */
static bool
-parse_src_vars (struct recode_trns *trns)
+parse_src_vars (struct recode_trns *trns, const struct dictionary *dict)
{
- if (!parse_variables (dataset_dict (current_dataset), &trns->src_vars, &trns->var_cnt,
+ if (!parse_variables (dict, &trns->src_vars, &trns->var_cnt,
PV_SAME_TYPE))
return false;
pool_register (trns->pool, free, trns->src_vars);
/* Parses a set of target variables into TRNS->dst_vars and
TRNS->dst_names. */
static bool
-parse_dst_vars (struct recode_trns *trns)
+parse_dst_vars (struct recode_trns *trns, const struct dictionary *dict)
{
size_t i;
size_t name_cnt;
size_t i;
- if (!parse_mixed_vars_pool (trns->pool, &trns->dst_names, &name_cnt,
+ if (!parse_mixed_vars_pool (dict, trns->pool,
+ &trns->dst_names, &name_cnt,
PV_NONE))
return false;
for (i = 0; i < trns->var_cnt; i++)
{
struct variable *v;
- v = trns->dst_vars[i] = dict_lookup_var (dataset_dict (current_dataset),
- trns->dst_names[i]);
+ v = trns->dst_vars[i] = dict_lookup_var (dict, trns->dst_names[i]);
if (v == NULL && trns->dst_type == ALPHA)
{
msg (SE, _("There is no variable named "
/* Creates destination variables that don't already exist. */
static void
-create_dst_vars (struct recode_trns *trns)
+create_dst_vars (struct recode_trns *trns, struct dictionary *dict)
{
size_t i;
struct variable **var = &trns->dst_vars[i];
const char *name = trns->dst_names[i];
- *var = dict_lookup_var (dataset_dict (current_dataset), name);
+ *var = dict_lookup_var (dict, name);
if (*var == NULL)
- *var = dict_create_var_assert (dataset_dict (current_dataset), name, 0);
+ *var = dict_create_var_assert (dict, name, 0);
assert ((*var)->type == trns->dst_type);
}
}
/* Performs RECODE transformation. */
static int
-recode_trns_proc (void *trns_, struct ccase *c, casenum_t case_idx UNUSED)
+recode_trns_proc (void *trns_, struct ccase *c, casenumber case_idx UNUSED)
{
struct recode_trns *trns = trns_;
size_t i;
static trns_free_func sample_trns_free;
int
-cmd_sample (void)
+cmd_sample (struct dataset *ds)
{
struct sample_trns *trns;
trns->N = b;
trns->m = trns->t = 0;
trns->frac = frac;
- add_transformation (current_dataset, sample_trns_proc, sample_trns_free, trns);
+ add_transformation (ds, sample_trns_proc, sample_trns_free, trns);
return lex_end_of_command ();
}
/* Executes a SAMPLE transformation. */
static int
sample_trns_proc (void *t_, struct ccase *c UNUSED,
- casenum_t case_num UNUSED)
+ casenumber case_num UNUSED)
{
struct sample_trns *t = t_;
double U;
/* Parses the SELECT IF transformation. */
int
-cmd_select_if (void)
+cmd_select_if (struct dataset *ds)
{
struct expression *e;
struct select_if_trns *t;
- e = expr_parse (dataset_dict (current_dataset), EXPR_BOOLEAN);
+ e = expr_parse (ds, EXPR_BOOLEAN);
if (!e)
return CMD_CASCADING_FAILURE;
t = xmalloc (sizeof *t);
t->e = e;
- add_transformation (current_dataset, select_if_proc, select_if_free, t);
+ add_transformation (ds, select_if_proc, select_if_free, t);
return CMD_SUCCESS;
}
/* Performs the SELECT IF transformation T on case C. */
static int
select_if_proc (void *t_, struct ccase *c,
- casenum_t case_num)
+ casenumber case_num)
{
struct select_if_trns *t = t_;
return (expr_evaluate_num (t->e, c, case_num) == 1.0
/* Parses the FILTER command. */
int
-cmd_filter (void)
+cmd_filter (struct dataset *ds)
{
+ struct dictionary *dict = dataset_dict (ds);
if (lex_match_id ("OFF"))
- dict_set_filter (dataset_dict (current_dataset), NULL);
+ dict_set_filter (dataset_dict (ds), NULL);
else if (token == '.')
{
msg (SW, _("Syntax error expecting OFF or BY. "
"Turning off case filtering."));
- dict_set_filter (dataset_dict (current_dataset), NULL);
+ dict_set_filter (dataset_dict (ds), NULL);
}
else
{
struct variable *v;
lex_match (T_BY);
- v = parse_variable ();
+ v = parse_variable (dict);
if (!v)
return CMD_FAILURE;
return CMD_FAILURE;
}
- dict_set_filter (dataset_dict (current_dataset), v);
+ dict_set_filter (dict, v);
}
return lex_end_of_command ();
/* First pass */
static void levene_precalc (const struct levene_info *l);
-static int levene_calc (const struct ccase *, void *);
+static int levene_calc (const struct dictionary *dict, const struct ccase *, void *);
static void levene_postcalc (void *);
/* Second pass */
static void levene2_precalc (void *);
-static int levene2_calc (const struct ccase *, void *);
+static int levene2_calc (const struct dictionary *,const struct ccase *, void *);
static void levene2_postcalc (void *);
void
-levene(const struct casefile *cf,
+levene(const struct dictionary *dict,
+ const struct casefile *cf,
struct variable *v_indep, size_t n_dep, struct variable **v_dep,
- enum lev_missing missing, is_missing_func value_is_missing)
+ enum lev_missing missing, is_missing_func value_is_missing)
{
struct casereader *r;
struct ccase c;
casereader_read (r, &c) ;
case_destroy (&c))
{
- levene_calc(&c,&l);
+ levene_calc (dict, &c,&l);
}
casereader_destroy (r);
levene_postcalc(&l);
casereader_read (r, &c) ;
case_destroy (&c))
{
- levene2_calc(&c,&l);
+ levene2_calc (dict, &c,&l);
}
casereader_destroy (r);
levene2_postcalc(&l);
}
static int
-levene_calc (const struct ccase *c, void *_l)
+levene_calc (const struct dictionary *dict, const struct ccase *c, void *_l)
{
size_t i;
bool warn = false;
struct levene_info *l = (struct levene_info *) _l;
const union value *gv = case_data (c, l->v_indep->fv);
struct group_statistics key;
- double weight = dict_get_case_weight (dataset_dict (current_dataset), c, &warn);
+ double weight = dict_get_case_weight (dict, c, &warn);
/* Skip the entire case if /MISSING=LISTWISE is set */
if ( l->missing == LEV_LISTWISE )
}
}
}
-
key.id = *gv;
}
static int
-levene2_calc (const struct ccase *c, void *_l)
+levene2_calc (const struct dictionary *dict, const struct ccase *c, void *_l)
{
size_t i;
bool warn = false;
struct levene_info *l = (struct levene_info *) _l;
- double weight = dict_get_case_weight (dataset_dict (current_dataset), c, &warn);
+ double weight = dict_get_case_weight (dict, c, &warn);
const union value *gv = case_data (c, l->v_indep->fv);
struct group_statistics key;
*/
-void levene(const struct casefile *cf,
+struct dictionary ;
+
+void levene(const struct dictionary *dict, const struct casefile *cf,
struct variable *v_indep, size_t n_dep, struct variable **v_dep,
enum lev_missing, is_missing_func);
static struct casefile *do_external_sort (struct casereader *,
const struct sort_criteria *);
-/* Get ready to sort the active file. */
-static void
-prepare_to_sort_active_file (void)
-{
- proc_cancel_temporary_transformations (current_dataset);
-}
/* Sorts the active file in-place according to CRITERIA.
Returns true if successful. */
bool
-sort_active_file_in_place (const struct sort_criteria *criteria)
+sort_active_file_in_place (struct dataset *ds,
+ const struct sort_criteria *criteria)
{
struct casefile *in, *out;
- prepare_to_sort_active_file ();
- if (!procedure (current_dataset,NULL, NULL))
+ proc_cancel_temporary_transformations (ds);
+ if (!procedure (ds, NULL, NULL))
return false;
- in = proc_capture_output (current_dataset);
+ in = proc_capture_output (ds);
out = sort_execute (casefile_get_destructive_reader (in), criteria);
if (out == NULL)
return false;
- proc_set_source (current_dataset, storage_source_create (out));
+ proc_set_source (ds, storage_source_create (out));
return true;
}
returns the sorted casefile. Returns a null pointer on
failure. */
struct casefile *
-sort_active_file_to_casefile (const struct sort_criteria *criteria)
+sort_active_file_to_casefile (struct dataset *ds,
+ const struct sort_criteria *criteria)
{
struct sort_to_casefile_cb_data cb_data;
- prepare_to_sort_active_file ();
+ proc_cancel_temporary_transformations (ds);
cb_data.criteria = criteria;
cb_data.output = NULL;
- if (!multipass_procedure (current_dataset,sort_to_casefile_callback, &cb_data))
+ if (!multipass_procedure (ds, sort_to_casefile_callback, &cb_data))
{
casefile_destroy (cb_data.output);
return NULL;
struct casefile *sort_execute (struct casereader *,
const struct sort_criteria *);
-bool sort_active_file_in_place (const struct sort_criteria *);
+struct dataset ;
+bool sort_active_file_in_place (struct dataset *ds,
+ const struct sort_criteria *);
-struct casefile *sort_active_file_to_casefile (const struct sort_criteria *);
+struct casefile *sort_active_file_to_casefile (struct dataset *ds,
+ const struct sort_criteria *);
#endif /* !sort_h */
/* Handle quit/term/int signals */
void interrupt_handler(int sig);
+static struct dataset * the_dataset = NULL;
+
/* Program entry point. */
readln_initialize ();
settings_init ();
random_init ();
- current_dataset = create_dataset ();
+ the_dataset = create_dataset ();
if (parse_command_line (argc, argv))
{
for (;;)
{
- int result = cmd_parse (proc_has_source (current_dataset)
+ int result = cmd_parse (the_dataset,
+ proc_has_source (the_dataset)
? CMD_STATE_DATA : CMD_STATE_INITIAL);
if (result == CMD_EOF || result == CMD_FINISH)
break;
{
terminating = true;
- destroy_dataset (current_dataset);
+ destroy_dataset (the_dataset);
random_done ();
settings_done ();
activity="run_program"
-$SUPERVISOR $PSPP $TESTFILE > /dev/null
+$SUPERVISOR $PSPP $TESTFILE
if [ $? -ne 0 ] ; then fail ; fi