X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fdata%2Fcasereader-filter.c;h=fcd264e9dc35e08f8d7737b83973ca9c5d4f9e40;hb=c3ac5a8af9c449072c7e872ca70a78c1755ae309;hp=afb72cca1434e7a40dea2a723ba5b7a68bcd8e69;hpb=5da5a98055ad574120c3e3922af097411a0dcf3a;p=pspp-builds.git diff --git a/src/data/casereader-filter.c b/src/data/casereader-filter.c index afb72cca..fcd264e9 100644 --- a/src/data/casereader-filter.c +++ b/src/data/casereader-filter.c @@ -1,20 +1,18 @@ -/* PSPP - computes sample statistics. +/* PSPP - a program for statistical analysis. Copyright (C) 2007 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 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. */ + along with this program. If not, see . */ #include @@ -45,7 +43,7 @@ struct casereader_filter struct casewriter *exclude; /* Writer that gets filtered cases, or NULL. */ }; -static struct casereader_class casereader_filter_class; +static const struct casereader_class casereader_filter_class; /* Creates and returns a casereader whose content is a filtered version of the data in SUBREADER. Only the cases for which @@ -132,7 +130,7 @@ casereader_filter_destroy (struct casereader *reader, void *filter_) } /* Filtering casereader class. */ -static struct casereader_class casereader_filter_class = +static const struct casereader_class casereader_filter_class = { casereader_filter_read, casereader_filter_destroy, @@ -247,6 +245,7 @@ struct casereader_filter_missing struct variable **vars; /* Variables whose values to filter. */ size_t var_cnt; /* Number of variables. */ enum mv_class class; /* Types of missing values to filter. */ + casenumber *n_missing; }; static bool casereader_filter_missing_include (const struct ccase *, void *); @@ -266,6 +265,9 @@ static bool casereader_filter_missing_destroy (void *); read or, if that never occurs, until the filtering casereader is destroyed. + If N_MISSING is non-null, then after reading, it will be filled + with the totla number of dropped cases. + After this function is called, READER must not ever again be referenced directly. It will be destroyed automatically when the filtering casereader is destroyed. */ @@ -273,6 +275,7 @@ struct casereader * casereader_create_filter_missing (struct casereader *reader, const struct variable **vars, size_t var_cnt, enum mv_class class, + casenumber *n_missing, struct casewriter *exclude) { if (var_cnt > 0 && class != MV_NEVER) @@ -281,6 +284,8 @@ casereader_create_filter_missing (struct casereader *reader, cfm->vars = xmemdup (vars, sizeof *vars * var_cnt); cfm->var_cnt = var_cnt; cfm->class = class; + cfm->n_missing = n_missing; + if (n_missing) *n_missing = 0; return casereader_create_filter_func (reader, casereader_filter_missing_include, casereader_filter_missing_destroy, @@ -304,7 +309,11 @@ casereader_filter_missing_include (const struct ccase *c, void *cfm_) struct variable *var = cfm->vars[i]; const union value *value = case_data (c, var); if (var_is_value_missing (var, value, cfm->class)) - return false; + { + if ( cfm->n_missing ) + (*cfm->n_missing)++; + return false; + } } return true; }