dnl Initialize.
 AC_PREREQ(2.63)
-AC_INIT([GNU PSPP], [0.8.5], [bug-gnu-pspp@gnu.org], [pspp])
+AC_INIT([GNU PSPP], [0.8.6], [bug-gnu-pspp@gnu.org], [pspp])
 AC_CONFIG_AUX_DIR([build-aux])
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_TESTDIR([tests])
 
   }
 CODE:
  struct file_handle *fh =
-  fh_create_file (NULL, name, fh_default_properties () );
+   fh_create_file (NULL, name, "UTF-8", fh_default_properties () );
  struct syswriter_info *swi = xmalloc (sizeof (*swi));
  swi->writer = sfm_open_writer (fh, dict->dict, opts);
  swi->dict = dict;
  struct casereader *reader;
  struct sysreader_info *sri = NULL;
  struct file_handle *fh =
-        fh_create_file (NULL, name, fh_default_properties () );
+   fh_create_file (NULL, name, "UTF-8", fh_default_properties () );
  struct dictionary *dict;
 
  sri = xmalloc (sizeof (*sri));
 
 =head3 new ($filename, $dict [,%opts])
 
 Creates a new system file from the dictionary C<dict>.  The file will
-be written to the file called C<filename>.
+be written to the file called C<filename>. The string C<filename> must 
+be encoded in UTF-8.
 C<opt>, if specified, is a hash containing optional parameters for the
 system file.  Currently, the only supported parameter is
 C<compress>. If C<compress> is non zero, then the system file written
 
 Open is used to read data from an existing system file. 
 It creates and returns a PSPP::Reader object which can be used to read 
-data and dictionary information from C<filename>.
+data and dictionary information from C<filename>.  The string C<filename> 
+must be in UTF-8 encoding.
 
 =head3 get_case_cnt ()
 
 
    existing file identifiers.  The new handle is associated with file FILE_NAME
    and the given PROPERTIES. */
 struct file_handle *
-fh_create_file (const char *id, const char *file_name,
+fh_create_file (const char *id, const char *file_name, const char *file_name_encoding,
                 const struct fh_properties *properties)
 {
   char *handle_name;
 
 
 /* Creating file handles. */
 struct file_handle *fh_create_file (const char *handle_name,
-                                    const char *file_name,
+                                    const char *file_name, const char *file_name_encoding,
                                     const struct fh_properties *);
 struct file_handle *fh_create_dataset (struct dataset *);
 const struct fh_properties *fh_default_properties (void);
 
   for (i = 0; i < n_values; i++)
     {
       struct string *output = &outputs[n_values - i - 1];
-      struct lex_reader *reader;
-
-      reader = lex_reader_for_substring_nocopy (ds_ss (output));
+      const char *encoding = lex_get_encoding (lexer);
+      struct lex_reader *reader = lex_reader_for_substring_nocopy (ds_ss (output), encoding);
       lex_reader_set_file_name (reader, file_name);
       reader->line_number = line_number;
       lex_include (lexer, reader);
 
   if (cmd.s_encoding != NULL)
     properties.encoding = cmd.s_encoding;
 
-  fh_create_file (handle_name, cmd.s_name, &properties);
+  fh_create_file (handle_name, cmd.s_name, lex_get_encoding (lexer), &properties);
 
   result = CMD_SUCCESS;
 
       if (lex_token (lexer) == T_ID)
         handle = fh_from_id (lex_tokcstr (lexer));
       if (handle == NULL)
-            handle = fh_create_file (NULL, lex_tokcstr (lexer),
+       handle = fh_create_file (NULL, lex_tokcstr (lexer), lex_get_encoding (lexer),
                                      fh_default_properties ());
       lex_get (lexer);
     }
 
   reader->syntax = LEX_SYNTAX_AUTO;
   reader->error = LEX_ERROR_CONTINUE;
   reader->file_name = NULL;
+  reader->encoding = NULL;
   reader->line_number = 0;
 }
 
   return src == NULL ? NULL : src->reader->file_name;
 }
 
+const char *
+lex_get_encoding (const struct lexer *lexer)
+{
+  struct lex_source *src = lex_source__ (lexer);
+  return src == NULL ? NULL : src->reader->encoding;
+}
+
+
 /* Returns the syntax mode for the syntax file from which the current drawn is
    drawn.  Returns LEX_SYNTAX_AUTO for a T_STOP token or if the command's
    source does not have line numbers.
 lex_source_destroy (struct lex_source *src)
 {
   char *file_name = src->reader->file_name;
+  char *encoding = src->reader->encoding;
   if (src->reader->class->destroy != NULL)
     src->reader->class->destroy (src->reader);
   free (file_name);
+  free (encoding);
   free (src->buffer);
   while (!deque_is_empty (&src->deque))
     lex_source_pop__ (src);
   r->reader.syntax = syntax;
   r->reader.error = error;
   r->reader.file_name = xstrdup (file_name);
+  r->reader.encoding = encoding ? xstrdup (encoding) : NULL;
   r->reader.line_number = 1;
   r->istream = istream;
 
 static struct lex_reader_class lex_string_reader_class;
 
 /* Creates and returns a new lex_reader for the contents of S, which must be
-   encoded in UTF-8.  The new reader takes ownership of S and will free it
+   encoded in the given ENCODING.  The new reader takes ownership of S and will free it
    with ss_dealloc() when it is closed. */
 struct lex_reader *
-lex_reader_for_substring_nocopy (struct substring s)
+lex_reader_for_substring_nocopy (struct substring s, const char *encoding)
 {
   struct lex_string_reader *r;
 
   r = xmalloc (sizeof *r);
   lex_reader_init (&r->reader, &lex_string_reader_class);
   r->reader.syntax = LEX_SYNTAX_AUTO;
+  r->reader.encoding = encoding ? xstrdup (encoding) : NULL;
   r->s = s;
   r->offset = 0;
 
 }
 
 /* Creates and returns a new lex_reader for a copy of null-terminated string S,
-   which must be encoded in UTF-8.  The caller retains ownership of S. */
+   which must be encoded in ENCODING.  The caller retains ownership of S. */
 struct lex_reader *
-lex_reader_for_string (const char *s)
+lex_reader_for_string (const char *s, const char *encoding)
 {
   struct substring ss;
   ss_alloc_substring (&ss, ss_cstr (s));
-  return lex_reader_for_substring_nocopy (ss);
+  return lex_reader_for_substring_nocopy (ss, encoding);
 }
 
 /* Formats FORMAT as a printf()-like format string and creates and returns a
    new lex_reader for the formatted result.  */
 struct lex_reader *
-lex_reader_for_format (const char *format, ...)
+lex_reader_for_format (const char *format, const char *encoding, ...)
 {
   struct lex_reader *r;
   va_list args;
 
-  va_start (args, format);
-  r = lex_reader_for_substring_nocopy (ss_cstr (xvasprintf (format, args)));
+  va_start (args, encoding);
+  r = lex_reader_for_substring_nocopy (ss_cstr (xvasprintf (format, args)), encoding);
   va_end (args);
 
   return r;
 
     const struct lex_reader_class *class;
     enum lex_syntax_mode syntax;
     enum lex_error_mode error;
+    char *encoding;
     char *file_name;            /* NULL if not associated with a file. */
     int line_number;            /* 1-based initial line number, 0 if none. */
   };
                                         const char *encoding,
                                         enum lex_syntax_mode syntax,
                                         enum lex_error_mode error);
