data-in: Get rid of first_column, last_column arguments.
[pspp] / src / language / data-io / data-reader.c
index 9b08625efaa93df7b68dd530d7c9f023a57d8eda..061505f889075cf2ea66d5709c1bc1e5563ad344 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-2004, 2006 Free Software Foundation, Inc.
+   Copyright (C) 1997-2004, 2006, 2010 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
@@ -34,6 +34,7 @@
 #include <language/lexer/lexer.h>
 #include <language/prompt.h>
 #include <libpspp/assertion.h>
+#include <libpspp/cast.h>
 #include <libpspp/integer-format.h>
 #include <libpspp/message.h>
 #include <libpspp/str.h>
@@ -140,13 +141,12 @@ dfm_open_reader (struct file_handle *fh, struct lexer *lexer)
   if (fh_get_referent (fh) != FH_REF_INLINE)
     {
       struct stat s;
-      r->where.file_name = fh_get_file_name (fh);
+      r->where.file_name = CONST_CAST (char *, fh_get_file_name (fh));
       r->where.line_number = 0;
-      r->file = fn_open (fh_get_file_name (fh),
-                         fh_get_mode (fh) == FH_MODE_TEXT ? "r" : "rb");
+      r->file = fn_open (fh_get_file_name (fh), "rb");
       if (r->file == NULL)
         {
-          msg (ME, _("Could not open \"%s\" for reading as a data file: %s."),
+          msg (ME, _("Could not open `%s' for reading as a data file: %s."),
                fh_get_file_name (r->fh), strerror (errno));
           fh_unlock (r->lock);
           fh_unref (fh);
@@ -187,6 +187,7 @@ read_inline_record (struct dfm_reader *r)
 
   if (!lex_get_line_raw (r->lexer))
     {
+      lex_discard_line (r->lexer);
       msg (SE, _("Unexpected end-of-file while reading data in BEGIN "
                  "DATA.  This probably indicates "
                  "a missing or misformatted END DATA command.  "
@@ -340,7 +341,7 @@ read_file_record (struct dfm_reader *r)
   switch (fh_get_mode (r->fh))
     {
     case FH_MODE_TEXT:
-      if (ds_read_line (&r->line, r->file))
+      if (ds_read_line (&r->line, r->file, SIZE_MAX))
         {
           ds_chomp (&r->line, '\n');
           return true;
@@ -596,7 +597,7 @@ dfm_expand_tabs (struct dfm_reader *r)
 }
 
 /* Returns the legacy character encoding of data read from READER. */
-enum legacy_encoding
+const char *
 dfm_reader_get_legacy_encoding (const struct dfm_reader *reader)
 {
   return fh_get_legacy_encoding (reader->fh);
@@ -676,20 +677,16 @@ dfm_get_column (const struct dfm_reader *r, const char *p)
   return ds_pointer_to_position (&r->line, p) + 1;
 }
 
-/* Pushes the file name and line number on the fn/ln stack. */
-void
-dfm_push (struct dfm_reader *r)
+const char *
+dfm_get_file_name (const struct dfm_reader *r)
 {
-  if (r->fh != fh_inline_file ())
-    msg_push_msg_locator (&r->where);
+  return fh_get_referent (r->fh) == FH_REF_FILE ? r->where.file_name : NULL;
 }
 
-/* Pops the file name and line number from the fn/ln stack. */
-void
-dfm_pop (struct dfm_reader *r)
+int
+dfm_get_line_number (const struct dfm_reader *r)
 {
-  if (r->fh != fh_inline_file ())
-    msg_pop_msg_locator (&r->where);
+  return fh_get_referent (r->fh) == FH_REF_FILE ? r->where.line_number : -1;
 }
 \f
 /* BEGIN DATA...END DATA procedure. */