changeset 20052:4b7b7ac7af2c

use get_home_directory instead of getenv ("HOME") (bug #44694) * files-dock-widget.cc (files_dock_widget::popdownmenu_home): Use get_home_directory instead of getenv ("HOME") for the benefit of Windows systems which may not have HOME set in the environment. * kpse.cc (kpse_tilde_expand): Likewise. * prefdir.m: Likewise. * system.tst: Likewise. * edit.m: Use get_home_directory instead of default_home. (default_home): Delete subfunction.
author John W. Eaton <jwe@octave.org>
date Thu, 02 Apr 2015 13:19:30 -0400
parents 47d420d769ba
children 9c26eee65266
files libgui/src/files-dock-widget.cc liboctave/util/kpse.cc scripts/miscellaneous/edit.m scripts/prefs/prefdir.m test/system.tst
diffstat 5 files changed, 10 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/files-dock-widget.cc	Thu Apr 02 13:08:34 2015 -0400
+++ b/libgui/src/files-dock-widget.cc	Thu Apr 02 13:19:30 2015 -0400
@@ -46,6 +46,7 @@
 #include <QFileDialog>
 
 #include "load-save.h"
+#include "oct-env.h"
 
 class FileTreeViewer : public QTreeView
 {
@@ -822,7 +823,8 @@
 void
 files_dock_widget::popdownmenu_home (bool)
 {
-  QString dir = qgetenv ("HOME");
+  QString dir = QString::fromStdString (octave_env::get_home_directory ());
+
   if (dir.isEmpty ())
     dir = QDir::homePath ();
 
--- a/liboctave/util/kpse.cc	Thu Apr 02 13:08:34 2015 -0400
+++ b/liboctave/util/kpse.cc	Thu Apr 02 13:19:30 2015 -0400
@@ -1201,7 +1201,7 @@
     }
   else if (name.length () == 1)
     {
-      expansion = octave_env::getenv ("HOME");
+      expansion = octave_env::get_home_directory ();
 
       if (expansion.empty ())
         expansion = ".";
@@ -1212,7 +1212,7 @@
   else if (IS_DIR_SEP (name[1]))
     {
       unsigned c = 1;
-      std::string home = octave_env::getenv ("HOME");
+      std::string home = octave_env::get_home_directory ();
 
       if (home.empty ())
         home = ".";
--- a/scripts/miscellaneous/edit.m	Thu Apr 02 13:08:34 2015 -0400
+++ b/scripts/miscellaneous/edit.m	Thu Apr 02 13:19:30 2015 -0400
@@ -125,7 +125,8 @@
 
   ## Pick up globals or default them.
 
-  persistent FUNCTION = struct ("HOME", fullfile (default_home, "octave"),
+  persistent FUNCTION = struct ("HOME",
+                                fullfile (get_home_directory (), "octave"),
                                 "AUTHOR", default_user(1),
                                 "EMAIL", [],
                                 "LICENSE", "GPL",
@@ -164,7 +165,7 @@
         return;
       case "HOME"
         if (! isempty (stateval) && stateval(1) == "~")
-          stateval = [ default_home, stateval(2:end) ];
+          stateval = [ get_home_directory, stateval(2:end) ];
         endif
         FUNCTION.HOME = stateval;
         return;
@@ -517,20 +518,6 @@
 
 endfunction
 
-function retval = default_home ()
-
-  retval = getenv ("HOME");
-  if (isempty (retval))
-    retval = glob ("~");
-    if (! isempty (retval))
-      retval = retval{1};
-    else
-      retval = "";
-    endif
-  endif
-
-endfunction
-
 ## Return the name associated with the current user ID.
 ##
 ## If LONG_FORM is 1, return the full name.  This will be the
--- a/scripts/prefs/prefdir.m	Thu Apr 02 13:08:34 2015 -0400
+++ b/scripts/prefs/prefdir.m	Thu Apr 02 13:19:30 2015 -0400
@@ -42,7 +42,7 @@
 
 function folder = prefdir ()
 
-  folder = getenv ("HOME");
+  folder = get_home_directory ();
 
 endfunction
 
--- a/test/system.tst	Thu Apr 02 13:08:34 2015 -0400
+++ b/test/system.tst	Thu Apr 02 13:19:30 2015 -0400
@@ -268,7 +268,7 @@
 
 %!error <... getgid> getgid (1)
 
-%!assert (getenv ("HOME"), tilde_expand ("~"))
+%!assert (get_home_directory (), tilde_expand ("~"))
 
 %!error <Invalid call to getenv> getenv ()
 %!error <Invalid call to getenv> getenv ("foo", 1)