From: Ben Pfaff Date: Sat, 5 Dec 2009 22:49:07 +0000 (-0800) Subject: casereader: New function casereader_advance(). X-Git-Tag: sid-i386-build114^0 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b4f0cbc9786b810e7f186030d4cb2d9f6bd7a56;p=pspp-builds.git casereader: New function casereader_advance(). --- diff --git a/src/data/casereader.c b/src/data/casereader.c index 0eb3baf5..77278851 100644 --- a/src/data/casereader.c +++ b/src/data/casereader.c @@ -264,13 +264,7 @@ casereader_count_cases__ (struct casereader *reader, casenumber max_cases) casenumber n_cases; clone = casereader_clone (reader); - for (n_cases = 0; n_cases < max_cases; n_cases++) - { - struct ccase *c = casereader_read (clone); - if (c == NULL) - break; - case_unref (c); - } + n_cases = casereader_advance (clone, max_cases); casereader_destroy (clone); return n_cases; @@ -315,6 +309,26 @@ casereader_get_proto (const struct casereader *reader) return reader->proto; } +/* Skips past N cases in READER, stopping when the last case in + READER has been read or on an input error. Returns the number + of cases successfully skipped. */ +casenumber +casereader_advance (struct casereader *reader, casenumber n) +{ + casenumber i; + + for (i = 0; i < n; i++) + { + struct ccase *c = casereader_read (reader); + if (c == NULL) + break; + case_unref (c); + } + + return i; +} + + /* Copies all the cases in READER to WRITER, propagating errors appropriately. */ void diff --git a/src/data/casereader.h b/src/data/casereader.h index 107e6069..fb9d50ff 100644 --- a/src/data/casereader.h +++ b/src/data/casereader.h @@ -80,6 +80,7 @@ casenumber casereader_count_cases (struct casereader *); void casereader_truncate (struct casereader *, casenumber); const struct caseproto *casereader_get_proto (const struct casereader *); +casenumber casereader_advance (struct casereader *, casenumber); void casereader_transfer (struct casereader *, struct casewriter *); struct casereader *