How about the attached patch?  It shouldn't make any difference for
non-windows systems, but hopefully it'll sort out the current default
dir for the rest.

J'


-- 
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://pgp.mit.edu or any PGP keyserver for public key.


diff --git a/src/libpspp/misc.c b/src/libpspp/misc.c
index de1ce3f..d1a3b35 100644
--- a/src/libpspp/misc.c
+++ b/src/libpspp/misc.c
@@ -16,6 +16,9 @@
 
 #include <config.h>
 #include "misc.h"
+#include <gl/dirname.h>
+#include <stdlib.h>
+#include <string.h>
 
 /* Returns the number of digits in X. */
 int
@@ -33,3 +36,48 @@ intlog10 (unsigned x)
   return digits;
 }
 
+
+#ifdef WINDOWS32
+
+const char *
+default_output_path (void)
+{
+  static const char *home_dir = NULL;
+
+  /* Windows NT defines HOMEDRIVE and HOMEPATH.  But give preference
+     to HOME, because the user can change HOME.  */
+  if (home_dir == NULL)
+    {
+      const char *home_drive = getenv ("HOMEDRIVE");
+      const char *home_path = getenv ("HOMEPATH");
+
+      if (home_drive != NULL && home_path != NULL)
+	{
+	  size_t home_drive_len = strlen (home_drive);
+	  size_t home_path_len = strlen (home_path);
+	  char *mem = xmalloc (home_drive_len + home_path_len + 2);
+
+	  strcpy (mem, home_drive);
+	  strcat (mem, home_path);
+	  strcat (mem, "/");
+
+	  home_dir = mem;
+	}
+      else
+	home_dir = "c:/users/default/"; /* poor default */
+    }
+  return home_dir;
+}
+
+#else
+
+const char *
+default_output_path (void)
+{
+  static char current_dir[]  = "";
+
+  return current_dir;
+}
+
+#endif
+
diff --git a/src/libpspp/misc.h b/src/libpspp/misc.h
index 3b02515..1fc75e9 100644
--- a/src/libpspp/misc.h
+++ b/src/libpspp/misc.h
@@ -77,4 +77,6 @@ maximize (double *dest, double src)
     *dest = src;
 }
 
-#endif /* libpspp/misc.h */
+const char * default_output_path (void);
+
+#endif
diff --git a/src/output/journal.c b/src/output/journal.c
index ef50285..e6239bc 100644
--- a/src/output/journal.c
+++ b/src/output/journal.c
@@ -18,6 +18,7 @@
 
 #include <output/journal.h>
 
