X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fdataset.c;h=9c3fe8cfecffc9003781836fe616bd3dc5858bf3;hb=8f5194875a0a3d41fef91825fd8378bb004d6f51;hp=10009f4a5cc463e215a0373547cb19b6cadc8ce2;hpb=e195fccfab97205acb29f90fd1168488d49f1573;p=pspp diff --git a/src/data/dataset.c b/src/data/dataset.c index 10009f4a5c..9c3fe8cfec 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, 2011 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010, 2011, 2013 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 @@ -203,6 +203,7 @@ dataset_destroy (struct dataset *ds) caseinit_destroy (ds->caseinit); trns_chain_destroy (ds->permanent_trns_chain); dataset_transformations_changed__ (ds, false); + free (ds->name); free (ds); } } @@ -804,6 +805,39 @@ proc_cancel_all_transformations (struct dataset *ds) return ok; } + +static int +store_case_num (void *var_, struct ccase **cc, casenumber case_num) +{ + struct variable *var = var_; + + *cc = case_unshare (*cc); + case_data_rw (*cc, var)->f = case_num; + + return TRNS_CONTINUE; +} + +/* Add a variable which we can sort by to get back the original order. */ +struct variable * +add_permanent_ordering_transformation (struct dataset *ds) +{ + struct variable *temp_var; + + temp_var = dict_create_var_assert (ds->dict, "$ORDER", 0); + if (proc_in_temporary_transformations (ds)) + { + struct variable *perm_var; + + perm_var = dict_clone_var_in_place_assert (ds->permanent_dict, temp_var); + trns_chain_append (ds->permanent_trns_chain, NULL, store_case_num, + NULL, perm_var); + trns_chain_finalize (ds->permanent_trns_chain); + } + else + add_transformation (ds, store_case_num, NULL, temp_var); + + return temp_var; +} /* Causes output from the next procedure to be discarded, instead of being preserved for use as input for the next procedure. */