changeset 18362:7f87b13b3b3d

maint: Periodic merge of gui-release to default.
author John W. Eaton <jwe@octave.org>
date Fri, 24 Jan 2014 03:48:06 -0500
parents 9ca314e79956 (current diff) 87d96a7d50e0 (diff)
children f9bc7b7125e3
files src/Makefile.am
diffstat 8 files changed, 271 insertions(+), 381 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/external.txi	Thu Jan 23 21:24:43 2014 -0500
+++ b/doc/interpreter/external.txi	Fri Jan 24 03:48:06 2014 -0500
@@ -461,7 +461,7 @@
 @example
 @group
 octave_value_list retval;
-charNDArray c;
+charNDArray ch;
 @dots{}
 // Create single quoted string
 retval(1) = octave_value (ch);        // default constructor is sq_string
@@ -675,7 +675,8 @@
 
 @example
 @group
-int nz = 4, nr = 3, nc = 4;
+int nz, nr, nc;
+nz = 4, nr = 3, nc = 4;
 
 ColumnVector ridx (nz);
 ColumnVector cidx (nz);
@@ -711,7 +712,8 @@
 
 @example
 @group
-int nz = 4, nr = 3, nc = 4;
+int nz, nr, nc;
+nz = 4, nr = 3, nc = 4;
 SparseMatrix sm (nr, nc, nz);
 sm(0,0) = 1; sm(0,1) = 2; sm(1,3) = 3; sm(2,3) = 4;
 @end group
@@ -730,7 +732,8 @@
 
 @example
 @group
-int nz = 4, nr = 3, nc = 4;
+int nr, nc;
+nr = 3, nc = 4;
 SparseMatrix sm (nr, nc, 0);
 sm(0,0) = 1; sm(0,1) = 2; sm(1,3) = 3; sm(2,3) = 4;
 @end group
@@ -759,7 +762,8 @@
 
 @example
 @group
-int nz = 6, nr = 3, nc = 4;
+int nz, nr, nc;
+nz = 6, nr = 3, nc = 4;
 
 SparseMatrix sm1 (nr, nc, nz);
 sm1(0,0) = 1; sm1(0,1) = 2; sm1(1,3) = 3; sm1(2,3) = 4;
@@ -782,7 +786,8 @@
 @example
 octave_value arg;
 @dots{}
-int nz = 6, nr = 3, nc = 4;   // Assume we know the max # nz
+int nz, nr, nc;
+nz = 6, nr = 3, nc = 4;   // Assume we know the max # nz
 SparseMatrix sm (nr, nc, nz);
 Matrix m = arg.matrix_value ();
 
@@ -816,7 +821,8 @@
 @example
 octave_value arg;
 @dots{}
-int nz = 6, nr = 3, nc = 4;   // Assume we know the max # nz
+int nz, nr, nc;
+nz = 6, nr = 3, nc = 4;   // Assume we know the max # nz
 SparseMatrix sm (nr, nc, nz);
 Matrix m = arg.matrix_value ();
 
@@ -1113,9 +1119,9 @@
 @group
 paramdemo ([1, 2, NaN, Inf])
 @result{} Properties of input array:
-      includes Inf or NaN values
-      includes other values than 1 and 0
-      includes only int, Inf or NaN values
+     includes Inf or NaN values
+     includes other values than 1 and 0
+     includes only int, Inf or NaN values
 @end group
 @end example
 
@@ -1492,8 +1498,8 @@
 @example
 @group
 mystring (["First String"; "Second String"])
-@result{} s1 = Second String
-        First String
+@result{} Second String
+   First String
 @end group
 @end example
 
@@ -1603,32 +1609,22 @@
 @example
 a(1).f1 = "f11"; a(1).f2 = "f12"; 
 a(2).f1 = "f21"; a(2).f2 = "f22";
-b = mystruct (a)
-@result{} field f1(0) = f11
+b = mystruct (a);
+@result{}  field f1(0) = f11
     field f1(1) = f21
     field f2(0) = f12
     field f2(1) = f22
-    b =
-    @{
-      this =
+b
+@result{} 2x2 struct array containing the fields:
 
-      (,
-        [1] = this1
-        [2] = this2
-        [3] = this3
-        [4] = this4
-      ,)
+     this
+     that
 
-      that =
+b(3)
+@result{} scalar structure containing the fields:
 
-      (,
-        [1] = that1
-        [2] = that2
-        [3] = that3
-        [4] = that4
-      ,)
-
-    @}
+     this = this3
+     that = that3
 @end example
 
 @node Sparse Matrices with Mex-Files
