diff src/sysdep.cc @ 6080:40ab35ab651c

[project @ 2006-10-25 03:26:36 by jwe]
author jwe
date Wed, 25 Oct 2006 03:26:36 +0000
parents 080c08b192d8
children 4278b170b9f9
line wrap: on
line diff
--- a/src/sysdep.cc	Wed Oct 25 01:40:26 2006 +0000
+++ b/src/sysdep.cc	Wed Oct 25 03:26:36 2006 +0000
@@ -106,6 +106,40 @@
 }
 #endif
 
+static void
+w32_set_octave_home (void)
+{
+#if defined (__WIN32__) && ! defined (_POSIX_VERSION)
+  int n = 1024;
+
+  std::string bin_dir (' ', n);
+
+  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 != NPOS)
+	octave_env::putenv ("OCTAVE_HOME", bin_dir.substr (0, pos));
+    }
+#endif
+}
+
 void
 w32_set_quiet_shutdown (void)
 {
@@ -132,6 +166,8 @@
 static void
 MINGW_init (void)
 {
+  w32_set_octave_home ();
+
   // Init mutex to protect setjmp/longjmp and get main thread context
   w32_sigint_init ();
 
@@ -139,6 +175,14 @@
 }
 #endif
 
+#if defined (_MSC_VER)
+static void
+MSVC_init (void)
+{
+  w32_set_octave_home ();
+}
+#endif
+
 #if defined (__CYGWIN__)
 
 #include <limits.h>
@@ -236,6 +280,8 @@
   CYGWIN_init ();
 #elif defined (__MINGW32__)
   MINGW_init ();
+#elif defined (_MSC_VER)
+  MSVC_init ();
 #elif defined (NeXT)
   NeXT_init ();
 #elif defined (__EMX__)