X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Fctables.c;h=5aa92f7e46ee6743d3b9611f0e7ba6783d47bd86;hb=c8758a83e8b5fd2b49e9a6d145757462987f069c;hp=6d3f44d327d10410898127ef171c497c52d6cbce;hpb=ea34fc3d157ce3038ea8cfe8c5e0ca21944762a7;p=pspp diff --git a/src/language/stats/ctables.c b/src/language/stats/ctables.c index 6d3f44d327..5aa92f7e46 100644 --- a/src/language/stats/ctables.c +++ b/src/language/stats/ctables.c @@ -4665,93 +4665,82 @@ ctables_prepare_table (struct ctables_table *t) nest->areas[at] = xmalloc (nest->n * sizeof *nest->areas[at]); nest->n_areas[at] = 0; - bool add_vars = (at == CTAT_LAYER ? a == PIVOT_AXIS_LAYER - : at == CTAT_LAYERROW ? a != PIVOT_AXIS_COLUMN - : at == CTAT_LAYERCOL ? a != PIVOT_AXIS_ROW - : at == CTAT_TABLE ? false - : true); - if (add_vars) + enum pivot_axis_type ata, atb; + if (at == CTAT_ROW || at == CTAT_LAYERROW) + { + ata = PIVOT_AXIS_ROW; + atb = PIVOT_AXIS_COLUMN; + } + else if (at == CTAT_COL || at == CTAT_LAYERCOL) + { + ata = PIVOT_AXIS_COLUMN; + atb = PIVOT_AXIS_ROW; + } + + if (((at == CTAT_LAYERCOL || at == CTAT_LAYERROW) + && a == atb && t->label_axis[a] != a) + || (at == CTAT_LAYER + && a != PIVOT_AXIS_LAYER + && t->label_axis[a] == PIVOT_AXIS_LAYER)) + { + for (size_t k = nest->n - 1; k < nest->n; k--) + if (k != nest->scale_idx) + { + nest->areas[at][nest->n_areas[at]++] = k; + break; + } + continue; + } + + if (at == CTAT_LAYER ? a == PIVOT_AXIS_LAYER + : at == CTAT_LAYERROW || at == CTAT_LAYERCOL ? a != atb + : at == CTAT_TABLE ? false + : true) for (size_t k = 0; k < nest->n; k++) { if (k == nest->scale_idx) continue; nest->areas[at][nest->n_areas[at]++] = k; } - else if ((at == CTAT_LAYERCOL && a == PIVOT_AXIS_ROW && t->label_axis[a] != a) - || (at == CTAT_LAYERROW && a == PIVOT_AXIS_COLUMN && t->label_axis[a] != a) - || (at == CTAT_LAYER && t->label_axis[a] == PIVOT_AXIS_LAYER)) - { - for (size_t k = nest->n - 1; k < nest->n; k--) - { - if (k == nest->scale_idx) - continue; - nest->areas[at][nest->n_areas[at]++] = k; - break; - } - continue; - } - size_t n_drop; - bool drop_inner = false; - if (at == CTAT_SUBTABLE - && t->clabels_from_axis != PIVOT_AXIS_LAYER) + int n_drop = 0; + switch (at) { - if (t->clabels_to_axis != PIVOT_AXIS_LAYER) + case CTAT_SUBTABLE: + if (t->clabels_from_axis == PIVOT_AXIS_LAYER) + n_drop = a != PIVOT_AXIS_LAYER; + else if (t->clabels_to_axis != PIVOT_AXIS_LAYER) n_drop = a == t->clabels_from_axis ? 2 : 0; + else if (a == t->clabels_from_axis) + n_drop = -1; else + n_drop = a != PIVOT_AXIS_LAYER; + break; + + case CTAT_LAYERROW: + case CTAT_LAYERCOL: + n_drop = a == ata && t->label_axis[ata] == atb; + break; + + case CTAT_ROW: + case CTAT_COL: + if (a == atb) { - drop_inner = a == t->clabels_from_axis; - n_drop = a != t->clabels_from_axis && a != PIVOT_AXIS_LAYER; + if (t->clabels_from_axis == atb) + n_drop = -1; + else if (t->clabels_to_axis != atb) + n_drop = 1; } - } - else if (at == CTAT_ROW && a == PIVOT_AXIS_COLUMN && t->label_axis[PIVOT_AXIS_ROW] == PIVOT_AXIS_COLUMN) - n_drop = 0; - else if (at == CTAT_ROW && a == PIVOT_AXIS_COLUMN && t->label_axis[PIVOT_AXIS_COLUMN] == PIVOT_AXIS_ROW) - { - drop_inner = true; - n_drop = 0; - } - else if (at == CTAT_ROW && a == PIVOT_AXIS_COLUMN && t->label_axis[PIVOT_AXIS_COLUMN] == PIVOT_AXIS_LAYER) - { - drop_inner = true; - n_drop = 0; - } - else if (at == CTAT_COL && a == PIVOT_AXIS_ROW && t->label_axis[PIVOT_AXIS_ROW] == PIVOT_AXIS_COLUMN) - { - drop_inner = true; - n_drop = 0; - } - else if (at == CTAT_COL && a == PIVOT_AXIS_ROW && t->label_axis[PIVOT_AXIS_COLUMN] == PIVOT_AXIS_ROW) - n_drop = 0; - else if (at == CTAT_COL && a == PIVOT_AXIS_ROW && t->label_axis[PIVOT_AXIS_ROW] == PIVOT_AXIS_LAYER) - { - drop_inner = true; - n_drop = 0; - } - else if (at == CTAT_LAYERROW) - n_drop = a == PIVOT_AXIS_ROW && t->label_axis[PIVOT_AXIS_ROW] == PIVOT_AXIS_COLUMN; - else if (at == CTAT_LAYERCOL) - n_drop = a == PIVOT_AXIS_COLUMN && t->label_axis[PIVOT_AXIS_COLUMN] == PIVOT_AXIS_ROW; - else if (at == CTAT_SUBTABLE) - n_drop = a != PIVOT_AXIS_LAYER; - else if (at == CTAT_ROW) - { - n_drop = a == PIVOT_AXIS_COLUMN; - if (a == PIVOT_AXIS_ROW && t->label_axis[PIVOT_AXIS_ROW] == PIVOT_AXIS_COLUMN) - n_drop++; - } - else if (at == CTAT_COL) - { - n_drop = a == PIVOT_AXIS_ROW; - if (a == PIVOT_AXIS_COLUMN && t->label_axis[PIVOT_AXIS_COLUMN] == PIVOT_AXIS_ROW) - n_drop++; - } - else - { - n_drop = 0; + else if (a == ata) + n_drop = t->label_axis[ata] == atb; + break; + + case CTAT_LAYER: + case CTAT_TABLE: + break; } - if (drop_inner) + if (n_drop < 0) { size_t n = nest->n_areas[at]; if (n > 1) @@ -4760,9 +4749,12 @@ ctables_prepare_table (struct ctables_table *t) nest->n_areas[at]--; } } - for (size_t i = 0; i < n_drop; i++) - if (nest->n_areas[at] > 0) - nest->n_areas[at]--; + else + { + for (int i = 0; i < n_drop; i++) + if (nest->n_areas[at] > 0) + nest->n_areas[at]--; + } } } }