annotate installer-files/octave-launch.c @ 5960:49b3f6c6d255

octave-launch: Don't use short path names when building default-octave. * installer-files/octave-launch.c: Conditionally don't transform to short path names. * binary-dist-rules.mk (octave-launch): De-activate transformation to short path names when building "default-octave".
author Markus Mützel <markus.muetzel@gmx.de>
date Sun, 21 Nov 2021 12:29:36 +0100
parents 9cd5425b033b
children 1569a1d140ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 * Wrapper application to set octave env variables and then run octave
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 *
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
4 * Copyright (C) 2020-2021 John Donoghue <john.donoghue@ieee.org>
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 *
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify it under
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 * the terms of the GNU General Public License as published by the Free Software
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 * Foundation; either version 3 of the License, or (at your option) any later
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 * version.
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 *
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but WITHOUT
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 * details.
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 *
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License along with
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 * this program; if not, see <http: *www.gnu.org/licenses/>.
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 #include <windows.h>
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 #include <shlwapi.h>
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
22 #include <strsafe.h>
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
24 static int ParentDir (wchar_t *dir)
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
26 int len = lstrlenW (dir);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
27 while (len > 0 && dir[len] != L'\\')
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 len --;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 dir[len] = 0;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 return len;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
33 wchar_t * FilePart (wchar_t *dir)
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
35 int len = lstrlenW (dir);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
36 while (len > 0 && dir[len-1] != L'\\')
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 len --;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 return &dir[len];
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 // Set up environment and launch octave.exe with appropriate
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 // arguments. NOTE: There are corresponding VBS and BAT script
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 // versions of this program so any changes here may need to be made in
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 // those scripts as well.
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
46 int wmain (int argc, wchar_t **argv)
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 PROCESS_INFORMATION pi;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 // FIXME: There are currently have no checks to ensure that the
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
51 // following fixed-size buffers are sufficiently large. MAX_PATH is
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
52 // 260 on Winndows by default. But a user might have increased that
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
53 // limit to 32767 characters by manually changing policy settings.
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
54 // Maybe it would be better if we used C++ and std::string objects?
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
55 // Note that the use of sizeof(path)-1 will fail if we switch to
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
56 // using
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 //
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
58 // wchar_t *path = (wchar_t *) malloc (...);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 //
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 // instead of literal character arrays.
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
62 #define PATH_SZ 1024
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
63 wchar_t msyspath[PATH_SZ];
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
64 wchar_t rootpath[PATH_SZ];
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
65 wchar_t path[PATH_SZ];
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
66 wchar_t binpath[PATH_SZ];
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 int gui_arg_found = 0;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 int no_gui_arg_found = 0;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 int no_gui_libs = 0;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 int i;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 /* get path of us which we will assume is the root of the install */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
75 DWORD nSize = GetModuleFileNameW (NULL, path, PATH_SZ-1);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 if (nSize)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
78 while (nSize > 0 && path[nSize] != L'\\')
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 nSize --;
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
80 path[nSize] = L'\0';
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82
5960
49b3f6c6d255 octave-launch: Don't use short path names when building default-octave.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5957
diff changeset
83 #ifdef NO_SHORT_PATH_NAMES
49b3f6c6d255 octave-launch: Don't use short path names when building default-octave.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5957
diff changeset
84 StringCchCopyW (rootpath, PATH_SZ, path);
49b3f6c6d255 octave-launch: Don't use short path names when building default-octave.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5957
diff changeset
85 #else
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
86 /* transform to short paths to work around issues with spaces in
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
87 paths */
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
88 /* FIXME: This won't help on systems with de-activated short paths */
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
89 nSize = GetShortPathNameW (path, rootpath, PATH_SZ-1);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 if (nSize == 0)
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
91 StringCchCopyW (rootpath, PATH_SZ, path);
5960
49b3f6c6d255 octave-launch: Don't use short path names when building default-octave.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5957
diff changeset
92 #endif
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
94 SetEnvironmentVariableW (L"MXE_ROOT", rootpath);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 /* get msys path and set env */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
98 StringCchCopyW (msyspath, PATH_SZ, rootpath);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
100 StringCchCopyW (path, PATH_SZ, rootpath);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
101 StringCchCatW (path, PATH_SZ, L"\\mingw64\\bin\\octave.exe");
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
102 if (PathFileExistsW (path))
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
104 SetEnvironmentVariableW (L"MSYSTEM", L"MINGW64");
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
105 StringCchCatW (msyspath, PATH_SZ, L"\\usr");
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
106 SetEnvironmentVariableW (L"MSYSPATH", msyspath);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
108 StringCchCatW (msyspath, PATH_SZ, L"\\bin");
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
110 StringCchCopyW (binpath, PATH_SZ, rootpath);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
111 StringCchCatW (binpath, PATH_SZ, L"\\mingw64\\bin");
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 else
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
115 StringCchCopyW (path, PATH_SZ, rootpath);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
116 StringCchCatW (path, PATH_SZ, L"\\mingw32\\bin\\octave.exe");
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
117 if (PathFileExistsW (path))
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
119 SetEnvironmentVariableW (L"MSYSTEM", L"MINGW32");
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
120 StringCchCatW (msyspath, PATH_SZ, L"\\usr");
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
121 SetEnvironmentVariableW (L"MSYSPATH", msyspath);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
123 StringCchCatW (msyspath, PATH_SZ, L"\\bin");
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
125 StringCchCopyW (binpath, PATH_SZ, rootpath);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
126 StringCchCatW (binpath, PATH_SZ, L"\\mingw32\\bin");
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 else
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
130 SetEnvironmentVariableW (L"MSYSTEM", L"MSYS");
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
131 SetEnvironmentVariableW (L"MSYSPATH", msyspath);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
133 StringCchCatW (msyspath, PATH_SZ, L"\\bin");
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
135 StringCchCopyW (binpath, PATH_SZ, rootpath);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
136 StringCchCatW (binpath, PATH_SZ, L"\\bin");
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140 /* binpath is to the octave bin dir so get the parent */
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
141 StringCchCopyW (path, PATH_SZ, binpath);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142 ParentDir (path);
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
144 #ifdef SHOW_PATHS
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
145 MessageBoxW (NULL, rootpath, L"octroot", MB_OK);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
146 MessageBoxW (NULL, path, L"octhome", MB_OK);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
147 MessageBoxW (NULL, binpath, L"octbin", MB_OK);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
148 MessageBoxW (NULL, msyspath, L"msysbin", MB_OK);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
149 #endif
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151 /* qt paths
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
152 * either %OCT_HOME%\qt5\plugins
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153 * or %OCT_HOME\plugins
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
154 */
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
155 nSize = lstrlenW (path);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
156 StringCchCatW (path, PATH_SZ, L"\\qt5\\plugins");
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
157 SetEnvironmentVariableW (L"QT_PLUGIN_PATH", path);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
159 path[nSize] = L'\0';
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161 /* exe paths */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
162 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
163 #define PATHBUF_SZ 8096
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
164 wchar_t pathbuffer[PATHBUF_SZ];
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
165 wchar_t newpathbuffer[PATHBUF_SZ];
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
167 nSize = GetEnvironmentVariableW (L"PATH", pathbuffer, PATHBUF_SZ-1);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
168 pathbuffer[nSize] = '\0';
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
169
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
170 /* set our paths first */
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
171 StringCchCopyW (newpathbuffer, PATHBUF_SZ, binpath);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
172 StringCchCatW (newpathbuffer, PATHBUF_SZ, L";");
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
173 StringCchCatW (newpathbuffer, PATHBUF_SZ, msyspath);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
174 StringCchCatW (newpathbuffer, PATHBUF_SZ, L";");
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
175 StringCchCatW (newpathbuffer, PATHBUF_SZ, pathbuffer);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
176
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
177 SetEnvironmentVariableW (L"PATH", newpathbuffer);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
179
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180 /* other env */
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
181 SetEnvironmentVariableW (L"TERM", L"cygwin");
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
182 SetEnvironmentVariableW (L"GNUTERM", L"wxt");
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
183 SetEnvironmentVariableW (L"GS", L"gs.exe");
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185 /* home set */
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
186 nSize = GetEnvironmentVariableW (L"HOME", path, PATH_SZ-1);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
187 if (nSize == 0 || path[0] == 0)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
189 wchar_t newhome[PATH_SZ];
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
191 nSize = GetEnvironmentVariableW (L"USERPROFILE", path, PATH_SZ-1);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192 if (nSize == 0 || path[0] == 0)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194 /* build dir from drive and path */
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
195 wchar_t tmpbuff[PATH_SZ];
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
196 nSize = GetEnvironmentVariableW (L"HOMEDRIVE", tmpbuff, PATH_SZ-1);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
197 if (nSize)
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
198 StringCchCopyW (path, PATH_SZ, tmpbuff);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199 else
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200 path[0] = '\0';
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
202 nSize = GetEnvironmentVariableW (L"HOMEPATH", tmpbuff, PATH_SZ-1);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
203 if (nSize)
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
204 StringCchCopyW (path, PATH_SZ, tmpbuff);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206
5960
49b3f6c6d255 octave-launch: Don't use short path names when building default-octave.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5957
diff changeset
207 #ifdef NO_SHORT_PATH_NAMES
49b3f6c6d255 octave-launch: Don't use short path names when building default-octave.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5957
diff changeset
208 StringCchCopyW (newhome, PATH_SZ, path);
49b3f6c6d255 octave-launch: Don't use short path names when building default-octave.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5957
diff changeset
209 #else
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
210 /* transform to short paths to work around issues with spaces in
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
211 paths */
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
212 /* FIXME: This won't help on systems with de-activated short
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
213 paths */
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
214 nSize = GetShortPathNameW (path, newhome, PATH_SZ-1);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216 if (nSize == 0)
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
217 StringCchCopyW (newhome, PATH_SZ, path);
5960
49b3f6c6d255 octave-launch: Don't use short path names when building default-octave.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5957
diff changeset
218 #endif
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
220 SetEnvironmentVariableW (L"HOME", newhome);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
221 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
222
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
223 /* check for gui mode */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
224 for (i = 1; i < argc; i++)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
226 if (StrCmpW (argv[i], L"--no-gui-libs") == 0)
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
228 if (gui_arg_found)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
229 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
230 /* Inconsistent options. We can't start the GUI without gui libs.
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
231 How should we fail? For now, --no-gui-libs will
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
232 override the other options. */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
233 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
234
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235 no_gui_libs = 1;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
236 }
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
237 else if (StrCmpW (argv[i], L"--gui") == 0
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
238 || StrCmpW (argv[i], L"--force-gui") == 0)
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
239 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
240 if (no_gui_libs)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
241 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
242 /* Inconsistent options. We can't start the GUI without gui libs.
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
243 How should we fail? For now, --no-gui-libs will
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
244 override the other options. */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
245 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
246
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
247 gui_arg_found = 1;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
248 }
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
249 else if (StrCmpW (argv[i], L"--no-gui") == 0)
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
250 no_gui_arg_found = 1;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
251
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
252 /* NOTE: specifying both --no-gui and --gui is also an
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
253 inconsistent set of options but we leave it to octave.exe to
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
254 detect that. */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
255 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
256
5957
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
257 #ifdef FIRST_TIME
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
258 {
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
259 /* change directory to USERPROFILE before starting Octave */
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
260 wchar_t tmpbuff[PATH_SZ];
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
261 nSize = GetEnvironmentVariableW (L"USERPROFILE", tmpbuff, PATH_SZ-1);
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
262 if (nSize)
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
263 StringCchCopyW (path, PATH_SZ, tmpbuff);
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
264
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
265 SetCurrentDirectoryW (path);
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
266 }
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
267 #endif
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
268
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
269 /* set up process args and start it */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
270 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
271 STARTUPINFO si;
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
272 #define ARGBUF_SZ 4096
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
273 wchar_t argbuffer[ARGBUF_SZ];
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
274
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
275 ZeroMemory (&si, sizeof (si));
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
276 si.cb = sizeof (si);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
277 ZeroMemory (&pi, sizeof (pi));
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
278
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
279 StringCchCopyW (path, PATH_SZ, binpath);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
280
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
281 StringCchCopyW (argbuffer, ARGBUF_SZ, L"octave.exe ");
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
282 StringCchCatW (path, PATH_SZ, L"\\octave.exe");
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
283
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
284 if (! (no_gui_libs || no_gui_arg_found))
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
285 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
286 /* Unless --no-gui or --no-gui-libs is specified, we will use a GUI window. */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
287 si.dwFlags = STARTF_USESHOWWINDOW;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
288
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
289 /* If none of the options --no-gui, --gui, or --force-gui
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
290 were specified, then we'll add --gui to start the gui as
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
291 most Windows users would expect. */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
292
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
293 if (! gui_arg_found)
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
294 StringCchCatW (argbuffer, ARGBUF_SZ, L"--gui ");
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
295 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
296
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
297 /* quote and append each arg */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
298 for (i = 1; i < argc; i++)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
299 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
300 StringCchCatW (argbuffer, ARGBUF_SZ, L"\"");
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
301 StringCchCatW (argbuffer, ARGBUF_SZ, argv[i]);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
302 StringCchCatW (argbuffer, ARGBUF_SZ, L"\" ");
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
303 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
304
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
305 /* Start the child process */
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
306 int status = CreateProcessW (path, // Module name
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
307 argbuffer, // Command line
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
308 NULL, // Process handle not inheritable
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
309 NULL, // Thread handle not inheritable
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
310 FALSE, // Set handle inheritance to FALSE
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
311 0, // No creation flags
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
312 NULL, // Use parent's environment block
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
313 NULL, // Use parent's starting directory
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
314 &si, // Pointer to STARTUPINFO
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
315 &pi); // Pointer to PROCESS_INFORMATION
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
316
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
317 if (! status)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
318 return 1;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
319 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
320
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
321 /* Wait until child process exits. */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
322 WaitForSingleObject (pi.hProcess, INFINITE);
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
323
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
324 /* Close process and thread handles */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
325 CloseHandle (pi.hProcess);
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
326 CloseHandle (pi.hThread);
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
327
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
328 return 0;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
329 }