Mercurial > octave
annotate src/octave.cc @ 11518:141b3fb5cef7
style fixes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 13 Jan 2011 16:52:30 -0500 |
parents | 944b7e20fc5a |
children | fd0a3ac60b0e |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
8920 | 4 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton |
1 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1 | 21 |
22 */ | |
23 | |
24 // Born February 20, 1992. | |
25 | |
240 | 26 #ifdef HAVE_CONFIG_H |
1192 | 27 #include <config.h> |
1 | 28 #endif |
29 | |
1355 | 30 #include <cassert> |
31 #include <cstdlib> | |
32 #include <cstring> | |
33 #include <ctime> | |
34 | |
3503 | 35 #include <iostream> |
1355 | 36 |
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> |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
38 |
2926 | 39 #include "cmd-edit.h" |
3690 | 40 #include "f77-fcn.h" |
4097 | 41 #include "file-ops.h" |
2926 | 42 #include "file-stat.h" |
240 | 43 #include "lo-error.h" |
2926 | 44 #include "oct-env.h" |
3019 | 45 #include "pathsearch.h" |
1907 | 46 #include "str-vec.h" |
223 | 47 |
2492 | 48 #include <defaults.h> |
3933 | 49 #include "Cell.h" |
1355 | 50 #include "defun.h" |
9335
f2d354df53ee
new option, --no-window-system
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
51 #include "display.h" |
1355 | 52 #include "error.h" |
53 #include "file-io.h" | |
1 | 54 #include "input.h" |
55 #include "lex.h" | |
5832 | 56 #include "load-path.h" |
4113 | 57 #include "octave.h" |
1742 | 58 #include "oct-hist.h" |
5654 | 59 #include "oct-map.h" |
3195 | 60 #include "oct-obj.h" |
2375 | 61 #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
|
62 #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
|
63 #include "ov-range.h" |
1670 | 64 #include "toplev.h" |
1 | 65 #include "parse.h" |
562 | 66 #include "procstream.h" |
1355 | 67 #include "sighandlers.h" |
68 #include "sysdep.h" | |
1 | 69 #include "unwind-prot.h" |
1355 | 70 #include "utils.h" |
71 #include "variables.h" | |
2492 | 72 #include <version.h> |
1 | 73 |
4159 | 74 // Kluge. |
5990 | 75 extern "C" F77_RET_T |
11518 | 76 F77_FUNC (xerbla, XERBLA) (F77_CONST_CHAR_ARG_DECL, |
77 const octave_idx_type& | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
78 F77_CHAR_ARG_LEN_DECL); |
4159 | 79 |
2910 | 80 extern void install_builtins (void); |
81 | |
1907 | 82 // The command-line options. |
83 static string_vector octave_argv; | |
1 | 84 |
5780 | 85 // The name used to invoke Octave. |
86 static std::string | |
87 octave_program_invocation_name; | |
88 | |
89 // The last component of octave_program_invocation_name. | |
90 static std::string octave_program_name; | |
91 | |
2239 | 92 // TRUE means we read ~/.octaverc and ./.octaverc. |
93 // (--norc; --no-init-file; -f) | |
94 static bool read_init_files = true; | |
95 | |
96 // TRUE means we read the site-wide octaverc files. | |
97 // (--norc; --no-site-file; -f) | |
2240 | 98 static bool read_site_files = true; |
1 | 99 |
6365 | 100 // 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
|
101 // (--no-init-path) |
6365 | 102 static bool set_initial_path = true; |
103 | |
3019 | 104 // TRUE means we don't print the usual startup message. |
616 | 105 // (--quiet; --silent; -q) |
2239 | 106 static bool inhibit_startup_message = false; |
1 | 107 |
3019 | 108 // TRUE means we turn on compatibility options. |
1410 | 109 // (--traditional) |
2239 | 110 static bool traditional = false; |
1410 | 111 |
3019 | 112 // If TRUE, print verbose info in some cases. |
1825 | 113 // (--verbose; -V) |
2239 | 114 static bool verbose_flag = false; |
1825 | 115 |
1 | 116 // Usage message |
139 | 117 static const char *usage_string = |
11140 | 118 "octave [-HVdfhiqvx] [--debug] [--echo-commands] [--eval CODE]\n\ |
5814 | 119 [--exec-path path] [--help] [--image-path path] [--info-file file]\n\ |
9336
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
120 [--info-program prog] [--interactive] [--line-editing]\n\ |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
121 [--no-history] [--no-init-file] [--no-init-path] [--no-line-editing]\n\ |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
122 [--no-site-file] [--no-window-system] [-p path] [--path path]\n\ |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
123 [--silent] [--traditional] [--verbose] [--version] [file]"; |
1 | 124 |
1358 | 125 // This is here so that it's more likely that the usage message and |
1410 | 126 // the real set of options will agree. Note: the `+' must come first |
127 // to prevent getopt from permuting arguments! | |
11140 | 128 static const char *short_opts = "+HVdfhip:qvx"; |
139 | 129 |
5189 | 130 // The code to evaluate at startup (--eval CODE) |
131 static std::string code_to_eval; | |
132 | |
133 // If TRUE, don't exit after evaluating code given by --eval option. | |
134 static bool persist = false; | |
4356 | 135 |
1103 | 136 // Long options. See the comments in getopt.h for the meanings of the |
137 // fields in this structure. | |
8861 | 138 #define DOC_CACHE_FILE_OPTION 1 |
139 #define EVAL_OPTION 2 | |
140 #define EXEC_PATH_OPTION 3 | |
141 #define IMAGE_PATH_OPTION 4 | |
142 #define INFO_FILE_OPTION 5 | |
143 #define INFO_PROG_OPTION 6 | |
9336
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
144 #define LINE_EDITING_OPTION 7 |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
145 #define NO_INIT_FILE_OPTION 8 |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
146 #define NO_INIT_PATH_OPTION 9 |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
147 #define NO_LINE_EDITING_OPTION 10 |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
148 #define NO_SITE_FILE_OPTION 11 |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
149 #define NO_WINDOW_SYSTEM_OPTION 12 |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
150 #define PERSIST_OPTION 13 |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
151 #define TRADITIONAL_OPTION 14 |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
152 struct option long_opts[] = |
139 | 153 { |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
154 { "braindead", no_argument, 0, TRADITIONAL_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
155 { "debug", no_argument, 0, 'd' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
156 { "doc-cache-file", required_argument, 0, DOC_CACHE_FILE_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
157 { "echo-commands", no_argument, 0, 'x' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
158 { "eval", required_argument, 0, EVAL_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
159 { "exec-path", required_argument, 0, EXEC_PATH_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
160 { "help", no_argument, 0, 'h' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
161 { "image-path", required_argument, 0, IMAGE_PATH_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
162 { "info-file", required_argument, 0, INFO_FILE_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
163 { "info-program", required_argument, 0, INFO_PROG_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
164 { "interactive", no_argument, 0, 'i' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
165 { "line-editing", no_argument, 0, LINE_EDITING_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
166 { "no-history", no_argument, 0, 'H' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
167 { "no-init-file", no_argument, 0, NO_INIT_FILE_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
168 { "no-init-path", no_argument, 0, NO_INIT_PATH_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
169 { "no-line-editing", no_argument, 0, NO_LINE_EDITING_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
170 { "no-site-file", no_argument, 0, NO_SITE_FILE_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
171 { "no-window-system", no_argument, 0, NO_WINDOW_SYSTEM_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
172 { "norc", no_argument, 0, 'f' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
173 { "path", required_argument, 0, 'p' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
174 { "persist", no_argument, 0, PERSIST_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
175 { "quiet", no_argument, 0, 'q' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
176 { "silent", no_argument, 0, 'q' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
177 { "traditional", no_argument, 0, TRADITIONAL_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
178 { "verbose", no_argument, 0, 'V' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
179 { "version", no_argument, 0, 'v' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
180 { 0, 0, 0, 0 } |
139 | 181 }; |
1 | 182 |
1355 | 183 // Store the command-line options for later use. |
184 | |
185 static void | |
186 intern_argv (int argc, char **argv) | |
187 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
188 assert (symbol_table::at_top_level ()); |
4892 | 189 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
190 symbol_table::varref (".nargin.") = argc - 1; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
191 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
192 symbol_table::mark_hidden (".nargin."); |
3195 | 193 |
10485
b4e14e628fc9
Truncate argv() for scripts used without command line parameters. Bug #29423
Judd Storrs <jstorrs@gmail.com>
parents:
10370
diff
changeset
|
194 if (argc > 0) |
1355 | 195 { |
7336 | 196 octave_argv.resize (argc - 1); |
3933 | 197 |
2495 | 198 // Skip program name in argv. |
3933 | 199 int i = argc; |
200 while (--i > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
201 octave_argv[i-1] = *(argv+i); |
1355 | 202 } |
203 } | |
204 | |
1792 | 205 static void |
206 initialize_pathsearch (void) | |
207 { | |
208 // This may seem odd, but doing it this way means that we don't have | |
209 // to modify the kpathsea library... | |
210 | |
3523 | 211 std::string odb = octave_env::getenv ("OCTAVE_DB_PATH"); |
3141 | 212 |
213 // For backward compatibility. | |
1792 | 214 |
2926 | 215 if (odb.empty ()) |
3141 | 216 odb = octave_env::getenv ("OCTAVE_DB_DIR"); |
1792 | 217 |
3141 | 218 if (odb.empty ()) |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
219 odb = Vdata_dir + file_ops::dir_sep_str () + "octave:" |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
220 + Vlibexec_dir + file_ops::dir_sep_str () + "octave"; |
1792 | 221 } |
222 | |
5654 | 223 DEFUN (__version_info__, args, , |
224 "-*- texinfo -*-\n\ | |
6678 | 225 @deftypefn {Built-in Function} {retval =} __version_info__ (@var{name}, @var{version}, @var{release}, @var{date})\n\ |
6945 | 226 Undocumented internal function.\n\ |
5654 | 227 @end deftypefn") |
228 { | |
229 octave_value retval; | |
230 | |
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
|
231 static octave_map vinfo; |
5654 | 232 |
233 int nargin = args.length (); | |
234 | |
5658 | 235 if (nargin == 4) |
5654 | 236 { |
6639 | 237 if (vinfo.nfields () == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
238 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
239 vinfo.assign ("Name", args (0)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
240 vinfo.assign ("Version", args (1)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
241 vinfo.assign ("Release", args (2)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
242 vinfo.assign ("Date", args (3)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
243 } |
5781 | 244 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
245 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
246 octave_idx_type n = vinfo.numel () + 1; |
5654 | 247 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
248 vinfo.resize (dim_vector (n, 1)); |
5781 | 249 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
250 octave_value idx (n); |
5781 | 251 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
252 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
|
253 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
|
254 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
|
255 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
|
256 } |
5654 | 257 } |
258 else if (nargin == 0) | |
259 retval = vinfo; | |
260 else | |
5823 | 261 print_usage (); |
5654 | 262 |
263 return retval; | |
264 } | |
265 | |
266 static void | |
267 initialize_version_info (void) | |
268 { | |
269 octave_value_list args; | |
270 | |
5658 | 271 args(3) = OCTAVE_RELEASE_DATE; |
272 args(2) = OCTAVE_RELEASE; | |
5654 | 273 args(1) = OCTAVE_VERSION; |
274 args(0) = "GNU Octave"; | |
275 | |
276 F__version_info__ (args, 0); | |
277 } | |
278 | |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
279 static void |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
280 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
|
281 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
282 std::cerr << "error: " << msg << "\n" |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
283 << "error: execution of " << file << " failed\n" |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
284 << "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
|
285 << std::endl; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
286 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
287 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
288 // 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
|
289 // 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
|
290 // 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
|
291 // the main loop in toplev.cc. |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
292 |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
293 static void |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
294 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
|
295 const std::string& context = std::string (), |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
296 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
|
297 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
|
298 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
299 try |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
300 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
301 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
|
302 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
303 catch (octave_interrupt_exception) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
304 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
305 recover_from_exception (); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
306 octave_stdout << "\n"; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
307 if (quitting_gracefully) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
308 clean_up_and_exit (exit_status); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
309 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
310 catch (octave_execution_exception) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
311 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
312 recover_from_exception (); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
313 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
|
314 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
315 catch (std::bad_alloc) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
316 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
317 recover_from_exception (); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
318 gripe_safe_source_exception |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
319 (file_name, |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
320 "memory exhausted or requested size too large for range of Octave's index type"); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
321 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
322 } |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
323 |
581 | 324 // Initialize by reading startup files. |
325 | |
1 | 326 static void |
327 execute_startup_files (void) | |
328 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
329 unwind_protect frame; |
315 | 330 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
331 frame.protect_var (input_from_startup_file); |
1651 | 332 |
3019 | 333 input_from_startup_file = true; |
315 | 334 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
335 std::string context; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
336 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
337 bool verbose = (verbose_flag && ! inhibit_startup_message); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
338 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
339 bool require_file = false; |
578 | 340 |
2239 | 341 if (read_site_files) |
1 | 342 { |
2239 | 343 // Execute commands from the site-wide configuration file. |
344 // First from the file $(prefix)/lib/octave/site/m/octaverc | |
345 // (if it exists), then from the file | |
3597 | 346 // $(prefix)/share/octave/$(version)/m/octaverc (if it exists). |
1755 | 347 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
348 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
|
349 require_file); |
1755 | 350 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
351 safe_source_file (Vsite_defaults_file, context, verbose, require_file); |
1 | 352 } |
353 | |
2239 | 354 if (read_init_files) |
355 { | |
2512 | 356 // Try to execute commands from $HOME/$OCTAVE_INITFILE and |
357 // $OCTAVE_INITFILE. If $OCTAVE_INITFILE is not set, .octaverc | |
358 // is assumed. | |
2239 | 359 |
4804 | 360 bool home_rc_already_executed = false; |
2512 | 361 |
3523 | 362 std::string initfile = octave_env::getenv ("OCTAVE_INITFILE"); |
2512 | 363 |
2926 | 364 if (initfile.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
365 initfile = ".octaverc"; |
2512 | 366 |
3523 | 367 std::string home_dir = octave_env::get_home_directory (); |
2926 | 368 |
4804 | 369 std::string home_rc = octave_env::make_absolute (initfile, home_dir); |
370 | |
371 std::string local_rc; | |
2239 | 372 |
5781 | 373 if (! home_rc.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
374 { |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
375 safe_source_file (home_rc, context, verbose, require_file); |
2239 | 376 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
377 // Names alone are not enough. |
2239 | 378 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
379 file_stat fs_home_rc (home_rc); |
2239 | 380 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
381 if (fs_home_rc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
382 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
383 // 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
|
384 // because doing that may change the working directory. |
4804 | 385 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
386 local_rc = octave_env::make_absolute (initfile); |
4804 | 387 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
388 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
|
389 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
390 } |
2239 | 391 |
392 if (! home_rc_already_executed) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
393 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
394 if (local_rc.empty ()) |
10250 | 395 local_rc = octave_env::make_absolute (initfile); |
4804 | 396 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
397 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
|
398 } |
2239 | 399 } |
1 | 400 } |
401 | |
5189 | 402 static int |
403 execute_eval_option_code (const std::string& code) | |
404 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
405 unwind_protect frame; |
5189 | 406 |
7202 | 407 octave_save_signal_mask (); |
408 | |
409 can_interrupt = true; | |
410 | |
411 octave_signal_hook = octave_signal_handler; | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
412 octave_interrupt_hook = 0; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
413 octave_bad_alloc_hook = 0; |
7202 | 414 |
415 octave_catch_interrupts (); | |
416 | |
417 octave_initialized = true; | |
418 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
419 frame.protect_var (interactive); |
5189 | 420 |
421 interactive = false; | |
422 | |
423 int parse_status = 0; | |
424 | |
6487 | 425 try |
426 { | |
427 eval_string (code, false, parse_status, 0); | |
428 } | |
7202 | 429 catch (octave_interrupt_exception) |
430 { | |
431 recover_from_exception (); | |
432 octave_stdout << "\n"; | |
9383 | 433 if (quitting_gracefully) |
434 clean_up_and_exit (exit_status); | |
7202 | 435 } |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
436 catch (octave_execution_exception) |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
437 { |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
438 recover_from_exception (); |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
439 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
|
440 << std::endl; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
441 } |
6487 | 442 catch (std::bad_alloc) |
443 { | |
6680 | 444 std::cerr << "error: memory exhausted or requested size too large for range of Octave's index type -- eval failed" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
445 << std::endl; |
6487 | 446 } |
5189 | 447 |
448 return parse_status; | |
449 } | |
450 | |
451 static void | |
452 execute_command_line_file (const std::string& fname) | |
453 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
454 unwind_protect frame; |
5189 | 455 |
7202 | 456 octave_save_signal_mask (); |
457 | |
458 can_interrupt = true; | |
459 | |
460 octave_signal_hook = octave_signal_handler; | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
461 octave_interrupt_hook = 0; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
462 octave_bad_alloc_hook = 0; |
7202 | 463 |
464 octave_catch_interrupts (); | |
465 | |
466 octave_initialized = true; | |
467 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
468 frame.protect_var (interactive); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
469 frame.protect_var (reading_script_file); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
470 frame.protect_var (input_from_command_line_file); |
5189 | 471 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
472 frame.protect_var (curr_fcn_file_name); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
473 frame.protect_var (curr_fcn_file_full_name); |
5189 | 474 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
475 frame.protect_var (octave_program_invocation_name); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
476 frame.protect_var (octave_program_name); |
5189 | 477 |
478 interactive = false; | |
479 reading_script_file = true; | |
480 input_from_command_line_file = true; | |
481 | |
482 curr_fcn_file_name = fname; | |
483 curr_fcn_file_full_name = curr_fcn_file_name; | |
484 | |
5780 | 485 octave_program_invocation_name = curr_fcn_file_name; |
5189 | 486 |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
487 size_t pos = curr_fcn_file_name.find_last_of (file_ops::dir_sep_chars ()); |
5189 | 488 |
8021 | 489 std::string tmp = (pos != std::string::npos) |
5189 | 490 ? curr_fcn_file_name.substr (pos+1) : curr_fcn_file_name; |
491 | |
5780 | 492 octave_program_name = tmp; |
5189 | 493 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
494 std::string context; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
495 bool verbose = false; |
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
496 bool require_file = true; |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
497 |
11368
944b7e20fc5a
improve handling of exceptions for startup files
John W. Eaton <jwe@octave.org>
parents:
11234
diff
changeset
|
498 safe_source_file (fname, context, verbose, require_file, "octave"); |
5189 | 499 } |
500 | |
581 | 501 // Usage message with extra help. |
502 | |
1 | 503 static void |
504 verbose_usage (void) | |
505 { | |
3922 | 506 std::cout << OCTAVE_NAME_VERSION_COPYRIGHT_COPYING_AND_WARRANTY "\n\ |
1613 | 507 \n\ |
10731
f5dbac015606
Add [FILE] to octave usage string (bug #30258).
Rik <octave@nomad.inbox5.com>
parents:
10613
diff
changeset
|
508 Usage: octave [options] [FILE]\n\ |
1613 | 509 \n\ |
510 Options:\n\ | |
1119 | 511 \n\ |
3180 | 512 --debug, -d Enter parser debugging mode.\n\ |
8923
d47290508a55
document --doc-cache-file option
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
513 --doc-cache-file FILE Use doc cache file FILE.\n\ |
3180 | 514 --echo-commands, -x Echo commands as they are executed.\n\ |
5191 | 515 --eval CODE Evaluate CODE. Exit when done unless --persist.\n\ |
1613 | 516 --exec-path PATH Set path for executing subprograms.\n\ |
11140 | 517 --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
|
518 --image-path PATH Add PATH to head of image search path.\n\ |
1613 | 519 --info-file FILE Use top-level info file FILE.\n\ |
520 --info-program PROGRAM Use PROGRAM for reading info files.\n\ | |
3180 | 521 --interactive, -i Force interactive behavior.\n\ |
6938 | 522 --line-editing Force readline use for command-line editing.\n\ |
3180 | 523 --no-history, -H Don't save commands to the history list\n\ |
2470 | 524 --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
|
525 --no-init-path Don't initialize function search path.\n\ |
2212 | 526 --no-line-editing Don't use readline for command-line editing.\n\ |
2470 | 527 --no-site-file Don't read the site-wide octaverc file.\n\ |
9335
f2d354df53ee
new option, --no-window-system
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
528 --no-window-system Disable window system, including graphics.\n\ |
3238 | 529 --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
|
530 --path PATH, -p PATH Add PATH to head of function search path.\n\ |
5189 | 531 --persist Go interactive after --eval or reading from FILE.\n\ |
3180 | 532 --silent, -q Don't print message at startup.\n\ |
9132
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
533 --traditional Set variables for closer MATLAB compatibility.\n\ |
3180 | 534 --verbose, -V Enable verbose output in some cases.\n\ |
535 --version, -v Print version number and exit.\n\ | |
1119 | 536 \n\ |
5190 | 537 FILE Execute commands from FILE. Exit when done\n\ |
5191 | 538 unless --persist is also specified.\n\ |
4829 | 539 \n" |
540 OCTAVE_WWW_STATEMENT "\n\ | |
4356 | 541 \n" |
542 OCTAVE_CONTRIB_STATEMENT "\n\ | |
543 \n" | |
544 OCTAVE_BUGS_STATEMENT "\n"; | |
285 | 545 |
613 | 546 exit (0); |
1 | 547 } |
548 | |
581 | 549 // Terse usage messsage. |
550 | |
1 | 551 static void |
552 usage (void) | |
553 { | |
11140 | 554 std::cerr << "\nusage: " << usage_string << "\n\n"; |
1 | 555 exit (1); |
556 } | |
557 | |
558 static void | |
559 print_version_and_exit (void) | |
560 { | |
3922 | 561 std::cout << OCTAVE_NAME_VERSION_COPYRIGHT_COPYING_WARRANTY_AND_BUGS "\n"; |
1 | 562 exit (0); |
563 } | |
564 | |
721 | 565 static void |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
566 lo_error_handler (const char *fmt, ...) |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
567 { |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
568 va_list args; |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
569 va_start (args, fmt); |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9724
diff
changeset
|
570 verror_with_cfn (fmt, args); |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
571 va_end (args); |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
572 |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
573 octave_throw_execution_exception (); |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
574 } |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
575 |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
576 static void |
10370
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
577 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
|
578 { |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
579 va_list args; |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
580 va_start (args, fmt); |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
581 verror_with_id_cfn (id, fmt, args); |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
582 va_end (args); |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
583 |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
584 octave_throw_execution_exception (); |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
585 } |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
586 |
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
587 static void |
721 | 588 initialize_error_handlers () |
589 { | |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
590 set_liboctave_error_handler (lo_error_handler); |
10370
9c4daf174387
implement IDs for common liboctave exceptions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
591 set_liboctave_error_with_id_handler (lo_error_with_id_handler); |
3325 | 592 set_liboctave_warning_handler (warning); |
5781 | 593 set_liboctave_warning_with_id_handler (warning_with_id); |
721 | 594 } |
595 | |
1410 | 596 // What happens on --traditional. |
597 | |
598 static void | |
599 maximum_braindamage (void) | |
600 { | |
5189 | 601 persist = true; |
602 | |
5794 | 603 bind_internal_variable ("PS1", ">> "); |
604 bind_internal_variable ("PS2", ""); | |
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
|
605 bind_internal_variable ("allow_noninteger_range_as_index", true); |
5794 | 606 bind_internal_variable ("beep_on_error", true); |
8473
4dd0213bb883
octave.cc (maximum_braindamage): set confirm_recursive_rmdir to false
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
607 bind_internal_variable ("confirm_recursive_rmdir", false); |
5794 | 608 bind_internal_variable ("crash_dumps_octave_core", false); |
609 bind_internal_variable ("default_save_options", "-mat-binary"); | |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
11066
diff
changeset
|
610 bind_internal_variable ("do_braindead_shortcircuit_evaluation", true); |
5794 | 611 bind_internal_variable ("fixed_point_format", true); |
612 bind_internal_variable ("history_timestamp_format_string", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
613 "%%-- %D %I:%M %p --%%"); |
5794 | 614 bind_internal_variable ("page_screen_output", false); |
615 bind_internal_variable ("print_empty_dimensions", false); | |
5904 | 616 |
9584
0fcbfddaa87f
allow abbreviated graphics property names to match, with optional warning
John W. Eaton <jwe@octave.org>
parents:
9383
diff
changeset
|
617 disable_warning ("Octave:abbreviated-property-match"); |
6159 | 618 disable_warning ("Octave:fopen-file-in-path"); |
5904 | 619 disable_warning ("Octave:function-name-clash"); |
6159 | 620 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
|
621 disable_warning ("Octave:possible-matlab-short-circuit-operator"); |
1410 | 622 } |
623 | |
581 | 624 // You guessed it. |
625 | |
1 | 626 int |
4368 | 627 octave_main (int argc, char **argv, int embedded) |
1 | 628 { |
3019 | 629 octave_env::set_program_name (argv[0]); |
630 | |
5780 | 631 octave_program_invocation_name = octave_env::get_program_invocation_name (); |
632 octave_program_name = octave_env::get_program_name (); | |
633 | |
2205 | 634 // The order of these calls is important. The call to |
2926 | 635 // install_defaults must come before install_builtins because |
3019 | 636 // default variable values must be available for the variables to be |
2205 | 637 // installed, and the call to install_builtins must come before the |
638 // options are processed because some command line options override | |
5794 | 639 // defaults by calling bind_internal_variable. |
721 | 640 |
5844 | 641 init_signals (); |
642 | |
1 | 643 sysdep_init (); |
644 | |
11234
2718e1fdf82f
IEEE math initialization tweaks
John W. Eaton <jwe@octave.org>
parents:
11157
diff
changeset
|
645 octave_ieee_init (); |
2718e1fdf82f
IEEE math initialization tweaks
John W. Eaton <jwe@octave.org>
parents:
11157
diff
changeset
|
646 |
4159 | 647 // The idea here is to force xerbla to be referenced so that we will |
648 // link to our own version instead of the one provided by the BLAS | |
649 // library. But octave_NaN should never be -1, so we should never | |
650 // actually call xerbla. | |
651 | |
652 if (octave_NaN == -1) | |
11157
c75130f19440
octave.cc: fix call to xerbla
John W. Eaton <jwe@octave.org>
parents:
11140
diff
changeset
|
653 F77_FUNC (xerbla, XERBLA) ("octave", 13 F77_CHAR_ARG_LEN (6)); |
4159 | 654 |
721 | 655 initialize_error_handlers (); |
223 | 656 |
5794 | 657 initialize_default_warning_state (); |
658 | |
2926 | 659 install_defaults (); |
1 | 660 |
1792 | 661 initialize_pathsearch (); |
1744 | 662 |
4368 | 663 if (! embedded) |
664 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
|
665 else |
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
666 quit_allowed = false; |
2205 | 667 |
668 initialize_file_io (); | |
669 | |
2375 | 670 install_types (); |
671 | |
672 install_ops (); | |
2205 | 673 |
674 install_builtins (); | |
675 | |
6938 | 676 bool forced_line_editing = false; |
677 | |
8273
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
8099
diff
changeset
|
678 bool read_history_file = true; |
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
8099
diff
changeset
|
679 |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
680 while (true) |
1 | 681 { |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
682 int long_idx; |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
683 |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
684 int optc = getopt_long (argc, argv, short_opts, long_opts, &long_idx); |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
685 |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
686 if (optc < 0) |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
687 break; |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
688 |
139 | 689 switch (optc) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
690 { |
11140 | 691 case '?': |
692 // Unrecognized option. getopt_long already printed a | |
693 // message about that, so we will just print the usage string | |
694 // and exit. | |
695 usage (); | |
696 break; | |
697 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
698 case 'H': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
699 read_history_file = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
700 bind_internal_variable ("saving_history", false); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
701 break; |
3180 | 702 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
703 case 'V': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
704 verbose_flag = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
705 break; |
793 | 706 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
707 case 'd': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
708 // This is the same as yydebug in parse.y. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
709 octave_debug++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
710 break; |
777 | 711 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
712 case 'f': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
713 read_init_files = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
714 read_site_files = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
715 break; |
777 | 716 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
717 case 'h': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
718 verbose_usage (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
719 break; |
777 | 720 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
721 case 'i': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
722 forced_interactive = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
723 break; |
777 | 724 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
725 case 'p': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
726 if (optarg) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
727 load_path::set_command_line_path (optarg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
728 break; |
777 | 729 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
730 case 'q': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
731 inhibit_startup_message = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
732 break; |
777 | 733 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
734 case 'x': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
735 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
736 double tmp = (ECHO_SCRIPTS | ECHO_FUNCTIONS | ECHO_CMD_LINE); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
737 bind_internal_variable ("echo_executing_commands", tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
738 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
739 break; |
777 | 740 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
741 case 'v': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
742 print_version_and_exit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
743 break; |
777 | 744 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
745 case DOC_CACHE_FILE_OPTION: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
746 if (optarg) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
747 bind_internal_variable ("doc_cache_file", optarg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
748 break; |
8861 | 749 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
750 case EVAL_OPTION: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
751 if (optarg) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
752 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
753 if (code_to_eval.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
754 code_to_eval = optarg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
755 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
756 code_to_eval += std::string (" ") + optarg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
757 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
758 break; |
5189 | 759 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
760 case EXEC_PATH_OPTION: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
761 if (optarg) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
762 set_exec_path (optarg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
763 break; |
5814 | 764 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
765 case IMAGE_PATH_OPTION: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
766 if (optarg) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
767 set_image_path (optarg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
768 break; |
1613 | 769 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
770 case INFO_FILE_OPTION: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
771 if (optarg) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
772 bind_internal_variable ("info_file", optarg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
773 break; |
777 | 774 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
775 case INFO_PROG_OPTION: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
776 if (optarg) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
777 bind_internal_variable ("info_program", optarg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
778 break; |
1613 | 779 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
780 case LINE_EDITING_OPTION: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
781 forced_line_editing = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
782 break; |
6938 | 783 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
784 case NO_INIT_FILE_OPTION: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
785 read_init_files = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
786 break; |
2239 | 787 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
788 case NO_INIT_PATH_OPTION: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
789 set_initial_path = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
790 break; |
9336
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
791 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
792 case NO_LINE_EDITING_OPTION: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
793 line_editing = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
794 break; |
2239 | 795 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
796 case NO_SITE_FILE_OPTION: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
797 read_site_files = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
798 break; |
1821 | 799 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
800 case NO_WINDOW_SYSTEM_OPTION: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
801 display_info::no_window_system (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
802 break; |
9335
f2d354df53ee
new option, --no-window-system
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
803 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
804 case PERSIST_OPTION: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
805 persist = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
806 break; |
9336
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
807 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
808 case TRADITIONAL_OPTION: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
809 traditional = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
810 break; |
1410 | 811 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
812 default: |
11140 | 813 // getopt_long should print a message about unrecognized |
814 // options and return '?', which is handled above. So if we | |
815 // end up here, it is because there was an option but we | |
816 // forgot to handle it. That should be fatal. | |
817 panic_impossible (); | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
818 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
819 } |
1 | 820 } |
821 | |
2077 | 822 // Make sure we clean up when we exit. Also allow users to register |
823 // functions. If we don't have atexit or on_exit, we're going to | |
824 // leave some junk files around if we exit abnormally. | |
825 | |
826 atexit (do_octave_atexit); | |
1 | 827 |
9320
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
828 // 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
|
829 // interactive. |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
830 |
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
|
831 // 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
|
832 // a redirected file. |
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
|
833 stdin_is_tty = isatty (fileno (stdin)); |
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
|
834 |
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
|
835 interactive = (! embedded && stdin_is_tty && isatty (fileno (stdout))); |
9320
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
836 |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
837 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
|
838 line_editing = false; |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
839 |
9321
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
9320
diff
changeset
|
840 // 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
|
841 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
|
842 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
|
843 |
1358 | 844 // These can come after command line args since none of them set any |
845 // defaults that might be changed by command line options. | |
581 | 846 |
9320
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
847 if (line_editing) |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
848 initialize_command_input (); |
315 | 849 |
578 | 850 if (! inhibit_startup_message) |
3538 | 851 std::cout << OCTAVE_STARTUP_MESSAGE "\n" << std::endl; |
578 | 852 |
1410 | 853 if (traditional) |
854 maximum_braindamage (); | |
855 | |
4217 | 856 octave_interpreter_ready = true; |
857 | |
5654 | 858 initialize_version_info (); |
859 | |
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
|
860 // 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
|
861 // 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
|
862 |
e0a6e54f5a19
octave.cc (octave_main): make all command-line arguments available to startup scripts
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
863 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
|
864 |
6365 | 865 load_path::initialize (set_initial_path); |
4217 | 866 |
2239 | 867 execute_startup_files (); |
1651 | 868 |
8273
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
8099
diff
changeset
|
869 initialize_history (read_history_file); |
1 | 870 |
578 | 871 if (! inhibit_startup_message && reading_startup_message_printed) |
3538 | 872 std::cout << std::endl; |
578 | 873 |
1358 | 874 // If there is an extra argument, see if it names a file to read. |
875 // Additional arguments are taken as command line options for the | |
876 // script. | |
1 | 877 |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
878 int last_arg_idx = optind; |
3019 | 879 |
1817 | 880 int remaining_args = argc - last_arg_idx; |
3019 | 881 |
5189 | 882 if (! code_to_eval.empty ()) |
149 | 883 { |
5189 | 884 int parse_status = execute_eval_option_code (code_to_eval); |
885 | |
5242 | 886 if (! (persist || remaining_args > 0)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
887 clean_up_and_exit (parse_status || error_state ? 1 : 0); |
1 | 888 } |
889 | |
5189 | 890 if (remaining_args > 0) |
891 { | |
892 // If we are running an executable script (#! /bin/octave) then | |
893 // we should only see the args passed to the script. | |
894 | |
895 intern_argv (remaining_args, argv+last_arg_idx); | |
896 | |
897 execute_command_line_file (argv[last_arg_idx]); | |
898 | |
899 if (! persist) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
900 clean_up_and_exit (error_state ? 1 : 0); |
5189 | 901 } |
902 | |
903 // Avoid counting commands executed from startup files. | |
904 | |
905 command_editor::reset_current_command_number (1); | |
906 | |
907 // Now argv should have the full set of args. | |
908 intern_argv (argc, argv); | |
909 | |
910 if (! embedded) | |
911 switch_to_buffer (create_buffer (get_input_from_stdin ())); | |
912 | |
1358 | 913 // Force input to be echoed if not really interactive, but the user |
914 // has forced interactive behavior. | |
1 | 915 |
1907 | 916 if (! interactive && forced_interactive) |
287 | 917 { |
2926 | 918 command_editor::blink_matching_paren (false); |
1588 | 919 |
5775 | 920 // FIXME -- is this the right thing to do? |
1588 | 921 |
5794 | 922 bind_internal_variable ("echo_executing_commands", ECHO_CMD_LINE); |
287 | 923 } |
1 | 924 |
4368 | 925 if (embedded) |
5502 | 926 { |
5775 | 927 // FIXME -- do we need to do any cleanup here before |
5502 | 928 // returning? If we don't, what will happen to Octave functions |
929 // that have been registered to execute with atexit, for example? | |
930 | |
931 return 1; | |
932 } | |
4368 | 933 |
5189 | 934 int retval = main_loop (); |
1 | 935 |
1005 | 936 if (retval == 1 && ! error_state) |
937 retval = 0; | |
938 | |
1 | 939 clean_up_and_exit (retval); |
4247 | 940 |
941 return 0; | |
1 | 942 } |
943 | |
5780 | 944 DEFUN (argv, args, , |
945 "-*- texinfo -*-\n\ | |
946 @deftypefn {Built-in Function} {} argv ()\n\ | |
947 Return the command line arguments passed to Octave. For example,\n\ | |
948 if you invoked Octave using the command\n\ | |
949 \n\ | |
950 @example\n\ | |
951 octave --no-line-editing --silent\n\ | |
952 @end example\n\ | |
953 \n\ | |
954 @noindent\n\ | |
955 @code{argv} would return a cell array of strings with the elements\n\ | |
10840 | 956 @option{--no-line-editing} and @option{--silent}.\n\ |
5780 | 957 \n\ |
958 If you write an executable Octave script, @code{argv} will return the\n\ | |
959 list of arguments passed to the script. @xref{Executable Octave Programs},\n\ | |
960 for an example of how to create an executable Octave script.\n\ | |
961 @end deftypefn") | |
962 { | |
963 octave_value retval; | |
964 | |
965 if (args.length () == 0) | |
966 retval = Cell (octave_argv); | |
967 else | |
5823 | 968 print_usage (); |
5780 | 969 |
970 return retval; | |
971 } | |
972 | |
973 DEFUN (program_invocation_name, args, , | |
974 "-*- texinfo -*-\n\ | |
9724
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9584
diff
changeset
|
975 @deftypefn {Built-in Function} {} program_invocation_name ()\n\ |
5780 | 976 Return the name that was typed at the shell prompt to run Octave.\n\ |
977 \n\ | |
978 If executing a script from the command line (e.g., @code{octave foo.m})\n\ | |
979 or using an executable Octave script, the program name is set to the\n\ | |
980 name of the script. @xref{Executable Octave Programs}, for an example of\n\ | |
981 how to create an executable Octave script.\n\ | |
982 @seealso{program_name}\n\ | |
983 @end deftypefn") | |
984 { | |
985 octave_value retval; | |
986 | |
987 if (args.length () == 0) | |
988 retval = octave_program_invocation_name; | |
989 else | |
5823 | 990 print_usage (); |
5780 | 991 |
992 return retval; | |
993 } | |
994 | |
995 DEFUN (program_name, args, , | |
996 "-*- texinfo -*-\n\ | |
997 @deftypefn {Built-in Function} {} program_name ()\n\ | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8273
diff
changeset
|
998 Return the last component of the value returned by\n\ |
5780 | 999 @code{program_invocation_name}.\n\ |
1000 @seealso{program_invocation_name}\n\ | |
1001 @end deftypefn") | |
1002 { | |
1003 octave_value retval; | |
1004 | |
1005 if (args.length () == 0) | |
1006 retval = octave_program_name; | |
1007 else | |
5823 | 1008 print_usage (); |
5780 | 1009 |
1010 return retval; | |
1011 } |