#include "file-handle.h"
#include "lexer.h"
#include "misc.h"
+#include "pool.h"
#include "settings.h"
#include "sfm.h"
#include "sort.h"
};
/* Attributes of aggregation functions. */
-static struct agr_func agr_func_tab[] =
+static const struct agr_func agr_func_tab[] =
{
{"<NONE>", 0, -1, {0, 0, 0}},
{"SUM", 0, -1, {FMT_F, 8, 2}},
/* ITEMWISE or COLUMNWISE. */
static int missing;
+/* Sort program. */
+static struct sort_cases_pgm *sort;
+
/* Aggregate variables. */
static struct agr_var *agr_first, *agr_next;
int
cmd_aggregate (void)
{
- /* From sort.c. */
- int parse_sort_variables (void);
-
/* Have we seen these subcommands? */
unsigned seen = 0;
outfile = NULL;
missing = ITEMWISE;
- v_sort = NULL;
+ sort = NULL;
prev_case = NULL;
agr_dict = dict_create ();
{
if (seen & 1)
{
- free (v_sort);
+ destroy_sort_cases_pgm (sort);
dict_destroy (agr_dict);
msg (SE, _("%s subcommand given multiple times."),"OUTFILE");
return CMD_FAILURE;
outfile = fh_parse_file_handle ();
if (outfile == NULL)
{
- free (v_sort);
+ destroy_sort_cases_pgm (sort);
dict_destroy (agr_dict);
return CMD_FAILURE;
}
lex_match ('=');
if (!lex_match_id ("COLUMNWISE"))
{
- free (v_sort);
+ destroy_sort_cases_pgm (sort);
dict_destroy (agr_dict);
lex_error (_("while expecting COLUMNWISE"));
return CMD_FAILURE;
{
if (seen & 8)
{
- free (v_sort);
+ destroy_sort_cases_pgm (sort);
dict_destroy (agr_dict);
msg (SE, _("%s subcommand given multiple times."),"BREAK");
return CMD_FAILURE;
seen |= 8;
lex_match ('=');
- if (!parse_sort_variables ())
+ sort = parse_sort ();
+ if (sort == NULL)
{
dict_destroy (agr_dict);
return CMD_FAILURE;
{
int i;
- for (i = 0; i < nv_sort; i++)
+ for (i = 0; i < sort->var_cnt; i++)
{
struct variable *v;
- v = dict_clone_var (agr_dict, v_sort[i], v_sort[i]->name);
+ v = dict_clone_var (agr_dict, sort->vars[i], sort->vars[i]->name);
assert (v != NULL);
}
}
if (!parse_aggregate_functions ())
{
free_aggregate_functions ();
- free (v_sort);
+ destroy_sort_cases_pgm (sort);
return CMD_FAILURE;
}
if (outfile != NULL)
type |= 4;
- if (nv_sort != 0 && (seen & 4) == 0)
+ if (sort != NULL && (seen & 4) == 0)
type |= 2;
if (temporary)
type |= 1;
cancel_temporary ();
/* fall through */
case 2:
- sort_cases (0);
+ sort_cases (sort, 0);
goto case0;
case 1:
case 6:
case 7:
- sort_cases (1);
+ sort_cases (sort, 1);
if (!create_sysfile ())
goto lossage;
- read_sort_output (agr_11x_func, NULL);
+ read_sort_output (sort, agr_11x_func, NULL);
{
struct ccase *save_temp_case = temp_case;
free (buf_1xx);
/* Clean up. */
- free (v_sort);
+ destroy_sort_cases_pgm (sort);
free_aggregate_functions ();
free (prev_case);
lossage:
/* Clean up. */
- free (v_sort);
+ destroy_sort_cases_pgm (sort);
free_aggregate_functions ();
free (prev_case);
if (!sfm_write_dictionary (&w))
{
free_aggregate_functions ();
- free (v_sort);
+ destroy_sort_cases_pgm (sort);
dict_destroy (agr_dict);
return 0;
}
int n_dest;
int include_missing;
- struct agr_func *function;
+ const struct agr_func *function;
int func_index;
union value arg[2];
{
int i;
- for (i = 0; i < nv_sort; i++)
- n_elem += v_sort[i]->nv;
+ for (i = 0; i < sort->var_cnt; i++)
+ n_elem += sort->vars[i]->nv;
}
prev_case = xmalloc (sizeof *prev_case * n_elem);
union value *iter = prev_case;
int i;
- for (i = 0; i < nv_sort; i++)
+ for (i = 0; i < sort->var_cnt; i++)
{
- struct variable *v = v_sort[i];
+ struct variable *v = sort->vars[i];
if (v->type == NUMERIC)
(iter++)->f = input->data[v->fv].f;
union value *iter = prev_case;
int i;
- for (i = 0; i < nv_sort; i++)
+ for (i = 0; i < sort->var_cnt; i++)
{
- struct variable *v = v_sort[i];
+ struct variable *v = sort->vars[i];
switch (v->type)
{
union value *iter = prev_case;
int i;
- for (i = 0; i < nv_sort; i++)
+ for (i = 0; i < sort->var_cnt; i++)
{
- struct variable *v = v_sort[i];
+ struct variable *v = sort->vars[i];
if (v->type == NUMERIC)
(iter++)->f = input->data[v->fv].f;
{
int i;
- for (i = 0; i < nv_sort; i++)
- n_elem += v_sort[i]->nv;
+ for (i = 0; i < sort->var_cnt; i++)
+ n_elem += sort->vars[i]->nv;
}
debug_printf (("n_elem=%d:", n_elem));
memcpy (output->data, prev_case, sizeof (union value) * n_elem);
active file. */
dump_aggregate_info (compaction_case);
vfm_sink_info.ncases++;
- vfm_sink->write ();
+ vfm_sink->class->write (vfm_sink, temp_case);
}
/* Transform the aggregate case buf_1xx, in internal format, to system
int i;
printf (" /BREAK=");
- for (i = 0; i < nv_sort; i++)
- printf ("%s(%c) ", v_sort[i]->name,
- v_sort[i]->p.srt.order == SRT_ASCEND ? 'A' : 'D');
+ for (i = 0; i < sort->var_cnt; i++)
+ printf ("%s(%c) ", sort->vars[i]->name,
+ sort->vars[i]->p.srt.order == SRT_ASCEND ? 'A' : 'D');
putc ('\n', stdout);
}