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