annotate src/main.in.cc @ 18163:eb51f47d9dee gui-release

maint: Periodic merge of stable to gui-release.
author John W. Eaton <jwe@octave.org>
date Mon, 23 Dec 2013 19:39:39 -0500
parents d13fb462dd92 65e4e0569ed4
children 87d96a7d50e0
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
18151
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
45 #ifndef OCTAVE_VERSION
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
46 #define OCTAVE_VERSION %OCTAVE_VERSION%
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
47 #endif
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
48
18162
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
49 #ifndef OCTAVE_ARCHLIBDIR
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
50 #define OCTAVE_ARCHLIBDIR %OCTAVE_ARCHLIBDIR%
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
51 #endif
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
52
18151
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
53 #ifndef OCTAVE_BINDIR
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
54 #define OCTAVE_BINDIR %OCTAVE_BINDIR%
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
55 #endif
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
56
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
57 #ifndef OCTAVE_PREFIX
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
58 #define OCTAVE_PREFIX %OCTAVE_PREFIX%
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
59 #endif
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
60
17782
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
61 #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
62
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
63 #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
64 #include <tlhelp32.h>
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
65
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
66 static std::string
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
67 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
68 {
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
69 std::string retval;
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
70
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
71 std::string bin_dir;
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
72
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
73 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
74 #ifdef TH32CS_SNAPMODULE32
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
75 | TH32CS_SNAPMODULE32
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
76 #endif
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
77 , 0);
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
78
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
79 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
80 {
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
81 MODULEENTRY32 mod_info;
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 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
84 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
85
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
86 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
87 {
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
88 do
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
89 {
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
90 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
91
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
92 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
93 {
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
94 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
95
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
96 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
97 bin_dir.append (1, '\\');
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 break;
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
100 }
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 while (Module32Next (h, &mod_info));
17789
f2b047f9b605 Use GNU style coding conventions for code in src/.
Rik <rik@octave.org>
parents: 17784
diff changeset
103 }
17782
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
104
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
105 CloseHandle (h);
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
106 }
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
107
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
108 if (! bin_dir.empty ())
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
109 {
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
110 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
111
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
112 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
113 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
114 }
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
115
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
116 return retval;
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
117 }
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
118
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
119 #endif
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
120
17994
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
121 #include <cstdlib>
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
122
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
123 #if defined (OCTAVE_USE_WINDOWS_API)
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
124 #include <windows.h>
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
125 #elif defined (HAVE_FRAMEWORK_CARBON)
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
126 #include <Carbon/Carbon.h>
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
127 #elif defined (HAVE_X_WINDOWS)
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
128 #include <X11/Xlib.h>
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
129 #endif
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
130
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
131 bool
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
132 display_available (std::string& err_msg)
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
133 {
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
134 bool dpy_avail = false;
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
135
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
136 err_msg = "";
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
137
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
138 #if defined (OCTAVE_USE_WINDOWS_API)
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
139
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
140 HDC hdc = GetDC (0);
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
141
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
142 if (hdc)
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
143 dpy_avail = true;
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
144 else
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
145 err_msg = "no graphical display found";
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
146
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
147 #elif defined (HAVE_FRAMEWORK_CARBON)
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
148
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
149 CGDirectDisplayID display = CGMainDisplayID ();
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
150
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
151 if (display)
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
152 dpy_avail = true;
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
153 else
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
154 err_msg = "no graphical display found";
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
155
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
156 #elif defined (HAVE_X_WINDOWS)
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
157
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
158 const char *display_name = getenv ("DISPLAY");
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
159
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
160 if (display_name && *display_name)
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
161 {
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
162 Display *display = XOpenDisplay (display_name);
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
163
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
164 if (display)
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
165 {
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
166 Screen *screen = DefaultScreenOfDisplay (display);
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
167
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
168 if (! screen)
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
169 err_msg = "X11 display has no default screen";
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
170
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
171 XCloseDisplay (display);
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
172
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
173 dpy_avail = true;
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
174 }
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
175 else
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
176 err_msg = "unable to open X11 DISPLAY";
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
177 }
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
178 else
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
179 err_msg = "X11 DISPLAY environment variable not set";
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
180
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
181 #else
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
182
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
183 err_msg = "no graphical display found";
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
184
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
185 #endif
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
186
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
187 return dpy_avail;
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
188 }
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
189
17814
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
190 #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
191 && ! 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
192
17780
8b353af4a1ca allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents: 17778
diff changeset
193 #include <signal.h>
17813
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
194 #include <fcntl.h>
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
195
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
196 // 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
197 // 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
198 #include "syswait.h"
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200 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
201
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202 // 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
203
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204 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
205
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
206 static int caught_signal = -1;
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
207
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208 static void
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209 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
210 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211 if (gui_pid > 0)
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
212 caught_signal = sig;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215 static sig_handler *
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216 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
217 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218 struct sigaction act, oact;
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 act.sa_handler = handler;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
221 act.sa_flags = 0;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
222
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
223 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
224 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
225
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
226 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
227
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
228 return oact.sa_handler;
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
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
231 static void
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
232 install_signal_handlers (void)
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
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235 #ifdef SIGINT
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
236 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
237 #endif
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 SIGBREAK
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 (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
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 SIGABRT
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 (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
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 SIGALRM
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 (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
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 SIGBUS
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 (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
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 // SIGCHLD
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
256 // SIGCLD
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
257 // SIGCONT
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
258
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
259 #ifdef SIGEMT
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
260 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
261 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
262
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
263 #ifdef SIGFPE
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
264 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
265 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
266
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
267 #ifdef SIGHUP
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
268 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
269 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
270
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
271 #ifdef SIGILL
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
272 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
273 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
274
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
275 // SIGINFO
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
276 // SIGINT
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 #ifdef SIGIOT
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
279 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
280 #endif
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 #ifdef SIGLOST
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
283 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
284 #endif
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 #ifdef SIGPIPE
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
287 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
288 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
289
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
290 #ifdef SIGPOLL
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
291 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
292 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
293
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
294 // SIGPROF
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
295 // SIGPWR
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
296
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
297 #ifdef SIGQUIT
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
298 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
299 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
300
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
301 #ifdef SIGSEGV
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
302 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
303 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
304
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
305 // SIGSTOP
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
306
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
307 #ifdef SIGSYS
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
308 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
309 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
310
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
311 #ifdef SIGTERM
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
312 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
313 #endif
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 #ifdef SIGTRAP
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
316 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
317 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
318
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
319 // SIGTSTP
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
320 // SIGTTIN
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
321 // SIGTTOU
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
322 // SIGURG
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
323
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
324 #ifdef SIGUSR1
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
325 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
326 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
327
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
328 #ifdef SIGUSR2
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
329 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
330 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
331
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
332 #ifdef SIGVTALRM
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
333 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
334 #endif
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 #ifdef SIGIO
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
337 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
338 #endif
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 // SIGWINCH
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 #ifdef SIGXCPU
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
343 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
344 #endif
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 #ifdef SIGXFSZ
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
347 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
348 #endif
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 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
351
17803
f5ada8597078 * main.in.cc (have_controlling_terminal): Return bool, not int.
John W. Eaton <jwe@octave.org>
parents: 17802
diff changeset
352 static bool
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
353 have_controlling_terminal (void)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
354 {
17803
f5ada8597078 * main.in.cc (have_controlling_terminal): Return bool, not int.
John W. Eaton <jwe@octave.org>
parents: 17802
diff changeset
355 int retval = false;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
356
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
357 #if defined (HAVE_CTERMID)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
358 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
359 #else
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
360 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
361 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
362
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
363 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
364
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
365 if (fd >= 0)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
366 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
367 gnulib::close (fd);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
368
17803
f5ada8597078 * main.in.cc (have_controlling_terminal): Return bool, not int.
John W. Eaton <jwe@octave.org>
parents: 17802
diff changeset
369 retval = true;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
370 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
371
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
372 return retval;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
373 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
374
17813
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
375 #endif
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
376
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
377 // 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
378 // installed.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
379
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
380 #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
381 && ! 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
382 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
383 #else
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
384 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
385 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
386
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
387 static std::string
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
388 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
389 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
390 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
391
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
392 return value ? value : "";
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
393 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
394
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
395 static std::string
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
396 get_octave_home (void)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
397 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
398 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
399
17782
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
400 #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
401 if (oh.empty ())
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
402 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
403 #endif
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
404
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
405 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
406 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
407
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
408 static std::string
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
409 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
410 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
411 std::string retval;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
412
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
413 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
414
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
415 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
416
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
417 retval = s;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
418
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
419 if (octave_home != prefix)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
420 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
421 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
422
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
423 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
424 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
425 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
426
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
427 if (dir_sep_char != '/')
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
428 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
429
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
430 return retval;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
431 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
432
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
433 static std::string
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
434 get_octave_bindir (void)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
435 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
436 // 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
437 // 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
438 // 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
439 // one originally configured.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
440
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
441 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
442
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
443 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
444 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
445
18162
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
446 static std::string
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
447 get_octave_archlibdir (void)
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
448 {
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
449 // Accept value from the environment literally, but substitute
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
450 // OCTAVE_HOME in the configuration value OCTAVE_ARCHLIBDIR in case
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
451 // Octave has been relocated to some installation directory other than
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
452 // the one originally configured.
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
453
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
454 std::string dir = octave_getenv ("OCTAVE_ARCHLIBDIR");
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
455
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
456 return dir.empty ()
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
457 ? subst_octave_home (std::string (OCTAVE_ARCHLIBDIR)) : dir;
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
458 }
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
459
18006
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
460 // Adapted from libtool wrapper.
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
461 #if defined (__WIN32__) && ! defined (__CYGWIN__)
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
462
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
463 /* 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
464 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
465 (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
466 ({ 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
467 GetVersionEx(&v);
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
468 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
469 }) ? "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
470 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
471 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
472 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
473 special way:
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
474 - 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
475 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
476 - 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
477 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
478 characters.
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
479 - 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
480 - 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
481 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
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 \\\\\" -> \\"
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
485 */
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
486 #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
487 #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
488 char **
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
489 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
490 {
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
491 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
492 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
493 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
494
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
495 /* 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
496 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
497 ;
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
498
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
499 /* 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
500 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
501
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
502 /* 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
503 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
504 {
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
505 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
506
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
507 if (string[0] == '\0')
18006
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
508 new_argv[i] = strdup ("\"\"");
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
509 else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
18006
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
510 {
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
511 int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
512 size_t length;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
513 unsigned int backslashes;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
514 const char *s;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
515 char *quoted_string;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
516 char *p;
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
517
18006
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
518 length = 0;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
519 backslashes = 0;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
520 if (quote_around)
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
521 length++;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
522 for (s = string; *s != '\0'; s++)
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
523 {
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
524 char c = *s;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
525 if (c == '"')
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
526 length += backslashes + 1;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
527 length++;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
528 if (c == '\\')
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
529 backslashes++;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
530 else
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
531 backslashes = 0;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
532 }
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
533 if (quote_around)
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
534 length += backslashes + 1;
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
535
18006
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
536 quoted_string = new char [length + 1];
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
537
18006
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
538 p = quoted_string;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
539 backslashes = 0;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
540 if (quote_around)
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
541 *p++ = '"';
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
542 for (s = string; *s != '\0'; s++)
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
543 {
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
544 char c = *s;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
545 if (c == '"')
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
546 {
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
547 unsigned int j;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
548 for (j = backslashes + 1; j > 0; j--)
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
549 *p++ = '\\';
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
550 }
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
551 *p++ = c;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
552 if (c == '\\')
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
553 backslashes++;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
554 else
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
555 backslashes = 0;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
556 }
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
557 if (quote_around)
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
558 {
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
559 unsigned int j;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
560 for (j = backslashes; j > 0; j--)
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
561 *p++ = '\\';
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
562 *p++ = '"';
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
563 }
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
564 *p = '\0';
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
565
18006
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
566 new_argv[i] = quoted_string;
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
567 }
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
568 else
18006
b992a17767fe main.in.cc: Replace tabs with spaces. Shorten lines > 80 chars.
Rik <rik@octave.org>
parents: 17994
diff changeset
569 new_argv[i] = (char *) string;
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
570 }
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
571 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
572
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
573 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
574 }
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
575
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
576 #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
577
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
578 static int
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
579 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
580 {
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
581 #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
582 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
583 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
584 #else
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
585 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
586
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
587 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
588
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
589 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
590 #endif
17778
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
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
593 static char *
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
594 strsave (const char *s)
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 if (! s)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
597 return 0;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
598
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
599 int len = strlen (s);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
600 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
601 tmp = strcpy (tmp, s);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
602 return tmp;
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 int
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
606 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
607 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
608 int retval = 0;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
609
18014
6df05f2fd354 maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents: 18008
diff changeset
610 bool start_gui = true;
6df05f2fd354 maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents: 18008
diff changeset
611 bool gui_libs = true;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
612
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
613 std::string octave_bindir = get_octave_bindir ();
18162
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18151
diff changeset
614 std::string octave_archlibdir = get_octave_archlibdir ();
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
615
18014
6df05f2fd354 maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents: 18008
diff changeset
616 #if defined (HAVE_OCTAVE_GUI)
18163
eb51f47d9dee maint: Periodic merge of stable to gui-release.
John W. Eaton <jwe@octave.org>
parents: 18156 18162
diff changeset
617 // The Octave version number is already embedded in the
eb51f47d9dee maint: Periodic merge of stable to gui-release.
John W. Eaton <jwe@octave.org>
parents: 18156 18162
diff changeset
618 // octave_archlibdir directory name so we don't need to append it to
eb51f47d9dee maint: Periodic merge of stable to gui-release.
John W. Eaton <jwe@octave.org>
parents: 18156 18162
diff changeset
619 // the octave-gui file name.
eb51f47d9dee maint: Periodic merge of stable to gui-release.
John W. Eaton <jwe@octave.org>
parents: 18156 18162
diff changeset
620
eb51f47d9dee maint: Periodic merge of stable to gui-release.
John W. Eaton <jwe@octave.org>
parents: 18156 18162
diff changeset
621 std::string file = octave_archlibdir + dir_sep_char + "octave-gui";
18014
6df05f2fd354 maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents: 18008
diff changeset
622 #else
18151
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
623 std::string file
18163
eb51f47d9dee maint: Periodic merge of stable to gui-release.
John W. Eaton <jwe@octave.org>
parents: 18156 18162
diff changeset
624 = octave_bindir + dir_sep_char + "octave-cli-" OCTAVE_VERSION;
18014
6df05f2fd354 maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents: 18008
diff changeset
625 #endif
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
626
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
627 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
628
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
629 int k = 1;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
630
17994
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
631 bool warn_display = true;
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
632
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
633 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
634 {
18014
6df05f2fd354 maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents: 18008
diff changeset
635 if (! strcmp (argv[i], "--no-gui-libs"))
17778
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 // 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
638 // 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
639 // 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
640 // 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
641 // 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
642
18014
6df05f2fd354 maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents: 18008
diff changeset
643 start_gui = false;
6df05f2fd354 maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents: 18008
diff changeset
644 gui_libs = false;
6df05f2fd354 maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents: 18008
diff changeset
645 file = octave_bindir + dir_sep_char + "octave-cli";
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
646 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
647 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
648 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
649 // 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
650 // don't have to create a child process and wait for it to
18151
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
651 // exit. But do exec "octave-gui", not "octave-cli", because
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
652 // even if the --no-gui option is given, we may be asked to do
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
653 // some plotting or ui* calls.
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
654
18014
6df05f2fd354 maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents: 18008
diff changeset
655 start_gui = false;
6df05f2fd354 maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents: 18008
diff changeset
656 new_argv[k++] = argv[i];
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
657 }
18008
2831a949a219 Restore passing '--silent' option from octave wrapper executable
Mike Miller <mtmiller@ieee.org>
parents: 18007
diff changeset
658 else if (! strcmp (argv[i], "--silent") || ! strcmp (argv[i], "--quiet")
2831a949a219 Restore passing '--silent' option from octave wrapper executable
Mike Miller <mtmiller@ieee.org>
parents: 18007
diff changeset
659 || ! strcmp (argv[i], "-q"))
18010
dc58d4810de6 main.in.cc: Respect --silent option and don't print startup message.
Rik <rik@octave.org>
parents: 18007
diff changeset
660 {
dc58d4810de6 main.in.cc: Respect --silent option and don't print startup message.
Rik <rik@octave.org>
parents: 18007
diff changeset
661 warn_display = false;
dc58d4810de6 main.in.cc: Respect --silent option and don't print startup message.
Rik <rik@octave.org>
parents: 18007
diff changeset
662 new_argv[k++] = argv[i];
dc58d4810de6 main.in.cc: Respect --silent option and don't print startup message.
Rik <rik@octave.org>
parents: 18007
diff changeset
663 }
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
664 else
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
665 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
666 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
667
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
668 new_argv[k] = 0;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
669
17994
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
670 if (gui_libs || start_gui)
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
671 {
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
672 std::string display_check_err_msg;
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
673
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
674 if (! display_available (display_check_err_msg))
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
675 {
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
676 start_gui = false;
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
677 gui_libs = false;
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
678
18151
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
679 file = octave_bindir + dir_sep_char + "octave-cli-" OCTAVE_VERSION;
17994
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
680
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
681 if (warn_display)
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
682 {
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
683 std::cerr << "octave: " << display_check_err_msg << std::endl;
18052
0c4a2e95c768 Correct typo in error message when no DISPLAY var set.
Rik <rik@octave.org>
parents: 18012
diff changeset
684 std::cerr << "octave: disabling GUI features" << std::endl;
17994
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
685 }
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
686 }
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
687 }
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
688
18151
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
689 #if defined (__WIN32__) && ! defined (__CYGWIN__)
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
690 file += ".exe";
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
691 #endif
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
692
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
693 new_argv[0] = strsave (file.c_str ());
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
694
17814
e50a3664bd45 make compilation of main.cc work again when not building GUI
John W. Eaton <jwe@octave.org>
parents: 17813
diff changeset
695 #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
696 && ! defined (__WIN32__) || defined (__CYGWIN__))
17813
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
697
17801
0b81d65d3c49 only fork and exec when starting gui
John W. Eaton <jwe@octave.org>
parents: 17789
diff changeset
698 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
699 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
700 install_signal_handlers ();
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
701
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
702 gui_pid = fork ();
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
703
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
704 if (gui_pid < 0)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
705 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
706 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
707
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
708 retval = 1;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
709 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
710 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
711 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
712 // Child.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
713
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
714 if (setsid () < 0)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
715 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
716 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
717
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
718 retval = 1;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
719 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
720
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
721 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
722 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
723 else
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
724 {
18007
25b6fbe82827 Make the CLI the default for the 3.8 release.
Rik <rik@octave.org>
parents: 18006
diff changeset
725 // Parent. Forward signals to child while waiting for it to exit.
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
726
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
727 int status;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
728
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
729 while (true)
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
730 {
17780
8b353af4a1ca allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents: 17778
diff changeset
731 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
732
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
733 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
734 {
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
735 int sig = caught_signal;
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
736
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
737 caught_signal = -1;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
738
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
739 kill (gui_pid, sig);
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
740 }
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
741 else if (WIFEXITED (status))
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
742 {
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
743 retval = WEXITSTATUS (status);
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
744 break;
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
745 }
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
746 else if (WIFSIGNALLED (status))
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
747 {
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
748 std::cerr << "octave exited with signal "
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
749 << 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
750 break;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
751 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
752 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
753 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
754 }
17801
0b81d65d3c49 only fork and exec when starting gui
John W. Eaton <jwe@octave.org>
parents: 17789
diff changeset
755 else
0b81d65d3c49 only fork and exec when starting gui
John W. Eaton <jwe@octave.org>
parents: 17789
diff changeset
756 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
757
17813
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
758 #else
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
759
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
760 retval = octave_exec (file, new_argv);
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
761
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
762 #endif
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
763
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
764 return retval;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
765 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
766
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
767 /*!
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
768 @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
769
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
770 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
771 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
772 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
773 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
774 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
775
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
776 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
777 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
778 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
779
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
780 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
781 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
782 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
783 */