@@ -1688,6 +1684,18 @@
 @EXAMPLEFILE(mysparse.c)
 @end example
 
+A sample usage of @code{mysparse} is
+
+@example
+@group
+sm = sparse ([1, 0; 0, pi]);
+mysparse (sm)
+@result{}
+Matrix is 2-by-2 real sparse matrix with 2 elements
+last non-zero element (2, 2) = 3.14159
+@end group
+@end example
+
 @node Calling Other Functions in Mex-Files
 @subsection Calling Other Functions in Mex-Files
 
--- a/examples/standalonebuiltin.cc	Thu Jan 23 21:24:43 2014 -0500
+++ b/examples/standalonebuiltin.cc	Fri Jan 24 03:48:06 2014 -0500
@@ -5,7 +5,6 @@
 int
 main (void)
 {
-
   int n = 2;
   Matrix a_matrix = Matrix (n, n);
 
@@ -13,10 +12,8 @@
     for (octave_idx_type j = 0; j < n; j++)
       a_matrix(i,j) = (i + 1) * 10 + (j + 1);
 
-  std::cout << "This is a matrix:" 
-            << std::endl 
-            << a_matrix
-            << std::endl;
+  std::cout << "This is a matrix:" << std::endl 
+            << a_matrix            << std::endl;
 
   octave_value_list in;
   in(0) = a_matrix;
@@ -24,10 +21,8 @@
   octave_value_list out = Fnorm (in, 1);
   double norm_of_the_matrix = out(0).double_value ();
 
-  std::cout << "This is the norm of the matrix:" 
-            << std::endl 
-            << norm_of_the_matrix
-            << std::endl;
+  std::cout << "This is the norm of the matrix:" << std::endl 
+            << norm_of_the_matrix                << std::endl;
   
   return 0;
 }
--- a/scripts/miscellaneous/mkoctfile.m	Thu Jan 23 21:24:43 2014 -0500
+++ b/scripts/miscellaneous/mkoctfile.m	Fri Jan 24 03:48:06 2014 -0500
@@ -18,7 +18,7 @@
 
 ## -*- texinfo -*-
 ## @deftypefn  {Command} {} mkoctfile [-options] file @dots{}
-## @deftypefnx {Function File} {[@var{output}, @var{status} =} mkoctfile (@dots{})
+## @deftypefnx {Function File} {[@var{output}, @var{status}] =} mkoctfile (@dots{})
 ##
 ## The @code{mkoctfile} function compiles source code written in C,
 ## C++, or Fortran.  Depending on the options used with @code{mkoctfile}, the
@@ -78,30 +78,33 @@
 ## Print the configuration variable VAR@.  Recognized variables are:
 ##
 ## @example
-##    ALL_CFLAGS                FFTW3F_LIBS
-##    ALL_CXXFLAGS              FLIBS
-##    ALL_FFLAGS                FPICFLAG
-##    ALL_LDFLAGS               INCFLAGS
-##    BLAS_LIBS                 LAPACK_LIBS
-##    CC                        LDFLAGS
-##    CFLAGS                    LD_CXX
-##    CPICFLAG                  LD_STATIC_FLAG
-##    CPPFLAGS                  LFLAGS
-##    CXX                       LIBOCTAVE
-##    CXXFLAGS                  LIBOCTINTERP
-##    CXXPICFLAG                LIBS
-##    DEPEND_EXTRA_SED_PATTERN  OCTAVE_LIBS
-##    DEPEND_FLAGS              OCTAVE_LINK_DEPS
-##    DL_LD                     OCT_LINK_DEPS
-##    DL_LDFLAGS                RDYNAMIC_FLAG
-##    EXEEXT                    READLINE_LIBS
-##    F77                       SED
-##    F77_INTEGER_8_FLAG        XTRA_CFLAGS
-##    FFLAGS                    XTRA_CXXFLAGS
-##    FFTW3_LDFLAGS
-##    FFTW3_LIBS
-##    FFTW3F_LDFLAGS
-##
+##    ALL_CFLAGS                  INCFLAGS
+##    ALL_CXXFLAGS                INCLUDEDIR
+##    ALL_FFLAGS                  LAPACK_LIBS
+##    ALL_LDFLAGS                 LD_CXX
+##    AR                          LDFLAGS
+##    BLAS_LIBS                   LD_STATIC_FLAG
+##    CC                          LFLAGS
+##    CFLAGS                      LIBDIR
+##    CPICFLAG                    LIBOCTAVE
+##    CPPFLAGS                    LIBOCTINTERP
+##    CXX                         LIBS
+##    CXXFLAGS                    OCTAVE_HOME
+##    CXXPICFLAG                  OCTAVE_LIBS
+##    DEPEND_EXTRA_SED_PATTERN    OCTAVE_LINK_DEPS
+##    DEPEND_FLAGS                OCTAVE_LINK_OPTS
+##    DL_LD                       OCTAVE_PREFIX
+##    DL_LDFLAGS                  OCTINCLUDEDIR
+##    F77                         OCTLIBDIR
+##    F77_INTEGER8_FLAG           OCT_LINK_DEPS
+##    FFLAGS                      OCT_LINK_OPTS
+##    FFTW3F_LDFLAGS              RANLIB
+##    FFTW3F_LIBS                 RDYNAMIC_FLAG
+##    FFTW3_LDFLAGS               READLINE_LIBS
+##    FFTW3_LIBS                  SED
+##    FFTW_LIBS                   SPECIAL_MATH_LIB
+##    FLIBS                       XTRA_CFLAGS
+##    FPICFLAG                    XTRA_CXXFLAGS
 ## @end example
 ##
 ## @item --link-stand-alone
