From: Ben Pfaff Date: Sun, 20 Mar 2011 18:25:53 +0000 (-0700) Subject: dataset: Rename functions with "dataset_" prefix. X-Git-Tag: v0.7.7~11 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e24f9a5c52650da0700066e8d9e72261c6492ad;p=pspp-builds.git dataset: Rename functions with "dataset_" prefix. --- diff --git a/src/data/dataset.c b/src/data/dataset.c index a94fba2c..1729c2d0 100644 --- a/src/data/dataset.c +++ b/src/data/dataset.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010, 2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -103,8 +103,7 @@ struct dataset { /* Default encoding for reading syntax files. */ char *syntax_encoding; -}; /* struct dataset */ - +}; static void add_case_limit_trns (struct dataset *ds); static void add_filter_trns (struct dataset *ds); @@ -117,9 +116,129 @@ dataset_set_unsaved (const struct dataset *ds) if (ds->callback) ds->callback (ds->cb_data); } +static void +dict_callback (struct dictionary *d UNUSED, void *ds_) +{ + struct dataset *ds = ds_; + dataset_set_unsaved (ds); +} -/* Public functions. */ +/* Creates and returns a new dataset. The dataset initially has an empty + dictionary and no data source. */ +struct dataset * +dataset_create (void) +{ + struct dataset *ds; + + ds = xzalloc (sizeof *ds); + ds->dict = dict_create (); + dict_set_change_callback (ds->dict, dict_callback, ds); + dict_set_encoding (ds->dict, get_default_encoding ()); + + ds->caseinit = caseinit_create (); + proc_cancel_all_transformations (ds); + ds->syntax_encoding = xstrdup ("Auto"); + return ds; +} +/* Destroys DS. */ +void +dataset_destroy (struct dataset *ds) +{ + if (ds != NULL) + { + dataset_clear (ds); + dict_destroy (ds->dict); + caseinit_destroy (ds->caseinit); + trns_chain_destroy (ds->permanent_trns_chain); + + if ( ds->xform_callback) + ds->xform_callback (false, ds->xform_callback_aux); + free (ds->syntax_encoding); + free (ds); + } +} + +/* Discards the active file dictionary, data, and transformations. */ +void +dataset_clear (struct dataset *ds) +{ + assert (ds->proc_state == PROC_COMMITTED); + + dict_clear (ds->dict); + fh_set_default_handle (NULL); + + ds->n_lag = 0; + + casereader_destroy (ds->source); + ds->source = NULL; + + proc_cancel_all_transformations (ds); +} + +/* Returns the dictionary within DS. This is always nonnull, although it + might not contain any variables. */ +struct dictionary * +dataset_dict (const struct dataset *ds) +{ + return ds->dict; +} + +/* Replaces DS's dictionary by DICT, discarding any source and + transformations. */ +void +dataset_set_dict (struct dataset *ds, struct dictionary *dict) +{ + assert (ds->proc_state == PROC_COMMITTED); + assert (ds->dict != dict); + + dataset_clear (ds); + + dict_destroy (ds->dict); + ds->dict = dict; + dict_set_change_callback (ds->dict, dict_callback, ds); +} + +/* Returns the casereader that will be read when a procedure is executed on + DS. This can be NULL if none has been set up yet. */ +const struct casereader * +dataset_source (const struct dataset *ds) +{ + return ds->source; +} + +/* Returns true if DS has a data source, false otherwise. */ +bool +dataset_has_source (const struct dataset *ds) +{ + return dataset_source (ds) != NULL; +} + +/* Replaces the active file's data by READER. READER's cases must have an + appropriate format for DS's dictionary. */ +bool +dataset_set_source (struct dataset *ds, struct casereader *reader) +{ + casereader_destroy (ds->source); + ds->source = reader; + + caseinit_clear (ds->caseinit); + caseinit_mark_as_preinited (ds->caseinit, ds->dict); + + return reader == NULL || !casereader_error (reader); +} + +/* Returns the data source from DS and removes it from DS. Returns a null + pointer if DS has no data source. */ +struct casereader * +dataset_steal_source (struct dataset *ds) +{ + struct casereader *reader = ds->source; + ds->source = NULL; + + return reader; +} + void dataset_set_callback (struct dataset *ds, void (*cb) (void *), void *cb_data) { @@ -354,7 +473,7 @@ proc_casereader_destroy (struct casereader *reader, void *ds_) ds->proc_state = PROC_CLOSED; ds->ok = casereader_destroy (ds->source) && ds->ok; ds->source = NULL; - proc_set_active_file_data (ds, NULL); + dataset_set_source (ds, NULL); } /* Must return false if the source casereader, a transformation, @@ -591,33 +710,6 @@ proc_cancel_all_transformations (struct dataset *ds) } -static void -dict_callback (struct dictionary *d UNUSED, void *ds_) -{ - struct dataset *ds = ds_; - dataset_set_unsaved (ds); -} - -/* Initializes procedure handling. */ -struct dataset * -create_dataset (void) -{ - struct dataset *ds = xzalloc (sizeof(*ds)); - ds->dict = dict_create (); - - dict_set_change_callback (ds->dict, dict_callback, ds); - - dict_set_encoding (ds->dict, get_default_encoding ()); - - ds->caseinit = caseinit_create (); - proc_cancel_all_transformations (ds); - - ds->syntax_encoding = xstrdup ("Auto"); - - return ds; -} - - void dataset_add_transform_change_callback (struct dataset *ds, transformation_change_callback_func *cb, @@ -627,22 +719,6 @@ dataset_add_transform_change_callback (struct dataset *ds, ds->xform_callback_aux = aux; } -/* Finishes up procedure handling. */ -void -destroy_dataset (struct dataset *ds) -{ - proc_discard_active_file (ds); - dict_destroy (ds->dict); - caseinit_destroy (ds->caseinit); - trns_chain_destroy (ds->permanent_trns_chain); - - if ( ds->xform_callback) - ds->xform_callback (false, ds->xform_callback_aux); - - free (ds->syntax_encoding); - free (ds); -} - /* Causes output from the next procedure to be discarded, instead of being preserved for use as input for the next procedure. */ void @@ -651,75 +727,6 @@ proc_discard_output (struct dataset *ds) ds->discard_output = true; } -/* Discards the active file dictionary, data, and - transformations. */ -void -proc_discard_active_file (struct dataset *ds) -{ - assert (ds->proc_state == PROC_COMMITTED); - - dict_clear (ds->dict); - fh_set_default_handle (NULL); - - ds->n_lag = 0; - - casereader_destroy (ds->source); - ds->source = NULL; - - proc_cancel_all_transformations (ds); -} - -/* Sets SOURCE as the source for procedure input for the next - procedure. */ -void -proc_set_active_file (struct dataset *ds, - struct casereader *source, - struct dictionary *dict) -{ - assert (ds->proc_state == PROC_COMMITTED); - assert (ds->dict != dict); - - proc_discard_active_file (ds); - - dict_destroy (ds->dict); - ds->dict = dict; - dict_set_change_callback (ds->dict, dict_callback, ds); - - proc_set_active_file_data (ds, source); -} - -/* Replaces the active file's data by READER without replacing - the associated dictionary. */ -bool -proc_set_active_file_data (struct dataset *ds, struct casereader *reader) -{ - casereader_destroy (ds->source); - ds->source = reader; - - caseinit_clear (ds->caseinit); - caseinit_mark_as_preinited (ds->caseinit, ds->dict); - - return reader == NULL || !casereader_error (reader); -} - -/* Returns true if an active file data source is available, false - otherwise. */ -bool -proc_has_active_file (const struct dataset *ds) -{ - return ds->source != NULL; -} - -/* Returns the active file data source from DS, or a null pointer - if DS has no data source, and removes it from DS. */ -struct casereader * -proc_extract_active_file_data (struct dataset *ds) -{ - struct casereader *reader = ds->source; - ds->source = NULL; - - return reader; -} /* Checks whether DS has a corrupted active file. If so, discards it and returns false. If not, returns true without @@ -731,7 +738,7 @@ dataset_end_of_command (struct dataset *ds) { if (casereader_error (ds->source)) { - proc_discard_active_file (ds); + dataset_clear (ds); return false; } else @@ -816,18 +823,6 @@ filter_trns_proc (void *filter_var_, } -struct dictionary * -dataset_dict (const struct dataset *ds) -{ - return ds->dict; -} - -const struct casereader * -dataset_source (const struct dataset *ds) -{ - return ds->source; -} - void dataset_need_lag (struct dataset *ds, int n_before) { diff --git a/src/data/dataset.h b/src/data/dataset.h index 4561f97e..7aa8b581 100644 --- a/src/data/dataset.h +++ b/src/data/dataset.h @@ -27,6 +27,24 @@ struct casereader; struct dataset; struct dictionary; +struct dataset *dataset_create (void); +void dataset_destroy (struct dataset *); + +void dataset_clear (struct dataset *); + +struct dictionary *dataset_dict (const struct dataset *); +void dataset_set_dict (struct dataset *, struct dictionary *); + +const struct casereader *dataset_source (const struct dataset *); +bool dataset_has_source (const struct dataset *ds); +bool dataset_set_source (struct dataset *, struct casereader *); +struct casereader *dataset_steal_source (struct dataset *); + +void dataset_set_callback (struct dataset *, void (*cb) (void *), void *); + +void dataset_set_default_syntax_encoding (struct dataset *, const char *); +const char *dataset_get_default_syntax_encoding (const struct dataset *); + /* Transformations. */ void add_transformation (struct dataset *ds, @@ -49,20 +67,10 @@ bool proc_cancel_temporary_transformations (struct dataset *ds); typedef void transformation_change_callback_func (bool non_empty, void *aux); -struct dataset * create_dataset (void); - -void destroy_dataset (struct dataset *); void dataset_add_transform_change_callback (struct dataset *, transformation_change_callback_func *, void *); -void proc_discard_active_file (struct dataset *); -void proc_set_active_file (struct dataset *, - struct casereader *, struct dictionary *); -bool proc_set_active_file_data (struct dataset *, struct casereader *); -bool proc_has_active_file (const struct dataset *ds); -struct casereader *proc_extract_active_file_data (struct dataset *); - void proc_discard_output (struct dataset *ds); bool proc_execute (struct dataset *ds); @@ -75,15 +83,7 @@ bool proc_commit (struct dataset *); bool dataset_end_of_command (struct dataset *); -struct dictionary *dataset_dict (const struct dataset *ds); -const struct casereader *dataset_source (const struct dataset *ds); - const struct ccase *lagged_case (const struct dataset *ds, int n_before); void dataset_need_lag (struct dataset *ds, int n_before); -void dataset_set_callback (struct dataset *ds, void (*cb) (void *), void *); - -void dataset_set_default_syntax_encoding (struct dataset *, const char *); -const char *dataset_get_default_syntax_encoding (const struct dataset *); - #endif /* dataset.h */ diff --git a/src/language/command.c b/src/language/command.c index 703ae3eb..d9fc4633 100644 --- a/src/language/command.c +++ b/src/language/command.c @@ -147,7 +147,7 @@ cmd_parse (struct lexer *lexer, struct dataset *ds) { const struct dictionary *dict = dataset_dict (ds); return cmd_parse_in_state (lexer, ds, - proc_has_active_file (ds) && + dataset_has_source (ds) && dict_get_var_cnt (dict) > 0 ? CMD_STATE_DATA : CMD_STATE_INITIAL); } @@ -541,6 +541,6 @@ cmd_erase (struct lexer *lexer, struct dataset *ds UNUSED) int cmd_new_file (struct lexer *lexer UNUSED, struct dataset *ds) { - proc_discard_active_file (ds); + dataset_clear (ds); return CMD_SUCCESS; } diff --git a/src/language/data-io/combine-files.c b/src/language/data-io/combine-files.c index a661d7c6..c290692e 100644 --- a/src/language/data-io/combine-files.c +++ b/src/language/data-io/combine-files.c @@ -206,7 +206,7 @@ combine_files (enum comb_command_type command, if (lex_match (lexer, T_ASTERISK)) { - if (!proc_has_active_file (ds)) + if (!dataset_has_source (ds)) { msg (SE, _("Cannot specify the active file since no active " "file has been defined.")); @@ -466,7 +466,8 @@ combine_files (enum comb_command_type command, if (active_file != NULL) proc_commit (ds); - proc_set_active_file (ds, casewriter_make_reader (proc.output), proc.dict); + dataset_set_dict (ds, proc.dict); + dataset_set_source (ds, casewriter_make_reader (proc.output)); proc.dict = NULL; proc.output = NULL; diff --git a/src/language/data-io/data-parser.c b/src/language/data-io/data-parser.c index 24a671ee..29a73685 100644 --- a/src/language/data-io/data-parser.c +++ b/src/language/data-io/data-parser.c @@ -782,7 +782,8 @@ data_parser_make_active_file (struct data_parser *parser, struct dataset *ds, casereader = casereader_create_sequential (NULL, r->proto, CASENUMBER_MAX, &data_parser_casereader_class, r); - proc_set_active_file (ds, casereader, dict); + dataset_set_dict (ds, dict); + dataset_set_source (ds, casereader); } static struct ccase * diff --git a/src/language/data-io/get-data.c b/src/language/data-io/get-data.c index 07000eb2..dd55752c 100644 --- a/src/language/data-io/get-data.c +++ b/src/language/data-io/get-data.c @@ -122,7 +122,10 @@ parse_get_psql (struct lexer *lexer, struct dataset *ds) struct casereader *reader = psql_open_reader (&psql, &dict); if ( reader ) - proc_set_active_file (ds, reader, dict); + { + dataset_set_dict (ds, dict); + dataset_set_source (ds, reader); + } } ds_destroy (&psql.sql); @@ -232,7 +235,10 @@ parse_get_gnm (struct lexer *lexer, struct dataset *ds) struct casereader *reader = gnumeric_open_reader (&gri, &dict); if ( reader ) - proc_set_active_file (ds, reader, dict); + { + dataset_set_dict (ds, dict); + dataset_set_source (ds, reader); + } } free (gri.file_name); diff --git a/src/language/data-io/get.c b/src/language/data-io/get.c index 1b63e75a..466d2a52 100644 --- a/src/language/data-io/get.c +++ b/src/language/data-io/get.c @@ -128,7 +128,8 @@ parse_read_command (struct lexer *lexer, struct dataset *ds, enum reader_command if (map != NULL) reader = case_map_create_input_translator (map, reader); - proc_set_active_file (ds, reader, dict); + dataset_set_dict (ds, dict); + dataset_set_source (ds, reader); fh_unref (fh); return CMD_SUCCESS; diff --git a/src/language/data-io/inpt-pgm.c b/src/language/data-io/inpt-pgm.c index de8b8100..99cc17a0 100644 --- a/src/language/data-io/inpt-pgm.c +++ b/src/language/data-io/inpt-pgm.c @@ -92,7 +92,7 @@ cmd_input_program (struct lexer *lexer, struct dataset *ds) struct input_program_pgm *inp; bool saw_END_CASE = false; - proc_discard_active_file (ds); + dataset_clear (ds); if (!lex_match (lexer, T_ENDCMD)) return lex_end_of_command (lexer); @@ -117,7 +117,7 @@ cmd_input_program (struct lexer *lexer, struct dataset *ds) if (result == CMD_EOF) msg (SE, _("Unexpected end-of-file within INPUT PROGRAM.")); inside_input_program = false; - proc_discard_active_file (ds); + dataset_clear (ds); destroy_input_program (inp); return result; } @@ -129,7 +129,7 @@ cmd_input_program (struct lexer *lexer, struct dataset *ds) if (dict_get_next_value_idx (dataset_dict (ds)) == 0) { msg (SE, _("Input program did not create any variables.")); - proc_discard_active_file (ds); + dataset_clear (ds); destroy_input_program (inp); return CMD_FAILURE; } @@ -144,7 +144,7 @@ cmd_input_program (struct lexer *lexer, struct dataset *ds) caseinit_mark_for_init (inp->init, dataset_dict (ds)); inp->proto = caseproto_ref (dict_get_proto (dataset_dict (ds))); - proc_set_active_file_data ( + dataset_set_source ( ds, casereader_create_sequential (NULL, inp->proto, CASENUMBER_MAX, &input_program_casereader_class, inp)); diff --git a/src/language/expressions/evaluate.c b/src/language/expressions/evaluate.c index fea0e56b..3df9a6c9 100644 --- a/src/language/expressions/evaluate.c +++ b/src/language/expressions/evaluate.c @@ -155,7 +155,7 @@ cmd_debug_evaluate (struct lexer *lexer, struct dataset *dsother UNUSED) if ( ds == NULL ) { - ds = create_dataset (); + ds = dataset_create (); d = dataset_dict (ds); } @@ -242,8 +242,7 @@ cmd_debug_evaluate (struct lexer *lexer, struct dataset *dsother UNUSED) retval = CMD_SUCCESS; done: - if (ds) - destroy_dataset (ds); + dataset_destroy (ds); case_unref (c); diff --git a/src/language/stats/aggregate.c b/src/language/stats/aggregate.c index b0df0b8e..eace3479 100644 --- a/src/language/stats/aggregate.c +++ b/src/language/stats/aggregate.c @@ -351,7 +351,8 @@ cmd_aggregate (struct lexer *lexer, struct dataset *ds) if (next_input == NULL) goto error; - proc_set_active_file (ds, next_input, agr.dict); + dataset_set_dict (ds, agr.dict); + dataset_set_source (ds, next_input); agr.dict = NULL; } else diff --git a/src/language/stats/flip.c b/src/language/stats/flip.c index e7896452..953ea1d8 100644 --- a/src/language/stats/flip.c +++ b/src/language/stats/flip.c @@ -198,7 +198,7 @@ cmd_flip (struct lexer *lexer, struct dataset *ds) /* Flip the data we read. */ if (!ok || !flip_file (flip)) { - proc_discard_active_file (ds); + dataset_clear (ds); goto error; } @@ -219,7 +219,7 @@ cmd_flip (struct lexer *lexer, struct dataset *ds) reader = casereader_create_sequential (NULL, dict_get_proto (dict), flip->n_vars, &flip_casereader_class, flip); - proc_set_active_file_data (ds, reader); + dataset_set_source (ds, reader); return CMD_SUCCESS; error: diff --git a/src/language/stats/rank.q b/src/language/stats/rank.q index 2a0b5c99..eb16f311 100644 --- a/src/language/stats/rank.q +++ b/src/language/stats/rank.q @@ -280,7 +280,7 @@ rank_cmd (struct dataset *ds, const struct subcase *sc, } ok = casegrouper_destroy (split_grouper); ok = proc_commit (ds) && ok; - ok = (proc_set_active_file_data (ds, casewriter_make_reader (output)) + ok = (dataset_set_source (ds, casewriter_make_reader (output)) && ok); if (!ok) break; @@ -784,7 +784,7 @@ cmd_rank (struct lexer *lexer, struct dataset *ds) result = proc_commit (ds) && result; dict_delete_var (dataset_dict (ds), order); - result = proc_set_active_file_data (ds, sorted) && result; + result = dataset_set_source (ds, sorted) && result; } rank_cleanup(); diff --git a/src/language/stats/sort-cases.c b/src/language/stats/sort-cases.c index cecdce27..f44656fd 100644 --- a/src/language/stats/sort-cases.c +++ b/src/language/stats/sort-cases.c @@ -71,7 +71,7 @@ cmd_sort_cases (struct lexer *lexer, struct dataset *ds) proc_discard_output (ds); output = sort_execute (proc_open (ds), &ordering); ok = proc_commit (ds); - ok = proc_set_active_file_data (ds, output) && ok; + ok = dataset_set_source (ds, output) && ok; done: min_buffers = 64; diff --git a/src/ui/gui/executor.c b/src/ui/gui/executor.c index 3afa1ecd..07906dd1 100644 --- a/src/ui/gui/executor.c +++ b/src/ui/gui/executor.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007, 2009, 2010 Free Software Foundation + Copyright (C) 2007, 2009, 2010, 2011 Free Software Foundation This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -67,9 +67,9 @@ execute_syntax (struct lex_reader *lex_reader) reader = lazy_casereader_create (proto, case_cnt, create_casereader_from_data_store, the_data_store, &lazy_serial); - proc_set_active_file_data (the_dataset, reader); + dataset_set_source (the_dataset, reader); - g_return_val_if_fail (proc_has_active_file (the_dataset), FALSE); + g_return_val_if_fail (dataset_has_source (the_dataset), FALSE); lexer = lex_create (); psppire_set_lexer (lexer); @@ -98,7 +98,7 @@ execute_syntax (struct lex_reader *lex_reader) psppire_dict_replace_dictionary (the_data_store->dict, dataset_dict (the_dataset)); - reader = proc_extract_active_file_data (the_dataset); + reader = dataset_steal_source (the_dataset); if (!lazy_casereader_destroy (reader, lazy_serial)) psppire_data_store_set_reader (the_data_store, reader); diff --git a/src/ui/gui/psppire.c b/src/ui/gui/psppire.c index b294f229..d4008659 100644 --- a/src/ui/gui/psppire.c +++ b/src/ui/gui/psppire.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2004, 2005, 2006, 2009, 2010 Free Software Foundation + Copyright (C) 2004, 2005, 2006, 2009, 2010, 2011 Free Software Foundation This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -96,7 +96,7 @@ initialize (const char *data_file) settings_init (); fh_init (); - the_dataset = create_dataset (); + the_dataset = dataset_create (); psppire_set_lexer (NULL); dictionary = psppire_dict_new_from_dict (dataset_dict (the_dataset)); diff --git a/src/ui/terminal/main.c b/src/ui/terminal/main.c index a709d993..805681d9 100644 --- a/src/ui/terminal/main.c +++ b/src/ui/terminal/main.c @@ -96,7 +96,7 @@ main (int argc, char **argv) random_init (); lexer = lex_create (); - the_dataset = create_dataset (); + the_dataset = dataset_create (); parser = argv_parser_create (); terminal_opts = terminal_opts_init (parser, &syntax_mode, &process_statrc, @@ -159,7 +159,7 @@ main (int argc, char **argv) } - destroy_dataset (the_dataset); + dataset_destroy (the_dataset); random_done (); settings_done ();