X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Ffastfile.c;h=7fa6eb85916e1befcbdb84c81c1c13abbcc20c15;hb=f49ed94900625697d344071290cf2360293c27e3;hp=9cdba1567648b002c7848b057ba431be88464ff4;hpb=57b436a22d9ae0e395fb2e3ce101c2b5c2e6939e;p=pspp diff --git a/src/data/fastfile.c b/src/data/fastfile.c index 9cdba15676..7fa6eb8591 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(). @@ -287,6 +290,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) @@ -748,4 +789,5 @@ static const struct class_casereader class_reader = fastfilereader_get_next_case, fastfilereader_cnum, fastfilereader_destroy, + fastfilereader_clone, };