From: John Darrington Date: Sat, 18 Oct 2008 01:09:47 +0000 (+0800) Subject: Added (source) configurable default output directory. X-Git-Tag: v0.7.1~6^2~4 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=commitdiff_plain;h=2fb98b792ed39c7b39dbd6325e933c612c277000 Added (source) configurable default output directory. Some systems expect files to be dumped in the home directory instead of the current directory. This change makes that easier. --- diff --git a/src/data/file-name.c b/src/data/file-name.c index 86c8e17e..14afd60e 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 b4231d2f..d34bd419 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 ef50285e..67657f62 100644 --- a/src/output/journal.c +++ b/src/output/journal.c @@ -22,6 +22,7 @@ #include #include +#include #include #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 bf647e90..c00e8c60 100644 --- a/src/ui/gui/output-viewer.c +++ b/src/ui/gui/output-viewer.c @@ -16,6 +16,7 @@ #include #include +#include #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 b5c9ffce..e5bf5c1c 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 239d153e..974d18b7 100644 --- a/src/ui/gui/psppire.c +++ b/src/ui/gui/psppire.c @@ -111,13 +111,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);