--- a/src/Makefile.am	Thu Jan 23 21:24:43 2014 -0500
+++ b/src/Makefile.am	Fri Jan 24 03:48:06 2014 -0500
@@ -51,6 +51,9 @@
   octave-cli \
   octave-config
 
+noinst_HEADERS = \
+  shared-fcns.h
+
 OCTAVE_VERSION_LINKS = octave-cli-$(version)$(EXEEXT)
 
 if AMCOND_BUILD_GUI
--- a/src/main.in.cc	Thu Jan 23 21:24:43 2014 -0500
+++ b/src/main.in.cc	Fri Jan 24 03:48:06 2014 -0500
@@ -58,65 +58,7 @@
 #define OCTAVE_PREFIX %OCTAVE_PREFIX%
 #endif
 
-#if defined (__WIN32__) && ! defined (_POSIX_VERSION)
-
-#define WIN32_LEAN_AND_MEAN
-#include <tlhelp32.h>
-
-static std::string
-w32_get_octave_home (void)
-{
-  std::string retval;
-
-  std::string bin_dir;
-
-  HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE
-#ifdef TH32CS_SNAPMODULE32
-                                       | TH32CS_SNAPMODULE32
-#endif
-                                       , 0);
-
-  if (h != INVALID_HANDLE_VALUE)
-    {
-      MODULEENTRY32 mod_info;
-
-      ZeroMemory (&mod_info, sizeof (mod_info));
-      mod_info.dwSize = sizeof (mod_info);
-
-      if (Module32First (h, &mod_info))
-        {
-          do
-            {
-              std::string mod_name (mod_info.szModule);
-
-              if (mod_name.find ("octave") != std::string::npos)
-                {
-                  bin_dir = mod_info.szExePath;
-
-                  if (bin_dir[bin_dir.length () - 1] != '\\')
-                    bin_dir.append (1, '\\');
-
-                  break;
-                }
-            }
-          while (Module32Next (h, &mod_info));
-        }
-
-      CloseHandle (h);
-    }
-
-  if (! bin_dir.empty ())
-    {
-      size_t pos = bin_dir.rfind ("\\bin\\");
-
-      if (pos != std::string::npos)
-        retval = bin_dir.substr (0, pos);
-    }
-
-  return retval;
-}
-
-#endif
+#include "shared-fcns.h"
 
 #include <cstdlib>
 
@@ -374,62 +316,6 @@
 
 #endif
 
