X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Ftransformations.c;h=c0fc35c2c88d13663b4876abb08ffdebf3ab23a0;hb=a22af84523eb716b947123186bd4f89a3d92945e;hp=4d1e22e3b7a0230a3f556dd5e09f3d5b78ef1c96;hpb=f5c108becd49d78f4898cab11352291f5689d24e;p=pspp diff --git a/src/data/transformations.c b/src/data/transformations.c index 4d1e22e3b7..c0fc35c2c8 100644 --- a/src/data/transformations.c +++ b/src/data/transformations.c @@ -1,31 +1,29 @@ -/* PSPP - computes sample statistics. - Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc. +/* PSPP - a program for statistical analysis. + Copyright (C) 1997-9, 2000, 2006, 2009, 2011, 2013 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 -#include +#include "data/transformations.h" #include #include -#include +#include "libpspp/str.h" -#include "xalloc.h" +#include "gl/xalloc.h" /* A single transformation. */ struct transformation @@ -61,26 +59,25 @@ trns_chain_create (void) return chain; } -/* Finalizes all the transformations in CHAIN. - A chain is only finalized once; afterward, calling this - function is a no-op. - Finalizers may add transformations to CHAIN, but after - finalization the chain's contents are fixed, so that no more - transformations may be added afterward. */ +/* Finalizes all the un-finalized transformations in CHAIN. + Any given transformation is only finalized once. */ void trns_chain_finalize (struct trns_chain *chain) { - if (!chain->finalized) + while (!chain->finalized) { size_t i; + chain->finalized = true; for (i = 0; i < chain->trns_cnt; i++) { struct transformation *trns = &chain->trns[i]; - if (trns->finalize != NULL) - trns->finalize (trns->aux); + trns_finalize_func *finalize = trns->finalize; + + trns->finalize = NULL; + if (finalize != NULL) + finalize (trns->aux); } - chain->finalized = true; } } @@ -129,7 +126,7 @@ trns_chain_append (struct trns_chain *chain, trns_finalize_func *finalize, { struct transformation *trns; - assert (!chain->finalized); + chain->finalized = false; if (chain->trns_cnt == chain->trns_cap) chain->trns = x2nrealloc (chain->trns, &chain->trns_cap, @@ -169,6 +166,7 @@ trns_chain_splice (struct trns_chain *dst, struct trns_chain *src) } dst->trns_cnt += src->trns_cnt; + src->trns_cnt = 0; trns_chain_destroy (src); } @@ -180,24 +178,23 @@ trns_chain_next (struct trns_chain *chain) return chain->trns_cnt; } -/* Executes the given CHAIN of transformations on C, - passing *CASE_NR as the case number. - If a transformation modifies *CASE_NR, it will affect the case - number passed to following transformations. +/* Executes the given CHAIN of transformations on *C, + passing CASE_NR as the case number. + *C may be replaced by a new case. Returns the result code that caused the transformations to terminate, or TRNS_CONTINUE if the transformations finished due to "falling off the end" of the set of transformations. */ enum trns_result -trns_chain_execute (struct trns_chain *chain, enum trns_result start, - struct ccase *c, const size_t *case_nr) +trns_chain_execute (const struct trns_chain *chain, enum trns_result start, + struct ccase **c, casenumber case_nr) { size_t i; assert (chain->finalized); - for (i = start < 0 ? 0 : start; i < chain->trns_cnt; ) + for (i = start < 0 ? 0 : start; i < chain->trns_cnt;) { struct transformation *trns = &chain->trns[i]; - int retval = trns->execute (trns->aux, c, *case_nr); + int retval = trns->execute (trns->aux, c, case_nr); if (retval == TRNS_CONTINUE) i++; else if (retval >= 0)