Mercurial > octave
annotate src/main.in.cc @ 17784:7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
* src/Makefile.in: If building GUI, compile main.cc with
-DHAVE_OCTAVE_GUI.
* main.in.cc (main): If HAVE_OCTAVE_GUI is not defined, then simply
exec octave-cli.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 28 Oct 2013 16:38:46 -0400 |
parents | 136a9e27256e |
children | f2b047f9b605 |
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 |
17780
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
42 // From gnulib, so OK for Windows too. |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 #include <unistd.h> |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 |
17782
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
45 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
46 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
47 #define WIN32_LEAN_AND_MEAN |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
48 #include <tlhelp32.h> |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
49 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
50 static std::string |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
51 w32_get_octave_home (void) |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
52 { |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
53 std::string retval; |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
54 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
55 std::string bin_dir; |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
56 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
57 HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
58 #ifdef TH32CS_SNAPMODULE32 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
59 | TH32CS_SNAPMODULE32 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
60 #endif |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
61 , 0); |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
62 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
63 if (h != INVALID_HANDLE_VALUE) |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
64 { |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
65 MODULEENTRY32 mod_info; |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
66 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
67 ZeroMemory (&mod_info, sizeof (mod_info)); |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
68 mod_info.dwSize = sizeof (mod_info); |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
69 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
70 if (Module32First (h, &mod_info)) |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
71 { |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
72 do |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
73 { |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
74 std::string mod_name (mod_info.szModule); |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
75 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
76 if (mod_name.find ("octave") != std::string::npos) |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
77 { |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
78 bin_dir = mod_info.szExePath; |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
79 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
80 if (bin_dir[bin_dir.length () - 1] != '\\') |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
81 bin_dir.append (1, '\\'); |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
82 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
83 break; |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
84 } |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
85 } |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
86 while (Module32Next (h, &mod_info)); |
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 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
89 CloseHandle (h); |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
90 } |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
91 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
92 if (! bin_dir.empty ()) |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
93 { |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
94 size_t pos = bin_dir.rfind ("\\bin\\"); |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
95 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
96 if (pos != std::string::npos) |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
97 retval = bin_dir.substr (0, pos); |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
98 } |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
99 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
100 return retval; |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
101 } |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
102 |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
103 #endif |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
104 |
17784
7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents:
17782
diff
changeset
|
105 #if (defined (HAVE_OCTAVE_GUI) \ |
7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents:
17782
diff
changeset
|
106 && ! defined (__WIN32__) && ! defined (__CYGWIN__)) |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
107 |
17780
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
108 #include <sys/types.h> |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
109 #include <signal.h> |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
110 #include <fcntl.h> |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
111 |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
112 // This is a liboctave header, but it doesn't include any other Octave |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
113 // headers or declare any functions that are defined in liboctave. |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
114 #include "syswait.h" |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
115 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
116 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
|
117 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 // 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
|
119 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
120 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
|
121 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
122 static void |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
123 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
|
124 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
125 if (gui_pid > 0) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
126 kill (gui_pid, sig); |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
127 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
128 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
129 static sig_handler * |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
130 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
|
131 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
132 struct sigaction act, oact; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
133 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
134 act.sa_handler = handler; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
135 act.sa_flags = 0; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
136 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
137 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
|
138 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
|
139 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
140 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
|
141 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
142 return oact.sa_handler; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
143 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
144 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
145 static void |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
146 install_signal_handlers (void) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
147 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
148 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
149 #ifdef SIGINT |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
150 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
|
151 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
152 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
153 #ifdef SIGBREAK |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
154 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
|
155 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
156 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
157 #ifdef SIGABRT |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
158 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
|
159 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
160 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
161 #ifdef SIGALRM |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
162 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
|
163 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
164 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
165 #ifdef SIGBUS |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
166 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
|
167 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
168 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
169 // SIGCHLD |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
170 // SIGCLD |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
171 // SIGCONT |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
172 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
173 #ifdef SIGEMT |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
174 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
|
175 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
176 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
177 #ifdef SIGFPE |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
178 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
|
179 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
180 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
181 #ifdef SIGHUP |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
182 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
|
183 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
184 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
185 #ifdef SIGILL |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
186 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
|
187 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
188 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
189 // SIGINFO |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
190 // SIGINT |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
191 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
192 #ifdef SIGIOT |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
193 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
|
194 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
195 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
196 #ifdef SIGLOST |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
197 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
|
198 #endif |
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 #ifdef SIGPIPE |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
201 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
|
202 #endif |
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 #ifdef SIGPOLL |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
205 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
|
206 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
207 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
208 // SIGPROF |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
209 // SIGPWR |
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 #ifdef SIGQUIT |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
212 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
|
213 #endif |
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 #ifdef SIGSEGV |
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 (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
|
217 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
218 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
219 // SIGSTOP |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
220 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
221 #ifdef SIGSYS |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
222 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
|
223 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
224 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
225 #ifdef SIGTERM |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
226 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
|
227 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
228 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
229 #ifdef SIGTRAP |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
230 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
|
231 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
232 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
233 // SIGTSTP |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
234 // SIGTTIN |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
235 // SIGTTOU |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
236 // SIGURG |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
237 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
238 #ifdef SIGUSR1 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
239 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
|
240 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
241 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
242 #ifdef SIGUSR2 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
243 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
|
244 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
245 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
246 #ifdef SIGVTALRM |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
247 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
|
248 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
249 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
250 #ifdef SIGIO |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
251 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
|
252 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
253 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
254 // SIGWINCH |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
255 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
256 #ifdef SIGXCPU |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
257 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
|
258 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
259 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
260 #ifdef SIGXFSZ |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
261 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
|
262 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
263 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
264 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
265 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
266 static int |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
267 have_controlling_terminal (void) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
268 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
269 int retval = 0; |
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 #if ! (defined (__WIN32__) || defined (__APPLE__)) || defined (__CYGWIN__) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
272 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
273 #if defined (HAVE_CTERMID) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
274 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
|
275 #else |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
276 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
|
277 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
278 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
279 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
|
280 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
281 if (fd >= 0) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
282 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
283 gnulib::close (fd); |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
284 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
285 retval = 1; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
286 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
287 |
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 return retval; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
291 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
292 |
17780
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
293 #endif |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
294 |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
295 #ifndef OCTAVE_BINDIR |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
296 #define OCTAVE_BINDIR %OCTAVE_BINDIR% |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
297 #endif |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
298 |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
299 #ifndef OCTAVE_PREFIX |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
300 #define OCTAVE_PREFIX %OCTAVE_PREFIX% |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
301 #endif |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
302 |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
303 // 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
|
304 // installed. |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
305 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
306 #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
|
307 && ! 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
|
308 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
|
309 #else |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
310 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
|
311 #endif |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
312 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
313 static std::string |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
314 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
|
315 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
316 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
|
317 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
318 return value ? value : ""; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
319 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
320 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
321 static std::string |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
322 get_octave_home (void) |
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 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
|
325 |
17782
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
326 #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
|
327 if (oh.empty ()) |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
328 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
|
329 #endif |
136a9e27256e
automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents:
17780
diff
changeset
|
330 |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
331 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
|
332 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
333 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
334 static std::string |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
335 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
|
336 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
337 std::string retval; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
338 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
339 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
|
340 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
341 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
|
342 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
343 retval = s; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
344 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
345 if (octave_home != prefix) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
346 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
347 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
|
348 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
349 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
|
350 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
|
351 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
352 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
353 if (dir_sep_char != '/') |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
354 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
|
355 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
356 return retval; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
357 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
358 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
359 static std::string |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
360 get_octave_bindir (void) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
361 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
362 // 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
|
363 // 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
|
364 // 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
|
365 // one originally configured. |
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 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
|
368 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
369 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
|
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 static int |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
373 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
|
374 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
375 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
|
376 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
377 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
|
378 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
379 return 1; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
380 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
381 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
382 static char * |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
383 strsave (const char *s) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
384 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
385 if (! s) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
386 return 0; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
387 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
388 int len = strlen (s); |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
389 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
|
390 tmp = strcpy (tmp, s); |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
391 return tmp; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
392 } |
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 int |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
395 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
|
396 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
397 int retval = 0; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
398 |
17784
7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents:
17782
diff
changeset
|
399 #if defined (HAVE_OCTAVE_GUI) |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
400 bool start_gui = true; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
401 bool cli_only = false; |
17784
7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents:
17782
diff
changeset
|
402 #endif |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
403 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
404 std::string octave_bindir = get_octave_bindir (); |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
405 |
17784
7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents:
17782
diff
changeset
|
406 std::string file = octave_bindir + dir_sep_char; |
7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents:
17782
diff
changeset
|
407 |
7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents:
17782
diff
changeset
|
408 #if defined (HAVE_OCTAVE_GUI) |
7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents:
17782
diff
changeset
|
409 file += "octave-gui"; |
7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents:
17782
diff
changeset
|
410 #else |
7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents:
17782
diff
changeset
|
411 file += "octave-cli"; |
7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents:
17782
diff
changeset
|
412 #endif |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
413 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
414 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
|
415 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
416 int k = 0; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
417 new_argv[k++] = strsave ("octave"); |
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 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
|
420 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
421 if (! strcmp (argv[i], "--no-gui-libs")) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
422 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
423 // 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
|
424 // 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
|
425 // 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
|
426 // 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
|
427 // 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
|
428 |
17784
7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents:
17782
diff
changeset
|
429 #if defined (HAVE_OCTAVE_GUI) |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
430 cli_only = true; |
17784
7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents:
17782
diff
changeset
|
431 #endif |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
432 file = octave_bindir + dir_sep_char + "octave-cli"; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
433 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
434 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
|
435 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
436 // 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
|
437 // don't have to create a child process and wait for it to |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
438 // exit. But do exec "octave", not "octave-cli", because even |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
439 // if the --no-gui option is given, we may be asked to do some |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
440 // plotting or ui* calls. |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
441 |
17784
7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents:
17782
diff
changeset
|
442 #if defined (HAVE_OCTAVE_GUI) |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
443 start_gui = false; |
17784
7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents:
17782
diff
changeset
|
444 #endif |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
445 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
|
446 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
447 else |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
448 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
|
449 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
450 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
451 new_argv[k] = 0; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
452 |
17784
7ae9bc04ec07
allow octave binary to work if building GUI is disabled (bug #40395)
John W. Eaton <jwe@octave.org>
parents:
17782
diff
changeset
|
453 #if ! defined (HAVE_OCTAVE_GUI) || defined (__WIN32__) || defined (__CYGWIN__) |
17780
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
454 |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
455 retval = octave_exec (file, new_argv); |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
456 |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
457 #else |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
458 |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
459 if (cli_only || (! 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
|
460 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
461 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
|
462 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
463 else |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
464 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
465 install_signal_handlers (); |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
466 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
467 gui_pid = fork (); |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
468 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
469 if (gui_pid < 0) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
470 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
471 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
|
472 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
473 retval = 1; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
474 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
475 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
|
476 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
477 // Child. |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
478 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
479 if (setsid () < 0) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
480 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
481 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
|
482 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
483 retval = 1; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
484 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
485 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
486 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
|
487 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
488 else |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
489 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
490 // Parent. Forward signals to the child while waiting for it |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
491 // to exit. |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
492 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
493 int status; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
494 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
495 while (1) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
496 { |
17780
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
497 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
|
498 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
499 if (WIFEXITED (status)) |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
500 { |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
501 retval = WIFEXITED (status) ? WEXITSTATUS (status) : 127; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
502 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
503 break; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
504 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
505 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
506 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
507 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
508 |
17780
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
509 #endif |
8b353af4a1ca
allow octave main program to work on Windows systems
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
510 |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
511 return retval; |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
512 } |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
513 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
514 /*! |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
515 @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
|
516 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
517 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
|
518 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
|
519 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
|
520 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
|
521 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
|
522 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
523 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
|
524 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
|
525 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
|
526 |
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
527 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
|
528 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
|
529 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
|
530 */ |