annotate installer-files/octave-launch.c @ 5957:9cd5425b033b

octave-launch-firsttime: New launcher executable for starting Octave first time. * installer-files/octave-launch.c: Conditionally change to USERPROFILE before running Octave. * binary-dist-rules.mk(octave-launch-firsttime, installer-files/octave-launch-firsttime.exe): Add build rules for new launcher executable. (copy-windows-dist-files): Copy octave-launch-firsttime.exe to $(OCTAVE_DIST_DIR).
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 20 Nov 2021 15:34:20 +0100
parents b8e9589b7794
children 49b3f6c6d255
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
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
83 /* 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
84 paths */
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
85 /* 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
86 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
87 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
88 StringCchCopyW (rootpath, PATH_SZ, path);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
90 SetEnvironmentVariableW (L"MXE_ROOT", rootpath);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 /* get msys path and set env */
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 StringCchCopyW (msyspath, PATH_SZ, rootpath);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
96 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
97 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
98 if (PathFileExistsW (path))
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 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
101 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
102 SetEnvironmentVariableW (L"MSYSPATH", msyspath);
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 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
105
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
106 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
107 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
108 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 else
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
111 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
112 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
113 if (PathFileExistsW (path))
5955
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 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
116 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
117 SetEnvironmentVariableW (L"MSYSPATH", msyspath);
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 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
120
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
121 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
122 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
123 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124 else
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
126 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
127 SetEnvironmentVariableW (L"MSYSPATH", msyspath);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
129 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
130
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
131 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
132 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
133 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136 /* 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
137 StringCchCopyW (path, PATH_SZ, binpath);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 ParentDir (path);
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
140 #ifdef SHOW_PATHS
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
141 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
142 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
143 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
144 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
145 #endif
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 /* qt paths
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148 * either %OCT_HOME%\qt5\plugins
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149 * or %OCT_HOME\plugins
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150 */
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
151 nSize = lstrlenW (path);
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
152 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
153 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
154
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
155 path[nSize] = L'\0';
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157 /* exe paths */
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 #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
160 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
161 wchar_t newpathbuffer[PATHBUF_SZ];
5955
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 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
164 pathbuffer[nSize] = '\0';
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
165
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166 /* 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
167 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
168 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
169 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
170 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
171 StringCchCatW (newpathbuffer, PATHBUF_SZ, pathbuffer);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
173 SetEnvironmentVariableW (L"PATH", newpathbuffer);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
174 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
176 /* other env */
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"TERM", L"cygwin");
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
178 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
179 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
180
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181 /* home set */
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
182 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
183 if (nSize == 0 || path[0] == 0)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
185 wchar_t newhome[PATH_SZ];
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
187 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
188 if (nSize == 0 || path[0] == 0)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190 /* 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
191 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
192 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
193 if (nSize)
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
194 StringCchCopyW (path, PATH_SZ, tmpbuff);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195 else
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196 path[0] = '\0';
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
197
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
198 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
199 if (nSize)
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
200 StringCchCopyW (path, PATH_SZ, tmpbuff);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
203 /* 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
204 paths */
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
205 /* 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
206 paths */
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
207 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
208
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209 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
210 StringCchCopyW (newhome, PATH_SZ, path);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
212 SetEnvironmentVariableW (L"HOME", newhome);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215 /* check for gui mode */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216 for (i = 1; i < argc; i++)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
218 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
219 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
220 if (gui_arg_found)
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 /* 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
223 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
224 override the other options. */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
226
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227 no_gui_libs = 1;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
228 }
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
229 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
230 || 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
231 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
232 if (no_gui_libs)
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 /* 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
235 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
236 override the other options. */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
237 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
238
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
239 gui_arg_found = 1;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
240 }
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
241 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
242 no_gui_arg_found = 1;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
243
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
244 /* 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
245 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
246 detect that. */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
247 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
248
5957
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
249 #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
250 {
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
251 /* 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
252 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
253 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
254 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
255 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
256
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
257 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
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 #endif
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
260
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
261 /* 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
262 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
263 STARTUPINFO si;
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
264 #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
265 wchar_t argbuffer[ARGBUF_SZ];
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
266
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
267 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
268 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
269 ZeroMemory (&pi, sizeof (pi));
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
270
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
271 StringCchCopyW (path, PATH_SZ, binpath);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
272
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
273 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
274 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
275
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
276 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
277 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
278 /* 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
279 si.dwFlags = STARTF_USESHOWWINDOW;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
280
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
281 /* 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
282 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
283 most Windows users would expect. */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
284
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
285 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
286 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
287 }
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 /* quote and append each arg */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
290 for (i = 1; i < argc; i++)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
291 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
292 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
293 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
294 StringCchCatW (argbuffer, ARGBUF_SZ, L"\" ");
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 /* 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
298 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
299 argbuffer, // Command line
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
300 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
301 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
302 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
303 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
304 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
305 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
306 &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
307 &pi); // Pointer to PROCESS_INFORMATION
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
308
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
309 if (! status)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
310 return 1;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
311 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
312
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
313 /* Wait until child process exits. */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
314 WaitForSingleObject (pi.hProcess, INFINITE);
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
315
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
316 /* Close process and thread handles */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
317 CloseHandle (pi.hProcess);
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
318 CloseHandle (pi.hThread);
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 return 0;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
321 }