X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Ffastfile.c;h=5856d07c80b359fc06ab7002614fa46efdb5945f;hb=dc78471910e82d59232ce9b137b7c4fc4992d174;hp=9cdba1567648b002c7848b057ba431be88464ff4;hpb=57b436a22d9ae0e395fb2e3ce101c2b5c2e6939e;p=pspp-builds.git diff --git a/src/data/fastfile.c b/src/data/fastfile.c index 9cdba156..5856d07c 100644 --- a/src/data/fastfile.c +++ b/src/data/fastfile.c @@ -1,6 +1,5 @@ /* PSPP - computes sample statistics. - Copyright (C) 2004, 2006 Free Software Foundation, Inc. - Written by Ben Pfaff . + Copyright (C) 2004, 2006, 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 @@ -18,9 +17,11 @@ 02110-1301, USA. */ #include + #include "casefile.h" #include "casefile-private.h" #include "fastfile.h" + #include #include #include @@ -28,16 +29,19 @@ #include #include #include + +#include +#include +#include +#include #include -#include "case.h" #include #include +#include +#include + #include "full-read.h" #include "full-write.h" -#include -#include "make-file.h" -#include "settings.h" -#include "variable.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -86,8 +90,7 @@ also read with casereaders in this phase, but the ability to create new casereaders is curtailed. - In this phase, casereaders could still be cloned (once - we eventually implement cloning). + In this phase, casereaders could still be cloned. To transition from phase 1 or 2 to phase 3 and create a casereader, call casefile_get_destructive_reader(). @@ -243,8 +246,7 @@ fastfilereader_get_next_case (struct casereader *cr) ffr->buffer_pos = 0; } - case_from_values (&ffr->c, ffr->buffer + ffr->buffer_pos, - ff->value_cnt); + case_copy_in (&ffr->c, 0, ffr->buffer + ffr->buffer_pos, ff->value_cnt); ffr->buffer_pos += ff->value_cnt; read_case = &ffr->c; @@ -287,6 +289,44 @@ fastfile_get_reader (const struct casefile *cf_) return reader; } + +/* Creates a copy of the casereader CR, and returns it */ +static struct casereader * +fastfilereader_clone (const struct casereader *cr) +{ + const struct fastfilereader *ffr = (const struct fastfilereader *) cr ; + struct fastfilereader *new_ffr = xzalloc (sizeof *new_ffr); + + struct casereader *new_reader = (struct casereader *) new_ffr; + + struct casefile *cf = casereader_get_casefile (cr); + struct fastfile *ff = (struct fastfile *) cf; + + assert (!cf->being_destroyed); + + /* Flush the buffer to disk if it's not empty. */ + if (ff->mode == WRITE && ff->storage == DISK) + flush_buffer (ff); + + ff->mode = READ; + + casereader_register (cf, new_reader, &class_reader); + + new_ffr->case_idx = ffr->case_idx ; + new_reader->destructive = cr->destructive; + new_ffr->fd = ffr->fd ; + new_ffr->buffer = ffr->buffer ; + new_ffr->buffer_pos = ffr->buffer_pos; + + if (ff->storage == DISK) + reader_open_file (new_ffr); + + return new_reader; +} + + + + /* Returns the number of `union value's in a case for CF. */ static size_t fastfile_get_value_cnt (const struct casefile *cf) @@ -604,7 +644,7 @@ write_case_to_disk (struct fastfile *ff, const struct ccase *c) if (!ff->ok) return; - case_to_values (c, ff->buffer + ff->buffer_used, ff->value_cnt); + case_copy_out (c, 0, ff->buffer + ff->buffer_used, ff->value_cnt); ff->buffer_used += ff->value_cnt; if (ff->buffer_used + ff->value_cnt > ff->buffer_size) flush_buffer (ff); @@ -748,4 +788,5 @@ static const struct class_casereader class_reader = fastfilereader_get_next_case, fastfilereader_cnum, fastfilereader_destroy, + fastfilereader_clone, };