+#include <libpspp/misc.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -83,7 +84,12 @@ journal_write (bool prefix, const char *line)
   if (journal_file == NULL)
     {
       if (journal_file_name == NULL)
-        journal_file_name = xstrdup ("pspp.jnl");
+	{
+	  const char *output_path = default_output_path ();
+	  journal_file_name = xmalloc (1 + strlen (output_path) + strlen ("pspp.jnl"));
+	  strcpy (journal_file_name, output_path);
+	  strcat (journal_file_name, "pspp.jnl");
+	}
       journal_file = fopen (journal_file_name, "w");
       if (journal_file == NULL)
         {
diff --git a/src/ui/gui/helper.c b/src/ui/gui/helper.c
index 1007ff9..d7ff89f 100644
--- a/src/ui/gui/helper.c
+++ b/src/ui/gui/helper.c
@@ -344,3 +344,6 @@ clone_list_store (const GtkListStore *src)
 }
 
 
+
+
+
diff --git a/src/ui/gui/helper.h b/src/ui/gui/helper.h
index 1a62090..4c9ae33 100644
--- a/src/ui/gui/helper.h
+++ b/src/ui/gui/helper.h
@@ -71,5 +71,7 @@ void marshaller_VOID__INT_INT_INT (GClosure     *closure,
 /* Create a deep copy of SRC */
 GtkListStore * clone_list_store (const GtkListStore *src);
 
+const char * output_text_file_name (void);
+
 
 #endif
diff --git a/src/ui/gui/output-viewer.c b/src/ui/gui/output-viewer.c
index bf647e9..d76d006 100644
--- a/src/ui/gui/output-viewer.c
+++ b/src/ui/gui/output-viewer.c
@@ -62,7 +62,7 @@ on_delete (GtkWidget *w, GdkEvent *event, gpointer user_data)
 
   the_output_viewer = NULL;
 
-  unlink (OUTPUT_FILE_NAME);
+  unlink (output_file_name ());
 
   return FALSE;
 }
@@ -181,7 +181,7 @@ reload_the_viewer (void)
   struct stat buf;
 
   /* If there is no output, then don't do anything */
-  if (0 != stat (OUTPUT_FILE_NAME, &buf))
+  if (0 != stat (output_file_name (), &buf))
     return ;
 
   if ( NULL == the_output_viewer )
@@ -248,10 +248,10 @@ reload_viewer (struct output_viewer *ov)
   {
     if ( ov->fp == NULL)
       {
-	ov->fp = fopen (OUTPUT_FILE_NAME, "r");
+	ov->fp = fopen (output_file_name (), "r");
 	if ( ov->fp == NULL)
 	  {
-	    g_print ("Cannot open %s\n", OUTPUT_FILE_NAME);
+	    g_print ("Cannot open %s\n", output_file_name ());
 	    return;
 	  }
       }
@@ -276,4 +276,21 @@ reload_viewer (struct output_viewer *ov)
 }
 
 
+#define OUTPUT_FILE_NAME "psppire.txt"
 
+const char *
+output_file_name (void)
+{
+  const char *dir = default_output_path ();
+  static char *filename = NULL;
+
+  if ( NULL == filename )
+    {
+      filename = xmalloc (1 + strlen (OUTPUT_FILE_NAME) + strlen (dir));
+
+      strcpy (filename, dir);
+      strcat (filename, OUTPUT_FILE_NAME);
+    }
+
+  return filename;
+}
diff --git a/src/ui/gui/output-viewer.h b/src/ui/gui/output-viewer.h
index b5c9ffc..e5bf5c1 100644
--- a/src/ui/gui/output-viewer.h
+++ b/src/ui/gui/output-viewer.h
@@ -33,7 +33,6 @@ void reload_viewer (struct output_viewer *);
 void reload_the_viewer (void);
 
 
-#define OUTPUT_FILE_NAME "psppire.txt"
-
+const char * output_file_name (void);
 
 #endif
diff --git a/src/ui/gui/psppire.c b/src/ui/gui/psppire.c
index 0467746..a62e426 100644
--- a/src/ui/gui/psppire.c
+++ b/src/ui/gui/psppire.c
@@ -112,13 +112,25 @@ initialize (void)
 
   create_icon_factory ();
 
-  outp_configure_driver_line (
-    ss_cstr ("gui:ascii:screen:squeeze=on headers=off top-margin=0 "
-             "bottom-margin=0 paginate=off length=auto width=auto "
-	     "emphasis=none "
-             "output-file=\"" OUTPUT_FILE_NAME "\" append=yes"));
+  {
+    const char *filename = output_file_name ();
+
+    struct string config_string;
+
+    ds_init_empty (&config_string);
+
+    ds_put_format (&config_string,
+		   "gui:ascii:screen:squeeze=on headers=off top-margin=0 "
+		   "bottom-margin=0 paginate=off length=auto width=auto "
+		   "emphasis=none "
+		   "output-file=\"%s\" append=yes", filename);
 
-  unlink (OUTPUT_FILE_NAME);
+    outp_configure_driver_line (ds_ss (&config_string));
+
+    unlink (filename);
+
+    ds_destroy (&config_string);
+  }
 
   journal_enable ();
   textdomain (PACKAGE);

Attachment: signature.asc
Description: Digital signature

_______________________________________________
pspp-dev mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/pspp-dev

Reply via email to