? a.out
? diffs
? file
? foo.c
? libtool
? pspp-0.4.2.tar.gz
? q.patch
? x.patch
? doc/.dirstamp
? glade/.deps
? lib/gsl-extras/.deps
? lib/gsl-extras/.dirstamp
? lib/gtksheet/.deps
? lib/gtksheet/.dirstamp
? lib/gtksheet/doit.sh
? lib/linreg/.deps
? lib/linreg/.dirstamp
? src/data/.deps
? src/data/.dirstamp
? src/language/.deps
? src/language/.dirstamp
? src/language/control/.deps
? src/language/control/.dirstamp
? src/language/data-io/.deps
? src/language/data-io/.dirstamp
? src/language/dictionary/.deps
? src/language/dictionary/.dirstamp
? src/language/expressions/.deps
? src/language/expressions/.dirstamp
? src/language/lexer/.deps
? src/language/lexer/.dirstamp
? src/language/stats/.deps
? src/language/stats/.dirstamp
? src/language/tests/.deps
? src/language/tests/.dirstamp
? src/language/utilities/.deps
? src/language/utilities/.dirstamp
? src/language/xforms/.deps
? src/language/xforms/.dirstamp
? src/libpspp/.deps
? src/libpspp/.dirstamp
? src/libpspp/src_libpspp_i18n_o
? src/libpspp/testquote.c
? src/math/.deps
? src/math/.dirstamp
? src/math/linreg/.deps
? src/math/linreg/.dirstamp
? src/math/ts/.deps
? src/math/ts/.dirstamp
? src/output/.deps
? src/output/.dirstamp
? src/output/charts/.deps
? src/output/charts/.dirstamp
? src/ui/.deps
? src/ui/.dirstamp
? src/ui/gui/.deps
? src/ui/gui/.dirstamp
? src/ui/gui/.libs
? src/ui/gui/libpsppire.la
? src/ui/gui/src_ui_gui_libpsppire_la-glade-register.lo
? src/ui/terminal/.deps
? src/ui/terminal/.dirstamp
? tests/formats/.deps
? tests/formats/.dirstamp
? tests/libpspp/.deps
? tests/libpspp/.dirstamp
? tests/libpspp/abt-test
? tests/libpspp/heap-test
Index: src/libpspp/automake.mk
===================================================================
RCS file: /sources/pspp/pspp/src/libpspp/automake.mk,v
retrieving revision 1.21
diff -U3 -r1.21 automake.mk
--- src/libpspp/automake.mk	26 Jan 2007 03:34:00 -0000	1.21
+++ src/libpspp/automake.mk	16 Feb 2007 13:38:54 -0000
@@ -44,6 +44,8 @@
 	src/libpspp/misc.h \
 	src/libpspp/pool.c \
 	src/libpspp/pool.h \
+	src/libpspp/quote.c \
+	src/libpspp/quote.h \
 	src/libpspp/message.c \
 	src/libpspp/message.h \
 	src/libpspp/start-date.c \
Index: src/libpspp/quote.c
===================================================================
RCS file: src/libpspp/quote.c
diff -N src/libpspp/quote.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/libpspp/quote.c	16 Feb 2007 13:38:54 -0000
@@ -0,0 +1,115 @@
+/* PSPP - computes sample statistics.
+   Copyright (C) 2007 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 the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA. */
+
+#include <config.h>
+#include <stdbool.h>
+
+#include <libpspp/str.h>
+#include <libpspp/assertion.h>
+#include <string.h>
+#include <mbchar.h>
+
+#include "quote.h"
+
+
+static bool
+has_single_quote (const char *s)
+{
+  return strchr (s, '\'');
+}
+
+static bool
+has_double_quote (const char *s)
+{
+  return strchr (s, '"');
+}
+
+void
+quote (struct string *str)
+{
+  quote_pad_percent (str, false);
+}
+
+/* 
+   Quotes the string STR. If STR contains no '\'' character, then
+   the returned value will be enclosed in single quotes.  Else, if STR
+   contains no '"' character, then it will be enclosed in double
+   quotes. Otherwise, it will be enclosed in single quotes, and each
+   '\'' will be padded with another '\''.  
+
+   STR must be encoded in UTF-8, and the quoted result will also be
+   encoded in UTF-8.  
+
+   If PRINTF_FORMAT is true, then every instance of '%' will be
+   replaced with '%%'
+*/
+void
+quote_pad_percent (struct string *str, bool printf_format)
+{
+  char c;
+  const char *s = ds_cstr (str);
+  static const char single_quote[] = "'";
+  static const char double_quote[] = "\"";
+
+  struct string quoted_str;
+
+  bool pad_single_quotes = false;
+  const char *delimiter ;
+
+  if ( has_double_quote (s))
+    {
+      delimiter = single_quote;
+      if ( has_single_quote (s))
+	pad_single_quotes = true;
+    }
+  else
+    {
+      delimiter = double_quote;
+    }
+
+  /* This seemingly simple implementation is possible, because UTF-8
+     garuantees that bytes corresponding to basic characters (such as
+     '\'') cannot appear in a multi-byte character sequence except to
+     represent that basic character.
+  */
+  assert (is_basic ('\''));
+  assert (is_basic ('%'));
+
+  /* Initialise with the opening delimiter */
+  ds_init_cstr (&quoted_str, delimiter);
+  while ((c = *s++))
+    {
+      ds_put_char (&quoted_str, c);
+
+      /* If c is a single quote, then append another one */
+      if ( c == '\'' && pad_single_quotes)
+	ds_put_char (&quoted_str, c);
+
+      if ( c == '%' && printf_format )
+	ds_put_char (&quoted_str, c);
+    }
+
+  /* Add the closing delimiter */
+  ds_put_cstr (&quoted_str, delimiter);
+
+  /* Copy the quoted string into str */
+  ds_destroy (str);
+  ds_init_string (str, &quoted_str);
+  ds_destroy (&quoted_str);
+}
+
Index: src/libpspp/quote.h
===================================================================
RCS file: src/libpspp/quote.h
diff -N src/libpspp/quote.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/libpspp/quote.h	16 Feb 2007 13:38:54 -0000
@@ -0,0 +1,27 @@
+/* PSPP - computes sample statistics.
+   Copyright (C) 2007 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 the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA. */
+
+#ifndef QUOTE_H
+#define QUOTE_H
+
+struct string;
+
+void quote_pad_percent (struct string *, bool);
+void quote (struct string *);
+
+#endif 
Index: src/ui/gui/data-editor.c
===================================================================
RCS file: /sources/pspp/pspp/src/ui/gui/data-editor.c,v
retrieving revision 1.17
diff -U3 -r1.17 data-editor.c
--- src/ui/gui/data-editor.c	7 Feb 2007 02:12:57 -0000	1.17
+++ src/ui/gui/data-editor.c	16 Feb 2007 13:38:55 -0000
@@ -41,6 +41,7 @@
 #include "data-editor.h"
 #include "syntax-editor.h"
 #include <language/syntax-string-source.h>
