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