[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: MSVC compiler support [patch 27]: OCTAVE_HOME
From: |
John W. Eaton |
Subject: |
Re: MSVC compiler support [patch 27]: OCTAVE_HOME |
Date: |
Tue, 24 Oct 2006 22:06:32 -0400 |
On 18-Oct-2006, Michael Goffioul wrote:
| David Bateman a écrit :
| > Michael Goffioul wrote:
| >
| >> Defines OCTAVE_HOME automatically, allowing the full installed package
| >> to be
| >> relocated in another directory
| >>
| >
| > This should be in src/sysdep.cc shouldn't it as its purely system
| > dependent..
| >
|
| Here's a new patch that put the code into sysdep.cc
|
| Michael.
| Index: src/sysdep.cc
| ===================================================================
| RCS file: /cvs/octave/src/sysdep.cc,v
| retrieving revision 1.119
| diff -c -r1.119 sysdep.cc
| *** src/sysdep.cc 19 May 2006 05:32:18 -0000 1.119
| --- src/sysdep.cc 18 Oct 2006 12:03:15 -0000
| ***************
| *** 139,144 ****
| --- 139,160 ----
| }
| #endif
|
| + #if defined(_MSC_VER)
| + static void
| + MSVC_init (void)
| + {
| + // Initialize OCTAVE_HOME
| + char buffer[1024];
| + if (GetModuleFileName(NULL, buffer, 1024) > 0)
| + {
| + std::string exec_dir = buffer;
| + int pos = exec_dir.rfind("\\bin\\");
| + if (pos != NPOS)
| + octave_env::putenv(std::string("OCTAVE_HOME"), exec_dir.substr(0,
pos));
| + }
| + }
| + #endif
| +
| #if defined (__CYGWIN__)
|
| #include <limits.h>
| ***************
| *** 236,241 ****
| --- 252,259 ----
| CYGWIN_init ();
| #elif defined (__MINGW32__)
| MINGW_init ();
| + #elif defined (_MSC_VER)
| + MSVC_init ();
| #elif defined (NeXT)
| NeXT_init ();
| #elif defined (__EMX__)
How about this version instead? It should avoid the arbitrary limit.
I'm assuming that the GetModuleFileName will eventually succeed if the
buffer is large enough. Is there any other reason that it could fail?
Also, I'm assuming that this code can be used with MinGW, not just
MSVC.
jwe
src/ChangeLog:
2006-10-24 John W. Eaton <address@hidden>
* sysdep.cc (MSC_init): New function.
(sysdep_init): Call it.
(w32_set_octave_home): New function, based on code from Michael
Goffioul <address@hidden>.
(MINGW_init): Call w32_set_octave_home here too.
Index: src/sysdep.cc
===================================================================
RCS file: /cvs/octave/src/sysdep.cc,v
retrieving revision 1.119
diff -u -u -r1.119 sysdep.cc
--- src/sysdep.cc 19 May 2006 05:32:18 -0000 1.119
+++ src/sysdep.cc 25 Oct 2006 02:05:12 -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__)
- MSVC compiler support [patch 25]: INFINITE, (continued)
- MSVC compiler support [patch 26]: MinGW code share, Michael Goffioul, 2006/10/17
- MSVC compiler support [patch 26]: MinGW code share, John W. Eaton, 2006/10/25
- MSVC compiler support [patch 27]: OCTAVE_HOME, Michael Goffioul, 2006/10/17
- Re: MSVC compiler support [patch 27]: OCTAVE_HOME, David Bateman, 2006/10/17
- Re: MSVC compiler support [patch 27]: OCTAVE_HOME, Michael Goffioul, 2006/10/17
- Re: MSVC compiler support [patch 27]: OCTAVE_HOME, Michael Goffioul, 2006/10/18
- Re: MSVC compiler support [patch 27]: OCTAVE_HOME,
John W. Eaton <=
- MSVC compiler support [patch 28]: setvbuf crash, Michael Goffioul, 2006/10/17
- MSVC compiler support [patch 28]: setvbuf crash, John W. Eaton, 2006/10/25
- MSVC compiler support [patch 29]: Backslash in path, Michael Goffioul, 2006/10/17
- MSVC compiler support [patch 29]: Backslash in path, John W. Eaton, 2006/10/27
- MSVC compiler support [patch 30]: Help MSVC with templates, Michael Goffioul, 2006/10/17
- MSVC compiler support [patch 30]: Help MSVC with templates, John W. Eaton, 2006/10/26
- MSVC compiler support [patch 31]: CHAR_BIT, Michael Goffioul, 2006/10/17
- MSVC compiler support [patch 31]: CHAR_BIT, John W. Eaton, 2006/10/17
- MSVC compiler support [patch 32]: ls, Michael Goffioul, 2006/10/17
- MSVC compiler support [patch 32]: ls, John W. Eaton, 2006/10/27