annotate src/main.in.cc @ 17959:1329866151be

[Win32] Use spawn instead of exec for main octave wrapper executable. * src/main.in.cc (prepare_spawn): New function, copied from libtool. (octave_exec): Use it and call spawnv instead of execv (note: execv kills the current process, instead of replacing it). (main): Make sure argv[0] always points to the executable, required by libtool wrappers.
author Michael Goffioul <michael.goffioul@gmail.com>
date Tue, 19 Nov 2013 14:25:32 -0500
parents dde06c2ac6c6
children a99b7d656a6c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 // %NO_EDIT_WARNING%
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 /*
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 Copyright (C) 2012-2013 John W. Eaton
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 This file is part of Octave.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 option) any later version.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 for more details.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 along with Octave; see the file COPYING. If not, see
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 <http://www.gnu.org/licenses/>.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 */
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 // NOTE: This program is supposed to be a small wrapper that exists
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 // primarily to give up the controlling TTY and then exec Octave with
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 // its GUI. It may also execute Octave without the GUI or the command
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 // line version of Octave that is not linked with GUI libraries. So
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 // that it remains small, it should NOT depend on or be linked with
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 // liboctave or libinterp.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #ifdef HAVE_CONFIG_H
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include <config.h>
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include <cstdlib>
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 #include <cstring>
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 #include <algorithm>
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include <iostream>
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #include <string>
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41
17805
2a15970da7f0 allow main.cc to build again with --disable-gui
John W. Eaton <jwe@octave.org>
parents: 17803
diff changeset
42 #include <sys/types.h>
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 #include <unistd.h>
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44
17782
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
45 #if defined (__WIN32__) && ! defined (_POSIX_VERSION)
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
46
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
47 #define WIN32_LEAN_AND_MEAN
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
48 #include <tlhelp32.h>
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
49
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
50 static std::string
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
51 w32_get_octave_home (void)
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
52 {
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
53 std::string retval;
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
54
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
55 std::string bin_dir;
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
56
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
57 HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
58 #ifdef TH32CS_SNAPMODULE32
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
59 | TH32CS_SNAPMODULE32
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
60 #endif
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
61 , 0);
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
62
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
63 if (h != INVALID_HANDLE_VALUE)
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
64 {
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
65 MODULEENTRY32 mod_info;
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
66
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
67 ZeroMemory (&mod_info, sizeof (mod_info));
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
68 mod_info.dwSize = sizeof (mod_info);
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
69
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
70 if (Module32First (h, &mod_info))
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
71 {
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
72 do
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
73 {
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
74 std::string mod_name (mod_info.szModule);
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
75
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
76 if (mod_name.find ("octave") != std::string::npos)
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
77 {
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
78 bin_dir = mod_info.szExePath;
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
79
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
80 if (bin_dir[bin_dir.length () - 1] != '\\')
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
81 bin_dir.append (1, '\\');
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
82
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
83 break;
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
84 }
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
85 }
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
86 while (Module32Next (h, &mod_info));
17789
f2b047f9b605 Use GNU style coding conventions for code in src/.
Rik <rik@octave.org>
parents: 17784
diff changeset
87 }
17782
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
88
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
89 CloseHandle (h);
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
90 }
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
91
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
92 if (! bin_dir.empty ())
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
93 {
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
94 size_t pos = bin_dir.rfind ("\\bin\\");
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
95
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
96 if (pos != std::string::npos)
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
97 retval = bin_dir.substr (0, pos);
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
98 }
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
99
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
100 return retval;
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
101 }
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
102
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
103 #endif
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
104
17814
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
105 #if (defined (HAVE_OCTAVE_GUI) \
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
106 && ! defined (__WIN32__) || defined (__CYGWIN__))
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107
17780
8b353af4a1ca allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents: 17778
diff changeset
108 #include <signal.h>
17813
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
109 #include <fcntl.h>
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
110
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
111 // This is a liboctave header, but it doesn't include any other Octave
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
112 // headers or declare any functions that are defined in liboctave.
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
113 #include "syswait.h"
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 typedef void sig_handler (int);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 // Forward signals to the GUI process.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 static pid_t gui_pid = 0;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
121 static int caught_signal = -1;
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
122
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 static void
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124 gui_driver_sig_handler (int sig)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 if (gui_pid > 0)
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
127 caught_signal = sig;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130 static sig_handler *
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 octave_set_signal_handler (int sig, sig_handler *handler)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 struct sigaction act, oact;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 act.sa_handler = handler;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136 act.sa_flags = 0;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 gnulib::sigemptyset (&act.sa_mask);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139 gnulib::sigemptyset (&oact.sa_mask);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141 gnulib::sigaction (sig, &act, &oact);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143 return oact.sa_handler;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
145
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146 static void
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 install_signal_handlers (void)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150 #ifdef SIGINT
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151 octave_set_signal_handler (SIGINT, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
152 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
154 #ifdef SIGBREAK
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 octave_set_signal_handler (SIGBREAK, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158 #ifdef SIGABRT
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 octave_set_signal_handler (SIGABRT, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
162 #ifdef SIGALRM
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
163 octave_set_signal_handler (SIGALRM, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
164 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
165
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166 #ifdef SIGBUS
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
167 octave_set_signal_handler (SIGBUS, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
168 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
169
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
170 // SIGCHLD
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
171 // SIGCLD
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172 // SIGCONT
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
173
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
174 #ifdef SIGEMT
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175 octave_set_signal_handler (SIGEMT, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
176 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
177
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178 #ifdef SIGFPE
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
179 octave_set_signal_handler (SIGFPE, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182 #ifdef SIGHUP
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183 octave_set_signal_handler (SIGHUP, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186 #ifdef SIGILL
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
187 octave_set_signal_handler (SIGILL, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190 // SIGINFO
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191 // SIGINT
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193 #ifdef SIGIOT
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194 octave_set_signal_handler (SIGIOT, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
197 #ifdef SIGLOST
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
198 octave_set_signal_handler (SIGLOST, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201 #ifdef SIGPIPE
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202 octave_set_signal_handler (SIGPIPE, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205 #ifdef SIGPOLL
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206 octave_set_signal_handler (SIGPOLL, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209 // SIGPROF
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
210 // SIGPWR
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
212 #ifdef SIGQUIT
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213 octave_set_signal_handler (SIGQUIT, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216 #ifdef SIGSEGV
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217 octave_set_signal_handler (SIGSEGV, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
220 // SIGSTOP
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
221
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
222 #ifdef SIGSYS
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
223 octave_set_signal_handler (SIGSYS, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
224 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
226 #ifdef SIGTERM
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227 octave_set_signal_handler (SIGTERM, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
228 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
229
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
230 #ifdef SIGTRAP
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
231 octave_set_signal_handler (SIGTRAP, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
232 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
233
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
234 // SIGTSTP
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235 // SIGTTIN
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
236 // SIGTTOU
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
237 // SIGURG
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
238
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
239 #ifdef SIGUSR1
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
240 octave_set_signal_handler (SIGUSR1, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
241 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
242
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
243 #ifdef SIGUSR2
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
244 octave_set_signal_handler (SIGUSR2, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
245 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
246
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
247 #ifdef SIGVTALRM
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
248 octave_set_signal_handler (SIGVTALRM, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
249 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
250
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
251 #ifdef SIGIO
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
252 octave_set_signal_handler (SIGIO, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
253 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
254
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
255 // SIGWINCH
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
256
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
257 #ifdef SIGXCPU
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
258 octave_set_signal_handler (SIGXCPU, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
259 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
260
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
261 #ifdef SIGXFSZ
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
262 octave_set_signal_handler (SIGXFSZ, gui_driver_sig_handler);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
263 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
264
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
265 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
266
17803
f5ada8597078 * main.in.cc (have_controlling_terminal): Return bool, not int.
John W. Eaton <jwe@octave.org>
parents: 17802
diff changeset
267 static bool
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
268 have_controlling_terminal (void)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
269 {
17803
f5ada8597078 * main.in.cc (have_controlling_terminal): Return bool, not int.
John W. Eaton <jwe@octave.org>
parents: 17802
diff changeset
270 int retval = false;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
271
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
272 #if defined (HAVE_CTERMID)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
273 const char *ctty = ctermid (0);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
274 #else
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
275 const char *ctty = "/dev/tty";
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
276 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
277
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
278 int fd = gnulib::open (ctty, O_RDWR, 0);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
279
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
280 if (fd >= 0)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
281 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
282 gnulib::close (fd);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
283
17803
f5ada8597078 * main.in.cc (have_controlling_terminal): Return bool, not int.
John W. Eaton <jwe@octave.org>
parents: 17802
diff changeset
284 retval = true;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
285 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
286
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
287 return retval;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
288 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
289
17813
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
290 #endif
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
291
17780
8b353af4a1ca allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents: 17778
diff changeset
292 #ifndef OCTAVE_BINDIR
8b353af4a1ca allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents: 17778
diff changeset
293 #define OCTAVE_BINDIR %OCTAVE_BINDIR%
8b353af4a1ca allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents: 17778
diff changeset
294 #endif
8b353af4a1ca allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents: 17778
diff changeset
295
8b353af4a1ca allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents: 17778
diff changeset
296 #ifndef OCTAVE_PREFIX
8b353af4a1ca allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents: 17778
diff changeset
297 #define OCTAVE_PREFIX %OCTAVE_PREFIX%
8b353af4a1ca allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents: 17778
diff changeset
298 #endif
8b353af4a1ca allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents: 17778
diff changeset
299
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
300 // Find the directory where the octave binary is supposed to be
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
301 // installed.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
302
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
303 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
304 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
305 static const char dir_sep_char = '\\';
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
306 #else
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
307 static const char dir_sep_char = '/';
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
308 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
309
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
310 static std::string
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
311 octave_getenv (const std::string& name)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
312 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
313 char *value = ::getenv (name.c_str ());
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
314
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
315 return value ? value : "";
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
316 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
317
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
318 static std::string
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
319 get_octave_home (void)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
320 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
321 std::string oh = octave_getenv ("OCTAVE_HOME");
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
322
17782
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
323 #if defined (__WIN32__) && ! defined (_POSIX_VERSION)
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
324 if (oh.empty ())
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
325 oh = w32_get_octave_home ();
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
326 #endif
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
327
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
328 return oh.empty () ? std::string (OCTAVE_PREFIX) : oh;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
329 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
330
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
331 static std::string
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
332 subst_octave_home (const std::string& s)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
333 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
334 std::string retval;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
335
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
336 std::string octave_home = get_octave_home ();
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
337
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
338 std::string prefix = OCTAVE_PREFIX;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
339
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
340 retval = s;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
341
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
342 if (octave_home != prefix)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
343 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
344 octave_idx_type len = prefix.length ();
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
345
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
346 if (s.substr (0, len) == prefix)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
347 retval.replace (0, len, octave_home);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
348 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
349
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
350 if (dir_sep_char != '/')
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
351 std::replace (retval.begin (), retval.end (), '/', dir_sep_char);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
352
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
353 return retval;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
354 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
355
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
356 static std::string
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
357 get_octave_bindir (void)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
358 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
359 // Accept value from the environment literally, but substitute
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
360 // OCTAVE_HOME in the configuration value OCTAVE_BINDIR in case Octave
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
361 // has been relocated to some installation directory other than the
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
362 // one originally configured.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
363
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
364 std::string obd = octave_getenv ("OCTAVE_BINDIR");
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
365
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
366 return obd.empty () ? subst_octave_home (std::string (OCTAVE_BINDIR)) : obd;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
367 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
368
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
369 #if defined (__WIN32__) && ! defined (__CYGWIN__) // Adapted from libtool wrapper.
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
370
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
371 /* Prepares an argument vector before calling spawn().
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
372 Note that spawn() does not by itself call the command interpreter
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
373 (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
374 ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
375 GetVersionEx(&v);
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
376 v.dwPlatformId == VER_PLATFORM_WIN32_NT;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
377 }) ? "cmd.exe" : "command.com").
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
378 Instead it simply concatenates the arguments, separated by ' ', and calls
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
379 CreateProcess(). We must quote the arguments since Win32 CreateProcess()
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
380 interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
381 special way:
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
382 - Space and tab are interpreted as delimiters. They are not treated as
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
383 delimiters if they are surrounded by double quotes: "...".
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
384 - Unescaped double quotes are removed from the input. Their only effect is
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
385 that within double quotes, space and tab are treated like normal
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
386 characters.
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
387 - Backslashes not followed by double quotes are not special.
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
388 - But 2*n+1 backslashes followed by a double quote become
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
389 n backslashes followed by a double quote (n >= 0):
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
390 \" -> "
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
391 \\\" -> \"
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
392 \\\\\" -> \\"
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
393 */
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
394 #define SHELL_SPECIAL_CHARS "\"\\ \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
395 #define SHELL_SPACE_CHARS " \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
396 char **
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
397 prepare_spawn (char **argv)
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
398 {
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
399 size_t argc;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
400 char **new_argv;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
401 size_t i;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
402
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
403 /* Count number of arguments. */
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
404 for (argc = 0; argv[argc] != NULL; argc++)
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
405 ;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
406
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
407 /* Allocate new argument vector. */
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
408 new_argv = new char* [argc + 1];
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
409
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
410 /* Put quoted arguments into the new argument vector. */
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
411 for (i = 0; i < argc; i++)
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
412 {
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
413 const char *string = argv[i];
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
414
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
415 if (string[0] == '\0')
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
416 new_argv[i] = strdup ("\"\"");
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
417 else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
418 {
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
419 int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
420 size_t length;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
421 unsigned int backslashes;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
422 const char *s;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
423 char *quoted_string;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
424 char *p;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
425
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
426 length = 0;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
427 backslashes = 0;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
428 if (quote_around)
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
429 length++;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
430 for (s = string; *s != '\0'; s++)
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
431 {
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
432 char c = *s;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
433 if (c == '"')
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
434 length += backslashes + 1;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
435 length++;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
436 if (c == '\\')
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
437 backslashes++;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
438 else
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
439 backslashes = 0;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
440 }
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
441 if (quote_around)
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
442 length += backslashes + 1;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
443
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
444 quoted_string = new char [length + 1];
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
445
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
446 p = quoted_string;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
447 backslashes = 0;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
448 if (quote_around)
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
449 *p++ = '"';
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
450 for (s = string; *s != '\0'; s++)
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
451 {
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
452 char c = *s;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
453 if (c == '"')
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
454 {
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
455 unsigned int j;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
456 for (j = backslashes + 1; j > 0; j--)
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
457 *p++ = '\\';
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
458 }
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
459 *p++ = c;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
460 if (c == '\\')
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
461 backslashes++;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
462 else
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
463 backslashes = 0;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
464 }
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
465 if (quote_around)
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
466 {
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
467 unsigned int j;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
468 for (j = backslashes; j > 0; j--)
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
469 *p++ = '\\';
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
470 *p++ = '"';
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
471 }
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
472 *p = '\0';
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
473
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
474 new_argv[i] = quoted_string;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
475 }
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
476 else
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
477 new_argv[i] = (char *) string;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
478 }
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
479 new_argv[argc] = NULL;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
480
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
481 return new_argv;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
482 }
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
483
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
484 #endif // __WIN32__ && ! __CYGWIN__
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
485
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
486 static int
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
487 octave_exec (const std::string& file, char **argv)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
488 {
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
489 #if defined (__WIN32__) && ! defined (__CYGWIN__)
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
490 argv = prepare_spawn (argv);
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
491 return _spawnv (_P_WAIT, file.c_str (), argv);
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
492 #else
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
493 execv (file.c_str (), argv);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
494
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
495 std::cerr << "octave: failed to exec '" << file << "'" << std::endl;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
496
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
497 return 1;
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
498 #endif
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
499 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
500
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
501 static char *
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
502 strsave (const char *s)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
503 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
504 if (! s)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
505 return 0;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
506
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
507 int len = strlen (s);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
508 char *tmp = new char [len+1];
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
509 tmp = strcpy (tmp, s);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
510 return tmp;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
511 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
512
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
513 int
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
514 main (int argc, char **argv)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
515 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
516 int retval = 0;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
517
17813
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
518 #if (defined (HAVE_OCTAVE_GUI) \
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
519 && (! defined (__WIN32__) || defined (__CYGWIN__)))
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
520 bool start_gui = true;
17801
0b81d65d3c49 only fork and exec when starting gui
John W. Eaton <jwe@octave.org>
parents: 17789
diff changeset
521 bool gui_libs = true;
17784
7ae9bc04ec07 allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents: 17782
diff changeset
522 #endif
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
523
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
524 std::string octave_bindir = get_octave_bindir ();
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
525
17814
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
526 std::string file = octave_bindir + dir_sep_char;
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
527
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
528 #if defined (HAVE_OCTAVE_GUI)
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
529 file += "octave-gui";
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
530 #else
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
531 file += "octave-cli";
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
532 #endif
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
533
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
534 char **new_argv = new char * [argc + 1];
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
535
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
536 #if defined (__WIN32__) && ! defined (__CYGWIN__)
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
537 int k = 1;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
538 #else
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
539 int k = 0;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
540 new_argv[k++] = strsave ("octave");
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
541 #endif
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
542
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
543 for (int i = 1; i < argc; i++)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
544 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
545 if (! strcmp (argv[i], "--no-gui-libs"))
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
546 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
547 // Run the version of Octave that is not linked with any GUI
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
548 // libraries. It may not be possible to do plotting or any
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
549 // ui* calls, but it will be a little faster to start and
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
550 // require less memory. Don't pass the --no-gui-libs option
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
551 // on as that option is not recognized by Octave.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
552
17814
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
553 #if (defined (HAVE_OCTAVE_GUI) \
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
554 && ! defined (__WIN32__) || defined (__CYGWIN__))
17801
0b81d65d3c49 only fork and exec when starting gui
John W. Eaton <jwe@octave.org>
parents: 17789
diff changeset
555 gui_libs = false;
17813
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
556 #endif
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
557 file = octave_bindir + dir_sep_char + "octave-cli";
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
558 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
559 else if (! strcmp (argv[i], "--no-gui"))
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
560 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
561 // If we see this option, then we can just exec octave; we
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
562 // don't have to create a child process and wait for it to
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
563 // exit. But do exec "octave", not "octave-cli", because even
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
564 // if the --no-gui option is given, we may be asked to do some
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
565 // plotting or ui* calls.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
566
17814
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
567 #if (defined (HAVE_OCTAVE_GUI) \
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
568 && ! defined (__WIN32__) || defined (__CYGWIN__))
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
569 start_gui = false;
17813
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
570 #endif
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
571 new_argv[k++] = argv[i];
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
572 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
573 else
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
574 new_argv[k++] = argv[i];
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
575 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
576
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
577 new_argv[k] = 0;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
578
17814
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
579 #if (defined (HAVE_OCTAVE_GUI) \
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
580 && ! defined (__WIN32__) || defined (__CYGWIN__))
17813
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
581
17801
0b81d65d3c49 only fork and exec when starting gui
John W. Eaton <jwe@octave.org>
parents: 17789
diff changeset
582 if (gui_libs && start_gui && have_controlling_terminal ())
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
583 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
584 install_signal_handlers ();
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
585
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
586 gui_pid = fork ();
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
587
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
588 if (gui_pid < 0)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
589 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
590 std::cerr << "octave: fork failed!" << std::endl;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
591
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
592 retval = 1;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
593 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
594 else if (gui_pid == 0)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
595 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
596 // Child.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
597
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
598 if (setsid () < 0)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
599 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
600 std::cerr << "octave: error calling setsid!" << std::endl;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
601
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
602 retval = 1;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
603 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
604
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
605 retval = octave_exec (file, new_argv);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
606 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
607 else
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
608 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
609 // Parent. Forward signals to the child while waiting for it
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
610 // to exit.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
611
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
612 int status;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
613
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
614 while (true)
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
615 {
17780
8b353af4a1ca allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents: 17778
diff changeset
616 WAITPID (gui_pid, &status, 0);
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
617
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
618 if (caught_signal > 0)
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
619 {
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
620 int sig = caught_signal;
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
621
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
622 caught_signal = -1;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
623
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
624 kill (gui_pid, sig);
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
625 }
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
626 else if (WIFEXITED (status))
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
627 {
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
628 retval = WEXITSTATUS (status);
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
629 break;
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
630 }
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
631 else if (WIFSIGNALLED (status))
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
632 {
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
633 std::cerr << "octave exited with signal "
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
634 << WTERMSIG (status) << std::endl;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
635 break;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
636 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
637 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
638 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
639 }
17801
0b81d65d3c49 only fork and exec when starting gui
John W. Eaton <jwe@octave.org>
parents: 17789
diff changeset
640 else
0b81d65d3c49 only fork and exec when starting gui
John W. Eaton <jwe@octave.org>
parents: 17789
diff changeset
641 retval = octave_exec (file, new_argv);
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
642
17813
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
643 #else
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
644
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
645 #if defined (__WIN32__) && ! defined (__CYGWIN__)
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
646 file += ".exe";
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
647 new_argv[0] = strsave (file.c_str ());
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
648 #endif
17813
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
649 retval = octave_exec (file, new_argv);
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
650
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
651 #endif
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
652
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
653 return retval;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
654 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
655
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
656 /*!
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
657 @mainpage Source code documentation for GNU Octave
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
658
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
659 GNU Octave is a high-level language, primarily intended for numerical
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
660 computations. It provides a convenient interactive command line
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
661 interface for solving linear and nonlinear problems numerically, and
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
662 for performing other numerical experiments. It may also be used as a
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
663 batch-oriented language for data processing.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
664
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
665 GNU Octave is free software. You may redistribute it and/or modify it
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
666 under the terms of the <a href="http://www.gnu.org/licenses/">GNU
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
667 General Public License</a> as published by the Free Software Foundation.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
668
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
669 This is the developer documentation for Octave's own source code. It is
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
670 intended to help for hacking Octave. It may also be useful for
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
671 understanding the Octave API when writing your own .oct files.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
672 */