From 244ade48f9c233532cc535d3233fdef53bf9266b Mon Sep 17 00:00:00 2001 From: John Darrington Date: Thu, 26 Oct 2006 06:16:36 +0000 Subject: [PATCH] Eliminated global variable current_dataset. The dataset is now owned by main, and passed around by pointer. --- src/data/dictionary.c | 4 +- src/data/procedure.c | 113 +++++++++---------- src/data/procedure.h | 27 ++--- src/data/transformations.h | 4 +- src/language/command.c | 34 +++--- src/language/command.h | 7 +- src/language/control/control-stack.c | 2 +- src/language/control/do-if.c | 39 ++++--- src/language/control/loop.c | 43 ++++---- src/language/control/repeat.c | 19 ++-- src/language/control/temporary.c | 6 +- src/language/data-io/data-list.c | 35 +++--- src/language/data-io/data-reader.c | 4 +- src/language/data-io/file-handle.q | 6 +- src/language/data-io/get.c | 105 +++++++++--------- src/language/data-io/inpt-pgm.c | 52 ++++----- src/language/data-io/list.q | 24 ++-- src/language/data-io/matrix-data.c | 103 ++++++++++-------- src/language/data-io/print-space.c | 8 +- src/language/data-io/print.c | 38 ++++--- src/language/dictionary/apply-dictionary.c | 8 +- src/language/dictionary/formats.c | 20 ++-- src/language/dictionary/missing-values.c | 4 +- src/language/dictionary/modify-variables.c | 22 ++-- src/language/dictionary/numeric.c | 12 +- src/language/dictionary/rename-variables.c | 8 +- src/language/dictionary/split-file.c | 15 +-- src/language/dictionary/split-file.h | 2 +- src/language/dictionary/sys-file-info.c | 30 ++--- src/language/dictionary/value-labels.c | 14 +-- src/language/dictionary/variable-display.c | 12 +- src/language/dictionary/variable-label.c | 4 +- src/language/dictionary/vector.c | 16 +-- src/language/dictionary/weight.c | 9 +- src/language/expressions/evaluate.c | 37 +++++-- src/language/expressions/generate.pl | 2 + src/language/expressions/operations.def | 12 +- src/language/expressions/parse.c | 45 ++++---- src/language/expressions/private.h | 4 +- src/language/expressions/public.h | 7 +- src/language/lexer/q2c.c | 23 ++-- src/language/lexer/variable-parser.c | 23 ++-- src/language/lexer/variable-parser.h | 9 +- src/language/stats/aggregate.c | 60 +++++----- src/language/stats/autorecode.c | 24 ++-- src/language/stats/correlations.q | 21 ++-- src/language/stats/crosstabs.q | 48 ++++---- src/language/stats/descriptives.c | 53 +++++---- src/language/stats/examine.q | 67 ++++++------ src/language/stats/flip.c | 57 +++++----- src/language/stats/frequencies.q | 46 ++++---- src/language/stats/means.q | 10 +- src/language/stats/oneway.q | 28 +++-- src/language/stats/rank.q | 121 ++++++++++++--------- src/language/stats/regression.q | 64 ++++++----- src/language/stats/sort-cases.c | 6 +- src/language/stats/t-test.q | 64 ++++++----- src/language/tests/casefile-test.c | 2 +- src/language/tests/moments-test.c | 3 +- src/language/tests/pool-test.c | 2 +- src/language/utilities/date.c | 2 +- src/language/utilities/echo.c | 2 +- src/language/utilities/include.c | 2 +- src/language/utilities/permissions.c | 2 +- src/language/utilities/set.q | 82 +++++++------- src/language/utilities/title.c | 31 +++--- src/language/xforms/compute.c | 76 +++++++------ src/language/xforms/count.c | 14 +-- src/language/xforms/fail.c | 8 +- src/language/xforms/recode.c | 36 +++--- src/language/xforms/sample.c | 6 +- src/language/xforms/select-if.c | 19 ++-- src/math/levene.c | 22 ++-- src/math/levene.h | 4 +- src/math/sort.c | 24 ++-- src/math/sort.h | 7 +- src/ui/terminal/main.c | 9 +- tests/bugs/lag_crash.sh | 2 +- 78 files changed, 1074 insertions(+), 961 deletions(-) diff --git a/src/data/dictionary.c b/src/data/dictionary.c index 6fe08f17..ac9c7d63 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -435,8 +435,8 @@ compare_var_ptrs (const void *a_, const void *b_, void *aux UNUSED) /* 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. diff --git a/src/data/procedure.c b/src/data/procedure.c index 5341de46..b59f1282 100644 --- a/src/data/procedure.c +++ b/src/data/procedure.c @@ -43,7 +43,7 @@ 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 */ @@ -88,13 +88,11 @@ struct dataset { }; /* 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 *); @@ -135,7 +133,7 @@ time_of_last_procedure (struct dataset *ds) 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); } @@ -152,7 +150,7 @@ struct multipass_aux_data /* 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); @@ -160,7 +158,7 @@ multipass_case_func (const struct ccase *c, void *aux_data_) /* 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 @@ -171,7 +169,7 @@ multipass_end_func (void *aux_data_) 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; @@ -197,8 +195,8 @@ multipass_procedure (struct dataset *ds, casefile_func_t proc_func, void *aux) 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; @@ -210,7 +208,7 @@ internal_procedure (struct dataset *ds, case_func_t case_func, /* 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 @@ -225,7 +223,7 @@ internal_procedure (struct dataset *ds, case_func_t case_func, 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); @@ -236,8 +234,8 @@ internal_procedure (struct dataset *ds, case_func_t case_func, 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); @@ -365,8 +363,8 @@ write_case (struct write_case_data *wc_data) } /* 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: @@ -476,15 +474,15 @@ struct split_aux_data 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 @@ -505,18 +503,18 @@ static bool split_procedure_end_func (void *); 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; @@ -530,7 +528,7 @@ procedure_with_splits (struct 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_; @@ -538,29 +536,28 @@ split_procedure_case_func (const struct ccase *c, void *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; } @@ -585,23 +582,19 @@ struct multipass_split_aux_data 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; @@ -609,7 +602,7 @@ multipass_procedure_with_splits (struct dataset *ds, case_nullify (&aux.prev_case); aux.casefile = NULL; - aux.split_func = split_func; + aux.split = split; aux.func_aux = func_aux; aux.dataset = ds; @@ -622,10 +615,9 @@ multipass_procedure_with_splits (struct 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. */ @@ -637,7 +629,7 @@ multipass_split_case_func (const struct ccase *c, void *aux_) /* 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 = @@ -649,19 +641,19 @@ multipass_split_case_func (const struct ccase *c, void *aux_) /* 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; @@ -827,6 +819,7 @@ destroy_dataset (struct dataset *ds) { discard_variables (ds); dict_destroy (ds->dict); + trns_chain_destroy (ds->permanent_trns_chain); free (ds); } @@ -901,7 +894,7 @@ add_case_limit_trns (struct dataset *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) @@ -940,7 +933,7 @@ add_filter_trns (struct dataset *ds) /* 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_; diff --git a/src/data/procedure.h b/src/data/procedure.h index 60e1e77f..e6e707d3 100644 --- a/src/data/procedure.h +++ b/src/data/procedure.h @@ -68,26 +68,29 @@ bool proc_has_source (const struct dataset *ds); 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; @@ -98,8 +101,6 @@ time_t time_of_last_procedure (struct dataset *ds); 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); diff --git a/src/data/transformations.h b/src/data/transformations.h index cc552a10..79527d86 100644 --- a/src/data/transformations.h +++ b/src/data/transformations.h @@ -23,7 +23,7 @@ #include #include -typedef unsigned long casenum_t ; +typedef unsigned long casenumber ; /* trns_proc_func return values. */ enum trns_result @@ -37,7 +37,7 @@ 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 *); /* Transformation chains. */ diff --git a/src/language/command.c b/src/language/command.c index 4ca3da9a..f98277aa 100644 --- a/src/language/command.c +++ b/src/language/command.c @@ -108,7 +108,7 @@ struct command 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. */ @@ -131,24 +131,24 @@ static void set_completion_state (enum cmd_state); /* 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; } @@ -156,7 +156,7 @@ cmd_parse (enum cmd_state state) /* 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; @@ -203,7 +203,7 @@ do_parse_command (enum cmd_state state) /* 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); @@ -649,14 +649,14 @@ cmd_complete (const char *prefix, const struct command **cmd) /* 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; @@ -666,23 +666,23 @@ cmd_n_of_cases (void) 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 ()) { @@ -811,7 +811,7 @@ run_command (void) /* Parses, performs the HOST command. */ int -cmd_host (void) +cmd_host (struct dataset *ds UNUSED) { int code; @@ -848,16 +848,16 @@ cmd_host (void) /* 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; diff --git a/src/language/command.h b/src/language/command.h index 3cf5b997..cca9f839 100644 --- a/src/language/command.h +++ b/src/language/command.h @@ -54,13 +54,16 @@ enum cmd_state 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 diff --git a/src/language/control/control-stack.c b/src/language/control/control-stack.c index cac206dd..4b57bdec 100644 --- a/src/language/control/control-stack.c +++ b/src/language/control/control-stack.c @@ -75,7 +75,7 @@ ctl_stack_search (const struct ctl_class *class) } void -ctl_stack_pop (void *private UNUSED) +ctl_stack_pop (void *private) { struct ctl_struct *top = ctl_stack; diff --git a/src/language/control/do-if.c b/src/language/control/do-if.c index 48373666..e53fc898 100644 --- a/src/language/control/do-if.c +++ b/src/language/control/do-if.c @@ -75,6 +75,7 @@ struct clause /* 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. */ @@ -82,7 +83,7 @@ struct do_if_trns 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 *); @@ -97,34 +98,36 @@ static trns_free_func do_if_trns_free; /* 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); @@ -133,9 +136,11 @@ cmd_else (void) /* 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; @@ -147,13 +152,13 @@ cmd_end_if (void) /* 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 @@ -162,7 +167,7 @@ static void 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. @@ -192,15 +197,15 @@ has_else (struct do_if_trns *do_if) 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 (); } @@ -214,7 +219,7 @@ add_clause (struct do_if_trns *do_if, 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); @@ -238,7 +243,7 @@ do_if_finalize_func (void *do_if_ UNUSED) 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; @@ -277,7 +282,7 @@ do_if_trns_free (void *do_if_) /* 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_; diff --git a/src/language/control/loop.c b/src/language/control/loop.c index ce80f665..5c22f3ca 100644 --- a/src/language/control/loop.c +++ b/src/language/control/loop.c @@ -58,6 +58,7 @@ struct loop_trns { struct pool *pool; + struct dataset *ds; /* Iteration limit. */ int max_pass_count; /* Maximum number of passes (-1=unlimited). */ @@ -85,7 +86,7 @@ static trns_finalize_func loop_trns_finalize; 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 *); @@ -94,13 +95,13 @@ 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")) @@ -112,9 +113,10 @@ cmd_loop (void) /* 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) @@ -124,7 +126,7 @@ cmd_loop (void) /* Parses END LOOP. */ int -cmd_end_loop (void) +cmd_end_loop (struct dataset *ds) { struct loop_trns *loop; bool ok = true; @@ -132,6 +134,8 @@ cmd_end_loop (void) loop = ctl_stack_top (&loop_class); if (loop == NULL) return CMD_CASCADING_FAILURE; + + assert (loop->ds == ds); /* Parse syntax. */ if (lex_match_id ("IF")) @@ -149,13 +153,13 @@ cmd_end_loop (void) /* 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 (); } @@ -167,8 +171,8 @@ close_loop (void *loop_) { 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. */ @@ -185,7 +189,7 @@ close_loop (void *loop_) 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; } @@ -206,7 +210,7 @@ parse_index_clause (struct loop_trns *loop, char index_var_name[]) 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; @@ -225,7 +229,7 @@ parse_index_clause (struct loop_trns *loop, char index_var_name[]) 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; } @@ -242,7 +246,7 @@ parse_index_clause (struct loop_trns *loop, char index_var_name[]) /* 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; @@ -250,10 +254,11 @@ create_loop_trns (void) 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); @@ -273,7 +278,7 @@ loop_trns_finalize (void *do_if_ UNUSED) /* 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_; @@ -325,7 +330,7 @@ loop_trns_free (void *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_; @@ -363,7 +368,7 @@ end_loop_trns_proc (void *loop_, struct ccase *c, casenum_t case_num UNUSED) /* 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_; diff --git a/src/language/control/repeat.c b/src/language/control/repeat.c index 0b4607ff..285acd7c 100644 --- a/src/language/control/repeat.c +++ b/src/language/control/repeat.c @@ -74,6 +74,7 @@ struct repeat_entry 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. */ @@ -86,7 +87,7 @@ static bool parse_specification (struct repeat_block *); 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 *); @@ -96,11 +97,12 @@ static bool do_repeat_read (struct string *line, char **file_name, 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; @@ -132,12 +134,13 @@ parse_specification (struct repeat_block *block) { 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); @@ -162,7 +165,7 @@ parse_specification (struct repeat_block *block) /* 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) @@ -331,18 +334,18 @@ create_vars (struct repeat_block *block) { /* 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 @@ -440,7 +443,7 @@ parse_strings (struct repeat_entry *e, struct pool *pool) } int -cmd_end_repeat (void) +cmd_end_repeat (struct dataset *ds UNUSED) { msg (SE, _("No matching DO REPEAT.")); return CMD_CASCADING_FAILURE; diff --git a/src/language/control/temporary.c b/src/language/control/temporary.c index 810ed519..45d7342b 100644 --- a/src/language/control/temporary.c +++ b/src/language/control/temporary.c @@ -41,10 +41,10 @@ /* 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.")); diff --git a/src/language/data-io/data-list.c b/src/language/data-io/data-list.c index 8012d888..b541f56a 100644 --- a/src/language/data-io/data-list.c +++ b/src/language/data-io/data-list.c @@ -103,8 +103,10 @@ struct data_list_pgm 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 *, @@ -114,8 +116,9 @@ static trns_free_func data_list_trns_free; 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 (); @@ -123,7 +126,7 @@ cmd_data_list (void) 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); @@ -166,9 +169,9 @@ cmd_data_list (void) 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) @@ -242,7 +245,7 @@ cmd_data_list (void) 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; @@ -262,10 +265,9 @@ cmd_data_list (void) 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); @@ -283,7 +285,8 @@ cmd_data_list (void) 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; @@ -316,7 +319,7 @@ parse_fixed (struct pool *tmp_pool, struct data_list_pgm *dls) /* 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. */ @@ -338,7 +341,7 @@ parse_fixed (struct pool *tmp_pool, struct data_list_pgm *dls) 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 " @@ -432,7 +435,7 @@ dump_fixed_table (const struct ll_list *specs, 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 != '.') @@ -465,7 +468,7 @@ parse_free (struct pool *tmp_pool, struct data_list_pgm *dls) 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) { @@ -772,7 +775,7 @@ data_list_trns_free (void *dls_) /* 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; diff --git a/src/language/data-io/data-reader.c b/src/language/data-io/data-reader.c index 31932af9..6cd92882 100644 --- a/src/language/data-io/data-reader.c +++ b/src/language/data-io/data-reader.c @@ -423,7 +423,7 @@ dfm_pop (struct dfm_reader *r) /* 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; @@ -441,7 +441,7 @@ cmd_begin_data (void) /* 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); diff --git a/src/language/data-io/file-handle.q b/src/language/data-io/file-handle.q index 81094a95..b3d15619 100644 --- a/src/language/data-io/file-handle.q +++ b/src/language/data-io/file-handle.q @@ -51,7 +51,7 @@ /* (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 (); @@ -76,7 +76,7 @@ cmd_file_handle (void) 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) @@ -127,7 +127,7 @@ cmd_file_handle (void) } int -cmd_close_file_handle (void) +cmd_close_file_handle (struct dataset *ds UNUSED) { struct file_handle *handle; diff --git a/src/language/data-io/get.c b/src/language/data-io/get.c index 663d2fc1..c7ba18a4 100644 --- a/src/language/data-io/get.c +++ b/src/language/data-io/get.c @@ -85,7 +85,7 @@ static void case_reader_pgm_free (struct case_reader_pgm *); /* 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; @@ -127,7 +127,7 @@ parse_read_command (enum reader_command type) goto error; } - discard_variables (current_dataset); + discard_variables (ds); pgm = xmalloc (sizeof *pgm); pgm->reader = any_reader_open (fh, &dict); @@ -149,10 +149,10 @@ parse_read_command (enum reader_command type) 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; @@ -227,16 +227,16 @@ static const struct case_source_class case_reader_source_class = /* 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); } /* Writing system and portable files. */ @@ -290,7 +290,8 @@ case_writer_destroy (struct case_writer *aw) 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) { @@ -313,7 +314,7 @@ parse_write_command (enum writer_type writer_type, *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; @@ -469,26 +470,26 @@ case_writer_write_case (struct case_writer *aw, const struct ccase *c) /* 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; @@ -496,22 +497,22 @@ parse_output_proc (enum writer_type writer_type) /* 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); } /* XSAVE and XEXPORT. */ @@ -527,23 +528,23 @@ static trns_free_func output_trns_free; /* 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); @@ -568,16 +569,16 @@ output_trns_free (void *trns_) /* 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); } static bool rename_variables (struct dictionary *dict); @@ -629,7 +630,7 @@ 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 ('=') @@ -799,8 +800,8 @@ static int mtf_merge_dictionary (struct dictionary *const, struct mtf_file *); 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 *); @@ -809,7 +810,7 @@ static struct variable *get_master (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; @@ -830,7 +831,7 @@ cmd_match_files (void) 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 @@ -895,20 +896,20 @@ cmd_match_files (void) } 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 { @@ -1125,7 +1126,7 @@ cmd_match_files (void) 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)); @@ -1137,20 +1138,22 @@ cmd_match_files (void) 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)) @@ -1164,7 +1167,7 @@ cmd_match_files (void) /* 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; @@ -1179,7 +1182,7 @@ mtf_processing_finish (void *mtf_) } while (mtf->head && mtf->head->type == MTF_FILE) - if (!mtf_processing (NULL, mtf)) + if (!mtf_processing (NULL, mtf, ds)) return false; return true; @@ -1323,7 +1326,7 @@ mtf_compare_BY_values (struct mtf_proc *mtf, /* 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_; diff --git a/src/language/data-io/inpt-pgm.c b/src/language/data-io/inpt-pgm.c index 668ede87..f07e119a 100644 --- a/src/language/data-io/inpt-pgm.c +++ b/src/language/data-io/inpt-pgm.c @@ -97,19 +97,19 @@ in_input_program (void) /* 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 (); @@ -120,12 +120,12 @@ cmd_input_program (void) 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) @@ -133,34 +133,34 @@ cmd_input_program (void) 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; @@ -172,16 +172,16 @@ cmd_input_program (void) } 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; @@ -288,7 +288,7 @@ static const struct case_source_class input_program_source_class = }; int -cmd_end_case (void) +cmd_end_case (struct dataset *ds UNUSED) { assert (in_input_program ()); if (token == '.') @@ -298,7 +298,7 @@ cmd_end_case (void) /* 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_; @@ -319,7 +319,7 @@ struct reread_trns /* 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. */ @@ -340,7 +340,7 @@ cmd_reread (void) 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; } @@ -364,14 +364,14 @@ cmd_reread (void) 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_; @@ -405,11 +405,11 @@ reread_trns_free (void *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 (); } @@ -417,7 +417,7 @@ cmd_end_file (void) /* 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; } diff --git a/src/language/data-io/list.q b/src/language/data-io/list.q index 54b09c34..8bb55106 100644 --- a/src/language/data-io/list.q +++ b/src/language/data-io/list.q @@ -83,11 +83,11 @@ static unsigned n_chars_width (struct outp_driver *d); 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. */ @@ -129,12 +129,12 @@ write_line (struct outp_driver *d, const char *s) /* 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. */ @@ -145,7 +145,7 @@ cmd_list (void) 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) { @@ -185,12 +185,12 @@ cmd_list (void) /* 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) { @@ -199,7 +199,7 @@ cmd_list (void) 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 @@ -229,7 +229,7 @@ cmd_list (void) 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 (); @@ -240,11 +240,11 @@ cmd_list (void) /* 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) @@ -609,7 +609,7 @@ determine_layout (void) /* 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; diff --git a/src/language/data-io/matrix-data.c b/src/language/data-io/matrix-data.c index 5c8e011b..1a586795 100644 --- a/src/language/data-io/matrix-data.c +++ b/src/language/data-io/matrix-data.c @@ -152,7 +152,7 @@ struct matrix_data_pgm /* 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. */ }; @@ -168,13 +168,13 @@ static const struct case_source_class matrix_data_without_rowtype_source_class; 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; @@ -183,7 +183,7 @@ cmd_matrix_data (void) unsigned seen = 0; - discard_variables (current_dataset); + discard_variables (ds); pool = pool_create (); mx = pool_alloc (pool, sizeof *mx); @@ -248,7 +248,7 @@ cmd_matrix_data (void) 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 @@ -258,7 +258,7 @@ cmd_matrix_data (void) 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); } @@ -313,7 +313,7 @@ cmd_matrix_data (void) 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_") @@ -324,27 +324,27 @@ cmd_matrix_data (void) 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++) @@ -373,7 +373,7 @@ cmd_matrix_data (void) } 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; @@ -572,7 +572,7 @@ cmd_matrix_data (void) } /* 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 @@ -581,9 +581,9 @@ cmd_matrix_data (void) 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); } @@ -601,9 +601,9 @@ cmd_matrix_data (void) 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; @@ -628,9 +628,9 @@ cmd_matrix_data (void) 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); @@ -639,7 +639,7 @@ cmd_matrix_data (void) 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; @@ -912,6 +912,7 @@ force_eol (struct dfm_reader *reader, const char *content) 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. */ @@ -932,7 +933,7 @@ static bool matrix_data_read_without_rowtype (struct case_source *source, /* 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; @@ -941,17 +942,18 @@ read_matrices_without_rowtype (struct matrix_data_pgm *mx) 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); @@ -1089,7 +1091,7 @@ nr_read_data_lines (struct nr_aux_data *nr, 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; } @@ -1206,7 +1208,7 @@ matrix_data_read_without_rowtype (struct case_source *source, 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; } @@ -1229,14 +1231,14 @@ nr_read_splits (struct nr_aux_data *nr, int compare) 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; @@ -1245,7 +1247,7 @@ nr_read_splits (struct nr_aux_data *nr, int compare) 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; @@ -1264,7 +1266,7 @@ nr_read_splits (struct nr_aux_data *nr, int compare) { 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; } } @@ -1327,7 +1329,8 @@ nr_read_factors (struct nr_aux_data *nr, int cell) 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) { @@ -1351,13 +1354,13 @@ dump_cell_content (struct matrix_data_pgm *mx, int content, double *cp, 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; @@ -1378,8 +1381,8 @@ nr_output_data (struct nr_aux_data *nr, struct ccase *c, 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]; } @@ -1407,7 +1410,8 @@ nr_output_data (struct nr_aux_data *nr, struct ccase *c, 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; } @@ -1428,7 +1432,7 @@ nr_output_data (struct nr_aux_data *nr, struct ccase *c, 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; } @@ -1451,6 +1455,7 @@ struct factor_data /* 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. */ @@ -1475,7 +1480,7 @@ static bool matrix_data_read_with_rowtype (struct case_source *, 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; @@ -1485,12 +1490,13 @@ read_matrices_with_rowtype (struct matrix_data_pgm *mx) 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; @@ -1534,7 +1540,7 @@ wr_read_splits (struct wr_aux_data *wr, 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; @@ -1628,8 +1634,8 @@ wr_output_data (struct wr_aux_data *wr, 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]; } @@ -1697,7 +1703,8 @@ wr_output_data (struct wr_aux_data *wr, 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; @@ -1956,7 +1963,7 @@ wr_read_indeps (struct wr_aux_data *wr) 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; } diff --git a/src/language/data-io/print-space.c b/src/language/data-io/print-space.c index 4414bb16..61568a4c 100644 --- a/src/language/data-io/print-space.c +++ b/src/language/data-io/print-space.c @@ -47,7 +47,7 @@ static trns_proc_func print_space_trns_proc; 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; @@ -68,7 +68,7 @@ cmd_print_space (void) if (token != '.') { - expr = expr_parse (dataset_dict (current_dataset), EXPR_NUMBER); + expr = expr_parse (ds, EXPR_NUMBER); if (token != '.') { expr_free (expr); @@ -95,7 +95,7 @@ cmd_print_space (void) 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; } @@ -103,7 +103,7 @@ cmd_print_space (void) /* 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; diff --git a/src/language/data-io/print.c b/src/language/data-io/print.c index 474404b6..c47189c9 100644 --- a/src/language/data-io/print.c +++ b/src/language/data-io/print.c @@ -94,39 +94,41 @@ enum which_formats 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 *); /* 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; @@ -177,7 +179,7 @@ internal_cmd_print (enum which_formats which_formats, bool eject) } /* 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) @@ -198,7 +200,7 @@ internal_cmd_print (enum which_formats which_formats, bool eject) 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); @@ -211,7 +213,8 @@ internal_cmd_print (enum which_formats which_formats, bool eject) 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); @@ -221,6 +224,7 @@ static bool parse_variable_argument (struct print_trns *, 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; @@ -236,7 +240,7 @@ parse_specs (struct pool *tmp_pool, struct print_trns *trns, 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; @@ -288,7 +292,8 @@ parse_string_argument (struct print_trns *trns, int record, int *column) 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) { @@ -298,8 +303,7 @@ parse_variable_argument (struct print_trns *trns, struct pool *tmp_pool, 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 == '(') @@ -416,7 +420,7 @@ static void flush_records (struct print_trns *, /* 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; diff --git a/src/language/dictionary/apply-dictionary.c b/src/language/dictionary/apply-dictionary.c index fc3c54b0..e0434161 100644 --- a/src/language/dictionary/apply-dictionary.c +++ b/src/language/dictionary/apply-dictionary.c @@ -39,7 +39,7 @@ /* Parses and executes APPLY DICTIONARY. */ int -cmd_apply_dictionary (void) +cmd_apply_dictionary (struct dataset *ds) { struct file_handle *handle; struct any_reader *reader; @@ -63,7 +63,7 @@ cmd_apply_dictionary (void) 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; @@ -128,10 +128,10 @@ cmd_apply_dictionary (void) 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); diff --git a/src/language/dictionary/formats.c b/src/language/dictionary/formats.c index 5e1bd7d4..995ee3fb 100644 --- a/src/language/dictionary/formats.c +++ b/src/language/dictionary/formats.c @@ -42,28 +42,28 @@ enum 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; @@ -83,7 +83,7 @@ internal_cmd_formats (int which) 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; diff --git a/src/language/dictionary/missing-values.c b/src/language/dictionary/missing-values.c index db7d1e67..5d121558 100644 --- a/src/language/dictionary/missing-values.c +++ b/src/language/dictionary/missing-values.c @@ -37,7 +37,7 @@ #define _(msgid) gettext (msgid) int -cmd_missing_values (void) +cmd_missing_values (struct dataset *ds) { struct variable **v; size_t nv; @@ -49,7 +49,7 @@ cmd_missing_values (void) { 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 ('(')) diff --git a/src/language/dictionary/modify-variables.c b/src/language/dictionary/modify-variables.c index 3bbf844f..b47d93ff 100644 --- a/src/language/dictionary/modify-variables.c +++ b/src/language/dictionary/modify-variables.c @@ -78,7 +78,7 @@ static bool rearrange_dict (struct dictionary *d, /* 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. */ @@ -92,7 +92,7 @@ cmd_modify_vars (void) 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.")); @@ -142,7 +142,7 @@ cmd_modify_vars (void) "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 { @@ -152,7 +152,7 @@ cmd_modify_vars (void) 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); @@ -194,7 +194,7 @@ cmd_modify_vars (void) 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 ('=')) @@ -239,7 +239,7 @@ cmd_modify_vars (void) 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 @@ -248,7 +248,7 @@ cmd_modify_vars (void) 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; @@ -283,14 +283,14 @@ cmd_modify_vars (void) 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) { @@ -320,11 +320,11 @@ cmd_modify_vars (void) 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; diff --git a/src/language/dictionary/numeric.c b/src/language/dictionary/numeric.c index e1358a53..5a1ab18d 100644 --- a/src/language/dictionary/numeric.c +++ b/src/language/dictionary/numeric.c @@ -37,7 +37,7 @@ /* Parses the NUMERIC command. */ int -cmd_numeric (void) +cmd_numeric (struct dataset *ds) { size_t i; @@ -78,7 +78,7 @@ cmd_numeric (void) /* 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 @@ -108,7 +108,7 @@ fail: /* Parses the STRING command. */ int -cmd_string (void) +cmd_string (struct dataset *ds) { size_t i; @@ -157,7 +157,7 @@ cmd_string (void) /* 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]); @@ -185,14 +185,14 @@ fail: /* 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; diff --git a/src/language/dictionary/rename-variables.c b/src/language/dictionary/rename-variables.c index 89827c93..0e0df1ec 100644 --- a/src/language/dictionary/rename-variables.c +++ b/src/language/dictionary/rename-variables.c @@ -38,7 +38,7 @@ /* 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; @@ -47,7 +47,7 @@ cmd_rename_variables (void) 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.")); @@ -61,7 +61,7 @@ cmd_rename_variables (void) 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 ('=')) @@ -93,7 +93,7 @@ cmd_rename_variables (void) } 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)) { diff --git a/src/language/dictionary/split-file.c b/src/language/dictionary/split-file.c index 625f34c5..ef34d7e9 100644 --- a/src/language/dictionary/split-file.c +++ b/src/language/dictionary/split-file.c @@ -41,10 +41,10 @@ #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; @@ -54,10 +54,10 @@ cmd_split_file (void) (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); } @@ -66,14 +66,15 @@ cmd_split_file (void) /* 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; @@ -84,7 +85,7 @@ output_split_file_values (const struct ccase *c) 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]; diff --git a/src/language/dictionary/split-file.h b/src/language/dictionary/split-file.h index bc014bb7..85083af8 100644 --- a/src/language/dictionary/split-file.h +++ b/src/language/dictionary/split-file.h @@ -20,6 +20,6 @@ #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 */ diff --git a/src/language/dictionary/sys-file-info.c b/src/language/dictionary/sys-file-info.c index c28723b0..b2e016ae 100644 --- a/src/language/dictionary/sys-file-info.c +++ b/src/language/dictionary/sys-file-info.c @@ -78,7 +78,7 @@ sysfile_info_dim (struct tab_table *t, struct outp_driver *d) /* SYSFILE INFO utility. */ int -cmd_sysfile_info (void) +cmd_sysfile_info (struct dataset *ds UNUSED) { struct file_handle *h; struct dictionary *d; @@ -176,12 +176,12 @@ cmd_sysfile_info (void) /* 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; @@ -193,19 +193,19 @@ cmd_display (void) 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 @@ -231,7 +231,7 @@ cmd_display (void) if (as == AS_VECTOR) { - display_vectors (sorted); + display_vectors (dataset_dict(ds), sorted); return CMD_SUCCESS; } @@ -241,7 +241,7 @@ cmd_display (void) 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; @@ -249,7 +249,7 @@ cmd_display (void) 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) { @@ -289,9 +289,9 @@ display_macros (void) } 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) @@ -567,14 +567,14 @@ compare_vectors_by_name (const void *a_, const void *b_) /* 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.")); @@ -583,7 +583,7 @@ display_vectors (int sorted) 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); diff --git a/src/language/dictionary/value-labels.c b/src/language/dictionary/value-labels.c index e9c9b3f9..c39bebd4 100644 --- a/src/language/dictionary/value-labels.c +++ b/src/language/dictionary/value-labels.c @@ -38,7 +38,7 @@ /* 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); @@ -46,21 +46,21 @@ 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); } /* 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. */ @@ -70,7 +70,7 @@ do_value_labels (int erase) 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) { diff --git a/src/language/dictionary/variable-display.c b/src/language/dictionary/variable-display.c index 6c2f24f5..fa6eae46 100644 --- a/src/language/dictionary/variable-display.c +++ b/src/language/dictionary/variable-display.c @@ -36,7 +36,7 @@ It affects nothing but GUIs */ int -cmd_variable_alignment (void) +cmd_variable_alignment (struct dataset *ds) { do { @@ -46,7 +46,7 @@ cmd_variable_alignment (void) 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('(') ) @@ -89,7 +89,7 @@ cmd_variable_alignment (void) It affects nothing but GUIs */ int -cmd_variable_width (void) +cmd_variable_width (struct dataset *ds) { do { @@ -97,7 +97,7 @@ cmd_variable_width (void) 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('(') ) @@ -123,7 +123,7 @@ cmd_variable_width (void) /* Set variables' measurement level */ int -cmd_variable_level (void) +cmd_variable_level (struct dataset *ds) { do { @@ -132,7 +132,7 @@ cmd_variable_level (void) 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('(') ) diff --git a/src/language/dictionary/variable-label.c b/src/language/dictionary/variable-label.c index 63d64ef5..c3bb4c22 100644 --- a/src/language/dictionary/variable-label.c +++ b/src/language/dictionary/variable-label.c @@ -35,7 +35,7 @@ #define _(msgid) gettext (msgid) int -cmd_variable_labels (void) +cmd_variable_labels (struct dataset *ds) { do { @@ -44,7 +44,7 @@ cmd_variable_labels (void) 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) diff --git a/src/language/dictionary/vector.c b/src/language/dictionary/vector.c index 050886d9..1216d9dd 100644 --- a/src/language/dictionary/vector.c +++ b/src/language/dictionary/vector.c @@ -37,7 +37,7 @@ #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 @@ -51,6 +51,8 @@ cmd_vector (void) /* 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 @@ -75,7 +77,7 @@ cmd_vector (void) 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; @@ -104,11 +106,11 @@ cmd_vector (void) 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 ('(')) @@ -158,7 +160,7 @@ cmd_vector (void) 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); @@ -175,9 +177,9 @@ cmd_vector (void) 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; } diff --git a/src/language/dictionary/weight.c b/src/language/dictionary/weight.c index fb0972f9..ec6d712b 100644 --- a/src/language/dictionary/weight.c +++ b/src/language/dictionary/weight.c @@ -34,16 +34,17 @@ #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) @@ -57,7 +58,7 @@ cmd_weight (void) return CMD_CASCADING_FAILURE; } - dict_set_weight (dataset_dict (current_dataset), v); + dict_set_weight (dict, v); } return lex_end_of_command (); diff --git a/src/language/expressions/evaluate.c b/src/language/expressions/evaluate.c index fd12a04b..3ff879f2 100644 --- a/src/language/expressions/evaluate.c +++ b/src/language/expressions/evaluate.c @@ -32,12 +32,19 @@ static void 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 (;;) @@ -102,18 +109,21 @@ expr_evaluate_str (struct expression *e, const struct ccase *c, int case_idx, #include 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")) @@ -148,9 +158,12 @@ cmd_debug_evaluate (void) 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); @@ -186,12 +199,13 @@ cmd_debug_evaluate (void) 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) @@ -242,12 +256,15 @@ cmd_debug_evaluate (void) retval = CMD_SUCCESS; done: + if (ds) + destroy_dataset (ds); + if (c != NULL) { case_destroy (c); free (c); } - dict_destroy (d); + return retval; } diff --git a/src/language/expressions/generate.pl b/src/language/expressions/generate.pl index 8216521a..6eab2436 100644 --- a/src/language/expressions/generate.pl +++ b/src/language/expressions/generate.pl @@ -111,6 +111,8 @@ sub init_all_types { 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. diff --git a/src/language/expressions/operations.def b/src/language/expressions/operations.def index dbd5ce2b..e1ae2a53 100644 --- a/src/language/expressions/operations.def +++ b/src/language/expressions/operations.def @@ -957,8 +957,9 @@ no_opt string operator STR_VAR () } 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); @@ -969,8 +970,9 @@ no_opt perm_only function LAG (num_var v, pos_int n_before) } 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); @@ -982,8 +984,9 @@ no_opt perm_only function LAG (num_var v) 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 @@ -992,8 +995,9 @@ no_opt perm_only string function LAG (str_var v, pos_int n_before) 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 diff --git a/src/language/expressions/parse.c b/src/language/expressions/parse.c index 43339baa..0e7a17d5 100644 --- a/src/language/expressions/parse.c +++ b/src/language/expressions/parse.c @@ -50,7 +50,7 @@ static parse_recursively_func parse_primary; 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); @@ -70,14 +70,14 @@ static union any_node *allocate_unary_variable (struct expression *, 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); @@ -93,9 +93,10 @@ expr_parse (struct dictionary *dict, enum expr_type type) 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; @@ -110,12 +111,12 @@ expr_free (struct expression *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) { @@ -733,7 +734,7 @@ parse_sysvar (struct expression *e) "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]; @@ -751,7 +752,7 @@ parse_sysvar (struct expression *e) 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, @@ -759,7 +760,7 @@ parse_sysvar (struct expression *e) } 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, @@ -792,7 +793,7 @@ parse_primary (struct expression *e) /* 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); @@ -802,12 +803,12 @@ parse_primary (struct expression *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 { @@ -872,7 +873,7 @@ parse_vector_element (struct expression *e) /* 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 (); @@ -1185,7 +1186,7 @@ parse_function (struct expression *e) 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, @@ -1231,7 +1232,7 @@ parse_function (struct expression *e) 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; @@ -1242,8 +1243,8 @@ parse_function (struct expression *e) 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) { @@ -1251,8 +1252,8 @@ parse_function (struct expression *e) 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); @@ -1268,12 +1269,12 @@ fail: /* 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; diff --git a/src/language/expressions/private.h b/src/language/expressions/private.h index a47c2216..48ac8897 100644 --- a/src/language/expressions/private.h +++ b/src/language/expressions/private.h @@ -156,7 +156,7 @@ union operation_data 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. */ @@ -168,7 +168,7 @@ struct expression 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 *); diff --git a/src/language/expressions/public.h b/src/language/expressions/public.h index 9a90cef7..864a258d 100644 --- a/src/language/expressions/public.h +++ b/src/language/expressions/public.h @@ -35,12 +35,15 @@ 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 *, diff --git a/src/language/lexer/q2c.c b/src/language/lexer/q2c.c index 11271270..70a4d780 100644 --- a/src/language/lexer/q2c.c +++ b/src/language/lexer/q2c.c @@ -1177,7 +1177,7 @@ dump_declarations (void) 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)); } @@ -1189,7 +1189,7 @@ dump_declarations (void) /* 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)); @@ -1584,7 +1584,7 @@ dump_subcommand (const subcommand *sbc) } 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), @@ -1595,7 +1595,7 @@ dump_subcommand (const subcommand *sbc) } 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)); @@ -1696,7 +1696,7 @@ dump_subcommand (const subcommand *sbc) } 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:"); @@ -1725,8 +1725,9 @@ dump_parser (int persistent) 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, "{"); @@ -1740,18 +1741,18 @@ dump_parser (int persistent) { 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)); @@ -1762,7 +1763,7 @@ dump_parser (int persistent) } 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:"); @@ -2063,7 +2064,5 @@ main (int argc, char *argv[]) dump (0, "#line %d \"%s\"", ln + 1, ifn); } - - return EXIT_SUCCESS; } diff --git a/src/language/lexer/variable-parser.c b/src/language/lexer/variable-parser.c index 54a4e85c..2de98829 100644 --- a/src/language/lexer/variable-parser.c +++ b/src/language/lexer/variable-parser.c @@ -79,7 +79,7 @@ parse_vs_variable (const struct var_set *vs) 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); @@ -87,16 +87,6 @@ parse_dict_variable (const struct dictionary *d) 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 @@ -533,7 +523,8 @@ parse_DATA_LIST_vars_pool (struct pool *pool, 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; @@ -548,12 +539,12 @@ parse_mixed_vars (char ***names, size_t *nnames, int pv_opts) } 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++) @@ -580,7 +571,7 @@ fail: 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; @@ -591,7 +582,7 @@ parse_mixed_vars_pool (struct pool *pool, 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; diff --git a/src/language/lexer/variable-parser.h b/src/language/lexer/variable-parser.h index f71a778e..9760d857 100644 --- a/src/language/lexer/variable-parser.h +++ b/src/language/lexer/variable-parser.h @@ -55,8 +55,7 @@ enum 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 *, @@ -66,8 +65,10 @@ bool parse_var_set_vars (const struct var_set *, struct variable ***, size_t *, 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 */ diff --git a/src/language/stats/aggregate.c b/src/language/stats/aggregate.c index a388b2d9..2b1ae5a0 100644 --- a/src/language/stats/aggregate.c +++ b/src/language/stats/aggregate.c @@ -146,6 +146,7 @@ struct agr_proc 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. */ }; @@ -154,25 +155,27 @@ static void initialize_aggregate_info (struct agr_proc *, 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 *); /* 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; @@ -185,8 +188,9 @@ cmd_aggregate (void) 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")) @@ -223,7 +227,7 @@ cmd_aggregate (void) 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) @@ -249,7 +253,7 @@ cmd_aggregate (void) /* Read in the aggregate functions. */ lex_match ('/'); - if (!parse_aggregate_functions (&agr)) + if (!parse_aggregate_functions (dict, &agr)) goto error; /* Delete documents. */ @@ -268,21 +272,21 @@ cmd_aggregate (void) { /* 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) { @@ -290,11 +294,11 @@ cmd_aggregate (void) 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); } @@ -312,7 +316,7 @@ cmd_aggregate (void) 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); @@ -332,7 +336,7 @@ cmd_aggregate (void) 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; } @@ -355,7 +359,7 @@ 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. */ @@ -462,7 +466,7 @@ parse_aggregate_functions (struct agr_proc *agr) 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; } @@ -580,7 +584,7 @@ parse_aggregate_functions (struct agr_proc *agr) 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; @@ -590,7 +594,7 @@ parse_aggregate_functions (struct agr_proc *agr) 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; @@ -748,7 +752,7 @@ accumulate_aggregate_info (struct agr_proc *agr, 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) @@ -1086,7 +1090,7 @@ initialize_aggregate_info (struct agr_proc *agr, const struct ccase *input) 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_; @@ -1099,7 +1103,7 @@ agr_to_active_file (const struct ccase *c, void *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_; diff --git a/src/language/stats/autorecode.c b/src/language/stats/autorecode.c index 2b44705f..db45d4ea 100644 --- a/src/language/stats/autorecode.c +++ b/src/language/stats/autorecode.c @@ -93,16 +93,16 @@ struct autorecode_pgm 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; @@ -121,7 +121,7 @@ cmd_autorecode (void) 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")) @@ -159,7 +159,7 @@ cmd_autorecode (void) { 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]); @@ -185,13 +185,13 @@ cmd_autorecode (void) 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; @@ -228,7 +228,7 @@ arc_free (struct autorecode_pgm *arc) /* 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; @@ -267,13 +267,13 @@ recode (const struct autorecode_pgm *arc) 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; @@ -347,7 +347,7 @@ hash_numeric_value (const void *a_, void *foo UNUSED) } 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; diff --git a/src/language/stats/correlations.q b/src/language/stats/correlations.q index e3a181f0..4564ec2c 100644 --- a/src/language/stats/correlations.q +++ b/src/language/stats/correlations.q @@ -46,12 +46,12 @@ static struct cor_set *cor_list, *cor_last; 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; } @@ -71,22 +71,23 @@ cmd_correlations (void) /* (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; @@ -94,18 +95,18 @@ cor_custom_variables (struct cmd_correlations *cmd UNUSED, void *aux UNUSED) /* 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); @@ -133,7 +134,7 @@ cor_custom_variables (struct cmd_correlations *cmd UNUSED, void *aux UNUSED) } 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; diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index e7466d72..8f392d5a 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -175,11 +175,11 @@ static struct cmd_crosstabs cmd; 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, @@ -187,9 +187,9 @@ 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); @@ -200,7 +200,7 @@ cmd_crosstabs (void) /* Parses and executes the CROSSTABS procedure. */ static int -internal_cmd_crosstabs (void) +internal_cmd_crosstabs (struct dataset *ds) { int i; bool ok; @@ -212,7 +212,7 @@ internal_cmd_crosstabs (void) 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; @@ -293,7 +293,7 @@ internal_cmd_crosstabs (void) 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); @@ -302,7 +302,7 @@ internal_cmd_crosstabs (void) /* 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; @@ -313,7 +313,7 @@ crs_custom_tables (struct cmd_crosstabs *cmd UNUSED, void *aux UNUSED) /* 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 ('='); @@ -321,7 +321,7 @@ crs_custom_tables (struct cmd_crosstabs *cmd UNUSED, void *aux UNUSED) 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; ;) @@ -406,7 +406,7 @@ crs_custom_tables (struct cmd_crosstabs *cmd UNUSED, void *aux UNUSED) /* 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) { @@ -423,7 +423,7 @@ crs_custom_variables (struct cmd_crosstabs *cmd UNUSED, void *aux UNUSED) 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; @@ -488,9 +488,9 @@ static unsigned hash_table_entry (const void *, void *); /* 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, @@ -563,12 +563,12 @@ precalc (const struct ccase *first, void *aux UNUSED) /* 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; @@ -637,12 +637,12 @@ calc_general (const struct ccase *c, void *aux UNUSED) } 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; @@ -762,8 +762,8 @@ static void output_pivot_table (struct table_entry **, struct table_entry **, 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) { @@ -799,6 +799,8 @@ postcalc (void *aux UNUSED) } hsh_destroy (gen_tab); + + return true; } static void insert_summary (struct tab_table *, int tab_index, double valid); diff --git a/src/language/stats/descriptives.c b/src/language/stats/descriptives.c index 858825da..a68f17c3 100644 --- a/src/language/stats/descriptives.c +++ b/src/language/stats/descriptives.c @@ -173,23 +173,27 @@ static enum dsc_statistic match_statistic (void); 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); /* 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; @@ -314,7 +318,7 @@ cmd_descriptives (void) { 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; @@ -335,7 +339,7 @@ cmd_descriptives (void) 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++; @@ -373,7 +377,7 @@ cmd_descriptives (void) 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++; @@ -410,11 +414,11 @@ cmd_descriptives (void) 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); @@ -469,11 +473,11 @@ free_dsc_proc (struct dsc_proc *dsc) /* 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)) @@ -486,7 +490,7 @@ try_name (struct dsc_proc *dsc, char *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]; @@ -494,7 +498,7 @@ generate_z_varname (struct dsc_proc *dsc, char *z_name, /* 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; @@ -521,7 +525,7 @@ generate_z_varname (struct dsc_proc *dsc, char *z_name, return false; } - if (try_name (dsc, name)) + if (try_name (dict, dsc, name)) { strcpy (z_name, name); return true; @@ -578,7 +582,7 @@ dump_z_table (struct dsc_proc *dsc) */ 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; @@ -631,7 +635,7 @@ descriptives_trns_free (void *trns_) /* 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; @@ -667,7 +671,7 @@ setup_z_trns (struct dsc_proc *dsc) 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); @@ -690,7 +694,7 @@ setup_z_trns (struct dsc_proc *dsc) } } - add_transformation (current_dataset, + add_transformation (ds, descriptives_trns_proc, descriptives_trns_free, t); } @@ -702,14 +706,15 @@ static bool listwise_missing (struct dsc_proc *dsc, const struct ccase *c); 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++) { @@ -729,7 +734,7 @@ calc_descriptives (const struct ccase *first, 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; @@ -774,7 +779,7 @@ calc_descriptives (const struct ccase *first, 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; diff --git a/src/language/stats/examine.q b/src/language/stats/examine.q index 6b748335..f72a8024 100644 --- a/src/language/stats/examine.q +++ b/src/language/stats/examine.q @@ -110,7 +110,7 @@ static struct factor *factors=0; 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); @@ -151,8 +151,8 @@ void box_plot_variables(const struct factor *fctr, /* 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); @@ -191,14 +191,14 @@ static short sbc_percentile; 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 */ @@ -222,7 +222,7 @@ cmd_examine(void) 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 ) { @@ -423,7 +423,8 @@ list_to_ptile_hash(const subc_list_double *l) /* 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; @@ -433,7 +434,7 @@ xmn_custom_percentiles(struct cmd_examine *p UNUSED, void *aux UNUSED) while ( lex_is_number() ) { - subc_list_double_push(&percentile_list,lex_number()); + subc_list_double_push (&percentile_list, lex_number()); lex_get(); @@ -464,13 +465,13 @@ xmn_custom_percentiles(struct cmd_examine *p UNUSED, void *aux UNUSED) 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; @@ -478,7 +479,7 @@ xmn_custom_percentiles(struct cmd_examine *p UNUSED, void *aux UNUSED) /* 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 ) { @@ -490,7 +491,8 @@ xmn_custom_total(struct cmd_examine *p, void *aux UNUSED) } 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 ) { @@ -506,17 +508,18 @@ xmn_custom_nototal(struct cmd_examine *p, void *aux UNUSED) /* 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); @@ -530,7 +533,7 @@ xmn_custom_variables(struct cmd_examine *cmd, void *aux UNUSED) 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) ; @@ -545,12 +548,12 @@ xmn_custom_variables(struct cmd_examine *cmd, void *aux UNUSED) /* 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 ) ; @@ -558,7 +561,7 @@ examine_parse_independent_vars(struct cmd_examine *cmd) } - sf->indep_var[0] = parse_variable(); + sf->indep_var[0] = parse_variable (dict); sf->indep_var[1] = 0; if ( token == T_BY ) @@ -566,14 +569,14 @@ examine_parse_independent_vars(struct cmd_examine *cmd) 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); } @@ -592,7 +595,7 @@ examine_parse_independent_vars(struct cmd_examine *cmd) if ( token == '.' || token == '/' ) return 1; - success = examine_parse_independent_vars(cmd); + success = examine_parse_independent_vars (dict, cmd); if ( success != 1 ) free ( sf ) ; @@ -678,8 +681,10 @@ factor_calc(struct ccase *c, int case_no, double weight, int case_missing) } 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; @@ -688,7 +693,7 @@ run_examine(const struct ccase *first, const struct casefile *cf, void *cmd_ ) 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 */ @@ -704,8 +709,6 @@ run_examine(const struct ccase *first, const struct casefile *cf, void *cmd_ ) fctr = next; } - - for ( v = 0 ; v < n_dependent_vars ; ++v ) metrics_precalc(&totals[v]); @@ -717,7 +720,7 @@ run_examine(const struct ccase *first, const struct casefile *cf, void *cmd_ ) 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 ) { diff --git a/src/language/stats/flip.c b/src/language/stats/flip.c index f304fb0e..8a6128bc 100644 --- a/src/language/stats/flip.c +++ b/src/language/stats/flip.c @@ -80,29 +80,30 @@ struct flip_pgm }; static void destroy_flip_pgm (struct flip_pgm *); -static struct case_sink *flip_sink_create (struct flip_pgm *); +static struct case_sink *flip_sink_create (struct dictionary *d, struct flip_pgm *); static struct case_source *flip_source_create (struct flip_pgm *); static bool flip_file (struct flip_pgm *); -static 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; @@ -115,25 +116,25 @@ cmd_flip (void) 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) { @@ -150,32 +151,32 @@ cmd_flip (void) /* 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; @@ -195,7 +196,7 @@ destroy_flip_pgm (struct flip_pgm *flip) /* Make a new variable with base name NAME, which is bowdlerized and mangled until acceptable, and returns success. */ static int -make_new_var (char name[]) +make_new_var (struct dictionary *dict, char name[]) { char *cp; @@ -219,7 +220,7 @@ make_new_var (char name[]) *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. */ @@ -234,7 +235,7 @@ make_new_var (char name[]) 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; } } @@ -245,9 +246,9 @@ make_new_var (char name[]) /* 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) { @@ -265,7 +266,7 @@ build_dictionary (struct flip_pgm *flip) 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 @@ -273,7 +274,7 @@ build_dictionary (struct flip_pgm *flip) 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; } @@ -282,7 +283,7 @@ build_dictionary (struct flip_pgm *flip) /* 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; @@ -309,7 +310,7 @@ flip_sink_create (struct flip_pgm *flip) 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. diff --git a/src/language/stats/frequencies.q b/src/language/stats/frequencies.q index d78f37a7..158fd429 100644 --- a/src/language/stats/frequencies.q +++ b/src/language/stats/frequencies.q @@ -278,9 +278,9 @@ static void determine_charts (void); 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 *); @@ -305,15 +305,15 @@ freq_tab_to_hist(const struct freq_tab *ft, const struct variable *var); /* 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); @@ -324,7 +324,7 @@ cmd_frequencies (void) } static int -internal_cmd_frequencies (void) +internal_cmd_frequencies (struct dataset *ds) { int i; bool ok; @@ -335,7 +335,7 @@ internal_cmd_frequencies (void) 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) @@ -391,7 +391,7 @@ internal_cmd_frequencies (void) /* Do it! */ - ok = procedure_with_splits (current_dataset, precalc, calc, postcalc, NULL); + ok = procedure_with_splits (ds, precalc, calc, postcalc, NULL); free_frequencies(&cmd); @@ -505,13 +505,13 @@ determine_charts (void) /* 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++) { @@ -566,11 +566,11 @@ calc (const struct ccase *c, void *aux UNUSED) /* 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 (); @@ -611,8 +611,8 @@ precalc (const struct ccase *first, void *aux UNUSED) /* 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; @@ -687,6 +687,8 @@ postcalc (void *aux UNUSED) cleanup_freq_tab (v); } + + return true; } /* Returns the comparison function that should be used for @@ -791,7 +793,7 @@ cleanup_freq_tab (struct variable *v) /* 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; @@ -801,10 +803,10 @@ frq_custom_variables (struct cmd_frequencies *cmd UNUSED, void *aux UNUSED) 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; @@ -879,10 +881,10 @@ frq_custom_variables (struct cmd_frequencies *cmd UNUSED, void *aux UNUSED) /* 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 (;;) { @@ -896,7 +898,7 @@ frq_custom_grouped (struct cmd_frequencies *cmd UNUSED, void *aux UNUSED) 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 ('(')) @@ -949,7 +951,7 @@ frq_custom_grouped (struct cmd_frequencies *cmd UNUSED, void *aux UNUSED) 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 ('/'); diff --git a/src/language/stats/means.q b/src/language/stats/means.q index bc927b47..fc01c07a 100644 --- a/src/language/stats/means.q +++ b/src/language/stats/means.q @@ -61,7 +61,7 @@ static struct variable **v_var; /* Parses and executes the T-TEST procedure. */ int -cmd_means (void) +cmd_means (struct dataset *ds) { struct cmd_means cmd; int success = CMD_FAILURE; @@ -71,7 +71,7 @@ cmd_means (void) v_dim = NULL; v_var = NULL; - if (!parse_means (&cmd, NULL)) + if (!parse_means (ds, &cmd, NULL)) goto free; if (cmd.sbc_cells) @@ -122,12 +122,12 @@ free: /* 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 ('='); @@ -139,7 +139,7 @@ mns_custom_tables (struct cmd_means *cmd, void *aux UNUSED) 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 diff --git a/src/language/stats/oneway.q b/src/language/stats/oneway.q index 9b5a36bc..86506710 100644 --- a/src/language/stats/oneway.q +++ b/src/language/stats/oneway.q @@ -96,7 +96,7 @@ static is_missing_func *value_is_missing; 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 */ @@ -116,12 +116,12 @@ void output_oneway(void); 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 */ @@ -149,7 +149,7 @@ cmd_oneway(void) } } - ok = multipass_procedure_with_splits (current_dataset, run_oneway, &cmd); + ok = multipass_procedure_with_splits (ds, run_oneway, &cmd); free (vars); free_oneway (&cmd); @@ -223,17 +223,17 @@ output_oneway(void) /* 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) ) { @@ -246,8 +246,7 @@ oneway_custom_variables(struct cmd_oneway *cmd UNUSED, void *aux UNUSED) if ( ! lex_match(T_BY)) return 2; - - indep_var = parse_variable(); + indep_var = parse_variable (dict); if ( !indep_var ) { @@ -255,7 +254,6 @@ oneway_custom_variables(struct cmd_oneway *cmd UNUSED, void *aux UNUSED) return 0; } - return 1; } @@ -894,14 +892,14 @@ precalc ( struct cmd_oneway *cmd UNUSED ) 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, @@ -917,7 +915,7 @@ run_oneway(const struct ccase *first, const struct casefile *cf, void *cmd_) 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); @@ -1006,7 +1004,7 @@ run_oneway(const struct ccase *first, const struct casefile *cf, void *cmd_) 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); diff --git a/src/language/stats/rank.q b/src/language/stats/rank.q index 5f58f8c6..f2b8eeb9 100644 --- a/src/language/stats/rank.q +++ b/src/language/stats/rank.q @@ -168,6 +168,7 @@ static struct cmd_rank cmd; 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, @@ -232,19 +233,19 @@ create_var_label (struct variable *dest_var, 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; @@ -263,10 +264,10 @@ rank_cmd (const struct sort_criteria *sc, 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) ; @@ -276,6 +277,7 @@ rank_cmd (const struct sort_criteria *sc, 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 ) @@ -284,7 +286,7 @@ rank_cmd (const struct sort_criteria *sc, continue ; } - proc_set_source (current_dataset, storage_source_create (out)); + proc_set_source (ds, storage_source_create (out)); } free (criteria.crits); @@ -487,6 +489,7 @@ rank_savage (double c, double cc, double cc_1, 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, @@ -516,7 +519,7 @@ rank_cases (struct casereader *cr, 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; @@ -535,7 +538,7 @@ rank_cases (struct casereader *cr, 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++; } @@ -589,6 +592,7 @@ same_group (const struct ccase *a, const struct ccase *b, 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, @@ -610,16 +614,17 @@ rank_sorted_casefile (struct casefile *cf, 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, @@ -634,7 +639,7 @@ rank_sorted_casefile (struct casefile *cf, 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); } @@ -667,7 +672,7 @@ create_resort_key (void *key_var_, struct ccase *cc, casenum_t case_num) 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) { @@ -676,14 +681,14 @@ create_rank_variable (enum RANK_FUNC f, 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; @@ -694,7 +699,7 @@ create_rank_variable (enum RANK_FUNC f, 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; } @@ -708,7 +713,7 @@ create_rank_variable (enum RANK_FUNC f, 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; } @@ -724,7 +729,7 @@ create_rank_variable (enum RANK_FUNC f, return var; } -int cmd_rank(void); +int cmd_rank(struct dataset *ds); static void rank_cleanup(void) @@ -753,14 +758,14 @@ 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; @@ -802,7 +807,7 @@ cmd_rank(void) 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], @@ -891,12 +896,12 @@ cmd_rank(void) /* 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 */ { @@ -909,11 +914,11 @@ cmd_rank(void) 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(); @@ -924,27 +929,27 @@ cmd_rank(void) /* 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); @@ -958,7 +963,7 @@ rank_custom_variables(struct cmd_rank *cmd UNUSED, void *aux UNUSED) /* 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; @@ -977,7 +982,7 @@ parse_rank_function(struct cmd_rank *cmd UNUSED, enum RANK_FUNC f) 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; @@ -988,7 +993,7 @@ parse_rank_function(struct cmd_rank *cmd UNUSED, enum RANK_FUNC f) 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(); @@ -1001,51 +1006,67 @@ parse_rank_function(struct cmd_rank *cmd UNUSED, enum RANK_FUNC f) 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() ) @@ -1060,5 +1081,5 @@ rank_custom_ntiles(struct cmd_rank *cmd, void *aux UNUSED ) else return 0; - return parse_rank_function(cmd, NTILES); + return parse_rank_function(dict, cmd, NTILES); } diff --git a/src/language/stats/regression.q b/src/language/stats/regression.q index 947f8285..5ac6b93a 100644 --- a/src/language/stats/regression.q +++ b/src/language/stats/regression.q @@ -118,7 +118,8 @@ static struct file_handle *model_file; 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. @@ -621,32 +622,35 @@ regression_trns_resid_proc (void *t_, struct ccase *c, } /* - 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; @@ -656,15 +660,16 @@ reg_save_var (const char *prefix, trns_proc_func * f, 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; @@ -690,12 +695,12 @@ subcommand_save (int save, pspp_linreg_cache ** models) 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); } } @@ -709,6 +714,7 @@ subcommand_save (int save, pspp_linreg_cache ** models) } } } + static int reg_inserted (const struct variable *v, struct variable **varlist, int n_vars) { @@ -723,6 +729,7 @@ 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) { @@ -907,8 +914,9 @@ subcommand_export (int export, 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 ('(')) @@ -930,15 +938,15 @@ regression_custom_export (struct cmd_regression *cmd UNUSED, void *aux UNUSED) } 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; @@ -996,18 +1004,20 @@ mark_missing_cases (const struct casefile *cf, struct variable *v, /* 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; @@ -1089,7 +1099,7 @@ coeff_init (pspp_linreg_cache * c, struct design_matrix *dm) 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. */ @@ -1113,11 +1123,11 @@ run_regression (const struct ccase *first, 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); } diff --git a/src/language/stats/sort-cases.c b/src/language/stats/sort-cases.c index 8ebf4b28..be8e3235 100644 --- a/src/language/stats/sort-cases.c +++ b/src/language/stats/sort-cases.c @@ -40,14 +40,14 @@ /* 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; @@ -68,7 +68,7 @@ cmd_sort_cases (void) lex_get (); } - success = sort_active_file_in_place (criteria); + success = sort_active_file_in_place (ds, criteria); done: min_buffers = 64; diff --git a/src/language/stats/t-test.q b/src/language/stats/t-test.q index 492820cd..3fbb6d88 100644 --- a/src/language/stats/t-test.q +++ b/src/language/stats/t-test.q @@ -218,25 +218,27 @@ enum { }; -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; @@ -256,11 +258,11 @@ static unsigned hash_group_binary(const struct group_statistics *g, 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) @@ -345,7 +347,7 @@ cmd_t_test(void) 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); @@ -367,13 +369,13 @@ cmd_t_test(void) } 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"); @@ -446,7 +448,7 @@ tts_custom_groups (struct cmd_t_test *cmd UNUSED, void *aux UNUSED) 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; @@ -459,7 +461,7 @@ tts_custom_pairs (struct cmd_t_test *cmd UNUSED, void *aux UNUSED) 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); @@ -471,7 +473,7 @@ tts_custom_pairs (struct cmd_t_test *cmd UNUSED, void *aux UNUSED) 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)) { @@ -1411,12 +1413,12 @@ pscbox(void) /* 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 */ @@ -1510,13 +1512,14 @@ common_postcalc ( struct cmd_t_test *cmd ) /* 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 ) @@ -1600,13 +1603,13 @@ paired_precalc (struct cmd_t_test *cmd UNUSED) 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 */ @@ -1745,14 +1748,15 @@ group_precalc (struct cmd_t_test *cmd ) } 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) ) { @@ -1839,8 +1843,10 @@ group_postcalc ( struct cmd_t_test *cmd ) 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; @@ -1849,13 +1855,13 @@ calculate(const struct ccase *first, const struct casefile *cf, void *cmd_) 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); @@ -1868,7 +1874,7 @@ calculate(const struct ccase *first, const struct casefile *cf, void *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); @@ -1880,10 +1886,10 @@ calculate(const struct ccase *first, const struct casefile *cf, void *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: @@ -1893,12 +1899,12 @@ calculate(const struct ccase *first, const struct casefile *cf, void *cmd_) 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; diff --git a/src/language/tests/casefile-test.c b/src/language/tests/casefile-test.c index 30ffdd2b..6f5a5d2e 100644 --- a/src/language/tests/casefile-test.c +++ b/src/language/tests/casefile-test.c @@ -45,7 +45,7 @@ static void test_casereader_clone (struct casereader *reader1, size_t case_cnt); static void fail_test (const char *message, ...); int -cmd_debug_casefile (void) +cmd_debug_casefile (struct dataset *ds UNUSED) { static const size_t sizes[] = { diff --git a/src/language/tests/moments-test.c b/src/language/tests/moments-test.c index 05f0981b..533b558f 100644 --- a/src/language/tests/moments-test.c +++ b/src/language/tests/moments-test.c @@ -26,6 +26,7 @@ #include #include #include "xalloc.h" +#include #define _(msgid) gettext (msgid) @@ -69,7 +70,7 @@ read_values (double **values, double **weights, size_t *cnt) } int -cmd_debug_moments (void) +cmd_debug_moments (struct dataset *ds UNUSED) { int retval = CMD_FAILURE; double *values = NULL; diff --git a/src/language/tests/pool-test.c b/src/language/tests/pool-test.c index 17674fbd..8f1484ff 100644 --- a/src/language/tests/pool-test.c +++ b/src/language/tests/pool-test.c @@ -32,7 +32,7 @@ /* 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; diff --git a/src/language/utilities/date.c b/src/language/utilities/date.c index 06115f91..7529f977 100644 --- a/src/language/utilities/date.c +++ b/src/language/utilities/date.c @@ -27,7 +27,7 @@ /* Stub for USE command. */ int -cmd_use (void) +cmd_use (struct dataset *ds UNUSED) { if (lex_match (T_ALL)) return lex_end_of_command (); diff --git a/src/language/utilities/echo.c b/src/language/utilities/echo.c index e4d8e685..5405d060 100644 --- a/src/language/utilities/echo.c +++ b/src/language/utilities/echo.c @@ -29,7 +29,7 @@ /* Echos a string to the output stream */ int -cmd_echo(void) +cmd_echo (struct dataset *ds UNUSED) { struct tab_table *tab; diff --git a/src/language/utilities/include.c b/src/language/utilities/include.c index 19f5c2e2..ef58a20e 100644 --- a/src/language/utilities/include.c +++ b/src/language/utilities/include.c @@ -31,7 +31,7 @@ #define _(msgid) gettext (msgid) int -cmd_include (void) +cmd_include (struct dataset *ds UNUSED) { /* Skip optional FILE=. */ if (lex_match_id ("FILE")) diff --git a/src/language/utilities/permissions.c b/src/language/utilities/permissions.c index 03b2241a..7ac9143c 100644 --- a/src/language/utilities/permissions.c +++ b/src/language/utilities/permissions.c @@ -42,7 +42,7 @@ int change_permissions(const char *file_name, enum PER per); /* Parses the PERMISSIONS command. */ int -cmd_permissions (void) +cmd_permissions (struct dataset *ds UNUSED) { char *fn = 0; diff --git a/src/language/utilities/set.q b/src/language/utilities/set.q index 113373d7..d5b84a71 100644 --- a/src/language/utilities/set.q +++ b/src/language/utilities/set.q @@ -120,12 +120,12 @@ int tgetnum (const char *); 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) @@ -289,7 +289,7 @@ do_cc (const char *cc_string, int idx) 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))) @@ -310,7 +310,7 @@ stc_custom_blanks (struct cmd_set *cmd UNUSED, void *aux UNUSED) /* 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")) @@ -336,7 +336,7 @@ stc_custom_epoch (struct cmd_set *cmd UNUSED, void *aux UNUSED) } 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; @@ -363,7 +363,7 @@ stc_custom_length (struct cmd_set *cmd UNUSED, void *aux UNUSED) } 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")) @@ -380,7 +380,7 @@ stc_custom_seed (struct cmd_set *cmd UNUSED, void *aux UNUSED) } 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")) @@ -406,7 +406,7 @@ stc_custom_width (struct cmd_set *cmd UNUSED, void *aux UNUSED) /* 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; @@ -426,7 +426,7 @@ stc_custom_format (struct cmd_set *cmd UNUSED, void *aux UNUSED) } 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")) @@ -443,7 +443,7 @@ stc_custom_journal (struct cmd_set *cmd UNUSED, void *aux UNUSED) } 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; @@ -463,13 +463,13 @@ stc_custom_listing (struct cmd_set *cmd UNUSED, void *aux UNUSED) } 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); } static void -show_blanks (void) +show_blanks (const struct dataset *ds UNUSED) { if (get_blanks () == SYSMIS) msg (SN, _("BLANKS is SYSMIS.")); @@ -511,79 +511,79 @@ show_cc (int idx) 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.")); @@ -592,7 +592,7 @@ show_scompression (void) } static void -show_undefined (void) +show_undefined (const struct dataset *ds UNUSED) { if (get_undefined ()) msg (SN, _("UNDEFINED is WARN.")); @@ -601,9 +601,9 @@ show_undefined (void) } 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 @@ -611,7 +611,7 @@ show_weight (void) } static void -show_width (void) +show_width (const struct dataset *ds UNUSED) { msg (SN, _("WIDTH is %d."), get_viewwidth ()); } @@ -619,7 +619,7 @@ show_width (void) struct show_sbc { const char *name; - void (*function) (void); + void (*function) (const struct dataset *); }; const struct show_sbc show_table[] = @@ -644,12 +644,12 @@ 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 @@ -662,36 +662,36 @@ show_all_cc (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; @@ -699,7 +699,7 @@ cmd_show (void) 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); diff --git a/src/language/utilities/title.c b/src/language/utilities/title.c index ffb2a48e..9e8bfaf7 100644 --- a/src/language/utilities/title.c +++ b/src/language/utilities/title.c @@ -39,13 +39,13 @@ 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); } @@ -88,7 +88,7 @@ get_title (const char *cmd, char **title) /* Performs the FILE LABEL command. */ int -cmd_file_label (void) +cmd_file_label (struct dataset *ds) { const char *label; @@ -97,22 +97,22 @@ cmd_file_label (void) 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); @@ -121,24 +121,25 @@ add_document_line (const char *line, int indent) 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 (;;) @@ -157,7 +158,7 @@ cmd_document (void) 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 (); @@ -171,9 +172,9 @@ cmd_document (void) /* 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 (); } diff --git a/src/language/xforms/compute.c b/src/language/xforms/compute.c index c4ea4c5a..46c693bb 100644 --- a/src/language/xforms/compute.c +++ b/src/language/xforms/compute.c @@ -43,11 +43,11 @@ struct lvalue; /* 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. */ @@ -69,35 +69,36 @@ struct compute_trns 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; /* 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 (); @@ -111,7 +112,7 @@ cmd_compute (void) /* 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_; @@ -126,7 +127,7 @@ compute_num (void *compute_, struct ccase *c, casenum_t case_num) /* 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_; @@ -158,7 +159,7 @@ compute_num_vec (void *compute_, struct ccase *c, casenum_t case_num) /* 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_; @@ -173,7 +174,7 @@ compute_str (void *compute_, struct ccase *c, casenum_t case_num) /* 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_; @@ -212,34 +213,35 @@ compute_str_vec (void *compute_, struct ccase *c, casenum_t case_num) /* 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 (); @@ -252,9 +254,9 @@ cmd_if (void) /* 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 @@ -265,11 +267,12 @@ get_proc_func (const struct lvalue *lvalue) /* 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. */ @@ -312,7 +315,7 @@ struct lvalue /* 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; @@ -327,7 +330,7 @@ lvalue_parse (void) 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); @@ -338,7 +341,7 @@ lvalue_parse (void) 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 (')')) @@ -360,11 +363,11 @@ lvalue_parse (void) /* 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 @@ -384,14 +387,15 @@ lvalue_is_vector (const struct lvalue *lvalue) /* 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; diff --git a/src/language/xforms/count.c b/src/language/xforms/count.c index 716c5d39..c392382a 100644 --- a/src/language/xforms/count.c +++ b/src/language/xforms/count.c @@ -97,7 +97,7 @@ static bool parse_numeric_criteria (struct pool *, struct criteria *); static bool parse_string_criteria (struct pool *, struct criteria *); int -cmd_count (void) +cmd_count (struct dataset *ds) { struct dst_var *dv; /* Destination var being parsed. */ struct count_trns *trns; /* Transformation. */ @@ -117,7 +117,7 @@ cmd_count (void) /* 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) @@ -140,7 +140,7 @@ cmd_count (void) 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); @@ -176,13 +176,13 @@ cmd_count (void) { /* 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: @@ -325,7 +325,7 @@ count_string (struct criteria *crit, struct ccase *c) /* 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; diff --git a/src/language/xforms/fail.c b/src/language/xforms/fail.c index ebc30e9c..2b1e7876 100644 --- a/src/language/xforms/fail.c +++ b/src/language/xforms/fail.c @@ -27,7 +27,7 @@ #include #include -static int trns_fail (void *x, struct ccase *c, casenum_t n); +static int trns_fail (void *x, struct ccase *c, casenumber n); @@ -35,17 +35,17 @@ static int trns_fail (void *x, struct ccase *c, casenum_t n); 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 (); } diff --git a/src/language/xforms/recode.c b/src/language/xforms/recode.c index 69443961..6af3e5d1 100644 --- a/src/language/xforms/recode.c +++ b/src/language/xforms/recode.c @@ -108,9 +108,9 @@ struct recode_trns 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 *); @@ -128,7 +128,7 @@ static void set_map_out_str (struct map_out *, struct pool *, 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; @@ -137,7 +137,7 @@ static trns_free_func recode_trns_free; /* Parses the RECODE transformation. */ int -cmd_recode (void) +cmd_recode (struct dataset *ds) { do { @@ -147,9 +147,9 @@ cmd_recode (void) /* 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; @@ -164,10 +164,10 @@ cmd_recode (void) 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 ('/')); @@ -179,9 +179,9 @@ cmd_recode (void) 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); @@ -415,7 +415,7 @@ set_map_out_str (struct map_out *out, struct pool *pool, /* 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; @@ -424,7 +424,8 @@ parse_dst_vars (struct recode_trns *trns) 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; @@ -442,8 +443,7 @@ parse_dst_vars (struct recode_trns *trns) 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 " @@ -516,7 +516,7 @@ enlarge_dst_widths (struct recode_trns *trns) /* 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; @@ -525,9 +525,9 @@ create_dst_vars (struct recode_trns *trns) 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); } } @@ -623,7 +623,7 @@ find_src_string (struct recode_trns *trns, const char *value, int width) /* 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; diff --git a/src/language/xforms/sample.c b/src/language/xforms/sample.c index 9daa69e2..83fae887 100644 --- a/src/language/xforms/sample.c +++ b/src/language/xforms/sample.c @@ -57,7 +57,7 @@ static trns_proc_func sample_trns_proc; static trns_free_func sample_trns_free; int -cmd_sample (void) +cmd_sample (struct dataset *ds) { struct sample_trns *trns; @@ -111,7 +111,7 @@ cmd_sample (void) 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 (); } @@ -119,7 +119,7 @@ cmd_sample (void) /* 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; diff --git a/src/language/xforms/select-if.c b/src/language/xforms/select-if.c index 8e4c0e91..66c8f9e4 100644 --- a/src/language/xforms/select-if.c +++ b/src/language/xforms/select-if.c @@ -47,12 +47,12 @@ static trns_free_func select_if_free; /* 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; @@ -65,7 +65,7 @@ cmd_select_if (void) 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; } @@ -73,7 +73,7 @@ cmd_select_if (void) /* 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 @@ -92,22 +92,23 @@ select_if_free (void *t_) /* 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; @@ -123,7 +124,7 @@ cmd_filter (void) return CMD_FAILURE; } - dict_set_filter (dataset_dict (current_dataset), v); + dict_set_filter (dict, v); } return lex_end_of_command (); diff --git a/src/math/levene.c b/src/math/levene.c index f30d51df..8fb41fed 100644 --- a/src/math/levene.c +++ b/src/math/levene.c @@ -82,20 +82,21 @@ struct levene_info /* 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; @@ -114,7 +115,7 @@ levene(const struct casefile *cf, casereader_read (r, &c) ; case_destroy (&c)) { - levene_calc(&c,&l); + levene_calc (dict, &c,&l); } casereader_destroy (r); levene_postcalc(&l); @@ -124,7 +125,7 @@ levene(const struct casefile *cf, casereader_read (r, &c) ; case_destroy (&c)) { - levene2_calc(&c,&l); + levene2_calc (dict, &c,&l); } casereader_destroy (r); levene2_postcalc(&l); @@ -184,14 +185,14 @@ levene_precalc (const struct levene_info *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 ) @@ -207,7 +208,6 @@ levene_calc (const struct ccase *c, void *_l) } } } - key.id = *gv; @@ -288,14 +288,14 @@ levene2_precalc (void *_l) } 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; diff --git a/src/math/levene.h b/src/math/levene.h index 886d3a36..c94c3d61 100644 --- a/src/math/levene.h +++ b/src/math/levene.h @@ -40,7 +40,9 @@ The dependent variables : v_dep; */ -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); diff --git a/src/math/sort.c b/src/math/sort.c index 3f42c23d..ee2bc6ea 100644 --- a/src/math/sort.c +++ b/src/math/sort.c @@ -59,30 +59,25 @@ static struct casefile *do_internal_sort (struct casereader *, 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; } @@ -106,15 +101,16 @@ sort_to_casefile_callback (const struct casefile *cf, void *cb_data_) 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; diff --git a/src/math/sort.h b/src/math/sort.h index bccf494a..7d945622 100644 --- a/src/math/sort.h +++ b/src/math/sort.h @@ -60,8 +60,11 @@ void sort_destroy_criteria (struct sort_criteria *); 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 */ diff --git a/src/ui/terminal/main.c b/src/ui/terminal/main.c index 3450ac9d..6a861b70 100644 --- a/src/ui/terminal/main.c +++ b/src/ui/terminal/main.c @@ -69,6 +69,8 @@ void bug_handler(int sig); /* Handle quit/term/int signals */ void interrupt_handler(int sig); +static struct dataset * the_dataset = NULL; + /* Program entry point. */ @@ -93,7 +95,7 @@ main (int argc, char **argv) readln_initialize (); settings_init (); random_init (); - current_dataset = create_dataset (); + the_dataset = create_dataset (); if (parse_command_line (argc, argv)) { @@ -102,7 +104,8 @@ main (int argc, char **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; @@ -178,7 +181,7 @@ terminate (bool success) { terminating = true; - destroy_dataset (current_dataset); + destroy_dataset (the_dataset); random_done (); settings_done (); diff --git a/tests/bugs/lag_crash.sh b/tests/bugs/lag_crash.sh index 0ed8e077..ae3c3748 100755 --- a/tests/bugs/lag_crash.sh +++ b/tests/bugs/lag_crash.sh @@ -70,7 +70,7 @@ if [ $? -ne 0 ] ; then no_result ; fi activity="run_program" -$SUPERVISOR $PSPP $TESTFILE > /dev/null +$SUPERVISOR $PSPP $TESTFILE if [ $? -ne 0 ] ; then fail ; fi -- 2.30.2