X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Ftable-select.c;h=5bbc8caa1eb948bec775c2d27ff652696356487f;hb=18e3610ace8a5286d301e2f8ebd62bb579b2ea96;hp=1c2956a819bc8744149c028f69f6bce4181ad279;hpb=d0b91eae59319ab2756d0d43b9cb15eb9cd3c234;p=pspp diff --git a/src/output/table-select.c b/src/output/table-select.c index 1c2956a819..5bbc8caa1e 100644 --- a/src/output/table-select.c +++ b/src/output/table-select.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009, 2010, 2011, 2014 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,9 +16,9 @@ #include -#include -#include -#include +#include "libpspp/assertion.h" +#include "libpspp/cast.h" +#include "output/table-provider.h" #include "gl/minmax.h" #include "gl/xalloc.h" @@ -35,7 +35,7 @@ static const struct table_class table_select_class; static struct table_select * table_select_cast (const struct table *table) { - assert (table->class == &table_select_class); + assert (table->klass == &table_select_class); return UP_CAST (table, struct table_select, table); } @@ -55,9 +55,9 @@ table_select (struct table *subtable, int rect[TABLE_N_AXES][2]) && rect[TABLE_VERT][1] == subtable->n[TABLE_VERT]) return subtable; - if (!table_is_shared (subtable) && subtable->class->select != NULL) + if (!table_is_shared (subtable) && subtable->klass->select != NULL) { - struct table *selected = subtable->class->select (subtable, rect); + struct table *selected = subtable->klass->select (subtable, rect); if (selected != NULL) return selected; } @@ -94,23 +94,30 @@ table_select_slice (struct table *subtable, enum table_axis axis, { struct table *table; int rect[TABLE_N_AXES][2]; + bool h0, h1; - if (add_headers) + h0 = add_headers && subtable->h[axis][0] > 0; + if (h0 && z0 == subtable->h[axis][0]) { - if (z0 == subtable->h[axis][0] && z1 == subtable->h[axis][1]) - return subtable; - - if (subtable->h[axis][0]) - table_ref (subtable); - if (subtable->h[axis][1]) - table_ref (subtable); + z0 = 0; + h0 = false; } - else + + h1 = add_headers && subtable->h[axis][1] > 0; + if (h1 && z1 == subtable->n[axis] - subtable->h[axis][1]) { - if (z0 == 0 && z1 == subtable->n[axis]) - return subtable; + z1 = subtable->n[axis]; + h1 = false; } + if (z0 == 0 && z1 == subtable->n[axis]) + return subtable; + + if (h0) + table_ref (subtable); + if (h1) + table_ref (subtable); + rect[TABLE_HORZ][0] = 0; rect[TABLE_VERT][0] = 0; rect[TABLE_HORZ][1] = subtable->n[TABLE_HORZ]; @@ -119,22 +126,18 @@ table_select_slice (struct table *subtable, enum table_axis axis, rect[axis][1] = z1; table = table_select (subtable, rect); - if (add_headers) - { - if (subtable->h[axis][0]) - table = table_paste ( - table_select_slice (subtable, axis, 0, subtable->h[axis][0], - false), - table, axis); - - if (subtable->h[axis][1]) - table = table_paste ( - table, - table_select_slice (subtable, axis, - subtable->n[axis] - subtable->h[axis][1], - subtable->n[axis], false), - axis); - } + if (h0) + table = table_paste ( + table_select_slice (subtable, axis, 0, subtable->h[axis][0], false), + table, axis); + + if (h1) + table = table_paste ( + table, + table_select_slice (subtable, axis, + subtable->n[axis] - subtable->h[axis][1], + subtable->n[axis], false), + axis); return table; }