Mercurial > octave
annotate src/octave.cc @ 9255:1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 25 May 2009 15:00:10 +0200 |
parents | ee7cf4d963f3 |
children | 9c2349a51218 |
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 | |
9009
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
370 static void |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
371 unmark_forced_vars (void *arg) |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
372 { |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
373 // Unmark any symbols that may have been tagged as local variables |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
374 // while parsing (for example, by force_local_variable in lex.l). |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
375 |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
376 symbol_table::scope_id *pscope = static_cast <symbol_table::scope_id *> (arg); |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
377 |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
378 if (pscope) |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
379 symbol_table::unmark_forced_variables (*pscope); |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
380 } |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
381 |
5189 | 382 static int |
383 execute_eval_option_code (const std::string& code) | |
384 { | |
385 unwind_protect::begin_frame ("execute_eval_option_code"); | |
386 | |
7202 | 387 octave_save_signal_mask (); |
388 | |
389 can_interrupt = true; | |
390 | |
391 octave_signal_hook = octave_signal_handler; | |
392 octave_interrupt_hook = unwind_protect::run_all; | |
393 octave_bad_alloc_hook = unwind_protect::run_all; | |
394 | |
395 octave_catch_interrupts (); | |
396 | |
397 octave_initialized = true; | |
398 | |
5189 | 399 unwind_protect_bool (interactive); |
400 | |
9009
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
401 // Do this with an unwind-protect cleanup function so that the |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
402 // forced variables will be unmarked in the event of an interrupt. |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
403 symbol_table::scope_id scope = symbol_table::top_scope (); |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
404 unwind_protect::add (unmark_forced_vars, &scope); |
da58ec8f62e8
tag bug don't define forced variables
John W. Eaton <jwe@octave.org>
parents:
8923
diff
changeset
|
405 |
5189 | 406 interactive = false; |
407 | |
408 int parse_status = 0; | |
409 | |
6487 | 410 try |
411 { | |
412 eval_string (code, false, parse_status, 0); | |
413 } | |
9217
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9132
diff
changeset
|
414 catch (octave_quit_exception e) |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9132
diff
changeset
|
415 { |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9132
diff
changeset
|
416 unwind_protect::run_frame ("execute_eval_option_code"); |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9132
diff
changeset
|
417 clean_up_and_exit (e.status); |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9132
diff
changeset
|
418 } |
7202 | 419 catch (octave_interrupt_exception) |
420 { | |
421 recover_from_exception (); | |
422 octave_stdout << "\n"; | |
423 } | |
6487 | 424 catch (std::bad_alloc) |
425 { | |
6680 | 426 std::cerr << "error: memory exhausted or requested size too large for range of Octave's index type -- eval failed" |
427 << std::endl; | |
6487 | 428 } |
5189 | 429 |
430 unwind_protect::run_frame ("execute_eval_option_code"); | |
431 | |
432 return parse_status; | |
433 } | |
434 | |
435 static void | |
436 execute_command_line_file (const std::string& fname) | |
437 { | |
438 unwind_protect::begin_frame ("execute_command_line_file"); | |
439 | |
7202 | 440 octave_save_signal_mask (); |
441 | |
442 can_interrupt = true; | |
443 | |
444 octave_signal_hook = octave_signal_handler; | |
445 octave_interrupt_hook = unwind_protect::run_all; | |
446 octave_bad_alloc_hook = unwind_protect::run_all; | |
447 | |
448 octave_catch_interrupts (); | |
449 | |
450 octave_initialized = true; | |
451 | |
5189 | 452 unwind_protect_bool (interactive); |
453 unwind_protect_bool (reading_script_file); | |
454 unwind_protect_bool (input_from_command_line_file); | |
455 | |
456 unwind_protect_str (curr_fcn_file_name); | |
457 unwind_protect_str (curr_fcn_file_full_name); | |
458 | |
5780 | 459 unwind_protect_str (octave_program_invocation_name); |
460 unwind_protect_str (octave_program_name); | |
5189 | 461 |
462 interactive = false; | |
463 reading_script_file = true; | |
464 input_from_command_line_file = true; | |
465 | |
466 curr_fcn_file_name = fname; | |
467 curr_fcn_file_full_name = curr_fcn_file_name; | |
468 | |
5780 | 469 octave_program_invocation_name = curr_fcn_file_name; |
5189 | 470 |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
471 size_t pos = curr_fcn_file_name.find_last_of (file_ops::dir_sep_chars ()); |
5189 | 472 |
8021 | 473 std::string tmp = (pos != std::string::npos) |
5189 | 474 ? curr_fcn_file_name.substr (pos+1) : curr_fcn_file_name; |
475 | |
5780 | 476 octave_program_name = tmp; |
5189 | 477 |
6504 | 478 try |
479 { | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
480 std::string context; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
481 bool verbose = false; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
482 bool require_file = true; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
483 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
484 source_file (fname, context, verbose, require_file, "octave"); |
6504 | 485 } |
9217
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9132
diff
changeset
|
486 catch (octave_quit_exception e) |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9132
diff
changeset
|
487 { |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9132
diff
changeset
|
488 unwind_protect::run_frame ("execute_command_line_file"); |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9132
diff
changeset
|
489 clean_up_and_exit (e.status); |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9132
diff
changeset
|
490 } |
7202 | 491 catch (octave_interrupt_exception) |
492 { | |
493 recover_from_exception (); | |
494 octave_stdout << "\n"; | |
495 } | |
6504 | 496 catch (std::bad_alloc) |
497 { | |
6680 | 498 std::cerr << "error: memory exhausted or requested size too large for range of Octave's index type -- execution of " |
499 << fname << " failed" << std::endl; | |
6504 | 500 } |
5189 | 501 |
502 unwind_protect::run_frame ("execute_command_line_file"); | |
503 } | |
504 | |
581 | 505 // Usage message with extra help. |
506 | |
1 | 507 static void |
508 verbose_usage (void) | |
509 { | |
3922 | 510 std::cout << OCTAVE_NAME_VERSION_COPYRIGHT_COPYING_AND_WARRANTY "\n\ |
1613 | 511 \n\ |
512 Usage: octave [options]\n\ | |
513 \n\ | |
514 Options:\n\ | |
1119 | 515 \n\ |
3180 | 516 --debug, -d Enter parser debugging mode.\n\ |
8923
d47290508a55
document --doc-cache-file option
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
517 --doc-cache-file FILE Use doc cache file FILE.\n\ |
3180 | 518 --echo-commands, -x Echo commands as they are executed.\n\ |
5191 | 519 --eval CODE Evaluate CODE. Exit when done unless --persist.\n\ |
1613 | 520 --exec-path PATH Set path for executing subprograms.\n\ |
3180 | 521 --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
|
522 --image-path PATH Add PATH to head of image search path.\n\ |
1613 | 523 --info-file FILE Use top-level info file FILE.\n\ |
524 --info-program PROGRAM Use PROGRAM for reading info files.\n\ | |
3180 | 525 --interactive, -i Force interactive behavior.\n\ |
6938 | 526 --line-editing Force readline use for command-line editing.\n\ |
3180 | 527 --no-history, -H Don't save commands to the history list\n\ |
2470 | 528 --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
|
529 --no-init-path Don't initialize function search path.\n\ |
2212 | 530 --no-line-editing Don't use readline for command-line editing.\n\ |
2470 | 531 --no-site-file Don't read the site-wide octaverc file.\n\ |
3238 | 532 --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
|
533 --path PATH, -p PATH Add PATH to head of function search path.\n\ |
5189 | 534 --persist Go interactive after --eval or reading from FILE.\n\ |
3180 | 535 --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
|
536 --traditional Set variables for closer MATLAB compatibility.\n\ |
3180 | 537 --verbose, -V Enable verbose output in some cases.\n\ |
538 --version, -v Print version number and exit.\n\ | |
1119 | 539 \n\ |
5190 | 540 FILE Execute commands from FILE. Exit when done\n\ |
5191 | 541 unless --persist is also specified.\n\ |
4829 | 542 \n" |
543 OCTAVE_WWW_STATEMENT "\n\ | |
4356 | 544 \n" |
545 OCTAVE_CONTRIB_STATEMENT "\n\ | |
546 \n" | |
547 OCTAVE_BUGS_STATEMENT "\n"; | |
285 | 548 |
613 | 549 exit (0); |
1 | 550 } |
551 | |
581 | 552 // Terse usage messsage. |
553 | |
1 | 554 static void |
555 usage (void) | |
556 { | |
3531 | 557 std::cerr << "usage: " << usage_string << "\n"; |
1 | 558 exit (1); |
559 } | |
560 | |
561 static void | |
562 print_version_and_exit (void) | |
563 { | |
3922 | 564 std::cout << OCTAVE_NAME_VERSION_COPYRIGHT_COPYING_WARRANTY_AND_BUGS "\n"; |
1 | 565 exit (0); |
566 } | |
567 | |
721 | 568 static void |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
569 lo_error_handler (const char *fmt, ...) |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
570 { |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
571 va_list args; |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
572 va_start (args, fmt); |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
573 verror (fmt, args); |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
574 va_end (args); |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
575 |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
576 octave_throw_execution_exception (); |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
577 } |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
578 |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
579 static void |
721 | 580 initialize_error_handlers () |
581 { | |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
582 set_liboctave_error_handler (lo_error_handler); |
3325 | 583 set_liboctave_warning_handler (warning); |
5781 | 584 set_liboctave_warning_with_id_handler (warning_with_id); |
721 | 585 } |
586 | |
1410 | 587 // What happens on --traditional. |
588 | |
589 static void | |
590 maximum_braindamage (void) | |
591 { | |
5189 | 592 persist = true; |
593 | |
5794 | 594 bind_internal_variable ("PS1", ">> "); |
595 bind_internal_variable ("PS2", ""); | |
596 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
|
597 bind_internal_variable ("confirm_recursive_rmdir", false); |
5794 | 598 bind_internal_variable ("crash_dumps_octave_core", false); |
599 bind_internal_variable ("default_save_options", "-mat-binary"); | |
600 bind_internal_variable ("fixed_point_format", true); | |
601 bind_internal_variable ("history_timestamp_format_string", | |
5305 | 602 "%%-- %D %I:%M %p --%%"); |
5794 | 603 bind_internal_variable ("page_screen_output", false); |
604 bind_internal_variable ("print_empty_dimensions", false); | |
5904 | 605 |
6159 | 606 disable_warning ("Octave:fopen-file-in-path"); |
5904 | 607 disable_warning ("Octave:function-name-clash"); |
6159 | 608 disable_warning ("Octave:load-file-in-path"); |
1410 | 609 } |
610 | |
581 | 611 // You guessed it. |
612 | |
1 | 613 int |
4368 | 614 octave_main (int argc, char **argv, int embedded) |
1 | 615 { |
3019 | 616 octave_env::set_program_name (argv[0]); |
617 | |
5780 | 618 octave_program_invocation_name = octave_env::get_program_invocation_name (); |
619 octave_program_name = octave_env::get_program_name (); | |
620 | |
2205 | 621 // The order of these calls is important. The call to |
2926 | 622 // install_defaults must come before install_builtins because |
3019 | 623 // default variable values must be available for the variables to be |
2205 | 624 // installed, and the call to install_builtins must come before the |
625 // options are processed because some command line options override | |
5794 | 626 // defaults by calling bind_internal_variable. |
721 | 627 |
5844 | 628 init_signals (); |
629 | |
1 | 630 sysdep_init (); |
631 | |
4159 | 632 // The idea here is to force xerbla to be referenced so that we will |
633 // link to our own version instead of the one provided by the BLAS | |
634 // library. But octave_NaN should never be -1, so we should never | |
635 // actually call xerbla. | |
636 | |
637 if (octave_NaN == -1) | |
638 F77_FUNC (xerbla, XERBLA) ("octave", 13, 6L); | |
639 | |
721 | 640 initialize_error_handlers (); |
223 | 641 |
5794 | 642 initialize_default_warning_state (); |
643 | |
2926 | 644 install_defaults (); |
1 | 645 |
1792 | 646 initialize_pathsearch (); |
1744 | 647 |
4368 | 648 if (! embedded) |
649 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
|
650 else |
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
651 quit_allowed = false; |
2205 | 652 |
653 initialize_file_io (); | |
654 | |
2375 | 655 install_types (); |
656 | |
657 install_ops (); | |
2205 | 658 |
659 install_builtins (); | |
660 | |
1817 | 661 prog_args args (argc, argv, short_opts, long_opts); |
662 | |
6938 | 663 bool forced_line_editing = false; |
664 | |
8273
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
8099
diff
changeset
|
665 bool read_history_file = true; |
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
8099
diff
changeset
|
666 |
139 | 667 int optc; |
1817 | 668 while ((optc = args.getopt ()) != EOF) |
1 | 669 { |
139 | 670 switch (optc) |
1 | 671 { |
3180 | 672 case 'H': |
8273
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
8099
diff
changeset
|
673 read_history_file = false; |
5794 | 674 bind_internal_variable ("saving_history", false); |
3180 | 675 break; |
676 | |
793 | 677 case 'V': |
2239 | 678 verbose_flag = true; |
793 | 679 break; |
680 | |
1 | 681 case 'd': |
4753 | 682 // This is the same as yydebug in parse.y. |
683 octave_debug++; | |
1 | 684 break; |
777 | 685 |
1 | 686 case 'f': |
2239 | 687 read_init_files = false; |
688 read_site_files = false; | |
1 | 689 break; |
777 | 690 |
1 | 691 case 'h': |
692 case '?': | |
693 verbose_usage (); | |
694 break; | |
777 | 695 |
1 | 696 case 'i': |
3019 | 697 forced_interactive = true; |
1 | 698 break; |
777 | 699 |
1 | 700 case 'p': |
1817 | 701 if (args.optarg ()) |
5832 | 702 load_path::set_command_line_path (args.optarg ()); |
1 | 703 break; |
777 | 704 |
1 | 705 case 'q': |
2239 | 706 inhibit_startup_message = true; |
1 | 707 break; |
777 | 708 |
1 | 709 case 'x': |
2205 | 710 { |
711 double tmp = (ECHO_SCRIPTS | ECHO_FUNCTIONS | ECHO_CMD_LINE); | |
5794 | 712 bind_internal_variable ("echo_executing_commands", tmp); |
2205 | 713 } |
1 | 714 break; |
777 | 715 |
1 | 716 case 'v': |
717 print_version_and_exit (); | |
718 break; | |
777 | 719 |
8861 | 720 case DOC_CACHE_FILE_OPTION: |
721 if (args.optarg ()) | |
722 bind_internal_variable ("doc_cache_file", args.optarg ()); | |
723 break; | |
724 | |
5189 | 725 case EVAL_OPTION: |
726 if (args.optarg ()) | |
5193 | 727 { |
728 if (code_to_eval.empty ()) | |
729 code_to_eval = args.optarg (); | |
730 else | |
731 code_to_eval += std::string (" ") + args.optarg (); | |
732 } | |
5189 | 733 break; |
734 | |
1613 | 735 case EXEC_PATH_OPTION: |
1817 | 736 if (args.optarg ()) |
5814 | 737 set_exec_path (args.optarg ()); |
738 break; | |
739 | |
740 case IMAGE_PATH_OPTION: | |
741 if (args.optarg ()) | |
742 set_image_path (args.optarg ()); | |
1613 | 743 break; |
744 | |
186 | 745 case INFO_FILE_OPTION: |
1817 | 746 if (args.optarg ()) |
5794 | 747 bind_internal_variable ("info_file", args.optarg ()); |
186 | 748 break; |
777 | 749 |
1613 | 750 case INFO_PROG_OPTION: |
1817 | 751 if (args.optarg ()) |
5794 | 752 bind_internal_variable ("info_program", args.optarg ()); |
1613 | 753 break; |
754 | |
9132
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
755 case LINE_EDITING_OPTION: |
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
756 forced_line_editing = true; |
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
757 break; |
6938 | 758 |
2239 | 759 case NO_INIT_FILE_OPTION: |
760 read_init_files = false; | |
761 break; | |
762 | |
1821 | 763 case NO_LINE_EDITING_OPTION: |
3019 | 764 line_editing = false; |
2239 | 765 break; |
766 | |
767 case NO_SITE_FILE_OPTION: | |
768 read_site_files = 0; | |
1821 | 769 break; |
770 | |
9132
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
771 case NO_INIT_PATH_OPTION: |
6365 | 772 set_initial_path = false; |
773 break; | |
774 | |
1410 | 775 case TRADITIONAL_OPTION: |
2239 | 776 traditional = true; |
1410 | 777 break; |
778 | |
5189 | 779 case PERSIST_OPTION: |
780 persist = true; | |
781 break; | |
782 | |
1 | 783 default: |
784 usage (); | |
785 break; | |
786 } | |
787 } | |
788 | |
1651 | 789 #if defined (HAVE_ATEXIT) || defined (HAVE_ON_EXIT) |
2077 | 790 // Make sure we clean up when we exit. Also allow users to register |
791 // functions. If we don't have atexit or on_exit, we're going to | |
792 // leave some junk files around if we exit abnormally. | |
793 | |
794 atexit (do_octave_atexit); | |
318 | 795 #endif |
1 | 796 |
1358 | 797 // These can come after command line args since none of them set any |
798 // defaults that might be changed by command line options. | |
581 | 799 |
2926 | 800 initialize_command_input (); |
315 | 801 |
578 | 802 if (! inhibit_startup_message) |
3538 | 803 std::cout << OCTAVE_STARTUP_MESSAGE "\n" << std::endl; |
578 | 804 |
1410 | 805 if (traditional) |
806 maximum_braindamage (); | |
807 | |
4217 | 808 octave_interpreter_ready = true; |
809 | |
5654 | 810 initialize_version_info (); |
811 | |
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
|
812 // 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
|
813 // 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
|
814 |
e0a6e54f5a19
octave.cc (octave_main): make all command-line arguments available to startup scripts
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
815 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
|
816 |
6365 | 817 load_path::initialize (set_initial_path); |
4217 | 818 |
2239 | 819 execute_startup_files (); |
1651 | 820 |
8273
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
8099
diff
changeset
|
821 initialize_history (read_history_file); |
1 | 822 |
578 | 823 if (! inhibit_startup_message && reading_startup_message_printed) |
3538 | 824 std::cout << std::endl; |
578 | 825 |
5189 | 826 // Is input coming from a terminal? If so, we are probably |
827 // interactive. | |
1358 | 828 |
5189 | 829 interactive = (! embedded |
830 && isatty (fileno (stdin)) && isatty (fileno (stdout))); | |
831 | |
6938 | 832 if (! interactive && ! forced_line_editing) |
5189 | 833 line_editing = false; |
1 | 834 |
1358 | 835 // If there is an extra argument, see if it names a file to read. |
836 // Additional arguments are taken as command line options for the | |
837 // script. | |
1 | 838 |
1817 | 839 int last_arg_idx = args.optind (); |
3019 | 840 |
1817 | 841 int remaining_args = argc - last_arg_idx; |
3019 | 842 |
5189 | 843 if (! code_to_eval.empty ()) |
149 | 844 { |
5189 | 845 int parse_status = execute_eval_option_code (code_to_eval); |
846 | |
5242 | 847 if (! (persist || remaining_args > 0)) |
5502 | 848 clean_up_and_exit (parse_status || error_state ? 1 : 0); |
1 | 849 } |
850 | |
5189 | 851 if (remaining_args > 0) |
852 { | |
853 // If we are running an executable script (#! /bin/octave) then | |
854 // we should only see the args passed to the script. | |
855 | |
856 intern_argv (remaining_args, argv+last_arg_idx); | |
857 | |
858 execute_command_line_file (argv[last_arg_idx]); | |
859 | |
860 if (! persist) | |
5502 | 861 clean_up_and_exit (error_state ? 1 : 0); |
5189 | 862 } |
863 | |
864 // Avoid counting commands executed from startup files. | |
865 | |
866 command_editor::reset_current_command_number (1); | |
867 | |
868 // Now argv should have the full set of args. | |
869 intern_argv (argc, argv); | |
870 | |
871 if (! embedded) | |
872 switch_to_buffer (create_buffer (get_input_from_stdin ())); | |
873 | |
1358 | 874 // Force input to be echoed if not really interactive, but the user |
875 // has forced interactive behavior. | |
1 | 876 |
1907 | 877 if (! interactive && forced_interactive) |
287 | 878 { |
2926 | 879 command_editor::blink_matching_paren (false); |
1588 | 880 |
5775 | 881 // FIXME -- is this the right thing to do? |
1588 | 882 |
5794 | 883 bind_internal_variable ("echo_executing_commands", ECHO_CMD_LINE); |
287 | 884 } |
1 | 885 |
4368 | 886 if (embedded) |
5502 | 887 { |
5775 | 888 // FIXME -- do we need to do any cleanup here before |
5502 | 889 // returning? If we don't, what will happen to Octave functions |
890 // that have been registered to execute with atexit, for example? | |
891 | |
892 return 1; | |
893 } | |
4368 | 894 |
5189 | 895 int retval = main_loop (); |
1 | 896 |
1005 | 897 if (retval == 1 && ! error_state) |
898 retval = 0; | |
899 | |
1 | 900 clean_up_and_exit (retval); |
4247 | 901 |
902 return 0; | |
1 | 903 } |
904 | |
5780 | 905 DEFUN (argv, args, , |
906 "-*- texinfo -*-\n\ | |
907 @deftypefn {Built-in Function} {} argv ()\n\ | |
908 Return the command line arguments passed to Octave. For example,\n\ | |
909 if you invoked Octave using the command\n\ | |
910 \n\ | |
911 @example\n\ | |
912 octave --no-line-editing --silent\n\ | |
913 @end example\n\ | |
914 \n\ | |
915 @noindent\n\ | |
916 @code{argv} would return a cell array of strings with the elements\n\ | |
917 @code{--no-line-editing} and @code{--silent}.\n\ | |
918 \n\ | |
919 If you write an executable Octave script, @code{argv} will return the\n\ | |
920 list of arguments passed to the script. @xref{Executable Octave Programs},\n\ | |
921 for an example of how to create an executable Octave script.\n\ | |
922 @end deftypefn") | |
923 { | |
924 octave_value retval; | |
925 | |
926 if (args.length () == 0) | |
927 retval = Cell (octave_argv); | |
928 else | |
5823 | 929 print_usage (); |
5780 | 930 |
931 return retval; | |
932 } | |
933 | |
934 DEFUN (program_invocation_name, args, , | |
935 "-*- texinfo -*-\n\ | |
936 @deftypefn {Built-in Function} program_invocation_name ()\n\ | |
937 Return the name that was typed at the shell prompt to run Octave.\n\ | |
938 \n\ | |
939 If executing a script from the command line (e.g., @code{octave foo.m})\n\ | |
940 or using an executable Octave script, the program name is set to the\n\ | |
941 name of the script. @xref{Executable Octave Programs}, for an example of\n\ | |
942 how to create an executable Octave script.\n\ | |
943 @seealso{program_name}\n\ | |
944 @end deftypefn") | |
945 { | |
946 octave_value retval; | |
947 | |
948 if (args.length () == 0) | |
949 retval = octave_program_invocation_name; | |
950 else | |
5823 | 951 print_usage (); |
5780 | 952 |
953 return retval; | |
954 } | |
955 | |
956 DEFUN (program_name, args, , | |
957 "-*- texinfo -*-\n\ | |
958 @deftypefn {Built-in Function} {} program_name ()\n\ | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8273
diff
changeset
|
959 Return the last component of the value returned by\n\ |
5780 | 960 @code{program_invocation_name}.\n\ |
961 @seealso{program_invocation_name}\n\ | |
962 @end deftypefn") | |
963 { | |
964 octave_value retval; | |
965 | |
966 if (args.length () == 0) | |
967 retval = octave_program_name; | |
968 else | |
5823 | 969 print_usage (); |
5780 | 970 |
971 return retval; | |
972 } | |
973 | |
560 | 974 /* |
1 | 975 ;;; Local Variables: *** |
976 ;;; mode: C++ *** | |
977 ;;; End: *** | |
978 */ |