Mercurial > octave
annotate src/main-gui.cc @ 22089:c2c668b3051b
use classes for octave application and interpreter
* main-cli.cc (main): Simplify using class objects.
* main-gui.cc (main): Likeiwse.
* octave.h, octave.cc (octave::cmdline_options, octave::application,
octave::cli_application, octave::embedded_application,
octave::interpreter): New classes. Replace ordinary functions and
static/global data with objects. Access global application data
through application object.
* octave-gui.h, octave-gui.cc (octave::gui_application): New class.
Replace ordinary functions and static/global data with objects.
* main-window.cc (main_window::m_app_context): New data member.
(main_window::main_window): Pass application object instead of
start_gui flag.
(main_window::construct_octave_qt_link): Pass m_app_context to
octave_qt_link constructor.
* octave-interpreter.h, octave-interpreter.cc
(octave_interpreter::m_app_context,
octave_interpreter::m_exit_status): New data members.
(octave_interpreter::execute): Use class object to start interpreter.
Save exit status.
* octave-qt-link.h, octave-qt-link.cc (octave_qt_link::m_app_context):
New data member.
(octave_qt_link::do_set_default_prompts): Make prompt settings
conditional on whether the GUI is running.
* input.h, input.cc (interactive, forced_interactive):
Delete global data.
* dirfns.cc, error.cc, input.cc, oct-stream.cc, pager.cc,
sighandlers.cc, sysdep.cc, toplev.cc, lex.ll: Access interactive and
forced_interactive through global application object.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 10 Jul 2016 07:15:21 -0400 |
parents | aba2e6293dd8 |
children | bac0d6f07a3e |
rev | line source |
---|---|
15139
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 /* |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17778
diff
changeset
|
3 Copyright (C) 2012-2015 John W. Eaton |
15139
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 This file is part of Octave. |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 Octave is free software; you can redistribute it and/or modify it |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 Free Software Foundation; either version 3 of the License, or (at your |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
10 option) any later version. |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 for more details. |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 */ |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21608
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
24 # include "config.h" |
15139
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 #endif |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 |
21608
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
27 #include <cstdlib> |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
28 |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
29 #include <iostream> |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
30 #include <string> |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
31 |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
32 #include "liboctave-build-info.h" |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
33 |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
34 #include "liboctinterp-build-info.h" |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
35 |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
36 #include "liboctgui-build-info.h" |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
37 |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
38 #include "oct-env.h" |
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
39 |
15262
ad1a980b0cb5
install default values before initializing interpreter (bug #37161)
John W. Eaton <jwe@octave.org>
parents:
15224
diff
changeset
|
40 #include "defaults.h" |
ad1a980b0cb5
install default values before initializing interpreter (bug #37161)
John W. Eaton <jwe@octave.org>
parents:
15224
diff
changeset
|
41 #include "octave.h" |
21608
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
42 #include "octave-build-info.h" |
15262
ad1a980b0cb5
install default values before initializing interpreter (bug #37161)
John W. Eaton <jwe@octave.org>
parents:
15224
diff
changeset
|
43 #include "octave-gui.h" |
15884
9ede91b3872b
do system-specific initialization before installing default variable values
John W. Eaton <jwe@octave.org>
parents:
15262
diff
changeset
|
44 #include "sysdep.h" |
15139
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 |
21608
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
46 static void |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
47 check_hg_versions (void) |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
48 { |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
49 bool ok = true; |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
50 |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
51 // Each library and executable has its own definition of the hg |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
52 // id. They should always match but may be different because of a |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
53 // botched installation or incorrect LD_LIBRARY_PATH or some other |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
54 // unusual problem. |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
55 |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
56 std::string octave_id = octave_hg_id (); |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
57 std::string liboctave_id = liboctave_hg_id (); |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
58 std::string liboctinterp_id = liboctinterp_hg_id (); |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
59 std::string liboctgui_id = liboctgui_hg_id (); |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
60 |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
61 if (octave_id != liboctave_id) |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
62 { |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
63 std::cerr << "octave hg id (" |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
64 << octave_id |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
65 << ") does not match liboctave hg id (" |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
66 << liboctave_id |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
67 << ")" << std::endl; |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
68 ok = false; |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
69 } |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
70 |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
71 if (octave_id != liboctinterp_id) |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
72 { |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
73 std::cerr << "octave hg id (" |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
74 << octave_id |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
75 << ") does not match liboctinterp hg id (" |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
76 << liboctinterp_id |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
77 << ")" << std::endl; |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
78 ok = false; |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
79 } |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
80 |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
81 if (octave_id != liboctgui_id) |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
82 { |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
83 std::cerr << "octave hg id (" |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
84 << octave_id |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
85 << ") does not match liboctgui hg id (" |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
86 << liboctgui_id |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
87 << ")" << std::endl; |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
88 ok = false; |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
89 } |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
90 |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
91 if (! ok) |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
92 exit (1); |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
93 } |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
94 |
15139
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
95 int |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
96 main (int argc, char **argv) |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
97 { |
21608
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
98 check_hg_versions (); |
80258bb3a14b
store hg id info in libgui and main exe and check for consistency (bug #45659)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
99 |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
100 octave::sys::env::set_program_name (argv[0]); |
16540
63b144e6a3d0
partially undo the changes in 9bc1f8278966
John W. Eaton <jwe@octave.org>
parents:
16528
diff
changeset
|
101 |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
102 octave::gui_application app (argc, argv); |
16540
63b144e6a3d0
partially undo the changes in 9bc1f8278966
John W. Eaton <jwe@octave.org>
parents:
16528
diff
changeset
|
103 |
22089
c2c668b3051b
use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
104 return app.execute (); |
17778
b5d58667d32d
new main program wrapper to handle giving up controlling tty
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
105 } |