X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Fsort.c;h=8ce955384b674eb4599f98a2b072e83eaa76c64b;hb=b0bf9b1b0f727fafac4296a048e3f45db5936f81;hp=9725da80a1a9896149636905599319f9e5d9c229;hpb=c1ed7e6b472a6fa7feb710ee3ca0472c9a024e6f;p=pspp-builds.git diff --git a/src/math/sort.c b/src/math/sort.c index 9725da80..8ce95538 100644 --- a/src/math/sort.c +++ b/src/math/sort.c @@ -57,24 +57,13 @@ static struct casefile *do_internal_sort (struct casereader *, static struct casefile *do_external_sort (struct casereader *, const struct sort_criteria *); -/* Gets ready to sort the active file, either in-place or to a - separate casefile. */ -static bool +/* Get ready to sort the active file. */ +static void prepare_to_sort_active_file (void) { - bool ok; - - /* Cancel temporary transformations and PROCESS IF. */ - if (temporary != 0) - cancel_temporary (); + proc_cancel_temporary_transformations (); expr_free (process_if_expr); process_if_expr = NULL; - - /* Make sure source cases are in a storage source. */ - ok = procedure (NULL, NULL); - assert (case_source_is_class (vfm_source, &storage_source_class)); - - return ok; } /* Sorts the active file in-place according to CRITERIA. @@ -82,21 +71,35 @@ prepare_to_sort_active_file (void) int sort_active_file_in_place (const struct sort_criteria *criteria) { - struct casefile *src, *dst; + struct casefile *in, *out; + + prepare_to_sort_active_file (); + if (!procedure (NULL, NULL)) + return 0; - if (!prepare_to_sort_active_file ()) + in = proc_capture_output (); + out = sort_execute (casefile_get_destructive_reader (in), criteria); + if (out == NULL) return 0; - src = storage_source_get_casefile (vfm_source); - dst = sort_execute (casefile_get_destructive_reader (src), criteria); - free_case_source (vfm_source); - vfm_source = NULL; + proc_set_source (storage_source_create (out)); + return 1; +} - if (dst == NULL) - return 0; +/* Data passed to sort_to_casefile_callback(). */ +struct sort_to_casefile_cb_data + { + const struct sort_criteria *criteria; + struct casefile *output; + }; - vfm_source = storage_source_create (dst); - return 1; +/* Sorts casefile CF according to the criteria in CB_DATA. */ +static bool +sort_to_casefile_callback (const struct casefile *cf, void *cb_data_) +{ + struct sort_to_casefile_cb_data *cb_data = cb_data_; + cb_data->output = sort_execute (casefile_get_reader (cf), cb_data->criteria); + return cb_data->output != NULL; } /* Sorts the active file to a separate casefile. If successful, @@ -105,13 +108,15 @@ sort_active_file_in_place (const struct sort_criteria *criteria) struct casefile * sort_active_file_to_casefile (const struct sort_criteria *criteria) { - struct casefile *src; + struct sort_to_casefile_cb_data cb_data; - if (!prepare_to_sort_active_file ()) - return NULL; + prepare_to_sort_active_file (); + + cb_data.criteria = criteria; + cb_data.output = NULL; + multipass_procedure (sort_to_casefile_callback, &cb_data); - src = storage_source_get_casefile (vfm_source); - return sort_execute (casefile_get_reader (src), criteria); + return cb_data.output; }