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