annotate installer-files/octave-launch.c @ 7197:e03680baccc7 default tip @

maint: Merge release to default.
author Markus Mützel <markus.muetzel@gmx.de>
date Wed, 15 May 2024 13:07:42 +0200
parents c4e795606e6c
children
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 /*
6780
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
2 * Windows wrapper application to set Octave env variables and then run Octave.
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 *
6780
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
4 * Copyright (C) 2020-2023 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
5978
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
33 static 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
5978
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
41 static size_t get_num_physical_cores (void)
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
42 {
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
43 DWORD length;
5985
1b5d45d7afd4 octave-launch: Don't use undefined behavior (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5984
diff changeset
44 char *lpi;
5978
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
45 BOOL res;
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
46 size_t num_physical_cores;
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
47 size_t offset;
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
48
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
49 length = 0;
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
50 GetLogicalProcessorInformationEx (RelationProcessorCore, NULL, &length);
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
51 if (GetLastError () != ERROR_INSUFFICIENT_BUFFER)
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
52 return 0;
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
53
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
54 lpi = malloc (length);
5984
532c6ba0156f octave-launch: Fix error when counting processor cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5978
diff changeset
55 res = GetLogicalProcessorInformationEx
532c6ba0156f octave-launch: Fix error when counting processor cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5978
diff changeset
56 (RelationProcessorCore,
532c6ba0156f octave-launch: Fix error when counting processor cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5978
diff changeset
57 (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX) lpi,
532c6ba0156f octave-launch: Fix error when counting processor cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5978
diff changeset
58 &length);
5978
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
59 if (! res)
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
60 {
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
61 free (lpi);
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
62 return 0;
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
63 }
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
64
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
65 num_physical_cores = 0;
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
66 offset = 0;
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
67 do
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
68 {
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
69 const PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX cur_lpi =
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
70 (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX) (lpi + offset);
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
71 offset += cur_lpi->Size;
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
72 num_physical_cores++;
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
73 }
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
74 while (offset < length);
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
75
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
76 free (lpi);
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
77
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
78 return num_physical_cores;
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
79 }
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
80
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 // 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
82 // 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
83 // 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
84 // those scripts as well.
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
86 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
87 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 PROCESS_INFORMATION pi;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89
6780
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
90 // FIXME: There are currently no checks to ensure that the following
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
91 // fixed-size buffers are sufficiently large. MAX_PATH is 260 on
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
92 // Windows by default. But a user might have increased that limit to
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
93 // 32767 characters by manually changing policy settings. Maybe it
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
94 // would be better if we used C++ and std::string objects?
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
95 // 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
96 // using
5955
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 // 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
99 //
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 // instead of literal character arrays.
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
102 #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
103 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
104 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
105 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
106 wchar_t binpath[PATH_SZ];
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 int gui_arg_found = 0;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 int no_gui_arg_found = 0;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 int no_gui_libs = 0;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 int i;
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 /* 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
114
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
115 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
116 if (nSize)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
118 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
119 nSize --;
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
120 path[nSize] = L'\0';
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122
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
123 #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
124 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
125 #else
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
126 /* 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
127 paths */
6780
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
128 /* FIXME: This won't help on systems with de-activated short paths. */
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
129 nSize = GetShortPathNameW (path, rootpath, PATH_SZ-1);
6843
c4e795606e6c * installer-files/octave-launch.c: check if short name worked
John Donoghue <john.donoghue@ieee.org>
parents: 6837
diff changeset
130 if (nSize == 0 || PathFileExistsW(rootpath) == FALSE)
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
131 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
132 #endif
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
134 SetEnvironmentVariableW (L"MXE_ROOT", rootpath);
5955
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 /* get msys path and set env */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
138 StringCchCopyW (msyspath, PATH_SZ, rootpath);
5955
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 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
141 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
142 if (PathFileExistsW (path))
5955
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 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
145 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
146 SetEnvironmentVariableW (L"MSYSPATH", msyspath);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
148 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
149
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
150 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
151 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
152 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153 else
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 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
156 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
157 if (PathFileExistsW (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 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
160 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
161 SetEnvironmentVariableW (L"MSYSPATH", msyspath);
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 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
164
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
165 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
166 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
167 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
168 else
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
169 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
170 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
171 SetEnvironmentVariableW (L"MSYSPATH", msyspath);
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 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
174
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
175 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
176 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
177 }
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
6780
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
180 /* 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
181 StringCchCopyW (path, PATH_SZ, binpath);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182 ParentDir (path);
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
184 #ifdef SHOW_PATHS
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
185 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
186 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
187 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
188 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
189 #endif
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191 /* qt paths
6837
6adeb47401d6 Add qt6 usage to mxe-octave
John Donoghue <john.donoghue@ieee.org>
parents: 6780
diff changeset
192 * either %OCT_HOME%\qtX\plugins
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193 * or %OCT_HOME\plugins
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194 */
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
195 nSize = lstrlenW (path);
6837
6adeb47401d6 Add qt6 usage to mxe-octave
John Donoghue <john.donoghue@ieee.org>
parents: 6780
diff changeset
196 StringCchPrintfW (&path[nSize], PATH_SZ-nSize, L"\\qt%d\\plugins", QTVERSION);
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
197 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
198
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
199 path[nSize] = L'\0';
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201 /* exe paths */
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 #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
204 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
205 wchar_t newpathbuffer[PATHBUF_SZ];
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
207 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
208 pathbuffer[nSize] = '\0';
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
210 /* 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
211 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
212 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
213 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
214 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
215 StringCchCatW (newpathbuffer, PATHBUF_SZ, pathbuffer);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
217 SetEnvironmentVariableW (L"PATH", newpathbuffer);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219
6174
cf7adc238c0c * installer-files/cmdshell.bat, installer-files/octave-firsttime.vbs,
John Donoghue <john.donoghue@ieee.org>
parents: 6025
diff changeset
220 /* pkg config pc path */
cf7adc238c0c * installer-files/cmdshell.bat, installer-files/octave-firsttime.vbs,
John Donoghue <john.donoghue@ieee.org>
parents: 6025
diff changeset
221 nSize = lstrlenW (path);
cf7adc238c0c * installer-files/cmdshell.bat, installer-files/octave-firsttime.vbs,
John Donoghue <john.donoghue@ieee.org>
parents: 6025
diff changeset
222 StringCchCatW (path, PATH_SZ, L"\\lib\\pkgconfig");
cf7adc238c0c * installer-files/cmdshell.bat, installer-files/octave-firsttime.vbs,
John Donoghue <john.donoghue@ieee.org>
parents: 6025
diff changeset
223 SetEnvironmentVariableW (L"PKG_CONFIG_PATH", path);
cf7adc238c0c * installer-files/cmdshell.bat, installer-files/octave-firsttime.vbs,
John Donoghue <john.donoghue@ieee.org>
parents: 6025
diff changeset
224
cf7adc238c0c * installer-files/cmdshell.bat, installer-files/octave-firsttime.vbs,
John Donoghue <john.donoghue@ieee.org>
parents: 6025
diff changeset
225 path[nSize] = L'\0';
cf7adc238c0c * installer-files/cmdshell.bat, installer-files/octave-firsttime.vbs,
John Donoghue <john.donoghue@ieee.org>
parents: 6025
diff changeset
226
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227 /* other env */
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
228 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
229 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
230 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
231
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
232 /* home set */
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
233 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
234 if (nSize == 0 || path[0] == 0)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
236 wchar_t newhome[PATH_SZ];
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
237
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
238 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
239 if (nSize == 0 || path[0] == 0)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
240 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
241 /* 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
242 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
243 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
244 if (nSize)
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
245 StringCchCopyW (path, PATH_SZ, tmpbuff);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
246 else
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
247 path[0] = '\0';
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 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
250 if (nSize)
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
251 StringCchCopyW (path, PATH_SZ, tmpbuff);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
252 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
253
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
254 #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
255 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
256 #else
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
257 /* 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
258 paths */
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
259 /* 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
260 paths */
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
261 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
262
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
263 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
264 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
265 #endif
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 SetEnvironmentVariableW (L"HOME", newhome);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
268 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
269
5978
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
270 /* set number of OpenBLAS threads */
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
271 nSize = GetEnvironmentVariableW (L"OPENBLAS_NUM_THREADS", NULL, 0);
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
272 if (nSize == 0)
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
273 {
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
274 /* Only set if it wasn't already set in the environment */
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
275 size_t num_threads;
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
276 num_threads = get_num_physical_cores ();
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
277
6025
9d6cbb229b0f octave-launch: Limit number of OpenBLAS threads to a maximum of 24.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6001
diff changeset
278 // Setting OPENBLAS_NUM_THREADS to something higher than what NUM_THREADS
9d6cbb229b0f octave-launch: Limit number of OpenBLAS threads to a maximum of 24.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6001
diff changeset
279 // was set to when OpenBLAS was configured, can lead to errors.
9d6cbb229b0f octave-launch: Limit number of OpenBLAS threads to a maximum of 24.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6001
diff changeset
280 // FIXME: Can/should we get that number from the library?
9d6cbb229b0f octave-launch: Limit number of OpenBLAS threads to a maximum of 24.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6001
diff changeset
281 #define MAX_NUM_THREADS 24
9d6cbb229b0f octave-launch: Limit number of OpenBLAS threads to a maximum of 24.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6001
diff changeset
282 if (num_threads > MAX_NUM_THREADS)
9d6cbb229b0f octave-launch: Limit number of OpenBLAS threads to a maximum of 24.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6001
diff changeset
283 num_threads = MAX_NUM_THREADS;
9d6cbb229b0f octave-launch: Limit number of OpenBLAS threads to a maximum of 24.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6001
diff changeset
284
5978
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
285 if (num_threads > 0)
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
286 {
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
287 #define THREADS_SZ 64
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
288 wchar_t buffer[THREADS_SZ];
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
289 StringCchPrintfW (buffer, THREADS_SZ, L"%zu", num_threads);
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
290 SetEnvironmentVariableW (L"OPENBLAS_NUM_THREADS", buffer);
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
291 }
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
292 }
1569a1d140ae octave-launch: Set number of OpenBLAS threads to number of cores (bug #61208).
Markus Mützel <markus.muetzel@gmx.de>
parents: 5960
diff changeset
293
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
294 /* check for gui mode */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
295 for (i = 1; i < argc; i++)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
296 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
297 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
298 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
299 if (gui_arg_found)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
300 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
301 /* 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
302 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
303 override the other options. */
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
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
306 no_gui_libs = 1;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
307 }
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
308 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
309 || 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
310 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
311 if (no_gui_libs)
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 /* 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
314 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
315 override the other options. */
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
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
318 gui_arg_found = 1;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
319 }
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
320 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
321 no_gui_arg_found = 1;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
322
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
323 /* 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
324 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
325 detect that. */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
326 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
327
5957
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
328 #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
329 {
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
330 /* 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
331 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
332 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
333 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
334 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
335
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
336 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
337 }
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
338 #endif
9cd5425b033b octave-launch-firsttime: New launcher executable for starting Octave first time.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5956
diff changeset
339
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
340 /* 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
341 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
342 STARTUPINFO si;
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
343 #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
344 wchar_t argbuffer[ARGBUF_SZ];
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
345
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
346 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
347 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
348 ZeroMemory (&pi, sizeof (pi));
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
349
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
350 StringCchCopyW (path, PATH_SZ, binpath);
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
351
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
352 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
353 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
354
6780
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
355 DWORD no_window = 0;
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
356 if (no_gui_libs || no_gui_arg_found)
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
357 {
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
358 /* If parent process has a console, attach to it.
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
359 Let the function fail silently, when parent has no console
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
360 (e.g., when program has been started from link in start menu).
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
361 No console will be shown in this case. */
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
362 AttachConsole (ATTACH_PARENT_PROCESS);
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
363 }
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
364 else
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
365 {
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
366 /* 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
367 si.dwFlags = STARTF_USESHOWWINDOW;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
368
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
369 /* 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
370 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
371 most Windows users would expect. */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
372
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
373 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
374 StringCchCatW (argbuffer, ARGBUF_SZ, L"--gui ");
6780
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
375
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
376 /* Detach from the console to allow hiding it. */
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
377 FreeConsole ();
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
378
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
379 /* Suppress creating a new console when starting the GUI. */
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
380 no_window = CREATE_NO_WINDOW;
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
381 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
382
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
383 /* quote and append each arg */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
384 for (i = 1; i < argc; i++)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
385 {
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
386 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
387 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
388 StringCchCatW (argbuffer, ARGBUF_SZ, L"\" ");
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
389 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
390
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
391 /* 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
392 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
393 argbuffer, // Command line
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
394 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
395 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
396 FALSE, // Set handle inheritance to FALSE
6780
ecb84ac8b317 launcher: Fix displaying stderr in CLI mode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 6777
diff changeset
397 no_window | CREATE_UNICODE_ENVIRONMENT, // Creation flags
5956
b8e9589b7794 octave-launch: Use Unicode strings in Windows API functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 5955
diff changeset
398 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
399 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
400 &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
401 &pi); // Pointer to PROCESS_INFORMATION
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
402
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
403 if (! status)
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
404 return 1;
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
405 }
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
406
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
407 /* Wait until child process exits. */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
408 WaitForSingleObject (pi.hProcess, INFINITE);
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
409
6777
392c5255d044 Return exit code of Octave executable from launcher (patch #10370).
Vipul Cariappa <vipulcariappa@gmail.com>
parents: 6174
diff changeset
410 /* Get the exit code of the child process */
392c5255d044 Return exit code of Octave executable from launcher (patch #10370).
Vipul Cariappa <vipulcariappa@gmail.com>
parents: 6174
diff changeset
411 DWORD exit_code = 0;
392c5255d044 Return exit code of Octave executable from launcher (patch #10370).
Vipul Cariappa <vipulcariappa@gmail.com>
parents: 6174
diff changeset
412 GetExitCodeProcess (pi.hProcess, &exit_code);
392c5255d044 Return exit code of Octave executable from launcher (patch #10370).
Vipul Cariappa <vipulcariappa@gmail.com>
parents: 6174
diff changeset
413
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
414 /* Close process and thread handles */
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
415 CloseHandle (pi.hProcess);
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
416 CloseHandle (pi.hThread);
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
417
6777
392c5255d044 Return exit code of Octave executable from launcher (patch #10370).
Vipul Cariappa <vipulcariappa@gmail.com>
parents: 6174
diff changeset
418 return exit_code;
5955
f42752ce0ae3 new octave-launcher.exe program from John Donoghue
John W. Eaton <jwe@octave.org>
parents:
diff changeset
419 }