Mercurial > octave
annotate libinterp/octave.cc @ 17755:9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
* load-save.h, load-save.cc (octave_prepare_hdf5,
octave_finalize_hdf5): New functions.
* octave.cc (octave_execute_interpreter): Call octave_prepare_hdf5.
* toplev.cc (do_octave_atexit): Call octave_finalize_hdf5.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 24 Oct 2013 17:13:02 -0400 |
parents | d63878346099 |
children | ae8905fbf1f8 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17570
diff
changeset
|
3 Copyright (C) 1993-2013 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1 | 20 |
21 */ | |
22 | |
23 // Born February 20, 1992. | |
24 | |
240 | 25 #ifdef HAVE_CONFIG_H |
1192 | 26 #include <config.h> |
1 | 27 #endif |
28 | |
1355 | 29 #include <cassert> |
30 #include <cstdlib> | |
31 #include <cstring> | |
32 #include <ctime> | |
33 | |
3503 | 34 #include <iostream> |
1355 | 35 |
17570
1c7d768c3847
don't fork if there is no controlling tty
John W. Eaton <jwe@octave.org>
parents:
17568
diff
changeset
|
36 #include <fcntl.h> |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
37 #include <getopt.h> |
12335
6e9f100c0d61
include <unistd.h> in octave.cc
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
38 #include <sys/types.h> |
6e9f100c0d61
include <unistd.h> in octave.cc
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
39 #include <unistd.h> |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
40 |
2926 | 41 #include "cmd-edit.h" |
3690 | 42 #include "f77-fcn.h" |
4097 | 43 #include "file-ops.h" |
2926 | 44 #include "file-stat.h" |
240 | 45 #include "lo-error.h" |
2926 | 46 #include "oct-env.h" |
1907 | 47 #include "str-vec.h" |
223 | 48 |
15475
da6c37ed0b42
eliminate calls to bind_internal_variable when setting --traditional options
John W. Eaton <jwe@octave.org>
parents:
15474
diff
changeset
|
49 #include "builtins.h" |
15262
ad1a980b0cb5
install default values before initializing interpreter (bug #37161)
John W. Eaton <jwe@octave.org>
parents:
15244
diff
changeset
|
50 #include "defaults.h" |
3933 | 51 #include "Cell.h" |
1355 | 52 #include "defun.h" |
9335
f2d354df53ee
new option, --no-window-system
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
53 #include "display.h" |
1355 | 54 #include "error.h" |
55 #include "file-io.h" | |
15473
457a2ff2a71b
set Vinfo_file and Vinfo_program variables directly from command line options
John W. Eaton <jwe@octave.org>
parents:
15472
diff
changeset
|
56 #include "help.h" |
1 | 57 #include "input.h" |
58 #include "lex.h" | |
5832 | 59 #include "load-path.h" |
17755
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
60 #include "load-save.h" |
4113 | 61 #include "octave.h" |
15139
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
62 #include "oct-conf.h" |
1742 | 63 #include "oct-hist.h" |
5654 | 64 #include "oct-map.h" |
13281
834f904a3dcb
Add support for full asynchronous graphics toolkit running in a separate
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13239
diff
changeset
|
65 #include "oct-mutex.h" |
3195 | 66 #include "oct-obj.h" |
2375 | 67 #include "ops.h" |
10613
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10605
diff
changeset
|
68 #include "ov.h" |
e103fb2182ce
use internal variable instead of warning state to control whether to allow non-integer ranges as indices
John W. Eaton <jwe@octave.org>
parents:
10605
diff
changeset
|
69 #include "ov-range.h" |
1670 | 70 #include "toplev.h" |
1 | 71 #include "parse.h" |
562 | 72 #include "procstream.h" |
1355 | 73 #include "sighandlers.h" |
74 #include "sysdep.h" | |
1 | 75 #include "unwind-prot.h" |
1355 | 76 #include "utils.h" |
77 #include "variables.h" | |
2492 | 78 #include <version.h> |
1 | 79 |
4159 | 80 // Kluge. |
5990 | 81 extern "C" F77_RET_T |
11518 | 82 F77_FUNC (xerbla, XERBLA) (F77_CONST_CHAR_ARG_DECL, |
83 const octave_idx_type& | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
84 F77_CHAR_ARG_LEN_DECL); |
4159 | 85 |
2910 | 86 extern void install_builtins (void); |
87 | |
15137
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
88 int octave_cmdline_argc; |
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
89 char **octave_cmdline_argv; |
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
90 int octave_embedded; |
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
91 |
1907 | 92 // The command-line options. |
93 static string_vector octave_argv; | |
1 | 94 |
5780 | 95 // The name used to invoke Octave. |
96 static std::string | |
97 octave_program_invocation_name; | |
98 | |
99 // The last component of octave_program_invocation_name. | |
100 static std::string octave_program_name; | |
101 | |
16210
78365c56a762
make global line_editing variable static in octave.cc
John W. Eaton <jwe@octave.org>
parents:
16208
diff
changeset
|
102 // TRUE means we are using readline. |
78365c56a762
make global line_editing variable static in octave.cc
John W. Eaton <jwe@octave.org>
parents:
16208
diff
changeset
|
103 // (--no-line-editing) |
78365c56a762
make global line_editing variable static in octave.cc
John W. Eaton <jwe@octave.org>
parents:
16208
diff
changeset
|
104 static bool line_editing = true; |
78365c56a762
make global line_editing variable static in octave.cc
John W. Eaton <jwe@octave.org>
parents:
16208
diff
changeset
|
105 |
2239 | 106 // TRUE means we read ~/.octaverc and ./.octaverc. |
107 // (--norc; --no-init-file; -f) | |
108 static bool read_init_files = true; | |
109 | |
110 // TRUE means we read the site-wide octaverc files. | |
111 // (--norc; --no-site-file; -f) | |
2240 | 112 static bool read_site_files = true; |
1 | 113 |
6365 | 114 // TRUE means we set the initial path to configured defaults. |
9132
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
115 // (--no-init-path) |
6365 | 116 static bool set_initial_path = true; |
117 | |
3019 | 118 // TRUE means we don't print the usual startup message. |
616 | 119 // (--quiet; --silent; -q) |
2239 | 120 static bool inhibit_startup_message = false; |
1 | 121 |
3019 | 122 // If TRUE, print verbose info in some cases. |
1825 | 123 // (--verbose; -V) |
2239 | 124 static bool verbose_flag = false; |
1825 | 125 |
15139
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
126 // If TRUE, force the GUI to start. |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
127 // (--force-gui) |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
128 static bool force_gui_option = false; |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
129 |
17568
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
130 // If TRUE don't fork when starting the GUI. |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
131 // (--no-fork) |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
132 static bool no_fork_option = false; |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
133 |
15139
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
134 // If TRUE don't start the GUI. |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
135 // (--no-gui) |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
136 static bool no_gui_option = false; |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
137 |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
138 // If TRUE, force readline command line editing. |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
139 // (--line-editing) |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
140 static bool forced_line_editing = false; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
141 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
142 // If TRUE, initialize history list from saved history file. |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
143 // (--no-history; -H) |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
144 static bool read_history_file = true; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
145 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
146 // The value of "path" specified on the command line. |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
147 // (--path; -p) |
15225
2d337a9869e9
correctly handle multiple --path command line arguments
John W. Eaton <jwe@octave.org>
parents:
15224
diff
changeset
|
148 static std::list<std::string> command_line_path; |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
149 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
150 // The value for "EXEC_PATH" specified on the command line. |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
151 // (--exec-path) |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
152 static std::string exec_path; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
153 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
154 // The value for "IMAGE_PATH" specified on the command line. |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
155 // (--image-path) |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
156 static std::string image_path; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
157 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
158 // If TRUE, ignore the window system even if it is available. |
16774
8d188159ce5f
Add -W command line option to disable window system (bug #38937)
Rik <rik@octave.org>
parents:
16753
diff
changeset
|
159 // (--no-window-system, -W) |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
160 static bool no_window_system = false; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
161 |
1 | 162 // Usage message |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
163 static const char *usage_string = |
16877
5482cd26311a
Rename enable_jit_compiler to jit_enable, enable_jit_debugging to debug_jit.
Rik <rik@octave.org>
parents:
16876
diff
changeset
|
164 "octave [-HVWdfhiqvx] [--debug] [--debug-jit] [--doc-cache-file file]\n\ |
16793
cc1657be1ee7
Rename cmdline option --jit-debugging to --jit-debug.
Rik <rik@octave.org>
parents:
16774
diff
changeset
|
165 [--echo-commands] [--eval CODE] [--exec-path path]\n\ |
cc1657be1ee7
Rename cmdline option --jit-debugging to --jit-debug.
Rik <rik@octave.org>
parents:
16774
diff
changeset
|
166 [--force-gui] [--help] [--image-path path]\n\ |
15139
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
167 [--info-file file] [--info-program prog] [--interactive]\n\ |
17568
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
168 [--line-editing] [--no-fork] [--no-gui] [--no-history]\n\ |
15310
b055fc077224
allow jit compiler to be enabled at run-time
John W. Eaton <jwe@octave.org>
parents:
15290
diff
changeset
|
169 [--no-init-file] [--no-init-path] [--no-jit-compiler]\n\ |
b055fc077224
allow jit compiler to be enabled at run-time
John W. Eaton <jwe@octave.org>
parents:
15290
diff
changeset
|
170 [--no-line-editing] [--no-site-file] [--no-window-system]\n\ |
16793
cc1657be1ee7
Rename cmdline option --jit-debugging to --jit-debug.
Rik <rik@octave.org>
parents:
16774
diff
changeset
|
171 [--norc] [-p path] [--path path] [--persist] [--silent]\n\ |
cc1657be1ee7
Rename cmdline option --jit-debugging to --jit-debug.
Rik <rik@octave.org>
parents:
16774
diff
changeset
|
172 [--traditional] [--verbose] [--version] [file]"; |
1 | 173 |
1358 | 174 // This is here so that it's more likely that the usage message and |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14160
diff
changeset
|
175 // the real set of options will agree. Note: the '+' must come first |
1410 | 176 // to prevent getopt from permuting arguments! |
16774
8d188159ce5f
Add -W command line option to disable window system (bug #38937)
Rik <rik@octave.org>
parents:
16753
diff
changeset
|
177 static const char *short_opts = "+HWVdfhip:qvx"; |
139 | 178 |
5189 | 179 // The code to evaluate at startup (--eval CODE) |
180 static std::string code_to_eval; | |
181 | |
182 // If TRUE, don't exit after evaluating code given by --eval option. | |
183 static bool persist = false; | |
4356 | 184 |
15702
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
185 // If TRUE, the GUI should be started. |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
186 static bool start_gui = false; |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
187 |
16528
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16485
diff
changeset
|
188 // If TRUE use traditional settings (--traditional) |
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16485
diff
changeset
|
189 static bool traditional = false; |
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16485
diff
changeset
|
190 |
1103 | 191 // Long options. See the comments in getopt.h for the meanings of the |
192 // fields in this structure. | |
15470
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
193 #define BUILT_IN_DOCSTRINGS_FILE_OPTION 1 |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
194 #define DOC_CACHE_FILE_OPTION 2 |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
195 #define EVAL_OPTION 3 |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
196 #define EXEC_PATH_OPTION 4 |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
197 #define FORCE_GUI_OPTION 5 |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
198 #define IMAGE_PATH_OPTION 6 |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
199 #define INFO_FILE_OPTION 7 |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
200 #define INFO_PROG_OPTION 8 |
16877
5482cd26311a
Rename enable_jit_compiler to jit_enable, enable_jit_debugging to debug_jit.
Rik <rik@octave.org>
parents:
16876
diff
changeset
|
201 #define DEBUG_JIT_OPTION 9 |
15470
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
202 #define LINE_EDITING_OPTION 10 |
17568
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
203 #define NO_FORK_OPTION 11 |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
204 #define NO_GUI_OPTION 12 |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
205 #define NO_INIT_FILE_OPTION 13 |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
206 #define NO_INIT_PATH_OPTION 14 |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
207 #define NO_JIT_COMPILER_OPTION 15 |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
208 #define NO_LINE_EDITING_OPTION 16 |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
209 #define NO_SITE_FILE_OPTION 17 |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
210 #define PERSIST_OPTION 18 |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
211 #define TEXI_MACROS_FILE_OPTION 19 |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
212 #define TRADITIONAL_OPTION 20 |
15470
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
213 struct option long_opts[] = { |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
214 { "braindead", no_argument, 0, TRADITIONAL_OPTION }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
215 { "built-in-docstrings-file", required_argument, 0, BUILT_IN_DOCSTRINGS_FILE_OPTION }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
216 { "debug", no_argument, 0, 'd' }, |
16877
5482cd26311a
Rename enable_jit_compiler to jit_enable, enable_jit_debugging to debug_jit.
Rik <rik@octave.org>
parents:
16876
diff
changeset
|
217 { "debug-jit", no_argument, 0, DEBUG_JIT_OPTION }, |
15470
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
218 { "doc-cache-file", required_argument, 0, DOC_CACHE_FILE_OPTION }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
219 { "echo-commands", no_argument, 0, 'x' }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
220 { "eval", required_argument, 0, EVAL_OPTION }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
221 { "exec-path", required_argument, 0, EXEC_PATH_OPTION }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
222 { "force-gui", no_argument, 0, FORCE_GUI_OPTION }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
223 { "help", no_argument, 0, 'h' }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
224 { "image-path", required_argument, 0, IMAGE_PATH_OPTION }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
225 { "info-file", required_argument, 0, INFO_FILE_OPTION }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
226 { "info-program", required_argument, 0, INFO_PROG_OPTION }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
227 { "interactive", no_argument, 0, 'i' }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
228 { "line-editing", no_argument, 0, LINE_EDITING_OPTION }, |
17568
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
229 { "no-fork", no_argument, 0, NO_FORK_OPTION }, |
15470
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
230 { "no-gui", no_argument, 0, NO_GUI_OPTION }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
231 { "no-history", no_argument, 0, 'H' }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
232 { "no-init-file", no_argument, 0, NO_INIT_FILE_OPTION }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
233 { "no-init-path", no_argument, 0, NO_INIT_PATH_OPTION }, |
15472
c8c828276b69
* octave.cc (long_opts): Use --no-jit-compiler to match docs.
John W. Eaton <jwe@octave.org>
parents:
15470
diff
changeset
|
234 { "no-jit-compiler", no_argument, 0, NO_JIT_COMPILER_OPTION }, |
15470
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
235 { "no-line-editing", no_argument, 0, NO_LINE_EDITING_OPTION }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
236 { "no-site-file", no_argument, 0, NO_SITE_FILE_OPTION }, |
16774
8d188159ce5f
Add -W command line option to disable window system (bug #38937)
Rik <rik@octave.org>
parents:
16753
diff
changeset
|
237 { "no-window-system", no_argument, 0, 'W' }, |
15470
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
238 { "norc", no_argument, 0, 'f' }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
239 { "path", required_argument, 0, 'p' }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
240 { "persist", no_argument, 0, PERSIST_OPTION }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
241 { "quiet", no_argument, 0, 'q' }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
242 { "silent", no_argument, 0, 'q' }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
243 { "texi-macros-file", required_argument, 0, TEXI_MACROS_FILE_OPTION }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
244 { "traditional", no_argument, 0, TRADITIONAL_OPTION }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
245 { "verbose", no_argument, 0, 'V' }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
246 { "version", no_argument, 0, 'v' }, |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
247 { 0, 0, 0, 0 } |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
248 }; |
1 | 249 |
1355 | 250 // Store the command-line options for later use. |
251 | |
252 static void | |
253 intern_argv (int argc, char **argv) | |
254 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
255 assert (symbol_table::at_top_level ()); |
4892 | 256 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16210
diff
changeset
|
257 symbol_table::assign (".nargin.", argc - 1); |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
258 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
259 symbol_table::mark_hidden (".nargin."); |
3195 | 260 |
10485
b4e14e628fc9
Truncate argv() for scripts used without command line parameters. Bug #29423
Judd Storrs <jstorrs@gmail.com>
parents:
10370
diff
changeset
|
261 if (argc > 0) |
1355 | 262 { |
7336 | 263 octave_argv.resize (argc - 1); |
3933 | 264 |
2495 | 265 // Skip program name in argv. |
3933 | 266 int i = argc; |
267 while (--i > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
268 octave_argv[i-1] = *(argv+i); |
1355 | 269 } |
270 } | |
271 | |
5654 | 272 DEFUN (__version_info__, args, , |
273 "-*- texinfo -*-\n\ | |
6678 | 274 @deftypefn {Built-in Function} {retval =} __version_info__ (@var{name}, @var{version}, @var{release}, @var{date})\n\ |
6945 | 275 Undocumented internal function.\n\ |
5654 | 276 @end deftypefn") |
277 { | |
278 octave_value retval; | |
279 | |
11066
e678346a47d9
toplev.cc, sighandlers.cc, utils.cc, octave.cc, pt-eval.cc pt-idx.cc: Octave_map to octave_map and octave_scalar_map conversion
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
280 static octave_map vinfo; |
5654 | 281 |
282 int nargin = args.length (); | |
283 | |
5658 | 284 if (nargin == 4) |
5654 | 285 { |
6639 | 286 if (vinfo.nfields () == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
287 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
288 vinfo.assign ("Name", args (0)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
289 vinfo.assign ("Version", args (1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
290 vinfo.assign ("Release", args (2)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
291 vinfo.assign ("Date", args (3)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
292 } |
5781 | 293 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
294 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
295 octave_idx_type n = vinfo.numel () + 1; |
5654 | 296 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
297 vinfo.resize (dim_vector (n, 1)); |
5781 | 298 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
299 octave_value idx (n); |
5781 | 300 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
301 vinfo.assign (idx, "Name", Cell (octave_value (args (0)))); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
302 vinfo.assign (idx, "Version", Cell (octave_value (args (1)))); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
303 vinfo.assign (idx, "Release", Cell (octave_value (args (2)))); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
304 vinfo.assign (idx, "Date", Cell (octave_value (args (3)))); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
305 } |
5654 | 306 } |
307 else if (nargin == 0) | |
308 retval = vinfo; | |
309 else | |
5823 | 310 print_usage (); |
5654 | 311 |
312 return retval; | |
313 } | |
314 | |
315 static void | |
316 initialize_version_info (void) | |
317 { | |
318 octave_value_list args; | |
319 | |
5658 | 320 args(3) = OCTAVE_RELEASE_DATE; |
321 args(2) = OCTAVE_RELEASE; | |
5654 | 322 args(1) = OCTAVE_VERSION; |
323 args(0) = "GNU Octave"; | |
324 | |
325 F__version_info__ (args, 0); | |
326 } | |
327 | |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
328 static void |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
329 gripe_safe_source_exception (const std::string& file, const std::string& msg) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
330 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
331 std::cerr << "error: " << msg << "\n" |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
332 << "error: execution of " << file << " failed\n" |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
333 << "error: trying to make my way to a command prompt" |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
334 << std::endl; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
335 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
336 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
337 // Execute commands from a file and catch potential exceptions in a |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
338 // consistent way. This function should be called anywhere we might |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
339 // parse and execute commands from a file before before we have entered |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
340 // the main loop in toplev.cc. |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
341 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
342 static void |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
343 safe_source_file (const std::string& file_name, |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
344 const std::string& context = std::string (), |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
345 bool verbose = false, bool require_file = true, |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
346 const std::string& warn_for = std::string ()) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
347 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
348 try |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
349 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
350 source_file (file_name, context, verbose, require_file, warn_for); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
351 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
352 catch (octave_interrupt_exception) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
353 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
354 recover_from_exception (); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
355 octave_stdout << "\n"; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
356 if (quitting_gracefully) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
357 clean_up_and_exit (exit_status); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
358 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
359 catch (octave_execution_exception) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
360 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
361 recover_from_exception (); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
362 gripe_safe_source_exception (file_name, "unhandled execution exception"); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
363 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
364 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
365 |
581 | 366 // Initialize by reading startup files. |
367 | |
1 | 368 static void |
369 execute_startup_files (void) | |
370 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
371 unwind_protect frame; |
315 | 372 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
373 std::string context; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
374 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
375 bool verbose = (verbose_flag && ! inhibit_startup_message); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
376 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
377 bool require_file = false; |
578 | 378 |
2239 | 379 if (read_site_files) |
1 | 380 { |
2239 | 381 // Execute commands from the site-wide configuration file. |
382 // First from the file $(prefix)/lib/octave/site/m/octaverc | |
383 // (if it exists), then from the file | |
3597 | 384 // $(prefix)/share/octave/$(version)/m/octaverc (if it exists). |
1755 | 385 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
386 safe_source_file (Vlocal_site_defaults_file, context, verbose, |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
387 require_file); |
1755 | 388 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
389 safe_source_file (Vsite_defaults_file, context, verbose, require_file); |
1 | 390 } |
391 | |
2239 | 392 if (read_init_files) |
393 { | |
2512 | 394 // Try to execute commands from $HOME/$OCTAVE_INITFILE and |
395 // $OCTAVE_INITFILE. If $OCTAVE_INITFILE is not set, .octaverc | |
396 // is assumed. | |
2239 | 397 |
4804 | 398 bool home_rc_already_executed = false; |
2512 | 399 |
3523 | 400 std::string initfile = octave_env::getenv ("OCTAVE_INITFILE"); |
2512 | 401 |
2926 | 402 if (initfile.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
403 initfile = ".octaverc"; |
2512 | 404 |
3523 | 405 std::string home_dir = octave_env::get_home_directory (); |
2926 | 406 |
4804 | 407 std::string home_rc = octave_env::make_absolute (initfile, home_dir); |
408 | |
409 std::string local_rc; | |
2239 | 410 |
5781 | 411 if (! home_rc.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
412 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
413 safe_source_file (home_rc, context, verbose, require_file); |
2239 | 414 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
415 // Names alone are not enough. |
2239 | 416 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
417 file_stat fs_home_rc (home_rc); |
2239 | 418 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
419 if (fs_home_rc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
420 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
421 // We want to check for curr_dir after executing home_rc |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
422 // because doing that may change the working directory. |
4804 | 423 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
424 local_rc = octave_env::make_absolute (initfile); |
4804 | 425 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
426 home_rc_already_executed = same_file (home_rc, local_rc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
427 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
428 } |
2239 | 429 |
430 if (! home_rc_already_executed) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
431 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
432 if (local_rc.empty ()) |
10250 | 433 local_rc = octave_env::make_absolute (initfile); |
4804 | 434 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
435 safe_source_file (local_rc, context, verbose, require_file); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
436 } |
2239 | 437 } |
1 | 438 } |
439 | |
5189 | 440 static int |
441 execute_eval_option_code (const std::string& code) | |
442 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
443 unwind_protect frame; |
5189 | 444 |
7202 | 445 octave_save_signal_mask (); |
446 | |
447 can_interrupt = true; | |
448 | |
449 octave_signal_hook = octave_signal_handler; | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
450 octave_interrupt_hook = 0; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
451 octave_bad_alloc_hook = 0; |
7202 | 452 |
453 octave_catch_interrupts (); | |
454 | |
455 octave_initialized = true; | |
456 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
457 frame.protect_var (interactive); |
5189 | 458 |
459 interactive = false; | |
460 | |
461 int parse_status = 0; | |
462 | |
6487 | 463 try |
464 { | |
465 eval_string (code, false, parse_status, 0); | |
466 } | |
7202 | 467 catch (octave_interrupt_exception) |
468 { | |
469 recover_from_exception (); | |
470 octave_stdout << "\n"; | |
9383 | 471 if (quitting_gracefully) |
472 clean_up_and_exit (exit_status); | |
7202 | 473 } |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
474 catch (octave_execution_exception) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
475 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
476 recover_from_exception (); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
477 std::cerr << "error: unhandled execution exception -- eval failed" |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
478 << std::endl; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
479 } |
5189 | 480 |
481 return parse_status; | |
482 } | |
483 | |
484 static void | |
485 execute_command_line_file (const std::string& fname) | |
486 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
487 unwind_protect frame; |
5189 | 488 |
7202 | 489 octave_save_signal_mask (); |
490 | |
491 can_interrupt = true; | |
492 | |
493 octave_signal_hook = octave_signal_handler; | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
494 octave_interrupt_hook = 0; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
495 octave_bad_alloc_hook = 0; |
7202 | 496 |
497 octave_catch_interrupts (); | |
498 | |
499 octave_initialized = true; | |
500 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
501 frame.protect_var (interactive); |
5189 | 502 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
503 frame.protect_var (octave_program_invocation_name); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
504 frame.protect_var (octave_program_name); |
5189 | 505 |
506 interactive = false; | |
507 | |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
508 octave_program_invocation_name = fname; |
5189 | 509 |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
510 size_t pos = fname.find_last_of (file_ops::dir_sep_chars ()); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
511 |
16203
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
512 octave_program_name |
127cccb037bf
move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents:
16199
diff
changeset
|
513 = (pos != std::string::npos) ? fname.substr (pos+1) : fname; |
5189 | 514 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
515 std::string context; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
516 bool verbose = false; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
517 bool require_file = true; |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
518 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
519 safe_source_file (fname, context, verbose, require_file, "octave"); |
5189 | 520 } |
521 | |
581 | 522 // Usage message with extra help. |
523 | |
1 | 524 static void |
525 verbose_usage (void) | |
526 { | |
17510
7542f4496974
eliminate some macros in version.h
John W. Eaton <jwe@octave.org>
parents:
16877
diff
changeset
|
527 std::cout << octave_name_version_copyright_copying_and_warranty () |
7542f4496974
eliminate some macros in version.h
John W. Eaton <jwe@octave.org>
parents:
16877
diff
changeset
|
528 << "\n\ |
1613 | 529 \n\ |
10731
f5dbac015606
Add [FILE] to octave usage string (bug #30258).
Rik <octave@nomad.inbox5.com>
parents:
10613
diff
changeset
|
530 Usage: octave [options] [FILE]\n\ |
1613 | 531 \n\ |
532 Options:\n\ | |
1119 | 533 \n\ |
16793
cc1657be1ee7
Rename cmdline option --jit-debugging to --jit-debug.
Rik <rik@octave.org>
parents:
16774
diff
changeset
|
534 --built-in-docstrings-file FILE Use docs for built-ins from FILE.\n\ |
3180 | 535 --debug, -d Enter parser debugging mode.\n\ |
16877
5482cd26311a
Rename enable_jit_compiler to jit_enable, enable_jit_debugging to debug_jit.
Rik <rik@octave.org>
parents:
16876
diff
changeset
|
536 --debug-jit Enable JIT compiler debugging/tracing.\n\ |
8923
d47290508a55
document --doc-cache-file option
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
537 --doc-cache-file FILE Use doc cache file FILE.\n\ |
3180 | 538 --echo-commands, -x Echo commands as they are executed.\n\ |
5191 | 539 --eval CODE Evaluate CODE. Exit when done unless --persist.\n\ |
1613 | 540 --exec-path PATH Set path for executing subprograms.\n\ |
15223
6ec6ddebb1a6
include --force-gui and --no-gui options in --help output
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
541 --force-gui Force graphical user interface to start.\n\ |
11140 | 542 --help, -h, Print short help message and exit.\n\ |
9132
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
543 --image-path PATH Add PATH to head of image search path.\n\ |
1613 | 544 --info-file FILE Use top-level info file FILE.\n\ |
545 --info-program PROGRAM Use PROGRAM for reading info files.\n\ | |
3180 | 546 --interactive, -i Force interactive behavior.\n\ |
6938 | 547 --line-editing Force readline use for command-line editing.\n\ |
17568
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
548 --no-fork Don't fork when starting the graphical user interface.\n\ |
15223
6ec6ddebb1a6
include --force-gui and --no-gui options in --help output
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
549 --no-gui Disable the graphical user interface.\n\ |
3180 | 550 --no-history, -H Don't save commands to the history list\n\ |
2470 | 551 --no-init-file Don't read the ~/.octaverc or .octaverc files.\n\ |
9132
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
552 --no-init-path Don't initialize function search path.\n\ |
15310
b055fc077224
allow jit compiler to be enabled at run-time
John W. Eaton <jwe@octave.org>
parents:
15290
diff
changeset
|
553 --no-jit-compiler Disable the JIT compiler.\n\ |
2212 | 554 --no-line-editing Don't use readline for command-line editing.\n\ |
2470 | 555 --no-site-file Don't read the site-wide octaverc file.\n\ |
16774
8d188159ce5f
Add -W command line option to disable window system (bug #38937)
Rik <rik@octave.org>
parents:
16753
diff
changeset
|
556 --no-window-system, -W Disable window system, including graphics.\n\ |
3238 | 557 --norc, -f Don't read any initialization files.\n\ |
9132
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
558 --path PATH, -p PATH Add PATH to head of function search path.\n\ |
5189 | 559 --persist Go interactive after --eval or reading from FILE.\n\ |
16793
cc1657be1ee7
Rename cmdline option --jit-debugging to --jit-debug.
Rik <rik@octave.org>
parents:
16774
diff
changeset
|
560 --silent, --quiet, -q Don't print message at startup.\n\ |
14619
be12c85c6ce7
Print useful help message for texi_macros_file on command line.
Rik <octave@nomad.inbox5.com>
parents:
14614
diff
changeset
|
561 --texi-macros-file FILE Use Texinfo macros in FILE for makeinfo command.\n\ |
9132
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
562 --traditional Set variables for closer MATLAB compatibility.\n\ |
3180 | 563 --verbose, -V Enable verbose output in some cases.\n\ |
564 --version, -v Print version number and exit.\n\ | |
1119 | 565 \n\ |
5190 | 566 FILE Execute commands from FILE. Exit when done\n\ |
5191 | 567 unless --persist is also specified.\n\ |
4829 | 568 \n" |
17510
7542f4496974
eliminate some macros in version.h
John W. Eaton <jwe@octave.org>
parents:
16877
diff
changeset
|
569 << octave_www_statement () |
7542f4496974
eliminate some macros in version.h
John W. Eaton <jwe@octave.org>
parents:
16877
diff
changeset
|
570 << "\n\n" |
7542f4496974
eliminate some macros in version.h
John W. Eaton <jwe@octave.org>
parents:
16877
diff
changeset
|
571 << octave_contrib_statement () |
7542f4496974
eliminate some macros in version.h
John W. Eaton <jwe@octave.org>
parents:
16877
diff
changeset
|
572 << "\n\n" |
7542f4496974
eliminate some macros in version.h
John W. Eaton <jwe@octave.org>
parents:
16877
diff
changeset
|
573 << octave_bugs_statement () |
7542f4496974
eliminate some macros in version.h
John W. Eaton <jwe@octave.org>
parents:
16877
diff
changeset
|
574 << "\n"; |
285 | 575 |
613 | 576 exit (0); |
1 | 577 } |
578 | |
581 | 579 // Terse usage messsage. |
580 | |
1 | 581 static void |
582 usage (void) | |
583 { | |
11140 | 584 std::cerr << "\nusage: " << usage_string << "\n\n"; |
1 | 585 exit (1); |
586 } | |
587 | |
588 static void | |
589 print_version_and_exit (void) | |
590 { | |
17510
7542f4496974
eliminate some macros in version.h
John W. Eaton <jwe@octave.org>
parents:
16877
diff
changeset
|
591 std::cout << octave_name_version_copyright_copying_warranty_and_bugs () |
7542f4496974
eliminate some macros in version.h
John W. Eaton <jwe@octave.org>
parents:
16877
diff
changeset
|
592 << "\n"; |
1 | 593 exit (0); |
594 } | |
595 | |
721 | 596 static void |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
597 lo_error_handler (const char *fmt, ...) |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
598 { |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
599 va_list args; |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
600 va_start (args, fmt); |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9724
diff
changeset
|
601 verror_with_cfn (fmt, args); |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
602 va_end (args); |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
603 |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
604 octave_throw_execution_exception (); |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
605 } |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
606 |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
607 static void |
10370
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
608 lo_error_with_id_handler (const char *id, const char *fmt, ...) |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
609 { |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
610 va_list args; |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
611 va_start (args, fmt); |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
612 verror_with_id_cfn (id, fmt, args); |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
613 va_end (args); |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
614 |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
615 octave_throw_execution_exception (); |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
616 } |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
617 |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
618 static void |
721 | 619 initialize_error_handlers () |
620 { | |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
621 set_liboctave_error_handler (lo_error_handler); |
10370
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
622 set_liboctave_error_with_id_handler (lo_error_with_id_handler); |
3325 | 623 set_liboctave_warning_handler (warning); |
5781 | 624 set_liboctave_warning_with_id_handler (warning_with_id); |
721 | 625 } |
626 | |
1410 | 627 // What happens on --traditional. |
628 | |
629 static void | |
630 maximum_braindamage (void) | |
631 { | |
5189 | 632 persist = true; |
633 | |
15475
da6c37ed0b42
eliminate calls to bind_internal_variable when setting --traditional options
John W. Eaton <jwe@octave.org>
parents:
15474
diff
changeset
|
634 FPS1 (octave_value (">> ")); |
da6c37ed0b42
eliminate calls to bind_internal_variable when setting --traditional options
John W. Eaton <jwe@octave.org>
parents:
15474
diff
changeset
|
635 FPS2 (octave_value ("")); |
da6c37ed0b42
eliminate calls to bind_internal_variable when setting --traditional options
John W. Eaton <jwe@octave.org>
parents:
15474
diff
changeset
|
636 FPS4 (octave_value ("")); |
da6c37ed0b42
eliminate calls to bind_internal_variable when setting --traditional options
John W. Eaton <jwe@octave.org>
parents:
15474
diff
changeset
|
637 Fallow_noninteger_range_as_index (octave_value (true)); |
da6c37ed0b42
eliminate calls to bind_internal_variable when setting --traditional options
John W. Eaton <jwe@octave.org>
parents:
15474
diff
changeset
|
638 Fbeep_on_error (octave_value (true)); |
da6c37ed0b42
eliminate calls to bind_internal_variable when setting --traditional options
John W. Eaton <jwe@octave.org>
parents:
15474
diff
changeset
|
639 Fconfirm_recursive_rmdir (octave_value (false)); |
da6c37ed0b42
eliminate calls to bind_internal_variable when setting --traditional options
John W. Eaton <jwe@octave.org>
parents:
15474
diff
changeset
|
640 Fcrash_dumps_octave_core (octave_value (false)); |
16875
b04ae15530fc
Rename default_save_options() to save_default_options().
Rik <rik@octave.org>
parents:
16793
diff
changeset
|
641 Fsave_default_options (octave_value ("-mat-binary")); |
15475
da6c37ed0b42
eliminate calls to bind_internal_variable when setting --traditional options
John W. Eaton <jwe@octave.org>
parents:
15474
diff
changeset
|
642 Fdo_braindead_shortcircuit_evaluation (octave_value (true)); |
da6c37ed0b42
eliminate calls to bind_internal_variable when setting --traditional options
John W. Eaton <jwe@octave.org>
parents:
15474
diff
changeset
|
643 Ffixed_point_format (octave_value (true)); |
da6c37ed0b42
eliminate calls to bind_internal_variable when setting --traditional options
John W. Eaton <jwe@octave.org>
parents:
15474
diff
changeset
|
644 Fhistory_timestamp_format_string (octave_value ("%%-- %D %I:%M %p --%%")); |
da6c37ed0b42
eliminate calls to bind_internal_variable when setting --traditional options
John W. Eaton <jwe@octave.org>
parents:
15474
diff
changeset
|
645 Fpage_screen_output (octave_value (false)); |
da6c37ed0b42
eliminate calls to bind_internal_variable when setting --traditional options
John W. Eaton <jwe@octave.org>
parents:
15474
diff
changeset
|
646 Fprint_empty_dimensions (octave_value (false)); |
5904 | 647 |
9584
0fcbfddaa87f
allow abbreviated graphics property names to match, with optional warning
John W. Eaton <jwe@octave.org>
parents:
9383
diff
changeset
|
648 disable_warning ("Octave:abbreviated-property-match"); |
6159 | 649 disable_warning ("Octave:fopen-file-in-path"); |
5904 | 650 disable_warning ("Octave:function-name-clash"); |
6159 | 651 disable_warning ("Octave:load-file-in-path"); |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11066
diff
changeset
|
652 disable_warning ("Octave:possible-matlab-short-circuit-operator"); |
1410 | 653 } |
654 | |
15139
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
655 // EMBEDDED is declared int instead of bool because this function is |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
656 // declared extern "C". |
581 | 657 |
1 | 658 int |
4368 | 659 octave_main (int argc, char **argv, int embedded) |
1 | 660 { |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
661 octave_process_command_line (argc, argv); |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
662 |
16540
63b144e6a3d0
partially undo the changes in 9bc1f8278966
John W. Eaton <jwe@octave.org>
parents:
16528
diff
changeset
|
663 sysdep_init (); |
63b144e6a3d0
partially undo the changes in 9bc1f8278966
John W. Eaton <jwe@octave.org>
parents:
16528
diff
changeset
|
664 |
63b144e6a3d0
partially undo the changes in 9bc1f8278966
John W. Eaton <jwe@octave.org>
parents:
16528
diff
changeset
|
665 install_defaults (); |
63b144e6a3d0
partially undo the changes in 9bc1f8278966
John W. Eaton <jwe@octave.org>
parents:
16528
diff
changeset
|
666 |
15137
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
667 octave_initialize_interpreter (argc, argv, embedded); |
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
668 |
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
669 return octave_execute_interpreter (); |
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
670 } |
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
671 |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
672 void |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
673 octave_process_command_line (int argc, char **argv) |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
674 { |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
675 octave_cmdline_argc = argc; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
676 octave_cmdline_argv = argv; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
677 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
678 while (true) |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
679 { |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
680 int long_idx; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
681 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
682 int optc = getopt_long (argc, argv, short_opts, long_opts, &long_idx); |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
683 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
684 if (optc < 0) |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
685 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
686 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
687 switch (optc) |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
688 { |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
689 case '?': |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
690 // Unrecognized option. getopt_long already printed a |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
691 // message about that, so we will just print the usage string |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
692 // and exit. |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
693 usage (); |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
694 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
695 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
696 case 'H': |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16875
diff
changeset
|
697 Fhistory_save (octave_value (false)); |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
698 read_history_file = false; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
699 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
700 |
16774
8d188159ce5f
Add -W command line option to disable window system (bug #38937)
Rik <rik@octave.org>
parents:
16753
diff
changeset
|
701 case 'W': |
8d188159ce5f
Add -W command line option to disable window system (bug #38937)
Rik <rik@octave.org>
parents:
16753
diff
changeset
|
702 no_window_system = true; |
8d188159ce5f
Add -W command line option to disable window system (bug #38937)
Rik <rik@octave.org>
parents:
16753
diff
changeset
|
703 break; |
8d188159ce5f
Add -W command line option to disable window system (bug #38937)
Rik <rik@octave.org>
parents:
16753
diff
changeset
|
704 |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
705 case 'V': |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
706 verbose_flag = true; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
707 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
708 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
709 case 'd': |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
710 // This is the same as yydebug in parse.y. |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
711 octave_debug++; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
712 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
713 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
714 case 'f': |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
715 read_init_files = false; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
716 read_site_files = false; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
717 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
718 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
719 case 'h': |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
720 verbose_usage (); |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
721 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
722 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
723 case 'i': |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
724 forced_interactive = true; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
725 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
726 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
727 case 'p': |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
728 if (optarg) |
15225
2d337a9869e9
correctly handle multiple --path command line arguments
John W. Eaton <jwe@octave.org>
parents:
15224
diff
changeset
|
729 command_line_path.push_back (optarg); |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
730 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
731 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
732 case 'q': |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
733 inhibit_startup_message = true; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
734 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
735 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
736 case 'x': |
15477
8b5fc510c6d6
don't use bind_internal_variable when handling -x option
John W. Eaton <jwe@octave.org>
parents:
15476
diff
changeset
|
737 { |
8b5fc510c6d6
don't use bind_internal_variable when handling -x option
John W. Eaton <jwe@octave.org>
parents:
15476
diff
changeset
|
738 int val = ECHO_SCRIPTS | ECHO_FUNCTIONS | ECHO_CMD_LINE; |
8b5fc510c6d6
don't use bind_internal_variable when handling -x option
John W. Eaton <jwe@octave.org>
parents:
15476
diff
changeset
|
739 Fecho_executing_commands (octave_value (val)); |
8b5fc510c6d6
don't use bind_internal_variable when handling -x option
John W. Eaton <jwe@octave.org>
parents:
15476
diff
changeset
|
740 } |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
741 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
742 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
743 case 'v': |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
744 print_version_and_exit (); |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
745 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
746 |
15470
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
747 case BUILT_IN_DOCSTRINGS_FILE_OPTION: |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
748 if (optarg) |
15480
c7d7d43f26bb
call Ffoo functions instead of setting Vfoo directly.
John W. Eaton <jwe@octave.org>
parents:
15479
diff
changeset
|
749 Fbuilt_in_docstrings_file (octave_value (optarg)); |
15470
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
750 break; |
bf0857c789f4
initialize docstrings for built-in functions from file
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
751 |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
752 case DOC_CACHE_FILE_OPTION: |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
753 if (optarg) |
15480
c7d7d43f26bb
call Ffoo functions instead of setting Vfoo directly.
John W. Eaton <jwe@octave.org>
parents:
15479
diff
changeset
|
754 Fdoc_cache_file (octave_value (optarg)); |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
755 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
756 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
757 case EVAL_OPTION: |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
758 if (optarg) |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
759 { |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
760 if (code_to_eval.empty ()) |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
761 code_to_eval = optarg; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
762 else |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
763 code_to_eval += std::string (" ") + optarg; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
764 } |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
765 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
766 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
767 case EXEC_PATH_OPTION: |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
768 if (optarg) |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
769 exec_path = optarg; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
770 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
771 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
772 case FORCE_GUI_OPTION: |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
773 force_gui_option = true; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
774 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
775 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
776 case IMAGE_PATH_OPTION: |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
777 if (optarg) |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
778 image_path = optarg; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
779 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
780 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
781 case INFO_FILE_OPTION: |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
782 if (optarg) |
15480
c7d7d43f26bb
call Ffoo functions instead of setting Vfoo directly.
John W. Eaton <jwe@octave.org>
parents:
15479
diff
changeset
|
783 Finfo_file (octave_value (optarg)); |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
784 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
785 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
786 case INFO_PROG_OPTION: |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
787 if (optarg) |
15480
c7d7d43f26bb
call Ffoo functions instead of setting Vfoo directly.
John W. Eaton <jwe@octave.org>
parents:
15479
diff
changeset
|
788 Finfo_program (octave_value (optarg)); |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
789 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
790 |
16877
5482cd26311a
Rename enable_jit_compiler to jit_enable, enable_jit_debugging to debug_jit.
Rik <rik@octave.org>
parents:
16876
diff
changeset
|
791 case DEBUG_JIT_OPTION: |
5482cd26311a
Rename enable_jit_compiler to jit_enable, enable_jit_debugging to debug_jit.
Rik <rik@octave.org>
parents:
16876
diff
changeset
|
792 Fdebug_jit (octave_value (true)); |
15310
b055fc077224
allow jit compiler to be enabled at run-time
John W. Eaton <jwe@octave.org>
parents:
15290
diff
changeset
|
793 break; |
b055fc077224
allow jit compiler to be enabled at run-time
John W. Eaton <jwe@octave.org>
parents:
15290
diff
changeset
|
794 |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
795 case LINE_EDITING_OPTION: |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
796 forced_line_editing = true; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
797 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
798 |
17568
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
799 case NO_FORK_OPTION: |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
800 no_fork_option = true; |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
801 break; |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
802 |
15310
b055fc077224
allow jit compiler to be enabled at run-time
John W. Eaton <jwe@octave.org>
parents:
15290
diff
changeset
|
803 case NO_GUI_OPTION: |
b055fc077224
allow jit compiler to be enabled at run-time
John W. Eaton <jwe@octave.org>
parents:
15290
diff
changeset
|
804 no_gui_option = true; |
b055fc077224
allow jit compiler to be enabled at run-time
John W. Eaton <jwe@octave.org>
parents:
15290
diff
changeset
|
805 break; |
b055fc077224
allow jit compiler to be enabled at run-time
John W. Eaton <jwe@octave.org>
parents:
15290
diff
changeset
|
806 |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
807 case NO_INIT_FILE_OPTION: |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
808 read_init_files = false; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
809 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
810 |
15310
b055fc077224
allow jit compiler to be enabled at run-time
John W. Eaton <jwe@octave.org>
parents:
15290
diff
changeset
|
811 case NO_INIT_PATH_OPTION: |
b055fc077224
allow jit compiler to be enabled at run-time
John W. Eaton <jwe@octave.org>
parents:
15290
diff
changeset
|
812 set_initial_path = false; |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
813 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
814 |
15310
b055fc077224
allow jit compiler to be enabled at run-time
John W. Eaton <jwe@octave.org>
parents:
15290
diff
changeset
|
815 case NO_JIT_COMPILER_OPTION: |
16877
5482cd26311a
Rename enable_jit_compiler to jit_enable, enable_jit_debugging to debug_jit.
Rik <rik@octave.org>
parents:
16876
diff
changeset
|
816 Fjit_enable (octave_value (false)); |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
817 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
818 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
819 case NO_LINE_EDITING_OPTION: |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
820 line_editing = false; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
821 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
822 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
823 case NO_SITE_FILE_OPTION: |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
824 read_site_files = 0; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
825 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
826 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
827 case PERSIST_OPTION: |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
828 persist = true; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
829 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
830 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
831 case TEXI_MACROS_FILE_OPTION: |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
832 if (optarg) |
15480
c7d7d43f26bb
call Ffoo functions instead of setting Vfoo directly.
John W. Eaton <jwe@octave.org>
parents:
15479
diff
changeset
|
833 Ftexi_macros_file (octave_value (optarg)); |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
834 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
835 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
836 case TRADITIONAL_OPTION: |
16528
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16485
diff
changeset
|
837 traditional = true; |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
838 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
839 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
840 default: |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
841 // getopt_long should print a message about unrecognized |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
842 // options and return '?', which is handled above. So if we |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
843 // end up here, it is because there was an option but we |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
844 // forgot to handle it. That should be fatal. |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
845 panic_impossible (); |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
846 break; |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
847 } |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
848 } |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
849 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
850 if (force_gui_option && no_gui_option) |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
851 { |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
852 error ("error: only one of --force-gui and --no-gui may be used"); |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
853 usage (); |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
854 } |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
855 } |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
856 |
15139
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
857 // EMBEDDED is declared int instead of bool because this function is |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
858 // declared extern "C". |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
859 |
15137
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
860 void |
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
861 octave_initialize_interpreter (int argc, char **argv, int embedded) |
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
862 { |
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
863 octave_embedded = embedded; |
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
864 |
3019 | 865 octave_env::set_program_name (argv[0]); |
866 | |
5780 | 867 octave_program_invocation_name = octave_env::get_program_invocation_name (); |
868 octave_program_name = octave_env::get_program_name (); | |
869 | |
13281
834f904a3dcb
Add support for full asynchronous graphics toolkit running in a separate
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13239
diff
changeset
|
870 octave_thread::init (); |
834f904a3dcb
Add support for full asynchronous graphics toolkit running in a separate
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13239
diff
changeset
|
871 |
16540
63b144e6a3d0
partially undo the changes in 9bc1f8278966
John W. Eaton <jwe@octave.org>
parents:
16528
diff
changeset
|
872 set_default_prompts (); |
16528
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16485
diff
changeset
|
873 |
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16485
diff
changeset
|
874 if (traditional) |
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16485
diff
changeset
|
875 maximum_braindamage (); |
9bc1f8278966
allow GUI to customize prompts at startup
John W. Eaton <jwe@octave.org>
parents:
16485
diff
changeset
|
876 |
5844 | 877 init_signals (); |
878 | |
11234
2718e1fdf82f
IEEE math initialization tweaks
John W. Eaton <jwe@octave.org>
parents:
11157
diff
changeset
|
879 octave_ieee_init (); |
2718e1fdf82f
IEEE math initialization tweaks
John W. Eaton <jwe@octave.org>
parents:
11157
diff
changeset
|
880 |
4159 | 881 // The idea here is to force xerbla to be referenced so that we will |
882 // link to our own version instead of the one provided by the BLAS | |
883 // library. But octave_NaN should never be -1, so we should never | |
884 // actually call xerbla. | |
885 | |
886 if (octave_NaN == -1) | |
11157
c75130f19440
octave.cc: fix call to xerbla
John W. Eaton <jwe@octave.org>
parents:
11140
diff
changeset
|
887 F77_FUNC (xerbla, XERBLA) ("octave", 13 F77_CHAR_ARG_LEN (6)); |
4159 | 888 |
721 | 889 initialize_error_handlers (); |
223 | 890 |
5794 | 891 initialize_default_warning_state (); |
892 | |
4368 | 893 if (! embedded) |
894 install_signal_handlers (); | |
9255
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
895 else |
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
896 quit_allowed = false; |
2205 | 897 |
898 initialize_file_io (); | |
899 | |
2375 | 900 install_types (); |
901 | |
902 install_ops (); | |
2205 | 903 |
904 install_builtins (); | |
905 | |
15225
2d337a9869e9
correctly handle multiple --path command line arguments
John W. Eaton <jwe@octave.org>
parents:
15224
diff
changeset
|
906 for (std::list<std::string>::const_iterator it = command_line_path.begin (); |
2d337a9869e9
correctly handle multiple --path command line arguments
John W. Eaton <jwe@octave.org>
parents:
15224
diff
changeset
|
907 it != command_line_path.end (); it++) |
2d337a9869e9
correctly handle multiple --path command line arguments
John W. Eaton <jwe@octave.org>
parents:
15224
diff
changeset
|
908 load_path::set_command_line_path (*it); |
777 | 909 |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
910 if (! exec_path.empty ()) |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
911 set_exec_path (exec_path); |
15139
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
912 |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
913 if (! image_path.empty ()) |
15327 | 914 set_image_path (image_path); |
777 | 915 |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
916 if (no_window_system) |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
917 display_info::no_window_system (); |
1410 | 918 |
9320
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
919 // Is input coming from a terminal? If so, we are probably |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
920 // interactive. |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
921 |
9999
653716f3d976
get_debug_input: force interactive input mode; don't get user input unless stdin is a tty
John W. Eaton <jwe@octave.org>
parents:
9753
diff
changeset
|
922 // If stdin is not a tty, then we are reading commands from a pipe or |
653716f3d976
get_debug_input: force interactive input mode; don't get user input unless stdin is a tty
John W. Eaton <jwe@octave.org>
parents:
9753
diff
changeset
|
923 // a redirected file. |
16208
ed91ab4d4515
eliminate stdin_is_tty global variable
John W. Eaton <jwe@octave.org>
parents:
16203
diff
changeset
|
924 bool stdin_is_tty = gnulib::isatty (fileno (stdin)); |
9999
653716f3d976
get_debug_input: force interactive input mode; don't get user input unless stdin is a tty
John W. Eaton <jwe@octave.org>
parents:
9753
diff
changeset
|
925 |
14160 | 926 interactive = (! embedded && stdin_is_tty |
927 && gnulib::isatty (fileno (stdout))); | |
9320
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
928 |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
929 if (! interactive && ! forced_line_editing) |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
930 line_editing = false; |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
931 |
9321
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
9320
diff
changeset
|
932 // Force default line editor if we don't want readline editing. |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
9320
diff
changeset
|
933 if (! line_editing) |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
9320
diff
changeset
|
934 command_editor::force_default_editor (); |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
9320
diff
changeset
|
935 |
1358 | 936 // These can come after command line args since none of them set any |
937 // defaults that might be changed by command line options. | |
581 | 938 |
9320
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
939 if (line_editing) |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
940 initialize_command_input (); |
315 | 941 |
4217 | 942 octave_interpreter_ready = true; |
943 | |
5654 | 944 initialize_version_info (); |
945 | |
8099
e0a6e54f5a19
octave.cc (octave_main): make all command-line arguments available to startup scripts
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
946 // Make all command-line arguments available to startup files, |
e0a6e54f5a19
octave.cc (octave_main): make all command-line arguments available to startup scripts
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
947 // including PKG_ADD files. |
e0a6e54f5a19
octave.cc (octave_main): make all command-line arguments available to startup scripts
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
948 |
e0a6e54f5a19
octave.cc (octave_main): make all command-line arguments available to startup scripts
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
949 intern_argv (argc, argv); |
e0a6e54f5a19
octave.cc (octave_main): make all command-line arguments available to startup scripts
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
950 |
6365 | 951 load_path::initialize (set_initial_path); |
4217 | 952 |
13239
3109c8b0cff4
Initialise history before executing startup files (bug #32900)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12855
diff
changeset
|
953 initialize_history (read_history_file); |
15137
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
954 } |
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
955 |
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
956 int |
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
957 octave_execute_interpreter (void) |
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
958 { |
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
959 if (! inhibit_startup_message) |
17510
7542f4496974
eliminate some macros in version.h
John W. Eaton <jwe@octave.org>
parents:
16877
diff
changeset
|
960 std::cout << octave_startup_message () << "\n" << std::endl; |
1651 | 961 |
17755
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
962 octave_prepare_hdf5 (); |
9c03b071fd7b
avoid HDF5 error message at exit (bug #37713)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
963 |
13239
3109c8b0cff4
Initialise history before executing startup files (bug #32900)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12855
diff
changeset
|
964 execute_startup_files (); |
1 | 965 |
578 | 966 if (! inhibit_startup_message && reading_startup_message_printed) |
3538 | 967 std::cout << std::endl; |
578 | 968 |
1358 | 969 // If there is an extra argument, see if it names a file to read. |
970 // Additional arguments are taken as command line options for the | |
971 // script. | |
1 | 972 |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
973 int last_arg_idx = optind; |
3019 | 974 |
15137
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
975 int remaining_args = octave_cmdline_argc - last_arg_idx; |
3019 | 976 |
5189 | 977 if (! code_to_eval.empty ()) |
149 | 978 { |
5189 | 979 int parse_status = execute_eval_option_code (code_to_eval); |
980 | |
5242 | 981 if (! (persist || remaining_args > 0)) |
16753
f8f35ddc49a2
exit gracefully after executing code from --eval
John W. Eaton <jwe@octave.org>
parents:
16540
diff
changeset
|
982 { |
f8f35ddc49a2
exit gracefully after executing code from --eval
John W. Eaton <jwe@octave.org>
parents:
16540
diff
changeset
|
983 quitting_gracefully = true; |
f8f35ddc49a2
exit gracefully after executing code from --eval
John W. Eaton <jwe@octave.org>
parents:
16540
diff
changeset
|
984 |
f8f35ddc49a2
exit gracefully after executing code from --eval
John W. Eaton <jwe@octave.org>
parents:
16540
diff
changeset
|
985 clean_up_and_exit (parse_status || error_state ? 1 : 0); |
f8f35ddc49a2
exit gracefully after executing code from --eval
John W. Eaton <jwe@octave.org>
parents:
16540
diff
changeset
|
986 } |
1 | 987 } |
988 | |
5189 | 989 if (remaining_args > 0) |
990 { | |
991 // If we are running an executable script (#! /bin/octave) then | |
992 // we should only see the args passed to the script. | |
993 | |
15137
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
994 intern_argv (remaining_args, octave_cmdline_argv+last_arg_idx); |
5189 | 995 |
15137
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
996 execute_command_line_file (octave_cmdline_argv[last_arg_idx]); |
5189 | 997 |
998 if (! persist) | |
14074
f90c3facfac3
don't reset parser when exiting (bug #35120)
John W. Eaton <jwe@octave.org>
parents:
13281
diff
changeset
|
999 { |
f90c3facfac3
don't reset parser when exiting (bug #35120)
John W. Eaton <jwe@octave.org>
parents:
13281
diff
changeset
|
1000 quitting_gracefully = true; |
f90c3facfac3
don't reset parser when exiting (bug #35120)
John W. Eaton <jwe@octave.org>
parents:
13281
diff
changeset
|
1001 |
f90c3facfac3
don't reset parser when exiting (bug #35120)
John W. Eaton <jwe@octave.org>
parents:
13281
diff
changeset
|
1002 clean_up_and_exit (error_state ? 1 : 0); |
f90c3facfac3
don't reset parser when exiting (bug #35120)
John W. Eaton <jwe@octave.org>
parents:
13281
diff
changeset
|
1003 } |
5189 | 1004 } |
1005 | |
1006 // Avoid counting commands executed from startup files. | |
1007 | |
1008 command_editor::reset_current_command_number (1); | |
1009 | |
1010 // Now argv should have the full set of args. | |
15137
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
1011 intern_argv (octave_cmdline_argc, octave_cmdline_argv); |
5189 | 1012 |
1358 | 1013 // Force input to be echoed if not really interactive, but the user |
1014 // has forced interactive behavior. | |
1 | 1015 |
1907 | 1016 if (! interactive && forced_interactive) |
287 | 1017 { |
2926 | 1018 command_editor::blink_matching_paren (false); |
1588 | 1019 |
5775 | 1020 // FIXME -- is this the right thing to do? |
1588 | 1021 |
15477
8b5fc510c6d6
don't use bind_internal_variable when handling -x option
John W. Eaton <jwe@octave.org>
parents:
15476
diff
changeset
|
1022 Fecho_executing_commands (octave_value (ECHO_CMD_LINE)); |
287 | 1023 } |
1 | 1024 |
15137
16a6b0a6855d
GUI: support for octave arguments and integrate with run-octave.
John W. Eaton <jwe@octave.org>
parents:
14619
diff
changeset
|
1025 if (octave_embedded) |
5502 | 1026 { |
5775 | 1027 // FIXME -- do we need to do any cleanup here before |
5502 | 1028 // returning? If we don't, what will happen to Octave functions |
1029 // that have been registered to execute with atexit, for example? | |
1030 | |
1031 return 1; | |
1032 } | |
4368 | 1033 |
5189 | 1034 int retval = main_loop (); |
1 | 1035 |
14074
f90c3facfac3
don't reset parser when exiting (bug #35120)
John W. Eaton <jwe@octave.org>
parents:
13281
diff
changeset
|
1036 quitting_gracefully = true; |
f90c3facfac3
don't reset parser when exiting (bug #35120)
John W. Eaton <jwe@octave.org>
parents:
13281
diff
changeset
|
1037 |
16485
8b783661e03f
improve exit sequence for GUI
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
1038 clean_up_and_exit (retval, true); |
4247 | 1039 |
16485
8b783661e03f
improve exit sequence for GUI
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
1040 return retval; |
1 | 1041 } |
1042 | |
15702
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1043 static bool |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1044 check_starting_gui (void) |
15139
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1045 { |
15290
99db33cae82b
don't start the GUI if window system is disabled
Mike Miller <mtmiller@ieee.org>
parents:
15262
diff
changeset
|
1046 if (no_window_system || ! display_info::display_available ()) |
15160
973296940c89
don't start GUI if display is not available
John W. Eaton <jwe@octave.org>
parents:
15139
diff
changeset
|
1047 return false; |
973296940c89
don't start GUI if display is not available
John W. Eaton <jwe@octave.org>
parents:
15139
diff
changeset
|
1048 |
15139
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1049 if (force_gui_option) |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1050 return true; |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1051 |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1052 if (no_gui_option) |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1053 return false; |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1054 |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1055 if (persist) |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1056 return true; |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1057 |
15224
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
1058 // If stdin is not a tty, then assume we are reading commands from a |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
1059 // pipe or a redirected file and the GUI should not start. If this is |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
1060 // not the case (for example, starting from a desktop "launcher" with |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
1061 // no terminal) and you want to start the GUI, you may use the |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
1062 // --force-gui option to start the GUI. |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
1063 |
a44e4a08fc55
perform fewer actions before starting GUI
John W. Eaton <jwe@octave.org>
parents:
15223
diff
changeset
|
1064 if (! gnulib::isatty (fileno (stdin))) |
15139
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1065 return false; |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1066 |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1067 // If we have code to eval or execute from a file, and we are going to |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1068 // exit immediately after executing it, don't start the gui. |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1069 |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1070 int last_arg_idx = optind; |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1071 int remaining_args = octave_cmdline_argc - last_arg_idx; |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1072 |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1073 if (! code_to_eval.empty () || remaining_args > 0) |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1074 return false; |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1075 |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1076 return true; |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1077 } |
bfc220d1de67
include gui in default Octave binary
John W. Eaton <jwe@octave.org>
parents:
15137
diff
changeset
|
1078 |
15702
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1079 // Return int instead of bool because this function is declared |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1080 // extern "C". |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1081 |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1082 int |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1083 octave_starting_gui (void) |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1084 { |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1085 start_gui = check_starting_gui (); |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1086 return start_gui; |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1087 } |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1088 |
17568
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
1089 int |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
1090 octave_fork_gui (void) |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
1091 { |
17570
1c7d768c3847
don't fork if there is no controlling tty
John W. Eaton <jwe@octave.org>
parents:
17568
diff
changeset
|
1092 bool have_ctty = false; |
1c7d768c3847
don't fork if there is no controlling tty
John W. Eaton <jwe@octave.org>
parents:
17568
diff
changeset
|
1093 |
1c7d768c3847
don't fork if there is no controlling tty
John W. Eaton <jwe@octave.org>
parents:
17568
diff
changeset
|
1094 #if ! (defined (__WIN32__) || defined (__APPLE__)) || defined (__CYGWIN__) |
1c7d768c3847
don't fork if there is no controlling tty
John W. Eaton <jwe@octave.org>
parents:
17568
diff
changeset
|
1095 |
1c7d768c3847
don't fork if there is no controlling tty
John W. Eaton <jwe@octave.org>
parents:
17568
diff
changeset
|
1096 #if defined (HAVE_CTERMID) |
1c7d768c3847
don't fork if there is no controlling tty
John W. Eaton <jwe@octave.org>
parents:
17568
diff
changeset
|
1097 const char *ctty = ctermid (0); |
1c7d768c3847
don't fork if there is no controlling tty
John W. Eaton <jwe@octave.org>
parents:
17568
diff
changeset
|
1098 #else |
1c7d768c3847
don't fork if there is no controlling tty
John W. Eaton <jwe@octave.org>
parents:
17568
diff
changeset
|
1099 const char *ctty = "/dev/tty"; |
1c7d768c3847
don't fork if there is no controlling tty
John W. Eaton <jwe@octave.org>
parents:
17568
diff
changeset
|
1100 #endif |
1c7d768c3847
don't fork if there is no controlling tty
John W. Eaton <jwe@octave.org>
parents:
17568
diff
changeset
|
1101 |
1c7d768c3847
don't fork if there is no controlling tty
John W. Eaton <jwe@octave.org>
parents:
17568
diff
changeset
|
1102 have_ctty = gnulib::open (ctty, O_RDWR, 0) > 0; |
1c7d768c3847
don't fork if there is no controlling tty
John W. Eaton <jwe@octave.org>
parents:
17568
diff
changeset
|
1103 |
1c7d768c3847
don't fork if there is no controlling tty
John W. Eaton <jwe@octave.org>
parents:
17568
diff
changeset
|
1104 #endif |
1c7d768c3847
don't fork if there is no controlling tty
John W. Eaton <jwe@octave.org>
parents:
17568
diff
changeset
|
1105 |
1c7d768c3847
don't fork if there is no controlling tty
John W. Eaton <jwe@octave.org>
parents:
17568
diff
changeset
|
1106 return (have_ctty && ! no_fork_option); |
17568
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
1107 } |
1b388d922e6b
provide --no-fork command line option
John W. Eaton <jwe@octave.org>
parents:
17510
diff
changeset
|
1108 |
15702
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1109 DEFUN (isguirunning, args, , |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1110 "-*- texinfo -*-\n\ |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1111 @deftypefn {Built-in Function} {} isguirunning ()\n\ |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1112 Return true if Octave is running in GUI mode and false otherwise.\n\ |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1113 @end deftypefn") |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1114 { |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1115 octave_value retval; |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1116 |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1117 if (args.length () == 0) |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1118 retval = start_gui; |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1119 else |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1120 print_usage (); |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1121 |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1122 return retval; |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1123 } |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1124 |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1125 /* |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1126 %!assert (islogical (isguirunning ())) |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1127 %!error isguirunning (1) |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1128 */ |
534b6f7108b7
Add isguirunning function to query whether the GUI is running
Mike Miller <mtmiller@ieee.org>
parents:
15490
diff
changeset
|
1129 |
5780 | 1130 DEFUN (argv, args, , |
1131 "-*- texinfo -*-\n\ | |
1132 @deftypefn {Built-in Function} {} argv ()\n\ | |
1133 Return the command line arguments passed to Octave. For example,\n\ | |
1134 if you invoked Octave using the command\n\ | |
1135 \n\ | |
1136 @example\n\ | |
1137 octave --no-line-editing --silent\n\ | |
1138 @end example\n\ | |
1139 \n\ | |
1140 @noindent\n\ | |
1141 @code{argv} would return a cell array of strings with the elements\n\ | |
10840 | 1142 @option{--no-line-editing} and @option{--silent}.\n\ |
5780 | 1143 \n\ |
1144 If you write an executable Octave script, @code{argv} will return the\n\ | |
1145 list of arguments passed to the script. @xref{Executable Octave Programs},\n\ | |
1146 for an example of how to create an executable Octave script.\n\ | |
1147 @end deftypefn") | |
1148 { | |
1149 octave_value retval; | |
1150 | |
1151 if (args.length () == 0) | |
1152 retval = Cell (octave_argv); | |
1153 else | |
5823 | 1154 print_usage (); |
5780 | 1155 |
1156 return retval; | |
1157 } | |
1158 | |
12848
e3323dda983b
codesprint: new tests for octave.cc
John W. Eaton <jwe@octave.org>
parents:
12335
diff
changeset
|
1159 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
1160 %!assert (iscellstr (argv ())) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
1161 %!error argv (1) |
12848
e3323dda983b
codesprint: new tests for octave.cc
John W. Eaton <jwe@octave.org>
parents:
12335
diff
changeset
|
1162 */ |
e3323dda983b
codesprint: new tests for octave.cc
John W. Eaton <jwe@octave.org>
parents:
12335
diff
changeset
|
1163 |
5780 | 1164 DEFUN (program_invocation_name, args, , |
1165 "-*- texinfo -*-\n\ | |
9724
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9584
diff
changeset
|
1166 @deftypefn {Built-in Function} {} program_invocation_name ()\n\ |
5780 | 1167 Return the name that was typed at the shell prompt to run Octave.\n\ |
1168 \n\ | |
1169 If executing a script from the command line (e.g., @code{octave foo.m})\n\ | |
1170 or using an executable Octave script, the program name is set to the\n\ | |
1171 name of the script. @xref{Executable Octave Programs}, for an example of\n\ | |
1172 how to create an executable Octave script.\n\ | |
1173 @seealso{program_name}\n\ | |
1174 @end deftypefn") | |
1175 { | |
1176 octave_value retval; | |
1177 | |
1178 if (args.length () == 0) | |
1179 retval = octave_program_invocation_name; | |
1180 else | |
5823 | 1181 print_usage (); |
5780 | 1182 |
1183 return retval; | |
1184 } | |
1185 | |
12848
e3323dda983b
codesprint: new tests for octave.cc
John W. Eaton <jwe@octave.org>
parents:
12335
diff
changeset
|
1186 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
1187 %!assert (ischar (program_invocation_name ())) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
1188 %!error program_invocation_name (1) |
12848
e3323dda983b
codesprint: new tests for octave.cc
John W. Eaton <jwe@octave.org>
parents:
12335
diff
changeset
|
1189 */ |
e3323dda983b
codesprint: new tests for octave.cc
John W. Eaton <jwe@octave.org>
parents:
12335
diff
changeset
|
1190 |
5780 | 1191 DEFUN (program_name, args, , |
1192 "-*- texinfo -*-\n\ | |
1193 @deftypefn {Built-in Function} {} program_name ()\n\ | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8273
diff
changeset
|
1194 Return the last component of the value returned by\n\ |
5780 | 1195 @code{program_invocation_name}.\n\ |
1196 @seealso{program_invocation_name}\n\ | |
1197 @end deftypefn") | |
1198 { | |
1199 octave_value retval; | |
1200 | |
1201 if (args.length () == 0) | |
1202 retval = octave_program_name; | |
1203 else | |
5823 | 1204 print_usage (); |
5780 | 1205 |
1206 return retval; | |
1207 } | |
12848
e3323dda983b
codesprint: new tests for octave.cc
John W. Eaton <jwe@octave.org>
parents:
12335
diff
changeset
|
1208 |
e3323dda983b
codesprint: new tests for octave.cc
John W. Eaton <jwe@octave.org>
parents:
12335
diff
changeset
|
1209 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
1210 %!assert (ischar (program_name ())) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
1211 %!error program_name (1) |
12848
e3323dda983b
codesprint: new tests for octave.cc
John W. Eaton <jwe@octave.org>
parents:
12335
diff
changeset
|
1212 */ |