+#include <libpspp/quote.h>
 #include "window-manager.h"
 
 #include "psppire-data-store.h"
@@ -838,22 +839,28 @@
 save_file (struct data_editor *de)
 {
   struct getl_interface *sss;
+  struct string file_name ;
 
   g_assert (de->file_name);
 
+  ds_init_cstr (&file_name, de->file_name);
+  quote (&file_name);
+
   if ( de->save_as_portable )
     {
       append_filename_suffix (de, ".por");
-      sss = create_syntax_string_source ("EXPORT OUTFILE='%s'.",
-					 de->file_name);
+      sss = create_syntax_string_source ("EXPORT OUTFILE=%s.",
+					 ds_cstr (&file_name));
     }
   else
     {
       append_filename_suffix (de, ".sav");
-      sss = create_syntax_string_source ("SAVE OUTFILE='%s'.",
-					 de->file_name);
+      sss = create_syntax_string_source ("SAVE OUTFILE=%s.",
+					 ds_cstr (&file_name));
     }
 
+  ds_destroy (&file_name);
+
   execute_syntax (sss);
 }
 
@@ -1003,13 +1010,20 @@
     case GTK_RESPONSE_ACCEPT:
       {
 	struct getl_interface *sss;
+	struct string filename;
 	g_free (de->file_name);
 	de->file_name =
 	  gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
 
-	sss = create_syntax_string_source ("GET FILE='%s'.", de->file_name);
+	ds_init_cstr (&filename, de->file_name);
+
+	quote (&filename);
+
+	sss = create_syntax_string_source ("GET FILE=%s.", 
+					   ds_cstr (&filename));
 
 	execute_syntax (sss);
+	ds_destroy (&filename);
 
 	window_set_name_from_filename (e, de->file_name);
       }
Index: src/ui/gui/window-manager.c
===================================================================
RCS file: /sources/pspp/pspp/src/ui/gui/window-manager.c,v
retrieving revision 1.8
diff -U3 -r1.8 window-manager.c
--- src/ui/gui/window-manager.c	9 Feb 2007 15:06:28 -0000	1.8
+++ src/ui/gui/window-manager.c	16 Feb 2007 13:38:55 -0000
@@ -157,14 +157,15 @@
    FILENAME is in "filename encoding" */
 void
 window_set_name_from_filename (struct editor_window *e,
-			       const gchar *filename)
+			       const gchar *fn)
 {
   gchar *title;
+  gchar *filename = g_filename_to_utf8 (fn, -1, NULL, NULL, NULL);
   gchar *basename = g_path_get_basename (filename);
 
   set_window_name (e, filename);
 
-  switch (e->type )
+  switch (e->type)
     {
     case WINDOW_SYNTAX:
       title = g_strdup_printf (_("%s --- PSPP Syntax Editor"), basename);
@@ -180,6 +181,7 @@
   gtk_window_set_title (GTK_WINDOW (e->window), title);
 
   g_free (title);
+  g_free (filename);
 }
 
 const gchar *
