#include <stdlib.h>
#include <ctype.h>
#include <float.h>
+#include "algorithm.h"
#include "alloc.h"
#include "command.h"
#include "data-in.h"
#include "var.h"
#include "vfm.h"
-#undef DEBUGGING
-/*#define DEBUGGING 1*/
#include "debug-print.h"
/* FIXME: /N subcommand not implemented. It should be pretty simple,
/* Compare two variables using p.mxd.vartype and p.mxd.subtype
fields. */
static int
-compare_variables_by_mxd_vartype (const void *pa, const void *pb)
+compare_variables_by_mxd_vartype (const void *a_, const void *b_)
{
- struct matrix_data_proc *a = &(*((struct variable **) pa))->p.mxd;
- struct matrix_data_proc *b = &(*((struct variable **) pb))->p.mxd;
-
- return (a->vartype != b->vartype
- ? a->vartype - b->vartype
- : a->subtype - b->subtype);
+ struct variable *const *pa = a_;
+ struct variable *const *pb = b_;
+ const struct matrix_data_proc *a = &(*pa)->p.mxd;
+ const struct matrix_data_proc *b = &(*pb)->p.mxd;
+
+ if (a->vartype != b->vartype)
+ return a->vartype > b->vartype ? 1 : -1;
+ else
+ return a->subtype < b->subtype ? -1 : a->subtype > b->subtype;
}
#if DEBUGGING
return 1;
}
-/* Return strcmp()-type comparison of the n_factors factors at _A and
- _B. Sort missing values toward the end. */
+/* Compares doubles A and B, treating SYSMIS as greatest. */
static int
-compare_factors (const void *pa, const void *pb)
+compare_doubles (const void *a_, const void *b_, void *aux unused)
{
- const double *a = (*(struct factor_data **) pa)->factors;
- const double *b = (*(struct factor_data **) pb)->factors;
- int i;
+ const double *a = a_;
+ const double *b = b_;
- for (i = 0; i < n_factors; i++, a++, b++)
- {
- if (*a == *b)
- continue;
-
- if (*a == SYSMIS)
- return 1;
- else if (*b == SYSMIS)
- return -1;
- else
- return *a - *b < 0 ? -1 : 1;
- }
+ if (*a == *b)
+ return 0;
+ else if (*a == SYSMIS)
+ return 1;
+ else if (*b == SYSMIS)
+ return -1;
+ else if (*a > *b)
+ return 1;
+ else
+ return -1;
+}
- return 0;
+/* Return strcmp()-type comparison of the n_factors factors at _A and
+ _B. Sort missing values toward the end. */
+static int
+compare_factors (const void *a_, const void *b_)
+{
+ struct factor_data *const *pa = a_;
+ struct factor_data *const *pb = b_;
+ const double *a = (*pa)->factors;
+ const double *b = (*pb)->factors;
+
+ return lexicographical_compare (a, n_factors,
+ b, n_factors,
+ sizeof *a,
+ compare_doubles, NULL);
}
/* Write out the data for the current split file to the active