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