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