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