-struct lex_reader *lex_reader_for_string (const char *);
-struct lex_reader *lex_reader_for_format (const char *, ...)
-  PRINTF_FORMAT (1, 2);
-struct lex_reader *lex_reader_for_substring_nocopy (struct substring);
+struct lex_reader *lex_reader_for_string (const char *, const char *encoding);
+struct lex_reader *lex_reader_for_format (const char *, const char *, ...)
+  PRINTF_FORMAT (1, 3);
+struct lex_reader *lex_reader_for_substring_nocopy (struct substring, const char *encoding);
 
 /* Initialization. */
 struct lexer *lex_create (void);
 int lex_get_first_column (const struct lexer *, int n);
 int lex_get_last_column (const struct lexer *, int n);
 const char *lex_get_file_name (const struct lexer *);
+const char *lex_get_encoding (const struct lexer *);
 
 /* Issuing errors. */
 void lex_error (struct lexer *, const char *, ...) PRINTF_FORMAT (2, 3);
 
 void
 execute_const_syntax_string (PsppireDataWindow *window, const gchar *syntax)
 {
-  execute_syntax (window, lex_reader_for_string (syntax));
+  execute_syntax (window, lex_reader_for_string (syntax, "UTF-8"));
 }
 
     }
 
   ok = execute_syntax (PSPPIRE_DATA_WINDOW (de),
-                       lex_reader_for_string (syntax));
+                       lex_reader_for_string (syntax, "UTF-8"));
   g_free (syntax);
 
   if (ok && syn == NULL)
 
       goto exit;
     }
 
-  input_fh = fh_create_file (NULL, input_filename, fh_default_properties ());
+  input_fh = fh_create_file (NULL, input_filename, NULL, fh_default_properties ());
   reader = any_reader_open_and_decode (input_fh, encoding, &dict, NULL);
   if (reader == NULL)
     exit (1);
 
-  output_fh = fh_create_file (NULL, output_filename, fh_default_properties ());
+  output_fh = fh_create_file (NULL, output_filename, NULL, fh_default_properties ());
   if (!strcmp (output_format, "csv") || !strcmp (output_format, "txt"))
     {
       struct csv_writer_options options;