X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fdatasheet.c;h=ad8333256c0bd2732692d107910c85ae2ef8fb6d;hb=81579d9e9f994fb2908f50af41c3eb033d216e58;hp=4a48368546ad71715a0b99f241251efb35b9a928;hpb=5c3291dc396b795696e94f47780308fd7ace6fc4;p=pspp-builds.git diff --git a/src/data/datasheet.c b/src/data/datasheet.c index 4a483685..ad833325 100644 --- a/src/data/datasheet.c +++ b/src/data/datasheet.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010, 2011 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,28 +16,28 @@ #include -#include +#include "data/datasheet.h" #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "minmax.h" -#include "md4.h" -#include "xalloc.h" +#include "data/casereader-provider.h" +#include "data/casereader.h" +#include "data/casewriter.h" +#include "data/lazy-casereader.h" +#include "data/settings.h" +#include "libpspp/array.h" +#include "libpspp/assertion.h" +#include "libpspp/misc.h" +#include "libpspp/range-map.h" +#include "libpspp/range-set.h" +#include "libpspp/sparse-xarray.h" +#include "libpspp/taint.h" +#include "libpspp/tower.h" + +#include "gl/minmax.h" +#include "gl/md4.h" +#include "gl/xalloc.h" struct column; @@ -275,7 +275,7 @@ datasheet_destroy (struct datasheet *ds) const struct caseproto * datasheet_get_proto (const struct datasheet *ds_) { - struct datasheet *ds = (struct datasheet *) ds_; + struct datasheet *ds = CONST_CAST (struct datasheet *, ds_); if (ds->proto == NULL) { size_t i; @@ -360,6 +360,8 @@ datasheet_insert_column (struct datasheet *ds, { struct column *col; + assert (before <= ds->n_columns); + ds->columns = xnrealloc (ds->columns, ds->n_columns + 1, sizeof *ds->columns); insert_element (ds->columns, ds->n_columns, sizeof *ds->columns, before); @@ -382,6 +384,8 @@ datasheet_insert_column (struct datasheet *ds, void datasheet_delete_columns (struct datasheet *ds, size_t start, size_t n) { + assert (start + n <= ds->n_columns); + if (n > 0) { size_t i; @@ -411,6 +415,9 @@ datasheet_move_columns (struct datasheet *ds, size_t old_start, size_t new_start, size_t n) { + assert (old_start + n <= ds->n_columns); + assert (new_start + n <= ds->n_columns); + move_range (ds->columns, ds->n_columns, sizeof *ds->columns, old_start, new_start, n); @@ -456,7 +463,6 @@ datasheet_resize_column (struct datasheet *ds, size_t column, int new_width, union value *, void *aux), void *resize_cb_aux) { - /* XXX needs a test. */ struct column old_col; struct column *col; int old_width; @@ -467,15 +473,13 @@ datasheet_resize_column (struct datasheet *ds, size_t column, int new_width, old_col = *col; old_width = old_col.width; - if (old_width == new_width) - { - /* FIXME: for consistency, we should call resize_cb() on - each row. */ - } - else if (new_width == -1) + if (new_width == -1) { - datasheet_delete_columns (ds, column, 1); - datasheet_insert_column (ds, NULL, -1, column); + if (old_width != -1) + { + datasheet_delete_columns (ds, column, 1); + datasheet_insert_column (ds, NULL, -1, column); + } } else if (old_width == -1) { @@ -491,23 +495,24 @@ datasheet_resize_column (struct datasheet *ds, size_t column, int new_width, else if (source_has_backing (col->source)) { unsigned long int n_rows = axis_get_size (ds->rows); + unsigned long int lrow; union value src, dst; - size_t row; source_release_column (col->source, col->byte_ofs, col->width); allocate_column (ds, new_width, col); value_init (&src, old_width); value_init (&dst, new_width); - for (row = 0; row < n_rows; row++) + for (lrow = 0; lrow < n_rows; lrow++) { - if (!source_read (&old_col, row, &src)) + unsigned long int prow = axis_map (ds->rows, lrow); + if (!source_read (&old_col, prow, &src)) { /* FIXME: back out col changes. */ return false; } resize_cb (&src, &dst, resize_cb_aux); - if (!source_write (col, row, &dst)) + if (!source_write (col, prow, &dst)) { /* FIXME: back out col changes. */ return false; @@ -550,7 +555,7 @@ datasheet_get_row (const struct datasheet *ds, casenumber row) { size_t n_columns = datasheet_get_n_columns (ds); struct ccase *c = case_create (datasheet_get_proto (ds)); - if (rw_case ((struct datasheet *) ds, OP_READ, + if (rw_case (CONST_CAST (struct datasheet *, ds), OP_READ, row, 0, n_columns, case_data_all_rw (c))) return c; else @@ -584,7 +589,8 @@ datasheet_get_value (const struct datasheet *ds, casenumber row, size_t column, union value *value) { assert (row >= 0); - return rw_case ((struct datasheet *) ds, OP_READ, row, column, 1, value); + return rw_case (CONST_CAST (struct datasheet *, ds), OP_READ, + row, column, 1, value); } /* Stores VALUE into DS in the given ROW and COLUMN. VALUE must