-/*
- PSPPIRE --- A Graphical User Interface for PSPP
- Copyright (C) 2006 Free Software Foundation
+/* PSPPIRE - a graphical user interface for PSPP.
+ Copyright (C) 2006 Free Software Foundation
- 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
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
+ 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
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include <string.h>
gboolean
-psppire_case_file_delete_cases (PsppireCaseFile *cf, gint n_cases, gint first)
+psppire_case_file_delete_cases (PsppireCaseFile *cf, casenumber n_cases, casenumber first)
{
g_return_val_if_fail (cf, FALSE);
g_return_val_if_fail (cf->datasheet, FALSE);
+ g_return_val_if_fail (cf->accessible, FALSE);
+
+ g_return_val_if_fail (first + n_cases <=
+ psppire_case_file_get_case_count (cf), FALSE);
datasheet_delete_rows (cf->datasheet, first, n_cases);
- g_signal_emit (cf, signals [CASES_DELETED], 0, n_cases, first);
+ g_signal_emit (cf, signals [CASES_DELETED], 0, first, n_cases);
return TRUE;
}
/* Insert case CC into the case file before POSN */
gboolean
psppire_case_file_insert_case (PsppireCaseFile *cf,
- struct ccase *cc,
- gint posn)
+ struct ccase *cc,
+ casenumber posn)
{
struct ccase tmp;
bool result ;
g_return_val_if_fail (cf, FALSE);
g_return_val_if_fail (cf->datasheet, FALSE);
+ g_return_val_if_fail (cf->accessible, FALSE);
case_clone (&tmp, cc);
result = datasheet_insert_rows (cf->datasheet, posn, &tmp, 1);
if ( result )
g_signal_emit (cf, signals [CASE_INSERTED], 0, posn);
else
- g_warning ("Cannot insert case at position %d\n", posn);
+ g_warning ("Cannot insert case at position %ld\n", posn);
return result;
}
/* Append a case to the case file */
-gboolean
+static gboolean
psppire_case_file_append_case (PsppireCaseFile *cf,
struct ccase *c)
{
g_return_val_if_fail (cf, FALSE);
g_return_val_if_fail (cf->datasheet, FALSE);
+ g_return_val_if_fail (cf->accessible, FALSE);
posn = datasheet_get_row_cnt (cf->datasheet);
}
-inline gint
+inline casenumber
psppire_case_file_get_case_count (const PsppireCaseFile *cf)
{
g_return_val_if_fail (cf, FALSE);
/* Set the IDXth value of case C to V.
Returns true if successful, false on I/O error. */
gboolean
-psppire_case_file_set_value (PsppireCaseFile *cf, gint casenum, gint idx,
+psppire_case_file_set_value (PsppireCaseFile *cf, casenumber casenum, gint idx,
union value *v, gint width)
{
bool ok;
/* Set the IDXth value of case C using D_IN */
gboolean
-psppire_case_file_data_in (PsppireCaseFile *cf, gint casenum, gint idx,
+psppire_case_file_data_in (PsppireCaseFile *cf, casenumber casenum, gint idx,
struct substring input, const struct fmt_spec *fmt)
{
union value *value;
/* Resize the cases in the casefile, by inserting N_VALUES into every
- one of them. */
+ one of them at the position immediately preceeding WHERE.
+*/
gboolean
psppire_case_file_insert_values (PsppireCaseFile *cf,
- gint n_values, gint before)
+ gint n_values, gint where)
{
- union value *values;
g_return_val_if_fail (cf, FALSE);
g_return_val_if_fail (cf->accessible, FALSE);
+ if ( n_values == 0 )
+ return FALSE;
+
+ g_assert (n_values > 0);
+
if ( ! cf->datasheet )
cf->datasheet = datasheet_create (NULL);
- values = xcalloc (n_values, sizeof *values);
- datasheet_insert_columns (cf->datasheet, values, n_values, before);
+ {
+ union value *values = xcalloc (n_values, sizeof *values);
+ datasheet_insert_columns (cf->datasheet, values, n_values, where);
free (values);
+ }
return TRUE;
}
+
/* Fills C with the CASENUMth case.
Returns true on success, false otherwise.
*/
gboolean
-psppire_case_file_get_case (const PsppireCaseFile *cf, gint casenum,
+psppire_case_file_get_case (const PsppireCaseFile *cf, casenumber casenum,
struct ccase *c)
{
g_return_val_if_fail (cf, FALSE);