GET: Add an ENCODING subcommand.
[pspp] / src / data / any-reader.c
index 807c4fe90e95aab67a2b91bd0226820feecd462a..1b488f208a84c78f27936f4c1b513d46864c4c0d 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2006, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2010, 2011, 2012 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
    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <config.h>
-#include "any-reader.h"
+
+#include "data/any-reader.h"
+
 #include <assert.h>
 #include <errno.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <libpspp/assertion.h>
-#include <libpspp/message.h>
-#include "file-handle-def.h"
-#include "file-name.h"
-#include "por-file-reader.h"
-#include "sys-file-reader.h"
-#include <libpspp/str.h>
-#include "scratch-reader.h"
-#include "xalloc.h"
+
+#include "data/dataset-reader.h"
+#include "data/file-handle-def.h"
+#include "data/file-name.h"
+#include "data/por-file-reader.h"
+#include "data/sys-file-reader.h"
+#include "libpspp/assertion.h"
+#include "libpspp/message.h"
+#include "libpspp/str.h"
+
+#include "gl/xalloc.h"
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -76,9 +80,15 @@ any_reader_may_open (const char *file)
 
 /* Returns a casereader for HANDLE.  On success, returns the new
    casereader and stores the file's dictionary into *DICT.  On
-   failure, returns a null pointer. */
+   failure, returns a null pointer.
+
+   Ordinarily the reader attempts to automatically detect the character
+   encoding based on the file's contents.  This isn't always possible,
+   especially for files written by old versions of SPSS or PSPP, so specifying
+   a nonnull ENCODING overrides the choice of character encoding.  */
 struct casereader *
-any_reader_open (struct file_handle *handle, struct dictionary **dict)
+any_reader_open (struct file_handle *handle, const char *encoding,
+                 struct dictionary **dict)
 {
   switch (fh_get_referent (handle))
     {
@@ -90,7 +100,7 @@ any_reader_open (struct file_handle *handle, struct dictionary **dict)
         if (result == IO_ERROR)
           return NULL;
         else if (result == YES)
-          return sfm_open_reader (handle, dict, NULL);
+          return sfm_open_reader (handle, encoding, dict, NULL);
 
         result = try_detect (fh_get_file_name (handle), pfm_detect);
         if (result == IO_ERROR)
@@ -107,8 +117,8 @@ any_reader_open (struct file_handle *handle, struct dictionary **dict)
       msg (SE, _("The inline file is not allowed here."));
       return NULL;
 
-    case FH_REF_SCRATCH:
-      return scratch_reader_open (handle, dict);
+    case FH_REF_DATASET:
+      return dataset_reader_open (handle, dict);
     }
   NOT_REACHED ();
 }