Here's a new patch with Ben's suggestions added. 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/data/file-name.c b/src/data/file-name.c
index 86c8e17..14afd60 100644
--- a/src/data/file-name.c
+++ b/src/data/file-name.c
@@ -452,3 +452,45 @@ fn_hash_identity (const struct file_identity *identity)
hash ^= hsh_hash_string (identity->name);
return hash;
}
+
+
+
+#ifdef WINDOWS32
+
+/* Apparently windoze users like to see output dumped into their home directory,
+ not the current directory (!) */
+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)
+ home_dir = xasprintf ("%s%s%c",
+ home_drive, home_path, DIRECTORY_SEPARATOR);
+ else
+ home_dir = "c:/users/default/"; /* poor default */
+ }
+ return home_dir;
+}
+
+#else
+
+/* ... whereas the rest of the world just likes it to be
+ put "here" for easy access. */
+const char *
+default_output_path (void)
+{
+ static char current_dir[] = "";
+
+ return current_dir;
+}
+
+#endif
+
diff --git a/src/data/file-name.h b/src/data/file-name.h
index b4231d2..d34bd41 100644
--- a/src/data/file-name.h
+++ b/src/data/file-name.h
@@ -52,4 +52,6 @@ int fn_compare_file_identities (const struct file_identity *,
const struct file_identity *);
unsigned int fn_hash_identity (const struct file_identity *);
+const char * default_output_path (void);
+
#endif /* file-name.h */
diff --git a/src/output/journal.c b/src/output/journal.c
index ef50285..67657f6 100644
--- a/src/output/journal.c
+++ b/src/output/journal.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <data/file-name.h>
#include <libpspp/str.h>
#include "fwriteerror.h"
@@ -83,7 +84,10 @@ 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 = xasprintf ("%s%s", output_path, "pspp.jnl");
+ }
journal_file = fopen (journal_file_name, "w");
if (journal_file == NULL)
{
diff --git a/src/ui/gui/output-viewer.c b/src/ui/gui/output-viewer.c
index bf647e9..c00e8c6 100644
--- a/src/ui/gui/output-viewer.c
+++ b/src/ui/gui/output-viewer.c
@@ -16,6 +16,7 @@
#include <config.h>
#include <gtk/gtk.h>
+#include <data/file-name.h>
#include "window-manager.h"
#include "output-viewer.h"
#include "helper.h"
@@ -62,7 +63,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 +182,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 +249,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 +277,17 @@ 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 = xasprintf ("%s%s", dir, 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);
signature.asc
Description: Digital signature
_______________________________________________ pspp-dev mailing list [email protected] http://lists.gnu.org/mailman/listinfo/pspp-dev
