annotate src/main.in.cc @ 29654:d13d090cb03a stable

use std::size_t and std::ptrdiff_t in C++ code (bug #60471) Files affected: make_int.cc, file-editor-tab.cc, octave-qscintilla.cc, Cell.cc, Cell.h, call-stack.cc, call-stack.h, cellfun.cc, data.cc, debug.cc, dlmread.cc, error.cc, event-queue.h, fcn-info.cc, fcn-info.h, file-io.cc, ft-text-renderer.cc, gl2ps-print.cc, graphics.cc, graphics.in.h, help.cc, hex2num.cc, input.cc, latex-text-renderer.cc, load-path.cc, load-save.cc, load-save.h, ls-hdf5.cc, ls-mat-ascii.cc, ls-mat5.cc, ls-oct-text.cc, mex.cc, mexproto.h, mxarray.h, oct-map.cc, oct-stream.cc, oct-stream.h, pager.cc, pager.h, pr-output.cc, regexp.cc, settings.h, stack-frame.cc, stack-frame.h, strfns.cc, syminfo.cc, symrec.h, symscope.cc, symscope.h, symtab.cc, sysdep.cc, toplev.cc, utils.cc, utils.h, variables.cc, __fltk_uigetfile__.cc, __init_fltk__.cc, audioread.cc, gzip.cc, cdef-class.cc, cdef-manager.cc, cdef-method.cc, cdef-object.cc, cdef-object.h, ov-base-diag.cc, ov-base-diag.h, ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.cc, ov-base-scalar.h, ov-base-sparse.h, ov-base.cc, ov-base.h, ov-cell.cc, ov-cell.h, ov-ch-mat.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-fcn-handle.cc, ov-java.cc, ov-lazy-idx.h, ov-perm.cc, ov-perm.h, ov-range.h, ov-str-mat.cc, ov-struct.cc, ov-struct.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, ovl.cc, octave.cc, bp-table.cc, jit-ir.cc, jit-ir.h, jit-typeinfo.cc, jit-typeinfo.h, jit-util.h, lex.h, lex.ll, oct-lvalue.cc, oct-parse.yy, parse.h, profiler.h, pt-eval.cc, pt-eval.h, pt-jit.cc, pt-jit.h, pt-pr-code.cc, pt-tm-const.cc, pt-tm-const.h, Array.h, CMatrix.cc, DiagArray2.h, PermMatrix.h, Sparse.h, dMatrix.cc, fCMatrix.cc, fMatrix.cc, bsxfun-defs.cc, oct-fftw.cc, oct-fftw.h, randpoisson.cc, sparse-chol.cc, mx-inlines.cc, file-ops.cc, lo-sysdep.cc, oct-env.cc, oct-time.cc, action-container.cc, action-container.h, base-list.h, caseless-str.h, cmd-edit.cc, cmd-hist.cc, data-conv.cc, data-conv.h, f77-fcn.h, file-info.cc, file-info.h, kpse.cc, kpse.h, lo-cutils.h, lo-hash.h, lo-regexp.cc, oct-base64.cc, oct-base64.h, oct-binmap.h, oct-glob.cc, oct-shlib.cc, oct-shlib.h, oct-sort.cc, oct-sparse.h, oct-string.cc, quit.cc, unwind-prot.h, url-transfer.cc, main.in.cc, mkoctfile.in.cc, and shared-fcns.h. (grafted from aef11bb4e6d1f303ad9de5688fcb7244ef48867e)
author John W. Eaton <jwe@octave.org>
date Wed, 28 Apr 2021 22:57:42 -0400
parents 0a5b15007766
children 32f4357ac8d9 dffd1c943f1a
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
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
3 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29191
diff changeset
5 // Copyright (C) 2012-2021 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
25 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
26 ////////////////////////////////////////////////////////////////////////
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 // 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
29 // 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
30 // 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
31 // 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
32 // 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
33 // liboctave or libinterp.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21440
diff changeset
35 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21286
diff changeset
36 # include "config.h"
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 #endif
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include <cstdlib>
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #include <cstring>
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 #include <algorithm>
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 #include <iostream>
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 #include <string>
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45
21927
6f62bd248919 use wrapper functions for mkoctfile and main
John W. Eaton <jwe@octave.org>
parents: 21921
diff changeset
46 #include "fcntl-wrappers.h"
21941
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
47 #include "signal-wrappers.h"
21927
6f62bd248919 use wrapper functions for mkoctfile and main
John W. Eaton <jwe@octave.org>
parents: 21921
diff changeset
48 #include "unistd-wrappers.h"
21921
ecfcc8527661 hide sys/wait.h header and provide wrappers for waitpid macros
John W. Eaton <jwe@octave.org>
parents: 21783
diff changeset
49 #include "wait-wrappers.h"
ecfcc8527661 hide sys/wait.h header and provide wrappers for waitpid macros
John W. Eaton <jwe@octave.org>
parents: 21783
diff changeset
50
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21440
diff changeset
51 #if ! defined (OCTAVE_VERSION)
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 20945
diff changeset
52 # define OCTAVE_VERSION %OCTAVE_VERSION%
18152
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
53 #endif
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
54
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21440
diff changeset
55 #if ! defined (OCTAVE_ARCHLIBDIR)
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 20945
diff changeset
56 # define OCTAVE_ARCHLIBDIR %OCTAVE_ARCHLIBDIR%
18163
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18152
diff changeset
57 #endif
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18152
diff changeset
58
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21440
diff changeset
59 #if ! defined (OCTAVE_BINDIR)
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 20945
diff changeset
60 # define OCTAVE_BINDIR %OCTAVE_BINDIR%
18152
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
61 #endif
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
62
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21440
diff changeset
63 #if ! defined (OCTAVE_PREFIX)
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 20945
diff changeset
64 # define OCTAVE_PREFIX %OCTAVE_PREFIX%
18152
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
65 #endif
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
66
23712
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
67 #if ! defined (OCTAVE_EXEC_PREFIX)
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
68 # define OCTAVE_EXEC_PREFIX %OCTAVE_EXEC_PREFIX%
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
69 #endif
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
70
19785
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
71 #include "display-available.h"
18360
f1ee47866e6b use common code to get OCTAVE_HOME in main, octave-config and mkoctfile
John W. Eaton <jwe@octave.org>
parents: 18163
diff changeset
72 #include "shared-fcns.h"
17782
136a9e27256e automatically locate wrapper binary on Windows systems (bug #40381)
John W. Eaton <jwe@octave.org>
parents: 17780
diff changeset
73
21979
d04da18a407a use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
74 #if defined (HAVE_OCTAVE_QT_GUI) && ! defined (OCTAVE_USE_WINDOWS_API)
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 // 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
77
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 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
79
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
80 static int caught_signal = -1;
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
81
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 static void
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 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
84 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 if (gui_pid > 0)
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
86 caught_signal = sig;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88
21941
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
89 static void
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
90 gui_driver_set_signal_handler (const char *signame,
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
91 octave_sig_handler *handler)
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 {
21941
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
93 octave_set_signal_handler_by_name (signame, handler, false);
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 static void
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 install_signal_handlers (void)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 {
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
99 // FIXME: do we need to handle and forward all the signals that Octave
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
100 // handles, or is it sufficient to only forward things like SIGINT,
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
101 // SIGBREAK, SIGABRT, SIGQUIT, and possibly a few others?
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
102
21941
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
103 gui_driver_set_signal_handler ("SIGINT", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
104 gui_driver_set_signal_handler ("SIGBREAK", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
105 gui_driver_set_signal_handler ("SIGABRT", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
106 gui_driver_set_signal_handler ("SIGALRM", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
107 gui_driver_set_signal_handler ("SIGBUS", gui_driver_sig_handler);
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 // SIGCHLD
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 // SIGCLD
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 // SIGCONT
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112
21941
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
113 gui_driver_set_signal_handler ("SIGEMT", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
114 gui_driver_set_signal_handler ("SIGFPE", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
115 gui_driver_set_signal_handler ("SIGHUP", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
116 gui_driver_set_signal_handler ("SIGILL", gui_driver_sig_handler);
17778
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 // SIGINFO
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 // SIGINT
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120
21941
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
121 gui_driver_set_signal_handler ("SIGIOT", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
122 gui_driver_set_signal_handler ("SIGLOST", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
123 gui_driver_set_signal_handler ("SIGPIPE", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
124 gui_driver_set_signal_handler ("SIGPOLL", gui_driver_sig_handler);
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 // SIGPROF
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 // SIGPWR
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128
21941
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
129 gui_driver_set_signal_handler ("SIGQUIT", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
130 gui_driver_set_signal_handler ("SIGSEGV", gui_driver_sig_handler);
17778
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 // SIGSTOP
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133
21941
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
134 gui_driver_set_signal_handler ("SIGSYS", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
135 gui_driver_set_signal_handler ("SIGTERM", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
136 gui_driver_set_signal_handler ("SIGTRAP", gui_driver_sig_handler);
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 // SIGTSTP
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139 // SIGTTIN
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140 // SIGTTOU
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141 // SIGURG
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142
21941
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
143 gui_driver_set_signal_handler ("SIGUSR1", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
144 gui_driver_set_signal_handler ("SIGUSR2", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
145 gui_driver_set_signal_handler ("SIGVTALRM", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
146 gui_driver_set_signal_handler ("SIGIO", gui_driver_sig_handler);
17778
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 // SIGWINCH
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149
21941
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
150 gui_driver_set_signal_handler ("SIGXCPU", gui_driver_sig_handler);
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
151 gui_driver_set_signal_handler ("SIGXFSZ", gui_driver_sig_handler);
17778
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
17813
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
154 #endif
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
155
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156 static std::string
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157 get_octave_bindir (void)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 // 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
160 // 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
161 // 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
162 // one originally configured.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
163
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
164 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
165
27934
49a0d90cd2a3 maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents: 27923
diff changeset
166 return obd.empty () ? prepend_octave_exec_home (std::string (OCTAVE_BINDIR))
49a0d90cd2a3 maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents: 27923
diff changeset
167 : obd;
17778
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
18163
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18152
diff changeset
170 static std::string
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18152
diff changeset
171 get_octave_archlibdir (void)
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18152
diff changeset
172 {
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18152
diff changeset
173 // Accept value from the environment literally, but substitute
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18152
diff changeset
174 // 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: 18152
diff changeset
175 // 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: 18152
diff changeset
176 // the one originally configured.
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18152
diff changeset
177
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18152
diff changeset
178 std::string dir = octave_getenv ("OCTAVE_ARCHLIBDIR");
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18152
diff changeset
179
23712
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
180 return dir.empty () ? prepend_octave_exec_home (std::string (OCTAVE_ARCHLIBDIR))
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19785
diff changeset
181 : dir;
18163
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18152
diff changeset
182 }
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18152
diff changeset
183
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184 static int
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185 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
186 {
21949
baeffde5c87d fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents: 21944
diff changeset
187 int status = octave_execv_wrapper (file.c_str (), argv);
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188
21949
baeffde5c87d fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents: 21944
diff changeset
189 std::cerr << argv[0] << ": failed to exec '" << file << "'" << std::endl;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190
21949
baeffde5c87d fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents: 21944
diff changeset
191 return status;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194 static char *
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195 strsave (const char *s)
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
197 if (! s)
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23767
diff changeset
198 return nullptr;
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 int len = strlen (s);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201 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
202 tmp = strcpy (tmp, s);
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203 return tmp;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206 int
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207 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
208 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209 int retval = 0;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
210
29189
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
211 int idx_gui = -1;
24898
91331c76d9c1 invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
212 bool start_gui = false;
18014
6df05f2fd354 maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents: 18008
diff changeset
213 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
214
29189
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
215 bool eval_code = false;
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
216 bool persist_octave = false;
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
217
23712
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
218 set_octave_home ();
b95c430c0649 revamp insertion of config variables into binaries and eliminate some macros
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
219
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
220 std::string octave_bindir = get_octave_bindir ();
18163
65e4e0569ed4 install octave-gui binary in libexec directory
John W. Eaton <jwe@octave.org>
parents: 18152
diff changeset
221 std::string octave_archlibdir = get_octave_archlibdir ();
21284
1bbd799ac7c7 Invoke correct version of octave-cli from main driver program
Mike Miller <mtmiller@octave.org>
parents: 19861
diff changeset
222 std::string octave_cli
1bbd799ac7c7 Invoke correct version of octave-cli from main driver program
Mike Miller <mtmiller@octave.org>
parents: 19861
diff changeset
223 = octave_bindir + dir_sep_char + "octave-cli-" OCTAVE_VERSION;
1bbd799ac7c7 Invoke correct version of octave-cli from main driver program
Mike Miller <mtmiller@octave.org>
parents: 19861
diff changeset
224 std::string octave_gui = octave_archlibdir + dir_sep_char + "octave-gui";
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225
21374
1487a68a496a untangle configuration of OpenGL, FLTK, and Qt (bug #47263)
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
226 #if defined (HAVE_OCTAVE_QT_GUI)
18164
eb51f47d9dee maint: Periodic merge of stable to gui-release.
John W. Eaton <jwe@octave.org>
parents: 18157 18163
diff changeset
227 // 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: 18157 18163
diff changeset
228 // octave_archlibdir directory name so we don't need to append it to
20713
2469d78a1d8b Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents: 19861
diff changeset
229 // the octave-gui filename.
18164
eb51f47d9dee maint: Periodic merge of stable to gui-release.
John W. Eaton <jwe@octave.org>
parents: 18157 18163
diff changeset
230
21284
1bbd799ac7c7 Invoke correct version of octave-cli from main driver program
Mike Miller <mtmiller@octave.org>
parents: 19861
diff changeset
231 std::string file = 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
232 #else
21284
1bbd799ac7c7 Invoke correct version of octave-cli from main driver program
Mike Miller <mtmiller@octave.org>
parents: 19861
diff changeset
233 std::string file = octave_cli;
18014
6df05f2fd354 maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents: 18008
diff changeset
234 #endif
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235
21440
062c65569ad7 avoid some address-sanitizer leak warnings (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21374
diff changeset
236 // Declaring new_argv static avoids leak warnings when using GCC's
062c65569ad7 avoid some address-sanitizer leak warnings (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 21374
diff changeset
237 // --address-sanitizer option.
29191
ae5d758c10e1 Increase size of dynamic variable new_argv by 1 to avoid indexing out of array.
Rik <rik@octave.org>
parents: 29189
diff changeset
238 static char **new_argv = new char * [argc + 2];
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
239
17959
1329866151be [Win32] Use spawn instead of exec for main octave wrapper executable.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17865
diff changeset
240 int k = 1;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
241
17994
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
242 bool warn_display = true;
21783
58a4c5633efd Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents: 21724
diff changeset
243 bool no_display = false;
17994
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
244
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
245 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
246 {
18014
6df05f2fd354 maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents: 18008
diff changeset
247 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
248 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
249 // 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
250 // 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
251 // 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
252 // 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
253 // 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
254
18014
6df05f2fd354 maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents: 18008
diff changeset
255 gui_libs = false;
21284
1bbd799ac7c7 Invoke correct version of octave-cli from main driver program
Mike Miller <mtmiller@octave.org>
parents: 19861
diff changeset
256 file = octave_cli;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
257 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
258 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
259 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
260 // 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
261 // don't have to create a child process and wait for it to
18152
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
262 // 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
263 // 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
264 // 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
265
18014
6df05f2fd354 maint: Back out changeset 25b6fbe82827 and set default to GUI for 4.0 release.
Rik <rik@octave.org>
parents: 18008
diff changeset
266 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
267 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
268 }
25187
9bb58f9580f4 restore proper handling of the --force-gui option (bug #53536)
Mike Miller <mtmiller@octave.org>
parents: 25068
diff changeset
269 else if (! strcmp (argv[i], "--gui") || ! strcmp (argv[i], "--force-gui"))
24898
91331c76d9c1 invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
270 {
91331c76d9c1 invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
271 // If we see this option, then we fork and exec octave with
91331c76d9c1 invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
272 // the --gui option, while continuing to handle signals in the
91331c76d9c1 invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
273 // terminal.
29189
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
274 // Do not copy the arg now, since we still not know if the
29191
ae5d758c10e1 Increase size of dynamic variable new_argv by 1 to avoid indexing out of array.
Rik <rik@octave.org>
parents: 29189
diff changeset
275 // gui should really be launched. Just store the index.
24898
91331c76d9c1 invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
276
29191
ae5d758c10e1 Increase size of dynamic variable new_argv by 1 to avoid indexing out of array.
Rik <rik@octave.org>
parents: 29189
diff changeset
277 start_gui = true;
29189
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
278 idx_gui = i;
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
279 }
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
280 else if (! strcmp (argv[i], "--persist"))
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
281 {
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
282 // FIXME: How can we reliably detect if this option appears
29191
ae5d758c10e1 Increase size of dynamic variable new_argv by 1 to avoid indexing out of array.
Rik <rik@octave.org>
parents: 29189
diff changeset
283 // after a FILE argument. In this case octave ignores
ae5d758c10e1 Increase size of dynamic variable new_argv by 1 to avoid indexing out of array.
Rik <rik@octave.org>
parents: 29189
diff changeset
284 // the option, but the GUI might still be launched if
29189
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
285 // --gui is also given.
29191
ae5d758c10e1 Increase size of dynamic variable new_argv by 1 to avoid indexing out of array.
Rik <rik@octave.org>
parents: 29189
diff changeset
286
29189
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
287 persist_octave = true;
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
288 new_argv[k++] = argv[i];
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
289 }
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
290 else if (! strcmp (argv[i], "--eval") ||
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
291 (strlen (argv[i]) > 0 && argv[i][0] != '-'))
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
292 {
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
293 eval_code = true;
24898
91331c76d9c1 invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
294 new_argv[k++] = argv[i];
91331c76d9c1 invert the logic for whether to start the GUI in the octave wrapper
Mike Miller <mtmiller@octave.org>
parents: 24534
diff changeset
295 }
23767
2387ce427601 improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents: 23712
diff changeset
296 else if (! strcmp (argv[i], "--silent") || ! strcmp (argv[i], "--quiet"))
18010
dc58d4810de6 main.in.cc: Respect --silent option and don't print startup message.
Rik <rik@octave.org>
parents: 18007
diff changeset
297 {
dc58d4810de6 main.in.cc: Respect --silent option and don't print startup message.
Rik <rik@octave.org>
parents: 18007
diff changeset
298 warn_display = false;
dc58d4810de6 main.in.cc: Respect --silent option and don't print startup message.
Rik <rik@octave.org>
parents: 18007
diff changeset
299 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
300 }
23767
2387ce427601 improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents: 23712
diff changeset
301 else if (! strcmp (argv[i], "--no-window-system"))
21783
58a4c5633efd Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents: 21724
diff changeset
302 {
58a4c5633efd Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents: 21724
diff changeset
303 no_display = true;
58a4c5633efd Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents: 21724
diff changeset
304 new_argv[k++] = argv[i];
58a4c5633efd Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents: 21724
diff changeset
305 }
23767
2387ce427601 improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents: 23712
diff changeset
306 else if (strlen (argv[i]) > 1 && argv[i][0] == '-' && argv[i][1] != '-')
2387ce427601 improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents: 23712
diff changeset
307 {
2387ce427601 improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents: 23712
diff changeset
308 // Handle all single-letter command line options here; they may
2387ce427601 improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents: 23712
diff changeset
309 // occur alone or may be aggregated into a single argument.
2387ce427601 improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents: 23712
diff changeset
310
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
311 std::size_t len = strlen (argv[i]);
23767
2387ce427601 improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents: 23712
diff changeset
312
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
313 for (std::size_t j = 1; j < len; j++)
23767
2387ce427601 improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents: 23712
diff changeset
314 switch (argv[i][j])
2387ce427601 improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents: 23712
diff changeset
315 {
27934
49a0d90cd2a3 maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents: 27923
diff changeset
316 case 'W':
49a0d90cd2a3 maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents: 27923
diff changeset
317 no_display = true;
49a0d90cd2a3 maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents: 27923
diff changeset
318 break;
49a0d90cd2a3 maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents: 27923
diff changeset
319 case 'q':
49a0d90cd2a3 maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents: 27923
diff changeset
320 warn_display = false;
49a0d90cd2a3 maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents: 27923
diff changeset
321 break;
49a0d90cd2a3 maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents: 27923
diff changeset
322 default:
49a0d90cd2a3 maint: Use Octave coding conventions in src/ directory.
Rik <rik@octave.org>
parents: 27923
diff changeset
323 break;
23767
2387ce427601 improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents: 23712
diff changeset
324 }
2387ce427601 improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents: 23712
diff changeset
325
2387ce427601 improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents: 23712
diff changeset
326 new_argv[k++] = argv[i];
2387ce427601 improve handling of single-letter command line options (bug #51461)
Mike Miller <mtmiller@octave.org>
parents: 23712
diff changeset
327 }
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
328 else
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
329 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
330 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
331
29189
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
332 if (start_gui && eval_code && ! persist_octave)
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
333 start_gui = false;
25068
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
334
29189
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
335 // At this point, we definitely know whether the gui has to
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
336 // be launched or not.
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
337 // gui_libs and start_gui are just about options, not
29191
ae5d758c10e1 Increase size of dynamic variable new_argv by 1 to avoid indexing out of array.
Rik <rik@octave.org>
parents: 29189
diff changeset
338 // the environment. Exit if they don't make sense.
25068
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
339 if (start_gui)
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
340 {
29189
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
341 // GUI should be started
25068
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
342 if (! gui_libs)
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
343 {
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
344 std::cerr << "octave: conflicting options: --no-gui-libs and --gui"
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
345 << std::endl;
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
346 return 1;
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
347 }
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
348
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
349 #if ! defined (HAVE_OCTAVE_QT_GUI)
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
350 std::cerr << "octave: GUI features missing or disabled in this build"
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
351 << std::endl;
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
352 return 1;
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
353 #endif
29189
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
354
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
355 // Finally, add --gui to the command line options. We can not
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
356 // just append it since options after a given file are ignored.
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
357 for (int j = k; j > 1; j--)
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
358 new_argv[j] = new_argv[j-1];
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
359
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
360 new_argv[1] = argv[idx_gui];
0fc400f15e35 avoid gui when octave is launched in non-interactive mode (bug #59628)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27934
diff changeset
361 k++;
25068
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
362 }
53440f9bffba disallow --gui option without GUI features (bug #53529)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
363
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23767
diff changeset
364 new_argv[k] = nullptr;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
365
21783
58a4c5633efd Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents: 21724
diff changeset
366 if (no_display)
58a4c5633efd Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents: 21724
diff changeset
367 {
58a4c5633efd Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents: 21724
diff changeset
368 start_gui = false;
58a4c5633efd Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents: 21724
diff changeset
369 gui_libs = false;
58a4c5633efd Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents: 21724
diff changeset
370
58a4c5633efd Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents: 21724
diff changeset
371 file = octave_cli;
58a4c5633efd Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents: 21724
diff changeset
372 }
58a4c5633efd Disable plotting graphics when --no-window-system used (bug #48017).
Rik <rik@octave.org>
parents: 21724
diff changeset
373 else if (gui_libs || start_gui)
17994
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
374 {
19785
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
375 int dpy_avail;
17994
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
376
19785
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
377 const char *display_check_err_msg = display_available (&dpy_avail);
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
378
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
379 if (! dpy_avail)
17994
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
380 {
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
381 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
382 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
383
21284
1bbd799ac7c7 Invoke correct version of octave-cli from main driver program
Mike Miller <mtmiller@octave.org>
parents: 19861
diff changeset
384 file = octave_cli;
17994
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
385
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
386 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
387 {
19785
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
388 if (! display_check_err_msg)
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
389 display_check_err_msg = "graphical display unavailable";
299fe39163a2 avoid C-style cast warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
390
17994
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
391 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
392 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
393 }
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
394 }
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
395 }
a99b7d656a6c start in CLI mode if display is not available (bug #40685)
John W. Eaton <jwe@octave.org>
parents: 17959
diff changeset
396
21979
d04da18a407a use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
397 #if defined (OCTAVE_USE_WINDOWS_API)
18152
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
398 file += ".exe";
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
399 #endif
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
400
91a3858ef8cf invoke versioned binaries from octave driver program (bug #40957)
John W. Eaton <jwe@octave.org>
parents: 18052
diff changeset
401 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
402
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
403 // The Octave interpreter may be multithreaded. If so, we attempt to
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
404 // ensure that signals are delivered to the main interpreter thread
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
405 // and no others by blocking signals before we exec the Octave
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
406 // interpreter executable. When that process starts, it will unblock
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
407 // signals in the main interpreter thread. When running the GUI as a
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
408 // subprocess, we also unblock signals that the parent process handles
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
409 // so we can forward them to the child.
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
410
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
411 octave_block_async_signals ();
26826
20881d195d20 fix handling of SIGTSTP (bug #51903)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
412 octave_block_signal_by_name ("SIGTSTP");
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
413
21979
d04da18a407a use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
414 #if defined (HAVE_OCTAVE_QT_GUI) && ! defined (OCTAVE_USE_WINDOWS_API)
17813
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
415
23194
c897282f1ec8 always fork and exec when starting the gui (bug #49609)
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
416 if (gui_libs && start_gui)
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
417 {
23194
c897282f1ec8 always fork and exec when starting the gui (bug #49609)
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
418 // Fork and exec when starting the GUI so that we will call
c897282f1ec8 always fork and exec when starting the gui (bug #49609)
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
419 // setsid to give up the controlling terminal (if any) and so that
c897282f1ec8 always fork and exec when starting the gui (bug #49609)
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
420 // the GUI process will be in a separate process group.
c897282f1ec8 always fork and exec when starting the gui (bug #49609)
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
421 //
c897282f1ec8 always fork and exec when starting the gui (bug #49609)
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
422 // The GUI process must be in a separate process group so that we
23196
b93e1d29790e * main.in.cc (main): Improve comment.
John W. Eaton <jwe@octave.org>
parents: 23194
diff changeset
423 // can send an interrupt signal to all child processes when
b93e1d29790e * main.in.cc (main): Improve comment.
John W. Eaton <jwe@octave.org>
parents: 23194
diff changeset
424 // interrupting the interpreter. See also bug #49609 and the
b93e1d29790e * main.in.cc (main): Improve comment.
John W. Eaton <jwe@octave.org>
parents: 23194
diff changeset
425 // function pthread_thread_manager::interrupt in the file
b93e1d29790e * main.in.cc (main): Improve comment.
John W. Eaton <jwe@octave.org>
parents: 23194
diff changeset
426 // libgui/src/thread-manager.cc.
23194
c897282f1ec8 always fork and exec when starting the gui (bug #49609)
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
427
21927
6f62bd248919 use wrapper functions for mkoctfile and main
John W. Eaton <jwe@octave.org>
parents: 21921
diff changeset
428 gui_pid = octave_fork_wrapper ();
17778
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 if (gui_pid < 0)
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 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
433
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
434 retval = 1;
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 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
437 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
438 // Child.
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
439
21927
6f62bd248919 use wrapper functions for mkoctfile and main
John W. Eaton <jwe@octave.org>
parents: 21921
diff changeset
440 if (octave_setsid_wrapper () < 0)
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
441 {
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
442 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
443
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
444 retval = 1;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
445 }
18722
f8203daed9d4 Abort Octave GUI if setsid() fails after fork().
Rik <rik@octave.org>
parents: 18361
diff changeset
446 else
f8203daed9d4 Abort Octave GUI if setsid() fails after fork().
Rik <rik@octave.org>
parents: 18361
diff changeset
447 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
448 }
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
449 else
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
450 {
18007
25b6fbe82827 Make the CLI the default for the 3.8 release.
Rik <rik@octave.org>
parents: 18006
diff changeset
451 // 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
452
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
453 install_signal_handlers ();
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
454
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
455 octave_unblock_async_signals ();
26826
20881d195d20 fix handling of SIGTSTP (bug #51903)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
456 octave_unblock_signal_by_name ("SIGTSTP");
24520
c5c11b07598a refactor signal handling (bug #52757)
John W. Eaton <jwe@octave.org>
parents: 24163
diff changeset
457
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
458 int status;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
459
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
460 while (true)
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
461 {
21921
ecfcc8527661 hide sys/wait.h header and provide wrappers for waitpid macros
John W. Eaton <jwe@octave.org>
parents: 21783
diff changeset
462 octave_waitpid_wrapper (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
463
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
464 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
465 {
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
466 int sig = caught_signal;
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
467
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
468 caught_signal = -1;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
469
21941
1d23b75cbcd1 hide signal.h from C++ sources
John W. Eaton <jwe@octave.org>
parents: 21927
diff changeset
470 octave_kill_wrapper (gui_pid, sig);
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
471 }
21921
ecfcc8527661 hide sys/wait.h header and provide wrappers for waitpid macros
John W. Eaton <jwe@octave.org>
parents: 21783
diff changeset
472 else if (octave_wifexited_wrapper (status))
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
473 {
21921
ecfcc8527661 hide sys/wait.h header and provide wrappers for waitpid macros
John W. Eaton <jwe@octave.org>
parents: 21783
diff changeset
474 retval = octave_wexitstatus_wrapper (status);
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
475 break;
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
476 }
21921
ecfcc8527661 hide sys/wait.h header and provide wrappers for waitpid macros
John W. Eaton <jwe@octave.org>
parents: 21783
diff changeset
477 else if (octave_wifsignaled_wrapper (status))
17865
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
478 {
dde06c2ac6c6 improve signal handling in driver program
John W. Eaton <jwe@octave.org>
parents: 17814
diff changeset
479 std::cerr << "octave exited with signal "
21921
ecfcc8527661 hide sys/wait.h header and provide wrappers for waitpid macros
John W. Eaton <jwe@octave.org>
parents: 21783
diff changeset
480 << octave_wtermsig_wrapper (status) << std::endl;
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
481 break;
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 }
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 }
17801
0b81d65d3c49 only fork and exec when starting gui
John W. Eaton <jwe@octave.org>
parents: 17789
diff changeset
486 else
21949
baeffde5c87d fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents: 21944
diff changeset
487 {
baeffde5c87d fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents: 21944
diff changeset
488 retval = octave_exec (file, new_argv);
baeffde5c87d fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents: 21944
diff changeset
489
baeffde5c87d fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents: 21944
diff changeset
490 if (retval < 0)
baeffde5c87d fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents: 21944
diff changeset
491 std::cerr << argv[0] << ": " << std::strerror (errno) << std::endl;
baeffde5c87d fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents: 21944
diff changeset
492 }
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
493
17813
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
494 #else
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
495
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
496 retval = octave_exec (file, new_argv);
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
497
21949
baeffde5c87d fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents: 21944
diff changeset
498 if (retval < 0)
baeffde5c87d fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents: 21944
diff changeset
499 std::cerr << argv[0] << ": " << std::strerror (errno) << std::endl;
baeffde5c87d fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents: 21944
diff changeset
500
17813
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
501 #endif
0a887758d1cc fix compilation of main.cc on Windows
John W. Eaton <jwe@octave.org>
parents: 17805
diff changeset
502
17778
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
503 return retval;
b5d58667d32d new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
diff changeset
504 }