-// Find the directory where the octave binary is supposed to be
-// installed.
-
-#if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
-     && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
-static const char dir_sep_char = '\\';
-#else
-static const char dir_sep_char = '/';
-#endif
-
-static std::string
-octave_getenv (const std::string& name)
-{
-  char *value = ::getenv (name.c_str ());
-
-  return value ? value : "";
-}
-
-static std::string
-get_octave_home (void)
-{
-  std::string oh = octave_getenv ("OCTAVE_HOME");
-
-#if defined (__WIN32__) && ! defined (_POSIX_VERSION)
-  if (oh.empty ())
-    oh = w32_get_octave_home ();
-#endif
-
-  return oh.empty () ? std::string (OCTAVE_PREFIX) : oh;
-}
-
-static std::string
-subst_octave_home (const std::string& s)
-{
-  std::string retval;
-
-  std::string octave_home = get_octave_home ();
-
-  std::string prefix = OCTAVE_PREFIX;
-
-  retval = s;
-
-  if (octave_home != prefix)
-    {
-      octave_idx_type len = prefix.length ();
-
-      if (s.substr (0, len) == prefix)
-        retval.replace (0, len, octave_home);
-    }
-
-  if (dir_sep_char != '/')
-    std::replace (retval.begin (), retval.end (), '/', dir_sep_char);
-
-  return retval;
-}
-
 static std::string
 get_octave_bindir (void)
 {
--- a/src/mkoctfile.in.cc	Thu Jan 23 21:24:43 2014 -0500
+++ b/src/mkoctfile.in.cc	Fri Jan 24 03:48:06 2014 -0500
@@ -1,3 +1,4 @@
+// %NO_EDIT_WARNING%
 /*
 
 Copyright (C) 2008-2013 Michael Goffioul
@@ -36,40 +37,19 @@
 
 #include <unistd.h>
 
-#if defined (__WIN32__) && ! defined (_POSIX_VERSION)
-#include <windows.h>
-#ifdef _MSC_VER
-#define popen _popen
-#define pclose _pclose
-#endif
-#endif
-
 using namespace std;
 
-static bool initialized = false;
 static map<string,string> vars;
 
-static string OCTAVE_VERSION = %OCTAVE_CONF_VERSION%;
-
-static string
-substitute_prefix (const string& s, const string& prefix,
-                   const string& new_prefix)
-{
-  string retval = s;
-
-  if (!prefix.empty () && new_prefix != prefix)
-    {
-      int len = prefix.length ();
-      if (retval.find (prefix) == 0)
-        retval.replace (0, len, new_prefix);
-    }
-
-#if defined (__WIN32__) && ! defined (_POSIX_VERSION)
-  replace (retval.begin (), retval.end (), '/', '\\');
+#ifndef OCTAVE_VERSION
+#define OCTAVE_VERSION %OCTAVE_CONF_VERSION%
 #endif
 
-  return retval;
-}
+#ifndef OCTAVE_PREFIX
+#define OCTAVE_PREFIX %OCTAVE_CONF_PREFIX%
+#endif
+
+#include "shared-fcns.h"
 
 static string
 get_line (FILE *fp)
@@ -116,70 +96,20 @@
 static void
 initialize (void)
 {
-  if (initialized)
-    return;
-
-  initialized = true;
-
-  vars["OCTAVE_HOME"] = get_variable ("OCTAVE_HOME", "");
-
-#if defined (__WIN32__) && ! defined (_POSIX_VERSION)
-  int n = 1024;
-
-  string bin_dir (n, '\0');
-
-  while (true)
-    {
-      int status = GetModuleFileName (0, &bin_dir[0], n);
-
-      if (status < n)
-        {
-          bin_dir.resize (status);
-          break;
-        }
-      else
-        {
-          n *= 2;
-          bin_dir.resize (n);
-        }
-    }
-
-  if (! bin_dir.empty ())
-    {
-      size_t pos = bin_dir.rfind ("\\bin\\");
-
-      if (pos != string::npos)
-        vars["OCTAVE_HOME"] = bin_dir.substr (0, pos);
-    }
-#endif
+  vars["OCTAVE_HOME"] = get_octave_home ();
+  vars["OCTAVE_PREFIX"] = OCTAVE_PREFIX;
 
   vars["SED"] = get_variable ("SED", %OCTAVE_CONF_SED%);
 
-  vars["OCTAVE_PREFIX"] = %OCTAVE_CONF_PREFIX%;
-
   string DEFAULT_OCTINCLUDEDIR = %OCTAVE_CONF_OCTINCLUDEDIR%;
   string DEFAULT_INCLUDEDIR = %OCTAVE_CONF_INCLUDEDIR%;
   string DEFAULT_LIBDIR = %OCTAVE_CONF_LIBDIR%;
   string DEFAULT_OCTLIBDIR = %OCTAVE_CONF_OCTLIBDIR%;
 
-  if (! vars["OCTAVE_HOME"].empty ())
-    {
-      DEFAULT_OCTINCLUDEDIR
-        = substitute_prefix (DEFAULT_OCTINCLUDEDIR, vars["OCTAVE_PREFIX"],
-                             vars["OCTAVE_HOME"]);
-
-      DEFAULT_INCLUDEDIR
-        = substitute_prefix (DEFAULT_INCLUDEDIR, vars["OCTAVE_PREFIX"],
-                             vars["OCTAVE_HOME"]);
-
-      DEFAULT_LIBDIR
-        = substitute_prefix (DEFAULT_LIBDIR, vars["OCTAVE_PREFIX"],
-                             vars["OCTAVE_HOME"]);
-
-      DEFAULT_OCTLIBDIR
-        = substitute_prefix (DEFAULT_OCTLIBDIR, vars["OCTAVE_PREFIX"],
-                             vars["OCTAVE_HOME"]);
-    }
+  DEFAULT_OCTINCLUDEDIR = subst_octave_home (DEFAULT_OCTINCLUDEDIR);
+  DEFAULT_INCLUDEDIR = subst_octave_home (DEFAULT_INCLUDEDIR);
+  DEFAULT_LIBDIR = subst_octave_home (DEFAULT_LIBDIR);
+  DEFAULT_OCTLIBDIR = subst_octave_home (DEFAULT_OCTLIBDIR);
 
   vars["OCTINCLUDEDIR"] = get_variable ("OCTINCLUDEDIR", DEFAULT_OCTINCLUDEDIR);
   vars["INCLUDEDIR"] = get_variable ("INCLUDEDIR", DEFAULT_INCLUDEDIR);
@@ -279,7 +209,7 @@
 }
 
 static string usage_msg = "usage: mkoctfile [options] file ...";
-static string version_msg = "mkoctfile, version " + OCTAVE_VERSION;
+static string version_msg = "mkoctfile, version " OCTAVE_VERSION;
 static bool debug = false;
 static string help_msg =
 "\n"
@@ -422,8 +352,7 @@
 bool
 is_true (const std::string& s)
 {
-  return (s == "yes"
-          || s == "true");
+  return (s == "yes" || s == "true");
 }
 
 int
@@ -449,7 +378,6 @@
   bool link_stand_alone = false;
   string output_ext = ".oct";
   bool depend = false;
-  bool compile = true;
 
   if (argc == 1)
     {
@@ -545,7 +473,6 @@
       else if (arg == "-M" || arg == "-depend" || arg == "--depend")
         {
           depend = true;
-          compile = false;
         }
       else if (arg == "-o" || arg == "-output" || arg == "--output")
         {
--- a/src/octave-config.in.cc	Thu Jan 23 21:24:43 2014 -0500
+++ b/src/octave-config.in.cc	Fri Jan 24 03:48:06 2014 -0500
@@ -1,3 +1,4 @@
+// %NO_EDIT_WARNING%
 /*
 
 Copyright (C) 2008-2013 Michael Goffioul
@@ -30,14 +31,16 @@
 #include <algorithm>
 #include <cstdlib>
 
-#if defined (__WIN32__) && ! defined (_POSIX_VERSION)
-#include <windows.h>
+#ifndef OCTAVE_PREFIX
+#define OCTAVE_PREFIX %OCTAVE_PREFIX%
 #endif
 
-static bool initialized = false;
+#include "shared-fcns.h"
+
 static std::map<std::string,std::string> vars;
-static std::string OCTAVE_HOME, PREFIX;
+
 static std::string usage_msg = "usage: octave-config [options]";
+
 static std::string help_msg =
 "\n"
 "Options:\n"
@@ -74,122 +77,46 @@
 "  -v, --version         Print the Octave version number.\n"
 "\n";
 
-static std::string
-substitute_prefix (const std::string& s, const std::string& prefix,
-                   const std::string new_prefix)
-{
-  std::string retval = s;
-
-  if (!prefix.empty () && new_prefix != prefix)
-    {
-      int len = prefix.length ();
-      if (retval.find (prefix) == 0)
-        retval.replace (0, len, new_prefix);
-    }
-
-#if defined (__WIN32__) && ! defined (_POSIX_VERSION)
-  std::replace (retval.begin (), retval.end (), '/', '\\');
-#endif
-
-  return retval;
-}
-
 static void
 initialize (void)
 {
-  if (initialized)
-    return;
-
-  initialized = true;
-
-  const char *homestr = getenv ("OCTAVE_HOME");
-  OCTAVE_HOME = (homestr ? homestr : "");
-  PREFIX = %OCTAVE_PREFIX%;
-
-#if defined (__WIN32__) && ! defined (_POSIX_VERSION)
-  int n = 1024;
-
-  std::string bin_dir (n, '\0');
-
-  while (true)
-    {
-      int status = GetModuleFileName (0, &bin_dir[0], n);
-
-      if (status < n)
-        {
-          bin_dir.resize (status);
-          break;
-        }
-      else
-        {
-          n *= 2;
-          bin_dir.resize (n);
-        }
-    }
-
-  if (! bin_dir.empty ())
-    {
-      size_t pos = bin_dir.rfind ("\\bin\\");
-
-      if (pos != std::string::npos)
-        OCTAVE_HOME = bin_dir.substr (0, pos);
-    }
-#endif
+  vars["OCTAVE_HOME"] = get_octave_home ();
+  vars["PREFIX"] = OCTAVE_PREFIX;
 
   vars["API_VERSION"] = %OCTAVE_API_VERSION%;
   vars["CANONICAL_HOST_TYPE"] = %OCTAVE_CANONICAL_HOST_TYPE%;
   vars["DEFAULT_PAGER"] = %OCTAVE_DEFAULT_PAGER%;
-  vars["ARCHLIBDIR"] = substitute_prefix (%OCTAVE_ARCHLIBDIR%,
-                                          PREFIX, OCTAVE_HOME);
-  vars["BINDIR"] = substitute_prefix (%OCTAVE_BINDIR%, PREFIX, OCTAVE_HOME);
-  vars["DATADIR"] = substitute_prefix (%OCTAVE_DATADIR%, PREFIX, OCTAVE_HOME);
-  vars["DATAROOTDIR"] = substitute_prefix (%OCTAVE_DATAROOTDIR%,
-                                           PREFIX, OCTAVE_HOME);
-  vars["EXEC_PREFIX"] = substitute_prefix (%OCTAVE_EXEC_PREFIX%,
-                                           PREFIX, OCTAVE_HOME);
-  vars["FCNFILEDIR"] = substitute_prefix (%OCTAVE_FCNFILEDIR%,
-                                          PREFIX, OCTAVE_HOME);
-  vars["IMAGEDIR"] = substitute_prefix (%OCTAVE_IMAGEDIR%, PREFIX, OCTAVE_HOME);
-  vars["INCLUDEDIR"] = substitute_prefix (%OCTAVE_INCLUDEDIR%,
-                                          PREFIX, OCTAVE_HOME);
-  vars["INFODIR"] = substitute_prefix (%OCTAVE_INFODIR%, PREFIX, OCTAVE_HOME);
-  vars["INFOFILE"] = substitute_prefix (%OCTAVE_INFOFILE%, PREFIX, OCTAVE_HOME);
-  vars["LIBDIR"] = substitute_prefix (%OCTAVE_LIBDIR%, PREFIX, OCTAVE_HOME);
-  vars["LIBEXECDIR"] = substitute_prefix (%OCTAVE_LIBEXECDIR%,
-                                          PREFIX, OCTAVE_HOME);
-  vars["LOCALAPIARCHLIBDIR"] = substitute_prefix (%OCTAVE_LOCALAPIARCHLIBDIR%,
-                                                  PREFIX, OCTAVE_HOME);
-  vars["LOCALAPIFCNFILEDIR"] = substitute_prefix (%OCTAVE_LOCALAPIFCNFILEDIR%,
-                                                  PREFIX, OCTAVE_HOME);
-  vars["LOCALAPIOCTFILEDIR"] = substitute_prefix (%OCTAVE_LOCALAPIOCTFILEDIR%,
-                                                  PREFIX, OCTAVE_HOME);
-  vars["LOCALARCHLIBDIR"] = substitute_prefix (%OCTAVE_LOCALARCHLIBDIR%,
-                                               PREFIX, OCTAVE_HOME);
-  vars["LOCALFCNFILEDIR"] = substitute_prefix (%OCTAVE_LOCALFCNFILEDIR%,
-                                               PREFIX, OCTAVE_HOME);
-  vars["LOCALOCTFILEDIR"] = substitute_prefix (%OCTAVE_LOCALOCTFILEDIR%,
-                                               PREFIX, OCTAVE_HOME);
-  vars["LOCALSTARTUPFILEDIR"] = substitute_prefix (%OCTAVE_LOCALSTARTUPFILEDIR%,
-                                                   PREFIX, OCTAVE_HOME);
-  vars["LOCALVERARCHLIBDIR"] = substitute_prefix (%OCTAVE_LOCALVERARCHLIBDIR%,
-                                                  PREFIX, OCTAVE_HOME);
-  vars["LOCALVERFCNFILEDIR"] = substitute_prefix (%OCTAVE_LOCALVERFCNFILEDIR%,
-                                                  PREFIX, OCTAVE_HOME);
-  vars["LOCALVEROCTFILEDIR"] = substitute_prefix (%OCTAVE_LOCALVEROCTFILEDIR%,
-                                                  PREFIX, OCTAVE_HOME);
-  vars["MAN1DIR"] = substitute_prefix (%OCTAVE_MAN1DIR%, PREFIX, OCTAVE_HOME);
   vars["MAN1EXT"] = %OCTAVE_MAN1EXT%;
-  vars["MANDIR"] = substitute_prefix (%OCTAVE_MANDIR%, PREFIX, OCTAVE_HOME);
-  vars["OCTFILEDIR"] = substitute_prefix (%OCTAVE_OCTFILEDIR%,
-                                          PREFIX, OCTAVE_HOME);
-  vars["OCTINCLUDEDIR"] = substitute_prefix (%OCTAVE_OCTINCLUDEDIR%,
-                                             PREFIX, OCTAVE_HOME);
-  vars["OCTLIBDIR"] = substitute_prefix (%OCTAVE_OCTLIBDIR%,
-                                         PREFIX, OCTAVE_HOME);
-  vars["PREFIX"] = (OCTAVE_HOME.empty () ? PREFIX : OCTAVE_HOME);
-  vars["STARTUPFILEDIR"] = substitute_prefix (%OCTAVE_STARTUPFILEDIR%,
-                                              PREFIX, OCTAVE_HOME);
   vars["VERSION"] = %OCTAVE_VERSION%;
+
+  vars["ARCHLIBDIR"] = subst_octave_home (%OCTAVE_ARCHLIBDIR%);
+  vars["BINDIR"] = subst_octave_home (%OCTAVE_BINDIR%);
+  vars["DATADIR"] = subst_octave_home (%OCTAVE_DATADIR%);
+  vars["DATAROOTDIR"] = subst_octave_home (%OCTAVE_DATAROOTDIR%);
+  vars["EXEC_PREFIX"] = subst_octave_home (%OCTAVE_EXEC_PREFIX%);
+  vars["FCNFILEDIR"] = subst_octave_home (%OCTAVE_FCNFILEDIR%);
+  vars["IMAGEDIR"] = subst_octave_home (%OCTAVE_IMAGEDIR%);
+  vars["INCLUDEDIR"] = subst_octave_home (%OCTAVE_INCLUDEDIR%);
+  vars["INFODIR"] = subst_octave_home (%OCTAVE_INFODIR%);
+  vars["INFOFILE"] = subst_octave_home (%OCTAVE_INFOFILE%);
+  vars["LIBDIR"] = subst_octave_home (%OCTAVE_LIBDIR%);
+  vars["LIBEXECDIR"] = subst_octave_home (%OCTAVE_LIBEXECDIR%);
+  vars["LOCALAPIARCHLIBDIR"] = subst_octave_home (%OCTAVE_LOCALAPIARCHLIBDIR%);
+  vars["LOCALAPIFCNFILEDIR"] = subst_octave_home (%OCTAVE_LOCALAPIFCNFILEDIR%);
+  vars["LOCALAPIOCTFILEDIR"] = subst_octave_home (%OCTAVE_LOCALAPIOCTFILEDIR%);
+  vars["LOCALARCHLIBDIR"] = subst_octave_home (%OCTAVE_LOCALARCHLIBDIR%);
+  vars["LOCALFCNFILEDIR"] = subst_octave_home (%OCTAVE_LOCALFCNFILEDIR%);
+  vars["LOCALOCTFILEDIR"] = subst_octave_home (%OCTAVE_LOCALOCTFILEDIR%);
+  vars["LOCALSTARTUPFILEDIR"] = subst_octave_home (%OCTAVE_LOCALSTARTUPFILEDIR%);
+  vars["LOCALVERARCHLIBDIR"] = subst_octave_home (%OCTAVE_LOCALVERARCHLIBDIR%);
+  vars["LOCALVERFCNFILEDIR"] = subst_octave_home (%OCTAVE_LOCALVERFCNFILEDIR%);
+  vars["LOCALVEROCTFILEDIR"] = subst_octave_home (%OCTAVE_LOCALVEROCTFILEDIR%);
+  vars["MAN1DIR"] = subst_octave_home (%OCTAVE_MAN1DIR%);
+  vars["MANDIR"] = subst_octave_home (%OCTAVE_MANDIR%);
+  vars["OCTFILEDIR"] = subst_octave_home (%OCTAVE_OCTFILEDIR%);
+  vars["OCTINCLUDEDIR"] = subst_octave_home (%OCTAVE_OCTINCLUDEDIR%);
+  vars["OCTLIBDIR"] = subst_octave_home (%OCTAVE_OCTLIBDIR%);
+  vars["STARTUPFILEDIR"] = subst_octave_home (%OCTAVE_STARTUPFILEDIR%);
 }
 
 int
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/shared-fcns.h	Fri Jan 24 03:48:06 2014 -0500
@@ -0,0 +1,141 @@
+/*
+
+Copyright (C) 2008-2013 Michael Goffioul
+
+This file is part of Octave.
+
+Octave 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 3 of the License, or (at your
+option) any later version.
+
+Octave 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 Octave; see the file COPYING.  If not, see
+<http://www.gnu.org/licenses/>.
+
+*/
+
+#if defined (__WIN32__) && ! defined (_POSIX_VERSION)
+
+#include <windows.h>
+
+#ifdef _MSC_VER
+#define popen _popen
+#define pclose _pclose
+#endif
+
+static std::string
+w32_get_octave_home (void)
+{
+  std::string retval;
+
+  std::string bin_dir;
+
+  HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE
+#ifdef TH32CS_SNAPMODULE32
+                                       | TH32CS_SNAPMODULE32
+#endif
+                                       , 0);
+
+  if (h != INVALID_HANDLE_VALUE)
+    {
+      MODULEENTRY32 mod_info;
+
+      ZeroMemory (&mod_info, sizeof (mod_info));
+      mod_info.dwSize = sizeof (mod_info);
+
+      if (Module32First (h, &mod_info))
+        {
+          do
+            {
+              std::string mod_name (mod_info.szModule);
+
+              if (mod_name.find ("octave") != std::string::npos)
+                {
+                  bin_dir = mod_info.szExePath;
+
+                  if (bin_dir[bin_dir.length () - 1] != '\\')
+                    bin_dir.append (1, '\\');
+
+                  break;
+                }
+            }
+          while (Module32Next (h, &mod_info));
+        }
+
+      CloseHandle (h);
+    }
+
+  if (! bin_dir.empty ())
+    {
+      size_t pos = bin_dir.rfind ("\\bin\\");
+
+      if (pos != std::string::npos)
+        retval = bin_dir.substr (0, pos);
+    }
+
+  return retval;
+}
+
+#endif
+
+// Find the directory where the octave binary is supposed to be
+// installed.
+
+#if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
+     && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
+static const char dir_sep_char = '\\';
+#else
+static const char dir_sep_char = '/';
+#endif
+
+static std::string
+octave_getenv (const std::string& name)
+{
+  char *value = ::getenv (name.c_str ());
+
+  return value ? value : "";
+}
+
+static std::string
+get_octave_home (void)
+{
+  std::string oh = octave_getenv ("OCTAVE_HOME");
+
+#if defined (__WIN32__) && ! defined (_POSIX_VERSION)
+  if (oh.empty ())
+    oh = w32_get_octave_home ();
+#endif
+
+  return oh.empty () ? std::string (OCTAVE_PREFIX) : oh;
+}
+
+static std::string
+subst_octave_home (const std::string& s)
+{
+  std::string retval;
+
+  std::string octave_home = get_octave_home ();
+
+  std::string prefix = OCTAVE_PREFIX;
+
+  retval = s;
+
+  if (octave_home != prefix)
+    {
+      octave_idx_type len = prefix.length ();
+
+      if (s.substr (0, len) == prefix)
+        retval.replace (0, len, octave_home);
+    }
+
+  if (dir_sep_char != '/')
+    std::replace (retval.begin (), retval.end (), '/', dir_sep_char);
+
+  return retval;
+}