+2007-12-07 Ben Pfaff <blp@gnu.org>
+
+ Patch #6302.
+
+ * casegrouper.c (casegrouper_get_next_group): Cause a casegrouper
+ made from an empty casereader produce a casegrouper with no
+ groups, instead of one with one group that has no cases.
+
+ * casereader.c (casereader_is_empty): New function.
+
2007-12-06 Ben Pfaff <blp@gnu.org>
Patch #6303.
{
if (grouper->reader != NULL)
{
- *reader = grouper->reader;
- grouper->reader = NULL;
- return true;
+ if (!casereader_is_empty (grouper->reader))
+ {
+ *reader = grouper->reader;
+ grouper->reader = NULL;
+ return true;
+ }
+ else
+ {
+ casereader_destroy (grouper->reader);
+ grouper->reader = NULL;
+ return false;
+ }
}
else
{
return false;
}
+/* Returns true if no cases remain to be read from READER, or if
+ an error has occurred on READER. (A return value of false
+ does *not* mean that the next call to casereader_peek or
+ casereader_read will return true, because an error can occur
+ in the meantime.) */
+bool
+casereader_is_empty (struct casereader *reader)
+{
+ struct ccase c;
+ if (reader->case_cnt == 0 || !casereader_peek (reader, 0, &c))
+ return true;
+ else
+ {
+ case_destroy (&c);
+ return false;
+ }
+}
+
/* Returns true if an I/O error or another hard error has
occurred on READER, a clone of READER, or on some object on
which READER's data has a dependency, false otherwise. */
bool casereader_peek (struct casereader *, casenumber, struct ccase *)
WARN_UNUSED_RESULT;
+bool casereader_is_empty (struct casereader *);
bool casereader_error (const struct casereader *);
void casereader_force_error (struct casereader *);