{
const char *a_label = var_lookup_value_label (var, a_val);
const char *b_label = var_lookup_value_label (var, b_val);
- int cmp = (a_label
- ? (b_label ? strcmp (a_label, b_label) : 1)
- : (b_label ? -1 : value_compare_3way (
- a_val, b_val, var_get_width (var))));
+ int cmp;
+ if (a_label)
+ {
+ if (!b_label)
+ return -1;
+ cmp = strcmp (a_label, b_label);
+ }
+ else
+ {
+ if (b_label)
+ return 1;
+ cmp = value_compare_3way (a_val, b_val, var_get_width (var));
+ }
if (cmp)
return a_cv->category->sort_ascending ? cmp : -cmp;
}
dnl - Summary functions:
dnl * Separate summary functions for totals and subtotals.
dnl * )CILEVEL in summary label specification
-dnl Category sorting:
-dnl * VALUE
-dnl * LABEL
-dnl * ascending/descending
dnl - CATEGORIES:
dnl * Date values
dnl * THRU (numeric ranges)
])
AT_CLEANUP
+AT_SETUP([CTABLES sorting categories])
+AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
+AT_DATA([ctables.sps],
+[[GET 'nhtsa.sav'.
+IF (QND5A=6) QND5A=-1.
+IF (QND5A=5) QND5A=-2.
+CTABLES /TABLE qnd5a /CATEGORIES VARIABLES=qnd5a KEY=VALUE ORDER=A
+ /TABLE qnd5a /CATEGORIES VARIABLES=qnd5a KEY=VALUE ORDER=D
+ /TABLE qnd5a /CATEGORIES VARIABLES=qnd5a KEY=LABEL ORDER=A
+ /TABLE qnd5a /CATEGORIES VARIABLES=qnd5a KEY=LABEL ORDER=D.
+]])
+AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl
+ Custom Tables
+╭────────────────────────────────────────────────────────────────────────┬─────╮
+│ │Count│
+├────────────────────────────────────────────────────────────────────────┼─────┤
+│D5a. What would you say is your primary ethnic -2.00 │ 52│
+│background? -1.00 │ 78│
+│ Cuban │ 20│
+│ Mexican │ 311│
+│ Spanish │ 48│
+│ South American │ 34│
+│ Central American │ 0│
+│ Puerto Rican, OR │ 0│
+│ Something else │ 68│
+│ Multiple - cannot choose│ 7│
+│ one │ │
+╰────────────────────────────────────────────────────────────────────────┴─────╯
+
+ Custom Tables
+╭────────────────────────────────────────────────────────────────────────┬─────╮
+│ │Count│
+├────────────────────────────────────────────────────────────────────────┼─────┤
+│D5a. What would you say is your primary ethnic Multiple - cannot choose│ 7│
+│background? one │ │
+│ Something else │ 68│
+│ Puerto Rican, OR │ 0│
+│ Central American │ 0│
+│ South American │ 34│
+│ Spanish │ 48│
+│ Mexican │ 311│
+│ Cuban │ 20│
+│ -1.00 │ 78│
+│ -2.00 │ 52│
+╰────────────────────────────────────────────────────────────────────────┴─────╯
+
+ Custom Tables
+╭────────────────────────────────────────────────────────────────────────┬─────╮
+│ │Count│
+├────────────────────────────────────────────────────────────────────────┼─────┤
+│D5a. What would you say is your primary ethnic Central American │ 0│
+│background? Cuban │ 20│
+│ Mexican │ 311│
+│ Multiple - cannot choose│ 7│
+│ one │ │
+│ Puerto Rican, OR │ 0│
+│ Something else │ 68│
+│ South American │ 34│
+│ Spanish │ 48│
+│ -2.00 │ 52│
+│ -1.00 │ 78│
+╰────────────────────────────────────────────────────────────────────────┴─────╯
+
+ Custom Tables
+╭────────────────────────────────────────────────────────────────────────┬─────╮
+│ │Count│
+├────────────────────────────────────────────────────────────────────────┼─────┤
+│D5a. What would you say is your primary ethnic Spanish │ 48│
+│background? South American │ 34│
+│ Something else │ 68│
+│ Puerto Rican, OR │ 0│
+│ Multiple - cannot choose│ 7│
+│ one │ │
+│ Mexican │ 311│
+│ Cuban │ 20│
+│ Central American │ 0│
+│ -1.00 │ 78│
+│ -2.00 │ 52│
+╰────────────────────────────────────────────────────────────────────────┴─────╯
+])
+AT_CLEANUP
+
AT_SETUP([CTABLES simple nesting])
AT_CHECK([ln $top_srcdir/examples/nhtsa.sav . || cp $top_srcdir/examples/nhtsa.sav .])
AT_DATA([ctables.sps],