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