Mercurial > octave
annotate libinterp/corefcn/interpreter.cc @ 22322:93b3cdd36854
move most f77 function decls to separate header files
* liboctave/numeric/lo-amos-proto.h,
liboctave/numeric/lo-arpack-proto.h,
liboctave/numeric/lo-blas-proto.h,
liboctave/numeric/lo-fftpack-proto.h,
liboctave/numeric/lo-lapack-proto.h,
liboctave/numeric/lo-qrupdate-proto.h,
liboctave/numeric/lo-ranlib-proto.h,
liboctave/numeric/lo-slatec-proto.h: New files.
* liboctave/numeric/module.mk: Update.
* __pchip_deriv__.cc, dot.cc, interpreter.cc, ordschur.cc, qz.cc,
CColVector.cc, CMatrix.cc, CNDArray.cc, CRowVector.cc, CSparse.cc,
dColVector.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc,
fCColVector.cc, fCMatrix.cc, fCNDArray.cc, fCRowVector.cc,
fColVector.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc, EIG.cc,
aepbalance.cc, chol.cc, eigs-base.cc, fEIG.cc, gepbalance.cc, gsvd.cc,
hess.cc, lo-specfun.cc, lu.cc, oct-rand.cc, qr.cc, qrp.cc,
randpoisson.cc, schur.cc, sparse-qr.cc, svd.cc:
Use new header files.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 17 Aug 2016 00:18:08 -0400 |
parents | dd992fd74fce |
children | bac0d6f07a3e |
rev | line source |
---|---|
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 /* |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
3 Copyright (C) 1993-2015 John W. Eaton |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 This file is part of Octave. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 Octave is free software; you can redistribute it and/or modify it |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 Free Software Foundation; either version 3 of the License, or (at your |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
10 option) any later version. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 for more details. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 */ |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 # include "config.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 #endif |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 #include <string> |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 #include <iostream> |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 #include "cmd-edit.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #include "file-ops.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 #include "file-stat.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 #include "fpucw-wrappers.h" |
22322
93b3cdd36854
move most f77 function decls to separate header files
John W. Eaton <jwe@octave.org>
parents:
22196
diff
changeset
|
34 #include "lo-blas-proto.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 #include "lo-error.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 #include "oct-env.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 #include "str-vec.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 #include "signal-wrappers.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 #include "unistd-wrappers.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 #include "builtins.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 #include "defaults.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 #include "Cell.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 #include "defun.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 #include "display.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 #include "error.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 #include "file-io.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 #include "graphics.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 #include "interpreter.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 #include "load-path.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 #include "load-save.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 #include "octave-link.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 #include "octave.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 #include "oct-hist.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 #include "oct-map.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 #include "oct-mutex.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 #include "ops.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 #include "ovl.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 #include "ov.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 #include "ov-classdef.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 #include "parse.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 #include "pt-eval.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 #include "pt-jump.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 #include "pt-stmt.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 #include "sighandlers.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
66 #include "sysdep.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
67 #include "unwind-prot.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 #include "utils.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
69 #include "variables.h" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 #include <version.h> |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
71 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 void (*octave_exit) (int) = ::exit; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 // TRUE means the quit() call is allowed. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 bool quit_allowed = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 // TRUE means we are ready to interpret commands, but not everything |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 // is ready for interactive use. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 bool octave_interpreter_ready = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 // TRUE means we've processed all the init code and we are good to go. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
82 bool octave_initialized = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
84 DEFUN (__version_info__, args, , |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
85 doc: /* -*- texinfo -*- |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
86 @deftypefn {} {retval =} __version_info__ (@var{name}, @var{version}, @var{release}, @var{date}) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
87 Undocumented internal function. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
88 @end deftypefn */) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
90 static octave_map vinfo; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
92 int nargin = args.length (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
93 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
94 if (nargin != 0 && nargin != 4) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
95 print_usage (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
96 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
97 octave_value retval; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
98 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
99 if (nargin == 0) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
100 retval = vinfo; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
101 else if (nargin == 4) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
102 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
103 if (vinfo.nfields () == 0) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
104 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
105 vinfo.assign ("Name", args(0)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
106 vinfo.assign ("Version", args(1)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
107 vinfo.assign ("Release", args(2)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
108 vinfo.assign ("Date", args(3)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
109 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
110 else |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
111 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
112 octave_idx_type n = vinfo.numel () + 1; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
113 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
114 vinfo.resize (dim_vector (n, 1)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
115 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
116 octave_value idx (n); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
117 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 vinfo.assign (idx, "Name", Cell (octave_value (args(0)))); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
119 vinfo.assign (idx, "Version", Cell (octave_value (args(1)))); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
120 vinfo.assign (idx, "Release", Cell (octave_value (args(2)))); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
121 vinfo.assign (idx, "Date", Cell (octave_value (args(3)))); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
122 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
123 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
124 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
125 return retval; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
126 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
127 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
128 static void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
129 initialize_version_info (void) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
130 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
131 octave_value_list args; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
132 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
133 args(3) = OCTAVE_RELEASE_DATE; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
134 args(2) = OCTAVE_RELEASE; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
135 args(1) = OCTAVE_VERSION; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
136 args(0) = "GNU Octave"; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
137 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
138 F__version_info__ (args, 0); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
139 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
140 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
141 OCTAVE_NORETURN static void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
142 lo_error_handler (const char *fmt, ...) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
143 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
144 va_list args; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
145 va_start (args, fmt); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
146 verror_with_cfn (fmt, args); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
147 va_end (args); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
148 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
149 octave_throw_execution_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
150 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
151 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
152 OCTAVE_NORETURN static void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
153 lo_error_with_id_handler (const char *id, const char *fmt, ...) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
154 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
155 va_list args; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
156 va_start (args, fmt); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
157 verror_with_id_cfn (id, fmt, args); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
158 va_end (args); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
159 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
160 octave_throw_execution_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
161 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
162 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
163 static void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
164 initialize_error_handlers () |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
165 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
166 set_liboctave_error_handler (lo_error_handler); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
167 set_liboctave_error_with_id_handler (lo_error_with_id_handler); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
168 set_liboctave_warning_handler (warning); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
169 set_liboctave_warning_with_id_handler (warning_with_id); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
170 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
171 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
172 // What internal options get configured by --traditional. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
173 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
174 static void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
175 maximum_braindamage (void) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
176 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
177 FPS1 (octave_value (">> ")); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
178 FPS2 (octave_value ("")); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
179 FPS4 (octave_value ("")); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
180 Fbeep_on_error (octave_value (true)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
181 Fconfirm_recursive_rmdir (octave_value (false)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
182 Fcrash_dumps_octave_core (octave_value (false)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
183 Fdisable_diagonal_matrix (octave_value (true)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
184 Fdisable_permutation_matrix (octave_value (true)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
185 Fdisable_range (octave_value (true)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
186 Ffixed_point_format (octave_value (true)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
187 Fhistory_timestamp_format_string (octave_value ("%%-- %D %I:%M %p --%%")); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
188 Fpage_screen_output (octave_value (false)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
189 Fprint_empty_dimensions (octave_value (false)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
190 Fsave_default_options (octave_value ("-mat-binary")); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
191 Fstruct_levels_to_print (octave_value (0)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
192 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
193 disable_warning ("Octave:abbreviated-property-match"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
194 disable_warning ("Octave:data-file-in-path"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
195 disable_warning ("Octave:function-name-clash"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
196 disable_warning ("Octave:possible-matlab-short-circuit-operator"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
197 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
198 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
199 void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
200 recover_from_exception (void) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
201 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
202 octave::can_interrupt = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
203 octave_interrupt_immediately = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
204 octave_interrupt_state = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
205 octave_signal_caught = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
206 octave_exception_state = octave_no_exception; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
207 octave_restore_signal_mask (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
208 octave::catch_interrupts (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
209 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
210 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
211 // Fix up things before exiting. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
212 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
213 static std::list<std::string> octave_atexit_functions; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
214 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
215 DEFUN (quit, args, , |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
216 doc: /* -*- texinfo -*- |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
217 @deftypefn {} {} exit |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
218 @deftypefnx {} {} exit (@var{status}) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
219 @deftypefnx {} {} quit |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
220 @deftypefnx {} {} quit (@var{status}) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
221 Exit the current Octave session. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
222 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
223 If the optional integer value @var{status} is supplied, pass that value to |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
224 the operating system as Octave's exit status. The default value is zero. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
225 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
226 When exiting, Octave will attempt to run the m-file @file{finish.m} if it |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
227 exists. User commands to save the workspace or clean up temporary files |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
228 may be placed in that file. Alternatively, another m-file may be scheduled |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
229 to run using @code{atexit}. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
230 @seealso{atexit} |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
231 @end deftypefn */) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
232 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
233 // Confirm OK to shutdown. Note: A dynamic function installation similar |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
234 // to overriding polymorphism for which the GUI can install its own "quit" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
235 // yet call this base "quit" could be nice. No link would be needed here. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
236 if (! octave_link::confirm_shutdown ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
237 return ovl (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
238 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
239 if (! quit_allowed) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
240 error ("quit: not supported in embedded mode"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
241 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
242 int exit_status = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
243 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
244 if (args.length () > 0) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
245 exit_status = args(0).nint_value (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
246 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
247 // Instead of simply calling exit, we thrown an exception so that no |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
248 // matter where the call to quit occurs, we will run the |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
249 // unwind_protect stack, clear the OCTAVE_LOCAL_BUFFER allocations, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
250 // etc. before exiting. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
251 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
252 clean_up_and_exit (exit_status); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
253 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
254 return ovl (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
255 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
256 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
257 DEFALIAS (exit, quit); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
258 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
259 void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
260 octave_add_atexit_function (const std::string& fname) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
261 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
262 octave_atexit_functions.push_front (fname); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
263 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
264 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
265 bool |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
266 octave_remove_atexit_function (const std::string& fname) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
267 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
268 bool found = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
269 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
270 for (std::list<std::string>::iterator p = octave_atexit_functions.begin (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
271 p != octave_atexit_functions.end (); p++) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
272 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
273 if (*p == fname) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
274 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
275 octave_atexit_functions.erase (p); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
276 found = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
277 break; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
278 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
279 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
280 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
281 return found; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
282 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
283 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
284 DEFUN (atexit, args, nargout, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
285 doc: /* -*- texinfo -*- |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
286 @deftypefn {} {} atexit (@var{fcn}) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
287 @deftypefnx {} {} atexit (@var{fcn}, @var{flag}) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
288 Register a function to be called when Octave exits. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
289 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
290 For example, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
291 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
292 @example |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
293 @group |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
294 function last_words () |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
295 disp ("Bye bye"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
296 endfunction |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
297 atexit ("last_words"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
298 @end group |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
299 @end example |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
300 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
301 @noindent |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
302 will print the message @qcode{"Bye bye"} when Octave exits. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
303 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
304 The additional argument @var{flag} will register or unregister @var{fcn} |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
305 from the list of functions to be called when Octave exits. If @var{flag} is |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
306 true, the function is registered, and if @var{flag} is false, it is |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
307 unregistered. For example, after registering the function @code{last_words} |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
308 above, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
309 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
310 @example |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
311 atexit ("last_words", false); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
312 @end example |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
313 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
314 @noindent |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
315 will remove the function from the list and Octave will not call |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
316 @code{last_words} when it exits. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
317 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
318 Note that @code{atexit} only removes the first occurrence of a function |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
319 from the list, so if a function was placed in the list multiple times with |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
320 @code{atexit}, it must also be removed from the list multiple times. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
321 @seealso{quit} |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
322 @end deftypefn */) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
323 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
324 int nargin = args.length (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
325 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
326 if (nargin < 1 || nargin > 2) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
327 print_usage (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
328 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
329 std::string arg = args(0).xstring_value ("atexit: FCN argument must be a string"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
330 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
331 bool add_mode = (nargin == 2) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
332 ? args(1).xbool_value ("atexit: FLAG argument must be a logical value") |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
333 : true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
334 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
335 octave_value_list retval; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
336 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
337 if (add_mode) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
338 octave_add_atexit_function (arg); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
339 else |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
340 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
341 bool found = octave_remove_atexit_function (arg); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
342 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
343 if (nargout > 0) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
344 retval = ovl (found); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
345 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
346 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
347 return retval; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
348 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
349 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
350 // Execute commands from a file and catch potential exceptions in a consistent |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
351 // way. This function should be called anywhere we might parse and execute |
22173
8de49f15e182
doc: Fix "doubled words" typos (\b(\w+)\s+\1\b)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
22133
diff
changeset
|
352 // commands from a file before we have entered the main loop in |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
353 // toplev.cc. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
354 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
355 static void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
356 safe_source_file (const std::string& file_name, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
357 const std::string& context = "", |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
358 bool verbose = false, bool require_file = true, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
359 const std::string& warn_for = "") |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
360 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
361 try |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
362 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
363 source_file (file_name, context, verbose, require_file, warn_for); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
364 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
365 catch (const index_exception& e) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
366 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
367 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
368 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
369 std::cerr << "error: index exception in " << file_name << ": " |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
370 << e.message () << std::endl; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
371 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
372 catch (const octave_exit_exception& ex) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
373 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
374 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
375 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
376 clean_up_and_exit (ex.exit_status (), ex.safe_to_return ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
377 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
378 catch (const octave_interrupt_exception&) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
379 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
380 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
381 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
382 catch (const octave_execution_exception&) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
383 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
384 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
385 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
386 std::cerr << "error: execution exception in " << file_name << std::endl; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
387 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
388 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
389 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
390 static void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
391 execute_pkg_add (const std::string& dir) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
392 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
393 std::string file_name = octave::sys::file_ops::concat (dir, "PKG_ADD"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
394 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
395 try |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
396 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
397 load_path::execute_pkg_add (dir); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
398 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
399 catch (const index_exception& e) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
400 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
401 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
402 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
403 std::cerr << "error: index exception in " << file_name << ": " |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
404 << e.message () << std::endl; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
405 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
406 catch (const octave_exit_exception& ex) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
407 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
408 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
409 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
410 clean_up_and_exit (ex.exit_status (), ex.safe_to_return ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
411 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
412 catch (const octave_interrupt_exception&) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
413 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
414 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
415 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
416 catch (const octave_execution_exception&) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
417 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
418 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
419 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
420 std::cerr << "error: execution exception in " << file_name << std::endl; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
421 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
422 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
423 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
424 static void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
425 initialize_load_path (bool set_initial_path) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
426 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
427 // Temporarily set the execute_pkg_add function to one that catches |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
428 // exceptions. This is better than wrapping load_path::initialize in |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
429 // a try-catch block because it will not stop executing PKG_ADD files |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
430 // at the first exception. It's also better than changing the default |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
431 // execute_pkg_add function to use safe_source file because that will |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
432 // normally be evaluated from the normal intepreter loop where |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
433 // exceptions are already handled. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
434 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
435 octave::unwind_protect frame; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
436 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
437 frame.add_fcn (load_path::set_add_hook, load_path::get_add_hook ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
438 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
439 load_path::set_add_hook (execute_pkg_add); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
440 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
441 load_path::initialize (set_initial_path); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
442 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
443 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
444 // Initialize by reading startup files. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
445 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
446 static void |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
447 execute_startup_files (bool read_site_files, bool read_init_files, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
448 bool verbose_flag, bool inhibit_startup_message) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
449 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
450 octave::unwind_protect frame; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
451 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
452 std::string context; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
453 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
454 bool verbose = (verbose_flag && ! inhibit_startup_message); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
455 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
456 bool require_file = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
457 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
458 if (read_site_files) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
459 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
460 // Execute commands from the site-wide configuration file. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
461 // First from the file $(prefix)/lib/octave/site/m/octaverc |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
462 // (if it exists), then from the file |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
463 // $(prefix)/share/octave/$(version)/m/octaverc (if it exists). |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
464 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
465 safe_source_file (Vlocal_site_defaults_file, context, verbose, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
466 require_file); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
467 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
468 safe_source_file (Vsite_defaults_file, context, verbose, require_file); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
469 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
470 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
471 if (read_init_files) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
472 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
473 // Try to execute commands from $HOME/$OCTAVE_INITFILE and |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
474 // $OCTAVE_INITFILE. If $OCTAVE_INITFILE is not set, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
475 // .octaverc is assumed. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
476 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
477 bool home_rc_already_executed = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
478 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
479 std::string initfile = octave::sys::env::getenv ("OCTAVE_INITFILE"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
480 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
481 if (initfile.empty ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
482 initfile = ".octaverc"; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
483 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
484 std::string home_dir = octave::sys::env::get_home_directory (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
485 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
486 std::string home_rc = octave::sys::env::make_absolute (initfile, home_dir); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
487 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
488 std::string local_rc; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
489 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
490 if (! home_rc.empty ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
491 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
492 safe_source_file (home_rc, context, verbose, require_file); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
493 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
494 // Names alone are not enough. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
495 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
496 octave::sys::file_stat fs_home_rc (home_rc); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
497 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
498 if (fs_home_rc) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
499 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
500 // We want to check for curr_dir after executing home_rc |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
501 // because doing that may change the working directory. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
502 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
503 local_rc = octave::sys::env::make_absolute (initfile); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
504 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
505 home_rc_already_executed = same_file (home_rc, local_rc); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
506 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
507 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
508 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
509 if (! home_rc_already_executed) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
510 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
511 if (local_rc.empty ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
512 local_rc = octave::sys::env::make_absolute (initfile); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
513 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
514 safe_source_file (local_rc, context, verbose, require_file); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
515 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
516 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
517 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
518 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
519 namespace octave |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
520 { |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
521 tree_evaluator *current_evaluator = 0; |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
522 |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
523 interpreter::interpreter (application *app_context, bool embedded) |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
524 : m_app_context (app_context), m_evaluator (new tree_evaluator (this)), |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
525 m_embedded (embedded), m_interactive (false), |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
526 m_quitting_gracefully (false) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
527 { |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
528 current_evaluator = m_evaluator; |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
529 |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
530 cmdline_options options = m_app_context->options (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
531 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
532 // Matlab uses "C" locale for LC_NUMERIC class regardless of local setting |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
533 setlocale (LC_NUMERIC, "C"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
534 setlocale (LC_TIME, "C"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
535 octave::sys::env::putenv ("LC_NUMERIC", "C"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
536 octave::sys::env::putenv ("LC_TIME", "C"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
537 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
538 // Initialize the default floating point unit control state. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
539 octave_set_default_fpucw (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
540 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
541 string_vector all_args = options.all_args (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
542 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
543 octave_thread::init (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
544 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
545 set_default_prompts (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
546 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
547 // Initialize default warning state before --traditional option |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
548 // that may reset them. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
549 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
550 initialize_default_warning_state (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
551 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
552 if (options.traditional ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
553 maximum_braindamage (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
554 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
555 octave_ieee_init (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
556 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
557 // The idea here is to force xerbla to be referenced so that we will link to |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
558 // our own version instead of the one provided by the BLAS library. But |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
559 // octave::numeric_limits<double>::NaN () should never be -1, so we |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
560 // should never actually call xerbla. FIXME (again!): If this |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
561 // becomes a constant expression the test might be optimized away and |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
562 // then the reference to the function might also disappear. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
563 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
564 if (octave::numeric_limits<double>::NaN () == -1) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
565 F77_FUNC (xerbla, XERBLA) ("octave", 13 F77_CHAR_ARG_LEN (6)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
566 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
567 initialize_error_handlers (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
568 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
569 if (! m_embedded) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
570 octave::install_signal_handlers (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
571 else |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
572 quit_allowed = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
573 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
574 initialize_file_io (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
575 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
576 install_types (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
577 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
578 install_ops (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
579 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
580 install_builtins (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
581 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
582 install_classdef (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
583 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
584 std::list<std::string> command_line_path = options.command_line_path (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
585 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
586 for (std::list<std::string>::const_iterator it = command_line_path.begin (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
587 it != command_line_path.end (); it++) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
588 load_path::set_command_line_path (*it); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
589 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
590 std::string exec_path = options.exec_path (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
591 if (! exec_path.empty ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
592 set_exec_path (exec_path); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
593 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
594 std::string image_path = options.image_path (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
595 if (! image_path.empty ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
596 set_image_path (image_path); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
597 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
598 if (options.no_window_system ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
599 display_info::no_window_system (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
600 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
601 // Is input coming from a terminal? If so, we are probably interactive. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
602 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
603 // If stdin is not a tty, then we are reading commands from a pipe or |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
604 // a redirected file. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
605 bool stdin_is_tty = octave_isatty_wrapper (fileno (stdin)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
606 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
607 m_interactive = (! m_embedded |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
608 && ! m_app_context->is_octave_program () |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
609 && stdin_is_tty |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
610 && octave_isatty_wrapper (fileno (stdout))); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
611 |
22184
a032ffb80704
don't print startup message for --eval (bug #48620)
John W. Eaton <jwe@octave.org>
parents:
22173
diff
changeset
|
612 // Check if the user forced an interactive session. |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
613 if (options.forced_interactive ()) |
22184
a032ffb80704
don't print startup message for --eval (bug #48620)
John W. Eaton <jwe@octave.org>
parents:
22173
diff
changeset
|
614 m_interactive = true; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
615 |
22184
a032ffb80704
don't print startup message for --eval (bug #48620)
John W. Eaton <jwe@octave.org>
parents:
22173
diff
changeset
|
616 bool line_editing = options.line_editing (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
617 if ((! m_interactive || options.forced_interactive ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
618 && ! options.forced_line_editing ()) |
22184
a032ffb80704
don't print startup message for --eval (bug #48620)
John W. Eaton <jwe@octave.org>
parents:
22173
diff
changeset
|
619 line_editing = false; |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
620 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
621 // Force default line editor if we don't want readline editing. |
22185
dc20b737ee79
* interpreter.cc (interpreter::interpreter): Fix typo in previous change.
John W. Eaton <jwe@octave.org>
parents:
22184
diff
changeset
|
622 if (! line_editing) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
623 octave::command_editor::force_default_editor (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
624 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
625 // These can come after command line args since none of them set any |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
626 // defaults that might be changed by command line options. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
627 |
22185
dc20b737ee79
* interpreter.cc (interpreter::interpreter): Fix typo in previous change.
John W. Eaton <jwe@octave.org>
parents:
22184
diff
changeset
|
628 if (line_editing) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
629 initialize_command_input (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
630 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
631 octave_interpreter_ready = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
632 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
633 initialize_version_info (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
634 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
635 // Make all command-line arguments available to startup files, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
636 // including PKG_ADD files. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
637 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
638 app_context->intern_argv (options.all_args ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
639 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
640 initialize_load_path (options.set_initial_path ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
641 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
642 initialize_history (options.read_history_file ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
643 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
644 |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
645 interpreter::~interpreter (void) |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
646 { |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
647 current_evaluator = 0; |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
648 |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
649 delete m_evaluator; |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
650 } |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
651 |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
652 int interpreter::execute (void) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
653 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
654 cmdline_options options = m_app_context->options (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
655 |
22184
a032ffb80704
don't print startup message for --eval (bug #48620)
John W. Eaton <jwe@octave.org>
parents:
22173
diff
changeset
|
656 if (m_interactive && ! options.inhibit_startup_message ()) |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
657 std::cout << octave_startup_message () << "\n" << std::endl; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
658 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
659 octave_prepare_hdf5 (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
660 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
661 execute_startup_files (options.read_site_files (), |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
662 options.read_init_files (), |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
663 options.verbose_flag (), |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
664 options.inhibit_startup_message ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
665 |
22184
a032ffb80704
don't print startup message for --eval (bug #48620)
John W. Eaton <jwe@octave.org>
parents:
22173
diff
changeset
|
666 if (m_interactive && ! options.inhibit_startup_message () |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
667 && reading_startup_message_printed) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
668 std::cout << std::endl; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
669 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
670 // Execute any code specified with --eval 'CODE' |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
671 std::string code_to_eval = options.code_to_eval (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
672 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
673 if (! code_to_eval.empty ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
674 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
675 int parse_status = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
676 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
677 try |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
678 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
679 parse_status = execute_eval_option_code (code_to_eval); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
680 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
681 catch (const octave_execution_exception&) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
682 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
683 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
684 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
685 parse_status = 1; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
686 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
687 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
688 if (! options.persist ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
689 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
690 m_quitting_gracefully = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
691 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
692 clean_up_and_exit (parse_status); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
693 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
694 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
695 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
696 // If there is an extra argument, see if it names a file to read. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
697 // Additional arguments are taken as command line options for the script. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
698 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
699 if (m_app_context->have_script_file ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
700 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
701 // If we are running an executable script (#! /bin/octave) then |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
702 // we should only see the args passed to the script. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
703 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
704 int exit_status = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
705 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
706 try |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
707 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
708 string_vector script_args = options.remaining_args (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
709 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
710 m_app_context->intern_argv (script_args); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
711 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
712 execute_command_line_file (script_args[0]); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
713 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
714 catch (const octave_execution_exception&) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
715 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
716 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
717 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
718 exit_status = 1; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
719 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
720 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
721 // Restore full set of args. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
722 m_app_context->intern_argv (options.all_args ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
723 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
724 if (! options.persist ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
725 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
726 m_quitting_gracefully = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
727 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
728 clean_up_and_exit (exit_status); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
729 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
730 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
731 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
732 // Avoid counting commands executed from startup or script files. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
733 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
734 octave::command_editor::reset_current_command_number (1); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
735 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
736 // Force input to be echoed if not really interactive, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
737 // but the user has forced interactive behavior. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
738 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
739 if (options.forced_interactive ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
740 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
741 octave::command_editor::blink_matching_paren (false); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
742 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
743 // FIXME: is this the right thing to do? |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
744 Fecho_executing_commands (octave_value (ECHO_CMD_LINE)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
745 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
746 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
747 if (m_embedded) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
748 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
749 // FIXME: Do we need to do any cleanup here before returning? |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
750 // If we don't, what will happen to Octave functions that have been |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
751 // registered to execute with atexit, for example? |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
752 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
753 return 1; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
754 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
755 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
756 int retval = main_loop (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
757 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
758 m_quitting_gracefully = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
759 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
760 clean_up_and_exit (retval, true); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
761 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
762 return retval; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
763 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
764 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
765 int interpreter::execute_eval_option_code (const std::string& code) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
766 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
767 octave::unwind_protect frame; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
768 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
769 octave_save_signal_mask (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
770 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
771 octave::can_interrupt = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
772 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
773 octave_signal_hook = octave::signal_handler; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
774 octave_interrupt_hook = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
775 octave_bad_alloc_hook = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
776 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
777 octave::catch_interrupts (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
778 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
779 octave_initialized = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
780 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
781 frame.add_method (this, &interpreter::interactive, m_interactive); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
782 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
783 m_interactive = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
784 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
785 int parse_status = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
786 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
787 try |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
788 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
789 eval_string (code, false, parse_status, 0); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
790 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
791 catch (const octave_exit_exception& ex) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
792 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
793 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
794 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
795 clean_up_and_exit (ex.exit_status (), ex.safe_to_return ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
796 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
797 catch (const octave_interrupt_exception&) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
798 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
799 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
800 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
801 catch (const octave_execution_exception&) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
802 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
803 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
804 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
805 std::cerr << "error: unhandled execution exception -- eval failed" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
806 << std::endl; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
807 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
808 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
809 return parse_status; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
810 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
811 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
812 void interpreter::execute_command_line_file (const std::string& fname) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
813 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
814 octave::unwind_protect frame; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
815 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
816 octave_save_signal_mask (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
817 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
818 octave::can_interrupt = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
819 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
820 octave_signal_hook = octave::signal_handler; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
821 octave_interrupt_hook = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
822 octave_bad_alloc_hook = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
823 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
824 octave::catch_interrupts (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
825 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
826 octave_initialized = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
827 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
828 frame.add_method (this, &interpreter::interactive, m_interactive); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
829 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
830 frame.add_method (m_app_context, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
831 &application::program_invocation_name, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
832 application::program_invocation_name ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
833 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
834 frame.add_method (m_app_context, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
835 &application::program_name, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
836 application::program_name ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
837 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
838 m_interactive = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
839 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
840 m_app_context->set_program_names (fname); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
841 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
842 std::string context; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
843 bool verbose = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
844 bool require_file = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
845 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
846 safe_source_file (fname, context, verbose, require_file, "octave"); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
847 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
848 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
849 int interpreter::main_loop (void) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
850 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
851 octave_save_signal_mask (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
852 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
853 octave::can_interrupt = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
854 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
855 octave_signal_hook = octave::signal_handler; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
856 octave_interrupt_hook = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
857 octave_bad_alloc_hook = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
858 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
859 octave::catch_interrupts (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
860 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
861 octave_initialized = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
862 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
863 // The big loop. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
864 |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
865 octave::lexer *lxr = (octave::application::interactive () |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
866 ? new octave::lexer () |
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
867 : new octave::lexer (stdin)); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
868 |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
869 octave::parser parser (*lxr); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
870 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
871 int retval = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
872 do |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
873 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
874 try |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
875 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
876 reset_error_handler (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
877 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
878 parser.reset (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
879 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
880 if (symbol_table::at_top_level ()) |
22196
dd992fd74fce
put parser, lexer, and evaluator in namespace; interpreter now owns evaluator
John W. Eaton <jwe@octave.org>
parents:
22186
diff
changeset
|
881 octave::tree_evaluator::reset_debug_state (); |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
882 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
883 retval = parser.run (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
884 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
885 if (retval == 0) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
886 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
887 if (parser.stmt_list) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
888 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
889 parser.stmt_list->accept (*current_evaluator); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
890 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
891 octave_quit (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
892 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
893 if (! octave::application::interactive ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
894 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
895 bool quit = (tree_return_command::returning |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
896 || tree_break_command::breaking); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
897 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
898 if (tree_return_command::returning) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
899 tree_return_command::returning = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
900 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
901 if (tree_break_command::breaking) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
902 tree_break_command::breaking--; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
903 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
904 if (quit) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
905 break; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
906 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
907 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
908 if (octave_completion_matches_called) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
909 octave_completion_matches_called = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
910 else |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
911 octave::command_editor::increment_current_command_number (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
912 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
913 else if (parser.lexer.end_of_input) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
914 break; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
915 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
916 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
917 catch (const octave_exit_exception& ex) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
918 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
919 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
920 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
921 clean_up_and_exit (ex.exit_status (), ex.safe_to_return ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
922 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
923 catch (const octave_interrupt_exception&) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
924 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
925 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
926 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
927 // Required newline when the user does Ctrl+C at the prompt. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
928 if (octave::application::interactive ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
929 octave_stdout << "\n"; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
930 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
931 catch (const index_exception& e) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
932 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
933 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
934 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
935 std::cerr << "error: unhandled index exception: " |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
936 << e.message () << " -- trying to return to prompt" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
937 << std::endl; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
938 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
939 catch (const octave_execution_exception& e) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
940 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
941 std::string stack_trace = e.info (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
942 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
943 if (! stack_trace.empty ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
944 std::cerr << stack_trace; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
945 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
946 if (octave::application::interactive ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
947 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
948 else |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
949 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
950 // We should exit with a nonzero status. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
951 retval = 1; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
952 break; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
953 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
954 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
955 catch (const std::bad_alloc&) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
956 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
957 recover_from_exception (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
958 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
959 std::cerr << "error: out of memory -- trying to return to prompt" |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
960 << std::endl; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
961 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
962 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
963 #if defined (DBSTOP_NANINF) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
964 if (Vdebug_on_naninf) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
965 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
966 if (setjump (naninf_jump) != 0) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
967 debug_or_throw_exception (true); // true = stack trace |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
968 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
969 #endif |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
970 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
971 while (retval == 0); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
972 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
973 if (octave::application::interactive ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
974 octave_stdout << "\n"; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
975 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
976 if (retval == EOF) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
977 retval = 0; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
978 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
979 return retval; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
980 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
981 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
982 void interpreter::clean_up_and_exit (int status, bool safe_to_return) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
983 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
984 static bool deja_vu = false; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
985 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
986 OCTAVE_SAFE_CALL (remove_input_event_hook_functions, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
987 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
988 while (! octave_atexit_functions.empty ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
989 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
990 std::string fcn = octave_atexit_functions.front (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
991 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
992 octave_atexit_functions.pop_front (); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
993 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
994 OCTAVE_SAFE_CALL (reset_error_handler, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
995 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
996 OCTAVE_SAFE_CALL (feval, (fcn, octave_value_list (), 0)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
997 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
998 OCTAVE_SAFE_CALL (flush_octave_stdout, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
999 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1000 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1001 if (! deja_vu) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1002 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1003 deja_vu = true; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1004 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1005 // Process pending events and disasble octave_link event |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1006 // processing with this call. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1007 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1008 octave_link::process_events (true); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1009 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1010 // Do this explicitly so that destructors for mex file objects |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1011 // are called, so that functions registered with mexAtExit are |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1012 // called. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1013 OCTAVE_SAFE_CALL (clear_mex_functions, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1014 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1015 OCTAVE_SAFE_CALL (octave::command_editor::restore_terminal_state, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1016 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1017 // FIXME: is this needed? Can it cause any trouble? |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1018 OCTAVE_SAFE_CALL (raw_mode, (0)); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1019 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1020 OCTAVE_SAFE_CALL (octave_history_write_timestamp, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1021 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1022 if (! octave::command_history::ignoring_entries ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1023 OCTAVE_SAFE_CALL (octave::command_history::clean_up_and_save, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1024 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1025 OCTAVE_SAFE_CALL (gh_manager::close_all_figures, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1026 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1027 OCTAVE_SAFE_CALL (gtk_manager::unload_all_toolkits, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1028 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1029 OCTAVE_SAFE_CALL (close_files, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1030 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1031 OCTAVE_SAFE_CALL (cleanup_tmp_files, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1032 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1033 OCTAVE_SAFE_CALL (symbol_table::cleanup, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1034 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1035 OCTAVE_SAFE_CALL (sysdep_cleanup, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1036 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1037 OCTAVE_SAFE_CALL (octave_finalize_hdf5, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1038 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1039 OCTAVE_SAFE_CALL (flush_octave_stdout, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1040 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1041 if (! m_quitting_gracefully && octave::application::interactive ()) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1042 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1043 octave_stdout << "\n"; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1044 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1045 // Yes, we want this to be separate from the call to |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1046 // flush_octave_stdout above. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1047 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1048 OCTAVE_SAFE_CALL (flush_octave_stdout, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1049 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1050 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1051 // Don't call singleton_cleanup_list::cleanup until we have the |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1052 // problems with registering/unregistering types worked out. For |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1053 // example, uncomment the following line, then use the make_int |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1054 // function from the examples directory to create an integer |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1055 // object and then exit Octave. Octave should crash with a |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1056 // segfault when cleaning up the typinfo singleton. We need some |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1057 // way to force new octave_value_X types that are created in |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1058 // .oct files to be unregistered when the .oct file shared library |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1059 // is unloaded. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1060 // |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1061 // OCTAVE_SAFE_CALL (singleton_cleanup_list::cleanup, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1062 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1063 OCTAVE_SAFE_CALL (octave_chunk_buffer::clear, ()); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1064 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1065 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1066 if (octave_link::exit (status)) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1067 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1068 if (safe_to_return) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1069 return; |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1070 else |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1071 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1072 // What should we do here? We might be called from some |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1073 // location other than the end of octave_execute_interpreter, |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1074 // so it might not be safe to return. |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1075 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1076 // We have nothing else to do at this point, and the |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1077 // octave_link::exit function is supposed to take care of |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1078 // exiting for us. Assume that job won't take more than a |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1079 // day... |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1080 |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1081 octave_sleep (86400); // FIXME: really needed? |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1082 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1083 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1084 else |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1085 { |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1086 if (octave_exit) |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1087 (*octave_exit) (status); |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1088 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1089 } |
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1090 } |