Mercurial > hg > octave-avbm
annotate src/toplev.cc @ 10066:2cd940306a06
make unwind_protect frames local
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 06 Jan 2010 13:18:41 +0100 |
parents | 2b008f1d3794 |
children | 829e69ec3110 |
rev | line source |
---|---|
1683 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
8920 | 4 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton |
1683 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1683 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1683 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include <cassert> | |
4489 | 29 #include <cerrno> |
1683 | 30 #include <cstdlib> |
31 #include <cstring> | |
4221 | 32 #include <new> |
1683 | 33 |
3503 | 34 #include <fstream> |
35 #include <iostream> | |
5765 | 36 #include <sstream> |
1728 | 37 #include <string> |
38 | |
1683 | 39 #ifdef HAVE_UNISTD_H |
2442 | 40 #ifdef HAVE_SYS_TYPES_H |
1683 | 41 #include <sys/types.h> |
2442 | 42 #endif |
1683 | 43 #include <unistd.h> |
44 #endif | |
45 | |
2926 | 46 #include "cmd-edit.h" |
47 #include "file-ops.h" | |
1683 | 48 #include "lo-error.h" |
2370 | 49 #include "lo-mappers.h" |
3020 | 50 #include "oct-env.h" |
4153 | 51 #include "quit.h" |
1755 | 52 #include "str-vec.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8347
diff
changeset
|
53 #include "oct-locbuf.h" |
1683 | 54 |
2492 | 55 #include <defaults.h> |
1683 | 56 #include "defun.h" |
57 #include "error.h" | |
58 #include "file-io.h" | |
59 #include "input.h" | |
60 #include "lex.h" | |
2492 | 61 #include <oct-conf.h> |
1742 | 62 #include "oct-hist.h" |
2162 | 63 #include "oct-map.h" |
2862 | 64 #include "oct-obj.h" |
1683 | 65 #include "pager.h" |
66 #include "parse.h" | |
67 #include "pathsearch.h" | |
68 #include "procstream.h" | |
2370 | 69 #include "ov.h" |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8581
diff
changeset
|
70 #include "pt-eval.h" |
2985 | 71 #include "pt-jump.h" |
2982 | 72 #include "pt-stmt.h" |
1683 | 73 #include "sighandlers.h" |
74 #include "sysdep.h" | |
2693 | 75 #include "syswait.h" |
1750 | 76 #include "toplev.h" |
1683 | 77 #include "unwind-prot.h" |
78 #include "utils.h" | |
79 #include "variables.h" | |
2492 | 80 #include <version.h> |
1683 | 81 |
9217
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9187
diff
changeset
|
82 void (*octave_exit) (int) = ::exit; |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9187
diff
changeset
|
83 |
9255
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
84 // TRUE means the quit() call is allowed. |
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
85 bool quit_allowed = true; |
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
86 |
3020 | 87 // TRUE means we are exiting via the builtin exit or quit functions. |
9383 | 88 bool quitting_gracefully = false; |
89 // This stores the exit status. | |
90 int exit_status = 0; | |
1683 | 91 |
4217 | 92 // TRUE means we are ready to interpret commands, but not everything |
93 // is ready for interactive use. | |
94 bool octave_interpreter_ready = false; | |
95 | |
4172 | 96 // TRUE means we've processed all the init code and we are good to go. |
97 bool octave_initialized = false; | |
98 | |
1683 | 99 // Current command to execute. |
100 tree_statement_list *global_command = 0; | |
101 | |
5743 | 102 octave_call_stack *octave_call_stack::instance = 0; |
103 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
104 int |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
105 octave_call_stack::do_current_line (void) const |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
106 { |
9484
bbe033dcfe13
make dbwhere work when called at keyboard prompt
John W. Eaton <jwe@octave.org>
parents:
9483
diff
changeset
|
107 tree_statement *stmt = do_current_statement (); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
108 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
109 return stmt ? stmt->line () : -1; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
110 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
111 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
112 int |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
113 octave_call_stack::do_current_column (void) const |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
114 { |
9484
bbe033dcfe13
make dbwhere work when called at keyboard prompt
John W. Eaton <jwe@octave.org>
parents:
9483
diff
changeset
|
115 tree_statement *stmt = do_current_statement (); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
116 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
117 return stmt ? stmt->column () : -1; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
118 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
119 |
7877 | 120 int |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
121 octave_call_stack::do_caller_user_code_line (void) const |
7877 | 122 { |
123 int retval = -1; | |
124 | |
7890 | 125 const_iterator p = cs.end (); |
126 | |
127 while (p != cs.begin ()) | |
7877 | 128 { |
7890 | 129 const call_stack_elt& elt = *(--p); |
7877 | 130 |
131 octave_function *f = elt.fcn; | |
132 | |
133 if (f && f->is_user_code ()) | |
134 { | |
135 tree_statement *stmt = elt.stmt; | |
136 | |
137 if (stmt) | |
138 { | |
139 retval = stmt->line (); | |
140 break; | |
141 } | |
142 } | |
143 } | |
144 | |
145 return retval; | |
146 } | |
147 | |
148 int | |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
149 octave_call_stack::do_caller_user_code_column (void) const |
7877 | 150 { |
151 int retval = -1; | |
152 | |
7890 | 153 const_iterator p = cs.end (); |
154 | |
155 while (p != cs.begin ()) | |
7877 | 156 { |
7890 | 157 const call_stack_elt& elt = *(--p); |
7877 | 158 |
159 octave_function *f = elt.fcn; | |
160 | |
161 if (f && f->is_user_code ()) | |
162 { | |
163 tree_statement *stmt = elt.stmt; | |
164 | |
165 if (stmt) | |
166 { | |
167 retval = stmt->column (); | |
168 break; | |
169 } | |
170 } | |
171 } | |
172 | |
173 return retval; | |
174 } | |
175 | |
7901 | 176 size_t |
177 octave_call_stack::do_num_user_code_frames (octave_idx_type& curr_user_frame) const | |
178 { | |
179 size_t retval = 0; | |
180 | |
181 curr_user_frame = 0; | |
182 | |
183 // Look for the caller of dbstack. | |
184 size_t frame = cs[curr_frame].prev; | |
185 | |
186 bool found = false; | |
187 | |
188 size_t k = cs.size (); | |
189 | |
190 for (const_reverse_iterator p = cs.rbegin (); p != cs.rend (); p++) | |
191 { | |
192 octave_function *f = (*p).fcn; | |
193 | |
194 if (--k == frame) | |
195 found = true; | |
196 | |
197 if (f && f->is_user_code ()) | |
198 { | |
199 if (! found) | |
200 curr_user_frame++; | |
201 | |
202 retval++; | |
203 } | |
204 } | |
205 | |
206 // We counted how many user frames were not the one, in reverse. | |
207 // Now set curr_user_frame to be the index in the other direction. | |
208 curr_user_frame = retval - curr_user_frame - 1; | |
209 | |
210 return retval; | |
211 } | |
212 | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
213 octave_user_code * |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
214 octave_call_stack::do_caller_user_code (size_t nskip) const |
5744 | 215 { |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
216 octave_user_code *retval = 0; |
5744 | 217 |
7890 | 218 const_iterator p = cs.end (); |
219 | |
220 while (p != cs.begin ()) | |
5744 | 221 { |
7890 | 222 const call_stack_elt& elt = *(--p); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
223 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
224 octave_function *f = elt.fcn; |
5744 | 225 |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
226 if (f && f->is_user_code ()) |
5744 | 227 { |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
228 if (nskip > 0) |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
229 nskip--; |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
230 else |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
231 { |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
232 retval = dynamic_cast<octave_user_code *> (f); |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
233 break; |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
234 } |
5744 | 235 } |
236 } | |
237 | |
238 return retval; | |
239 } | |
240 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
241 Octave_map |
7901 | 242 octave_call_stack::do_backtrace (size_t nskip, |
243 octave_idx_type& curr_user_frame) const | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
244 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
245 Octave_map retval; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
246 |
7901 | 247 size_t user_code_frames = do_num_user_code_frames (curr_user_frame); |
248 | |
249 size_t nframes = nskip <= user_code_frames ? user_code_frames - nskip : 0; | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
250 |
7901 | 251 // Our list is reversed. |
252 curr_user_frame = nframes - curr_user_frame - 1; | |
253 | |
254 Cell keys (6, 1); | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
255 |
7901 | 256 keys(0) = "file"; |
257 keys(1) = "name"; | |
258 keys(2) = "line"; | |
259 keys(3) = "column"; | |
260 keys(4) = "scope"; | |
261 keys(5) = "context"; | |
7890 | 262 |
7901 | 263 Cell file (nframes, 1); |
264 Cell name (nframes, 1); | |
265 Cell line (nframes, 1); | |
266 Cell column (nframes, 1); | |
267 Cell scope (nframes, 1); | |
268 Cell context (nframes, 1); | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
269 |
7901 | 270 if (nframes > 0) |
271 { | |
272 int k = 0; | |
273 | |
274 for (const_reverse_iterator p = cs.rbegin (); p != cs.rend (); p++) | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
275 { |
7901 | 276 const call_stack_elt& elt = *p; |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
277 |
7736 | 278 octave_function *f = elt.fcn; |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
279 |
7901 | 280 if (f && f->is_user_code ()) |
7736 | 281 { |
7901 | 282 if (nskip > 0) |
283 nskip--; | |
7736 | 284 else |
285 { | |
7901 | 286 scope(k) = elt.scope; |
287 context(k) = elt.context; | |
288 | |
289 file(k) = f->fcn_file_name (); | |
290 std::string parent_fcn_name = f->parent_fcn_name (); | |
291 if (parent_fcn_name == std::string ()) | |
292 name(k) = f->name (); | |
293 else | |
294 name(k) = f->parent_fcn_name () + Vfilemarker + f->name (); | |
295 | |
296 tree_statement *stmt = elt.stmt; | |
297 | |
298 if (stmt) | |
299 { | |
300 line(k) = stmt->line (); | |
301 column(k) = stmt->column (); | |
302 } | |
303 else | |
304 { | |
305 line(k) = -1; | |
306 column(k) = -1; | |
307 } | |
308 | |
309 k++; | |
7736 | 310 } |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
311 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
312 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
313 |
7736 | 314 retval.assign ("file", file); |
315 retval.assign ("name", name); | |
316 retval.assign ("line", line); | |
317 retval.assign ("column", column); | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
318 retval.assign ("scope", scope); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
319 retval.assign ("context", context); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
320 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
321 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
322 return retval; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
323 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
324 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
325 bool |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
326 octave_call_stack::do_goto_frame (size_t n, bool verbose) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
327 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
328 bool retval = false; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
329 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
330 if (n < cs.size ()) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
331 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
332 retval = true; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
333 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
334 curr_frame = n; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
335 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
336 const call_stack_elt& elt = cs[n]; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
337 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
338 symbol_table::set_scope_and_context (elt.scope, elt.context); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
339 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
340 if (verbose) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
341 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
342 octave_function *f = elt.fcn; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
343 std::string nm = f ? f->name () : std::string ("<unknown>"); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
344 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
345 tree_statement *s = elt.stmt; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
346 int l = -1; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
347 int c = -1; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
348 if (s) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
349 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
350 l = s->line (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
351 c = s->column (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
352 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
353 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
354 octave_stdout << "stopped in " << nm |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
355 << " at line " << l << " column " << c |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
356 << " (" << elt.scope << "[" << elt.context << "])" |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
357 << std::endl; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
358 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
359 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
360 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
361 return retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
362 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
363 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
364 bool |
7901 | 365 octave_call_stack::do_goto_frame_relative (int nskip, bool verbose) |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
366 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
367 bool retval = false; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
368 |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
369 int incr = 0; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
370 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
371 if (nskip < 0) |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
372 incr = -1; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
373 else if (nskip > 0) |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
374 incr = 1; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
375 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
376 // Start looking with the caller of dbup/dbdown/keyboard. |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
377 size_t frame = cs[curr_frame].prev; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
378 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
379 while (true) |
7890 | 380 { |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
381 if ((incr < 0 && frame == 0) || (incr > 0 && frame == cs.size () - 1)) |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
382 break; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
383 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
384 frame += incr; |
7901 | 385 |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
386 const call_stack_elt& elt = cs[frame]; |
7901 | 387 |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
388 octave_function *f = elt.fcn; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
389 |
9990
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
390 if (frame == 0 || (f && f->is_user_code ())) |
7901 | 391 { |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
392 if (nskip > 0) |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
393 nskip--; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
394 else if (nskip < 0) |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
395 nskip++; |
7901 | 396 |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
397 if (nskip == 0) |
7901 | 398 { |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
399 curr_frame = frame; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
400 cs[cs.size () - 1].prev = curr_frame; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
401 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
402 symbol_table::set_scope_and_context (elt.scope, elt.context); |
7901 | 403 |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
404 if (verbose) |
7901 | 405 { |
9990
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
406 std::ostringstream buf; |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
407 |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
408 if (f) |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
409 { |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
410 tree_statement *s = elt.stmt; |
7901 | 411 |
9990
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
412 int l = s ? s->line () : -1; |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
413 int c = s ? s->column () : -1; |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
414 |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
415 buf << f->name () << ": " << " line " << l |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
416 << ", column " << c << std::endl; |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
417 } |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
418 else |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
419 buf << "at top level" << std::endl; |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
420 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
421 octave_stdout << buf.str (); |
7901 | 422 } |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
423 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
424 retval = true; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
425 break; |
7901 | 426 } |
427 } | |
428 | |
429 // There is no need to set scope and context here. That will | |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
430 // happen when the dbup/dbdown/keyboard frame is popped and we |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
431 // jump to the new "prev" frame set above. |
7890 | 432 } |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
433 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
434 return retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
435 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
436 |
5744 | 437 void |
7901 | 438 octave_call_stack::do_goto_caller_frame (void) |
439 { | |
440 size_t frame = curr_frame; | |
441 | |
442 bool skipped = false; | |
443 | |
444 while (frame != 0) | |
445 { | |
446 frame = cs[frame].prev; | |
447 | |
448 const call_stack_elt& elt = cs[frame]; | |
449 | |
450 octave_function *f = elt.fcn; | |
451 | |
8581
6adcafc70c32
toplev.cc (octave_call_stack::do_goto_caller_frame): allow caller frame to be base frame
John W. Eaton <jwe@octave.org>
parents:
8574
diff
changeset
|
452 if (frame == 0 || (f && f->is_user_code ())) |
7901 | 453 { |
454 if (! skipped) | |
455 // We found the current user code frame, so skip it. | |
456 skipped = true; | |
457 else | |
458 { | |
459 // We found the caller user code frame. | |
460 call_stack_elt tmp (elt); | |
461 tmp.prev = curr_frame; | |
462 | |
463 curr_frame = cs.size (); | |
464 | |
465 cs.push_back (tmp); | |
466 | |
467 symbol_table::set_scope_and_context (tmp.scope, tmp.context); | |
468 | |
469 break; | |
470 } | |
471 } | |
472 } | |
473 } | |
474 | |
475 void | |
476 octave_call_stack::do_goto_base_frame (void) | |
477 { | |
478 call_stack_elt tmp (cs[0]); | |
479 tmp.prev = curr_frame; | |
480 | |
481 curr_frame = cs.size (); | |
482 | |
483 cs.push_back (tmp); | |
484 | |
485 symbol_table::set_scope_and_context (tmp.scope, tmp.context); | |
486 } | |
487 | |
488 void | |
8013
b3e667f1ab4c
call backtrace_error_message in eval functions, not when popping stack
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
489 octave_call_stack::do_backtrace_error_message (void) const |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
490 { |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
491 if (error_state > 0) |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
492 { |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
493 error_state = -1; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
494 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
495 error ("called from:"); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
496 } |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
497 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
498 if (! cs.empty ()) |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
499 { |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
500 const call_stack_elt& elt = cs.back (); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
501 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
502 octave_function *fcn = elt.fcn; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
503 tree_statement *stmt = elt.stmt; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
504 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
505 std::string fcn_name = "?unknown?"; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
506 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
507 if (fcn) |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
508 { |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
509 fcn_name = fcn->fcn_file_name (); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
510 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
511 if (fcn_name.empty ()) |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
512 fcn_name = fcn->name (); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
513 } |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
514 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
515 int line = stmt ? stmt->line () : -1; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
516 int column = stmt ? stmt->column () : -1; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
517 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
518 error (" %s at line %d, column %d", |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
519 fcn_name.c_str (), line, column); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
520 } |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
521 } |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
522 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
523 void |
4180 | 524 recover_from_exception (void) |
525 { | |
526 can_interrupt = true; | |
4182 | 527 octave_interrupt_immediately = 0; |
4180 | 528 octave_interrupt_state = 0; |
5142 | 529 octave_signal_caught = 0; |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7409
diff
changeset
|
530 octave_exception_state = octave_no_exception; |
4180 | 531 octave_restore_signal_mask (); |
532 octave_catch_interrupts (); | |
533 } | |
534 | |
1907 | 535 int |
5189 | 536 main_loop (void) |
1907 | 537 { |
2016 | 538 octave_save_signal_mask (); |
539 | |
3020 | 540 can_interrupt = true; |
1907 | 541 |
5142 | 542 octave_signal_hook = octave_signal_handler; |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9990
diff
changeset
|
543 octave_interrupt_hook = 0; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9990
diff
changeset
|
544 octave_bad_alloc_hook = 0; |
4429 | 545 |
2554 | 546 octave_catch_interrupts (); |
1907 | 547 |
4172 | 548 octave_initialized = true; |
549 | |
1907 | 550 // The big loop. |
551 | |
4153 | 552 int retval = 0; |
1907 | 553 do |
554 { | |
4180 | 555 try |
1907 | 556 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9990
diff
changeset
|
557 unwind_protect frame; |
9260
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9255
diff
changeset
|
558 |
4318 | 559 reset_error_handler (); |
560 | |
4153 | 561 reset_parser (); |
2620 | 562 |
9260
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9255
diff
changeset
|
563 // Do this with an unwind-protect cleanup function so that |
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9255
diff
changeset
|
564 // the forced variables will be unmarked in the event of an |
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9255
diff
changeset
|
565 // interrupt. |
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9255
diff
changeset
|
566 symbol_table::scope_id scope = symbol_table::top_scope (); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9990
diff
changeset
|
567 frame.add_fcn (symbol_table::unmark_forced_variables, scope); |
9260
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9255
diff
changeset
|
568 |
4753 | 569 // This is the same as yyparse in parse.y. |
570 retval = octave_parse (); | |
2620 | 571 |
4153 | 572 if (retval == 0) |
573 { | |
7913
f46e73bcb85b
toplev.cc (main_loop): undo previous change; input.cc (get_debug_input): don't delete global_command here
John W. Eaton <jwe@octave.org>
parents:
7903
diff
changeset
|
574 if (global_command) |
3804 | 575 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8581
diff
changeset
|
576 global_command->accept (*current_evaluator); |
3883 | 577 |
7913
f46e73bcb85b
toplev.cc (main_loop): undo previous change; input.cc (get_debug_input): don't delete global_command here
John W. Eaton <jwe@octave.org>
parents:
7903
diff
changeset
|
578 delete global_command; |
3883 | 579 |
7913
f46e73bcb85b
toplev.cc (main_loop): undo previous change; input.cc (get_debug_input): don't delete global_command here
John W. Eaton <jwe@octave.org>
parents:
7903
diff
changeset
|
580 global_command = 0; |
3883 | 581 |
4171 | 582 OCTAVE_QUIT; |
583 | |
3883 | 584 if (! (interactive || forced_interactive)) |
585 { | |
4207 | 586 bool quit = (tree_return_command::returning |
587 || tree_break_command::breaking); | |
4153 | 588 |
4207 | 589 if (tree_return_command::returning) |
590 tree_return_command::returning = 0; | |
4153 | 591 |
4207 | 592 if (tree_break_command::breaking) |
593 tree_break_command::breaking--; | |
4153 | 594 |
595 if (quit) | |
596 break; | |
597 } | |
598 | |
599 if (error_state) | |
600 { | |
601 if (! (interactive || forced_interactive)) | |
602 { | |
603 // We should exit with a non-zero status. | |
604 retval = 1; | |
605 break; | |
606 } | |
607 } | |
608 else | |
609 { | |
610 if (octave_completion_matches_called) | |
611 octave_completion_matches_called = false; | |
612 else | |
613 command_editor::increment_current_command_number (); | |
3883 | 614 } |
615 } | |
4153 | 616 else if (parser_end_of_input) |
617 break; | |
2620 | 618 } |
4153 | 619 } |
4182 | 620 catch (octave_interrupt_exception) |
4153 | 621 { |
4180 | 622 recover_from_exception (); |
9383 | 623 octave_stdout << "\n"; |
624 if (quitting_gracefully) | |
625 { | |
626 clean_up_and_exit (exit_status); | |
627 break; // If user has overriden the exit func. | |
628 } | |
4180 | 629 } |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
630 catch (octave_execution_exception) |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
631 { |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
632 recover_from_exception (); |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
633 std::cerr |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
634 << "error: unhandled execution exception -- trying to return to prompt" |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
635 << std::endl; |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
636 } |
4181 | 637 catch (std::bad_alloc) |
4180 | 638 { |
639 recover_from_exception (); | |
640 std::cerr | |
6680 | 641 << "error: memory exhausted or requested size too large for range of Octave's index type -- trying to return to prompt" |
642 << std::endl; | |
1907 | 643 } |
644 } | |
645 while (retval == 0); | |
646 | |
647 return retval; | |
648 } | |
649 | |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
650 // Call a function with exceptions handled to avoid problems with |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
651 // errors while shutting down. |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
652 |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
653 #define IGNORE_EXCEPTION(E) \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
654 catch (E) \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
655 { \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
656 std::cerr << "error: ignoring " #E " while preparing to exit" << std::endl; \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
657 recover_from_exception (); \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
658 } |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
659 |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
660 #define SAFE_CALL(F, ARGS) \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
661 try \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
662 { \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
663 F ARGS; \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
664 } \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
665 IGNORE_EXCEPTION (octave_interrupt_exception) \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
666 IGNORE_EXCEPTION (octave_execution_exception) \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
667 IGNORE_EXCEPTION (std::bad_alloc) |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
668 |
1683 | 669 // Fix up things before exiting. |
670 | |
671 void | |
3162 | 672 clean_up_and_exit (int retval) |
673 { | |
3216 | 674 do_octave_atexit (); |
1683 | 675 |
9981
692ab4eaf965
clean up top-level variables when exiting Octave
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
676 // Clean up symbol table. |
692ab4eaf965
clean up top-level variables when exiting Octave
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
677 SAFE_CALL (symbol_table::cleanup, ()); |
692ab4eaf965
clean up top-level variables when exiting Octave
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
678 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
679 SAFE_CALL (sysdep_cleanup, ()) |
5451 | 680 |
9217
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9187
diff
changeset
|
681 if (octave_exit) |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9187
diff
changeset
|
682 (*octave_exit) (retval == EOF ? 0 : retval); |
1683 | 683 } |
684 | |
3180 | 685 DEFUN (quit, args, nargout, |
3332 | 686 "-*- texinfo -*-\n\ |
687 @deftypefn {Built-in Function} {} exit (@var{status})\n\ | |
688 @deftypefnx {Built-in Function} {} quit (@var{status})\n\ | |
689 Exit the current Octave session. If the optional integer value\n\ | |
690 @var{status} is supplied, pass that value to the operating system as the\n\ | |
6615 | 691 Octave's exit status. The default value is zero.\n\ |
3333 | 692 @end deftypefn") |
1683 | 693 { |
2086 | 694 octave_value_list retval; |
2068 | 695 |
9255
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
696 if (! quit_allowed) |
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
697 error ("quit: not supported in embedded mode."); |
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
698 else if (nargout == 0) |
2068 | 699 { |
3180 | 700 if (args.length () > 0) |
701 { | |
3202 | 702 int tmp = args(0).nint_value (); |
1683 | 703 |
3202 | 704 if (! error_state) |
705 exit_status = tmp; | |
3180 | 706 } |
707 | |
9383 | 708 if (! error_state) |
709 { | |
710 quitting_gracefully = true; | |
711 | |
712 // Simulate interrupt. | |
713 | |
714 octave_interrupt_state = -1; | |
715 | |
716 octave_throw_interrupt_exception (); | |
717 } | |
2068 | 718 } |
3180 | 719 else |
720 error ("quit: invalid number of output arguments"); | |
2068 | 721 |
1683 | 722 return retval; |
723 } | |
724 | |
725 DEFALIAS (exit, quit); | |
726 | |
1957 | 727 DEFUN (warranty, , , |
3446 | 728 "-*- texinfo -*-\n\ |
729 @deftypefn {Built-in Function} {} warranty ()\n\ | |
730 Describe the conditions for copying and distributing Octave.\n\ | |
731 @end deftypefn") | |
1683 | 732 { |
2086 | 733 octave_value_list retval; |
1683 | 734 |
3922 | 735 octave_stdout << "\n" \ |
736 OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\ | |
737 \n\ | |
1683 | 738 This program is free software; you can redistribute it and/or modify\n\ |
739 it under the terms of the GNU General Public License as published by\n\ | |
7016 | 740 the Free Software Foundation; either version 3 of the License, or\n\ |
1683 | 741 (at your option) any later version.\n\ |
742 \n\ | |
743 This program is distributed in the hope that it will be useful,\n\ | |
744 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ | |
745 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ | |
746 GNU General Public License for more details.\n\ | |
747 \n\ | |
748 You should have received a copy of the GNU General Public License\n\ | |
7016 | 749 along with this program. If not, see <http://www.gnu.org/licenses/>.\n\ |
1683 | 750 \n"; |
751 | |
752 return retval; | |
753 } | |
754 | |
755 // Execute a shell command. | |
756 | |
1965 | 757 static void |
758 cleanup_iprocstream (void *p) | |
759 { | |
3060 | 760 iprocstream *cmd = static_cast<iprocstream *> (p); |
761 | |
762 octave_child_list::remove (cmd->pid ()); | |
763 | |
764 delete cmd; | |
1965 | 765 } |
766 | |
6316 | 767 static int |
768 wait_for_input (int fid) | |
769 { | |
770 int retval = -1; | |
771 | |
772 #if defined (HAVE_SELECT) | |
773 if (fid >= 0) | |
774 { | |
775 fd_set set; | |
776 | |
777 FD_ZERO (&set); | |
778 FD_SET (fid, &set); | |
779 | |
780 retval = select (FD_SETSIZE, &set, 0, 0, 0); | |
781 } | |
782 #else | |
783 retval = 1; | |
784 #endif | |
785 | |
786 return retval; | |
787 } | |
788 | |
2086 | 789 static octave_value_list |
3523 | 790 run_command_and_return_output (const std::string& cmd_str) |
2083 | 791 { |
2086 | 792 octave_value_list retval; |
2083 | 793 |
794 iprocstream *cmd = new iprocstream (cmd_str.c_str ()); | |
795 | |
3060 | 796 if (cmd) |
2083 | 797 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9990
diff
changeset
|
798 unwind_protect frame; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9990
diff
changeset
|
799 frame.add (cleanup_iprocstream, cmd); |
3060 | 800 |
801 if (*cmd) | |
802 { | |
6316 | 803 int fid = cmd->file_number (); |
2095 | 804 |
6316 | 805 std::ostringstream output_buf; |
4494 | 806 |
3060 | 807 char ch; |
3147 | 808 |
4489 | 809 for (;;) |
3147 | 810 { |
4489 | 811 if (cmd->get (ch)) |
812 output_buf.put (ch); | |
813 else | |
814 { | |
815 if (! cmd->eof () && errno == EAGAIN) | |
816 { | |
817 cmd->clear (); | |
3147 | 818 |
6316 | 819 if (wait_for_input (fid) != 1) |
820 break; | |
4489 | 821 } |
822 else | |
823 break; | |
824 } | |
3147 | 825 } |
826 | |
3252 | 827 int cmd_status = cmd->close (); |
2083 | 828 |
3060 | 829 if (WIFEXITED (cmd_status)) |
830 cmd_status = WEXITSTATUS (cmd_status); | |
831 else | |
832 cmd_status = 127; | |
2083 | 833 |
8810
c9e1db15035b
eliminate unnecessary casts
John W. Eaton <jwe@octave.org>
parents:
8772
diff
changeset
|
834 retval(0) = cmd_status; |
5765 | 835 retval(1) = output_buf.str (); |
3060 | 836 } |
2083 | 837 } |
838 else | |
839 error ("unable to start subprocess for `%s'", cmd_str.c_str ()); | |
840 | |
841 return retval; | |
842 } | |
843 | |
5285 | 844 enum system_exec_type { et_sync, et_async }; |
845 | |
1957 | 846 DEFUN (system, args, nargout, |
3301 | 847 "-*- texinfo -*-\n\ |
848 @deftypefn {Built-in Function} {} system (@var{string}, @var{return_output}, @var{type})\n\ | |
849 Execute a shell command specified by @var{string}. The second\n\ | |
850 argument is optional. If @var{type} is @code{\"async\"}, the process\n\ | |
851 is started in the background and the process id of the child process\n\ | |
852 is returned immediately. Otherwise, the process is started, and\n\ | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8013
diff
changeset
|
853 Octave waits until it exits. If the @var{type} argument is omitted, a\n\ |
3301 | 854 value of @code{\"sync\"} is assumed.\n\ |
2083 | 855 \n\ |
3301 | 856 If two input arguments are given (the actual value of\n\ |
857 @var{return_output} is irrelevant) and the subprocess is started\n\ | |
858 synchronously, or if @var{system} is called with one input argument and\n\ | |
859 one or more output arguments, the output from the command is returned.\n\ | |
5097 | 860 Otherwise, if the subprocess is executed synchronously, its output is\n\ |
2321 | 861 sent to the standard output. To send the output of a command executed\n\ |
3301 | 862 with @var{system} through the pager, use a command like\n\ |
2321 | 863 \n\ |
3301 | 864 @example\n\ |
865 disp (system (cmd, 1));\n\ | |
866 @end example\n\ | |
2321 | 867 \n\ |
3301 | 868 @noindent\n\ |
2321 | 869 or\n\ |
870 \n\ | |
3301 | 871 @example\n\ |
9079
4d610aba7347
Cleanup documentation for system.texi, package.texi
Rik <rdrider0-list@yahoo.com>
parents:
9035
diff
changeset
|
872 printf (\"%s\\n\", system (cmd, 1));\n\ |
3301 | 873 @end example\n\ |
874 \n\ | |
5659 | 875 The @code{system} function can return two values. The first is the\n\ |
876 exit status of the command and the second is any output from the\n\ | |
877 command that was written to the standard output stream. For example,\n\ | |
3301 | 878 \n\ |
879 @example\n\ | |
5717 | 880 [status, output] = system (\"echo foo; exit 2\");\n\ |
3301 | 881 @end example\n\ |
882 \n\ | |
883 @noindent\n\ | |
884 will set the variable @code{output} to the string @samp{foo}, and the\n\ | |
885 variable @code{status} to the integer @samp{2}.\n\ | |
886 @end deftypefn") | |
1683 | 887 { |
2086 | 888 octave_value_list retval; |
1683 | 889 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9990
diff
changeset
|
890 unwind_protect frame; |
3834 | 891 |
1683 | 892 int nargin = args.length (); |
893 | |
2083 | 894 if (nargin > 0 && nargin < 4) |
1683 | 895 { |
5672 | 896 bool return_output = (nargout > 1 || nargin > 1); |
2083 | 897 |
3523 | 898 std::string cmd_str = args(0).string_value (); |
2083 | 899 |
5285 | 900 system_exec_type type = et_sync; |
2083 | 901 |
902 if (! error_state) | |
903 { | |
904 if (nargin > 2) | |
905 { | |
3523 | 906 std::string type_str = args(2).string_value (); |
1683 | 907 |
2083 | 908 if (! error_state) |
909 { | |
910 if (type_str == "sync") | |
5285 | 911 type = et_sync; |
2083 | 912 else if (type_str == "async") |
5285 | 913 type = et_async; |
2083 | 914 else |
915 error ("system: third arg must be \"sync\" or \"async\""); | |
916 } | |
917 else | |
918 error ("system: third argument must be a string"); | |
919 } | |
920 } | |
921 else | |
3523 | 922 error ("system: expecting std::string as first argument"); |
1683 | 923 |
2083 | 924 if (! error_state) |
925 { | |
7104 | 926 #if defined (__WIN32__) && ! defined (__CYGWIN__) |
927 // Work around weird double-quote handling on Windows systems. | |
928 if (type == et_sync) | |
929 cmd_str = "\"" + cmd_str + "\""; | |
930 #endif | |
931 | |
5285 | 932 if (type == et_async) |
2083 | 933 { |
6222 | 934 // FIXME -- maybe this should go in sysdep.cc? |
4086 | 935 #ifdef HAVE_FORK |
2083 | 936 pid_t pid = fork (); |
937 | |
938 if (pid < 0) | |
939 error ("system: fork failed -- can't create child process"); | |
940 else if (pid == 0) | |
941 { | |
5775 | 942 // FIXME -- should probably replace this |
3273 | 943 // call with something portable. |
944 | |
5510 | 945 execl ("/bin/sh", "sh", "-c", cmd_str.c_str (), |
946 static_cast<void *> (0)); | |
3273 | 947 |
948 panic_impossible (); | |
2083 | 949 } |
950 else | |
4254 | 951 retval(0) = pid; |
6222 | 952 #elif defined (__WIN32__) |
953 STARTUPINFO si; | |
954 PROCESS_INFORMATION pi; | |
955 ZeroMemory (&si, sizeof (si)); | |
956 ZeroMemory (&pi, sizeof (pi)); | |
957 OCTAVE_LOCAL_BUFFER (char, xcmd_str, cmd_str.length()+1); | |
6676 | 958 strcpy (xcmd_str, cmd_str.c_str ()); |
6222 | 959 |
960 if (! CreateProcess (0, xcmd_str, 0, 0, FALSE, 0, 0, 0, &si, &pi)) | |
961 error ("system: CreateProcess failed -- can't create child process"); | |
962 else | |
963 { | |
964 retval(0) = pi.dwProcessId; | |
965 CloseHandle (pi.hProcess); | |
966 CloseHandle (pi.hThread); | |
967 } | |
4086 | 968 #else |
969 error ("asynchronous system calls are not supported"); | |
970 #endif | |
2083 | 971 } |
2321 | 972 else if (return_output) |
973 retval = run_command_and_return_output (cmd_str); | |
2083 | 974 else |
2321 | 975 { |
976 int status = system (cmd_str.c_str ()); | |
977 | |
978 // The value in status is as returned by waitpid. If | |
979 // the process exited normally, extract the actual exit | |
980 // status of the command. Otherwise, return 127 as a | |
981 // failure code. | |
982 | |
2693 | 983 if (WIFEXITED (status)) |
984 status = WEXITSTATUS (status); | |
2321 | 985 |
4233 | 986 retval(0) = status; |
2321 | 987 } |
2083 | 988 } |
1683 | 989 } |
990 else | |
5823 | 991 print_usage (); |
1683 | 992 |
993 return retval; | |
994 } | |
995 | |
996 DEFALIAS (shell_cmd, system); | |
997 | |
5775 | 998 // FIXME -- this should really be static, but that causes |
2614 | 999 // problems on some systems. |
6680 | 1000 std::list<std::string> octave_atexit_functions; |
2077 | 1001 |
1002 void | |
1003 do_octave_atexit (void) | |
1004 { | |
3216 | 1005 static bool deja_vu = false; |
1006 | |
2077 | 1007 while (! octave_atexit_functions.empty ()) |
1008 { | |
6680 | 1009 std::string fcn = octave_atexit_functions.front (); |
4214 | 1010 |
6680 | 1011 octave_atexit_functions.pop_front (); |
2077 | 1012 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1013 SAFE_CALL (reset_error_handler, ()) |
5237 | 1014 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1015 SAFE_CALL (feval, (fcn, octave_value_list (), 0)) |
3215 | 1016 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1017 SAFE_CALL (flush_octave_stdout, ()) |
2077 | 1018 } |
3216 | 1019 |
1020 if (! deja_vu) | |
1021 { | |
1022 deja_vu = true; | |
1023 | |
6068 | 1024 // Do this explicitly so that destructors for mex file objects |
1025 // are called, so that functions registered with mexAtExit are | |
1026 // called. | |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1027 SAFE_CALL (clear_mex_functions, ()) |
6068 | 1028 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1029 SAFE_CALL (command_editor::restore_terminal_state, ()) |
3216 | 1030 |
5775 | 1031 // FIXME -- is this needed? Can it cause any trouble? |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1032 SAFE_CALL (raw_mode, (0)) |
3216 | 1033 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1034 SAFE_CALL (octave_history_write_timestamp, ()) |
5305 | 1035 |
8735
afbfd7f4fd93
toplev.cc (do_octave_atexit): only save history if Vsaving_history is true
John W. Eaton <jwe@octave.org>
parents:
8719
diff
changeset
|
1036 if (Vsaving_history) |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1037 SAFE_CALL (command_history::clean_up_and_save, ()) |
3216 | 1038 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1039 SAFE_CALL (close_files, ()) |
3216 | 1040 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1041 SAFE_CALL (cleanup_tmp_files, ()) |
3216 | 1042 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1043 SAFE_CALL (flush_octave_stdout, ()) |
3216 | 1044 |
5305 | 1045 if (! quitting_gracefully && (interactive || forced_interactive)) |
5629 | 1046 { |
1047 octave_stdout << "\n"; | |
1048 | |
1049 // Yes, we want this to be separate from the call to | |
1050 // flush_octave_stdout above. | |
1051 | |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1052 SAFE_CALL (flush_octave_stdout, ()) |
5629 | 1053 } |
3216 | 1054 } |
2077 | 1055 } |
1056 | |
7409 | 1057 void |
1058 octave_add_atexit_function (const std::string& fname) | |
1059 { | |
1060 octave_atexit_functions.push_front (fname); | |
1061 } | |
1062 | |
1063 bool | |
1064 octave_remove_atexit_function (const std::string& fname) | |
1065 { | |
1066 bool found = false; | |
1067 | |
1068 for (std::list<std::string>::iterator p = octave_atexit_functions.begin (); | |
1069 p != octave_atexit_functions.end (); p++) | |
1070 { | |
1071 if (*p == fname) | |
1072 { | |
1073 octave_atexit_functions.erase (p); | |
1074 found = true; | |
1075 break; | |
1076 } | |
1077 } | |
1078 | |
1079 return found; | |
1080 } | |
1081 | |
1082 | |
6680 | 1083 DEFUN (atexit, args, nargout, |
3332 | 1084 "-*- texinfo -*-\n\ |
1085 @deftypefn {Built-in Function} {} atexit (@var{fcn})\n\ | |
9133
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1086 @deftypefnx {Built-in Function} {} atexit (@var{fcn}, @var{flag})\n\ |
3332 | 1087 Register a function to be called when Octave exits. For example,\n\ |
2077 | 1088 \n\ |
3332 | 1089 @example\n\ |
1090 @group\n\ | |
9035
57649dcecb55
Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
1091 function last_words ()\n\ |
6620 | 1092 disp (\"Bye bye\");\n\ |
3332 | 1093 endfunction\n\ |
9035
57649dcecb55
Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
1094 atexit (\"last_words\");\n\ |
3332 | 1095 @end group\n\ |
1096 @end example\n\ | |
1097 \n\ | |
1098 @noindent\n\ | |
6620 | 1099 will print the message \"Bye bye\" when Octave exits.\n\ |
6680 | 1100 \n\ |
9133
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1101 The additional argument @var{flag} will register or unregister\n\ |
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1102 @var{fcn} from the list of functions to be called when Octave\n\ |
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1103 exits. If @var{flag} is true, the function is registered, and if\n\ |
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1104 @var{flag} is false, it is unregistered. For example,\n\ |
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1105 after registering the function @code{last_words} above,\n\ |
6680 | 1106 \n\ |
1107 @example\n\ | |
9035
57649dcecb55
Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
1108 atexit (\"last_words\", false);\n\ |
6680 | 1109 @end example\n\ |
1110 \n\ | |
1111 @noindent\n\ | |
1112 will remove the function from the list and Octave will not call\n\ | |
9133
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1113 @code{last_words} when it exits.\n\ |
6680 | 1114 \n\ |
7001 | 1115 Note that @code{atexit} only removes the first occurrence of a function\n\ |
6680 | 1116 from the list, so if a function was placed in the list multiple\n\ |
1117 times with @code{atexit}, it must also be removed from the list\n\ | |
1118 multiple times.\n\ | |
3333 | 1119 @end deftypefn") |
2077 | 1120 { |
2086 | 1121 octave_value_list retval; |
2077 | 1122 |
1123 int nargin = args.length (); | |
1124 | |
6680 | 1125 if (nargin == 1 || nargin == 2) |
2077 | 1126 { |
3523 | 1127 std::string arg = args(0).string_value (); |
2077 | 1128 |
1129 if (! error_state) | |
6680 | 1130 { |
1131 bool add_mode = true; | |
1132 | |
1133 if (nargin == 2) | |
1134 { | |
1135 add_mode = args(1).bool_value (); | |
1136 | |
1137 if (error_state) | |
1138 error ("atexit: second argument must be a logical value"); | |
1139 } | |
1140 | |
1141 if (! error_state) | |
1142 { | |
1143 if (add_mode) | |
7409 | 1144 octave_add_atexit_function (arg); |
6680 | 1145 else |
1146 { | |
7409 | 1147 bool found = octave_remove_atexit_function (arg); |
6680 | 1148 |
1149 if (nargout > 0) | |
1150 retval(0) = found; | |
1151 } | |
1152 } | |
1153 } | |
2077 | 1154 else |
6680 | 1155 error ("atexit: argument must be a string"); |
2077 | 1156 } |
1157 else | |
5823 | 1158 print_usage (); |
2077 | 1159 |
1160 return retval; | |
1161 } | |
1162 | |
2689 | 1163 DEFUN (octave_config_info, args, , |
3301 | 1164 "-*- texinfo -*-\n\ |
1165 @deftypefn {Built-in Function} {} octave_config_info (@var{option})\n\ | |
1166 Return a structure containing configuration and installation\n\ | |
1167 information for Octave.\n\ | |
2689 | 1168 \n\ |
3301 | 1169 if @var{option} is a string, return the configuration information for the\n\ |
2689 | 1170 specified option.\n\ |
1171 \n\ | |
3301 | 1172 @end deftypefn") |
2162 | 1173 { |
2689 | 1174 octave_value retval; |
1175 | |
4128 | 1176 #if defined (ENABLE_DYNAMIC_LINKING) |
2689 | 1177 bool octave_supports_dynamic_linking = true; |
1178 #else | |
1179 bool octave_supports_dynamic_linking = false; | |
1180 #endif | |
1181 | |
4357 | 1182 static bool initialized = false; |
1183 static Octave_map m; | |
2162 | 1184 |
6274 | 1185 struct conf_info_struct |
1186 { | |
1187 bool subst_home; | |
1188 const char *key; | |
1189 const char *val; | |
1190 }; | |
1191 | |
1192 static const conf_info_struct conf_info[] = | |
4357 | 1193 { |
6274 | 1194 { false, "ALL_CFLAGS", OCTAVE_CONF_ALL_CFLAGS }, |
1195 { false, "ALL_CXXFLAGS", OCTAVE_CONF_ALL_CXXFLAGS }, | |
1196 { false, "ALL_FFLAGS", OCTAVE_CONF_ALL_FFLAGS }, | |
1197 { false, "ALL_LDFLAGS", OCTAVE_CONF_ALL_LDFLAGS }, | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1198 { false, "AMD_CPPFLAGS", OCTAVE_CONF_AMD_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1199 { false, "AMD_LDFLAGS", OCTAVE_CONF_AMD_LDFLAGS }, |
9514 | 1200 { false, "AMD_LIBS", OCTAVE_CONF_AMD_LIBS }, |
6274 | 1201 { false, "AR", OCTAVE_CONF_AR }, |
1202 { false, "ARFLAGS", OCTAVE_CONF_ARFLAGS }, | |
9568
d3fccc4c4b9e
use OCTAVE_CHECK_LIBRARY to check for ARPACK
John W. Eaton <jwe@octave.org>
parents:
9542
diff
changeset
|
1203 { false, "ARPACK_CPPFLAGS", OCTAVE_CONF_ARPACK_CPPFLAGS }, |
d3fccc4c4b9e
use OCTAVE_CHECK_LIBRARY to check for ARPACK
John W. Eaton <jwe@octave.org>
parents:
9542
diff
changeset
|
1204 { false, "ARPACK_LDFLAGS", OCTAVE_CONF_ARPACK_LDFLAGS }, |
9514 | 1205 { false, "ARPACK_LIBS", OCTAVE_CONF_ARPACK_LIBS }, |
6274 | 1206 { false, "BLAS_LIBS", OCTAVE_CONF_BLAS_LIBS }, |
8772
aeedc045cfe3
toplev.cc (Foctave_config_info): add CARBON_LIBS, X11_INCFLAGS, and X11_LIBS to the struct
John W. Eaton <jwe@octave.org>
parents:
8735
diff
changeset
|
1207 { false, "CARBON_LIBS", OCTAVE_CONF_CARBON_LIBS }, |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1208 { false, "CAMD_CPPFLAGS", OCTAVE_CONF_CAMD_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1209 { false, "CAMD_LDFLAGS", OCTAVE_CONF_CAMD_LDFLAGS }, |
9514 | 1210 { false, "CAMD_LIBS", OCTAVE_CONF_CAMD_LIBS }, |
6274 | 1211 { false, "CC", OCTAVE_CONF_CC }, |
1212 { false, "CC_VERSION", OCTAVE_CONF_CC_VERSION }, | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1213 { false, "CCOLAMD_CPPFLAGS", OCTAVE_CONF_CCOLAMD_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1214 { false, "CCOLAMD_LDFLAGS", OCTAVE_CONF_CCOLAMD_LDFLAGS }, |
9514 | 1215 { false, "CCOLAMD_LIBS", OCTAVE_CONF_CCOLAMD_LIBS }, |
6274 | 1216 { false, "CFLAGS", OCTAVE_CONF_CFLAGS }, |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1217 { false, "CHOLMOD_CPPFLAGS", OCTAVE_CONF_CHOLMOD_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1218 { false, "CHOLMOD_LDFLAGS", OCTAVE_CONF_CHOLMOD_LDFLAGS }, |
9514 | 1219 { false, "CHOLMOD_LIBS", OCTAVE_CONF_CHOLMOD_LIBS }, |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1220 { false, "COLAMD_CPPFLAGS", OCTAVE_CONF_COLAMD_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1221 { false, "COLAMD_LDFLAGS", OCTAVE_CONF_COLAMD_LDFLAGS }, |
9514 | 1222 { false, "COLAMD_LIBS", OCTAVE_CONF_COLAMD_LIBS }, |
6274 | 1223 { false, "CPICFLAG", OCTAVE_CONF_CPICFLAG }, |
1224 { false, "CPPFLAGS", OCTAVE_CONF_CPPFLAGS }, | |
9519
ee99f9f37505
improve configure checks for qhull and curl libs
John W. Eaton <jwe@octave.org>
parents:
9515
diff
changeset
|
1225 { false, "CURL_CPPFLAGS", OCTAVE_CONF_CURL_CPPFLAGS }, |
ee99f9f37505
improve configure checks for qhull and curl libs
John W. Eaton <jwe@octave.org>
parents:
9515
diff
changeset
|
1226 { false, "CURL_LDFLAGS", OCTAVE_CONF_CURL_LDFLAGS }, |
6274 | 1227 { false, "CURL_LIBS", OCTAVE_CONF_CURL_LIBS }, |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1228 { false, "CXSPARSE_CPPFLAGS", OCTAVE_CONF_CXSPARSE_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1229 { false, "CXSPARSE_LDFLAGS", OCTAVE_CONF_CXSPARSE_LDFLAGS }, |
9514 | 1230 { false, "CXSPARSE_LIBS", OCTAVE_CONF_CXSPARSE_LIBS }, |
6274 | 1231 { false, "CXX", OCTAVE_CONF_CXX }, |
1232 { false, "CXXCPP", OCTAVE_CONF_CXXCPP }, | |
1233 { false, "CXXFLAGS", OCTAVE_CONF_CXXFLAGS }, | |
1234 { false, "CXXPICFLAG", OCTAVE_CONF_CXXPICFLAG }, | |
1235 { false, "CXX_VERSION", OCTAVE_CONF_CXX_VERSION }, | |
1236 { false, "DEFAULT_PAGER", OCTAVE_DEFAULT_PAGER }, | |
1237 { false, "DEFS", OCTAVE_CONF_DEFS }, | |
1238 { false, "DL_LD", OCTAVE_CONF_DL_LD }, | |
1239 { false, "DL_LDFLAGS", OCTAVE_CONF_DL_LDFLAGS }, | |
9515 | 1240 { false, "DL_LIBS", OCTAVE_CONF_DL_LIBS }, |
6274 | 1241 { false, "ENABLE_DYNAMIC_LINKING", OCTAVE_CONF_ENABLE_DYNAMIC_LINKING }, |
1242 { false, "EXEEXT", OCTAVE_CONF_EXEEXT }, | |
1243 { false, "F77", OCTAVE_CONF_F77 }, | |
1244 { false, "F77_FLOAT_STORE_FLAG", OCTAVE_CONF_F77_FLOAT_STORE_FLAG }, | |
1245 { false, "FC", OCTAVE_CONF_FC }, | |
1246 { false, "FFLAGS", OCTAVE_CONF_FFLAGS }, | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1247 { false, "FFTW3_CPPFLAGS", OCTAVE_CONF_FFTW3_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1248 { false, "FFTW3_LDFLAGS", OCTAVE_CONF_FFTW3_LDFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1249 { false, "FFTW3_LIBS", OCTAVE_CONF_FFTW3_LIBS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1250 { false, "FFTW3F_CPPFLAGS", OCTAVE_CONF_FFTW3F_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1251 { false, "FFTW3F_LDFLAGS", OCTAVE_CONF_FFTW3F_LDFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1252 { false, "FFTW3F_LIBS", OCTAVE_CONF_FFTW3F_LIBS }, |
6274 | 1253 { false, "FLIBS", OCTAVE_CONF_FLIBS }, |
1254 { false, "FPICFLAG", OCTAVE_CONF_FPICFLAG }, | |
9514 | 1255 { false, "FT2_LIBS", OCTAVE_CONF_FT2_LIBS }, |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1256 { false, "GLPK_CPPFLAGS", OCTAVE_CONF_GLPK_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1257 { false, "GLPK_LDFLAGS", OCTAVE_CONF_GLPK_LDFLAGS }, |
6274 | 1258 { false, "GLPK_LIBS", OCTAVE_CONF_GLPK_LIBS }, |
7361 | 1259 { false, "GNUPLOT", OCTAVE_CONF_GNUPLOT }, |
9514 | 1260 { false, "GRAPHICS_LIBS", OCTAVE_CONF_GRAPHICS_LIBS }, |
9542
f5ec5dc66824
use OCTAVE_CHECK_LIBRARY to check for HDF5
John W. Eaton <jwe@octave.org>
parents:
9538
diff
changeset
|
1261 { false, "HDF5_CPPFLAGS", OCTAVE_CONF_HDF5_CPPFLAGS }, |
f5ec5dc66824
use OCTAVE_CHECK_LIBRARY to check for HDF5
John W. Eaton <jwe@octave.org>
parents:
9538
diff
changeset
|
1262 { false, "HDF5_LDFLAGS", OCTAVE_CONF_HDF5_LDFLAGS }, |
9514 | 1263 { false, "HDF5_LIBS", OCTAVE_CONF_HDF5_LIBS }, |
6274 | 1264 { false, "INCFLAGS", OCTAVE_CONF_INCFLAGS }, |
9794
0d4613a736e9
convert build system to use automake and libtool
John W. Eaton <jwe@octave.org>
parents:
9575
diff
changeset
|
1265 { false, "LAPACK_LIBS", OCTAVE_CONF_LAPACK_LIBS }, |
6274 | 1266 { false, "LDFLAGS", OCTAVE_CONF_LDFLAGS }, |
1267 { false, "LD_CXX", OCTAVE_CONF_LD_CXX }, | |
1268 { false, "LD_STATIC_FLAG", OCTAVE_CONF_LD_STATIC_FLAG }, | |
1269 { false, "LEX", OCTAVE_CONF_LEX }, | |
1270 { false, "LEXLIB", OCTAVE_CONF_LEXLIB }, | |
1271 { false, "LFLAGS", OCTAVE_CONF_LFLAGS }, | |
1272 { false, "LIBCRUFT", OCTAVE_CONF_LIBCRUFT }, | |
1273 { false, "LIBEXT", OCTAVE_CONF_LIBEXT }, | |
1274 { false, "LIBFLAGS", OCTAVE_CONF_LIBFLAGS }, | |
1275 { false, "LIBOCTAVE", OCTAVE_CONF_LIBOCTAVE }, | |
1276 { false, "LIBOCTINTERP", OCTAVE_CONF_LIBOCTINTERP }, | |
1277 { false, "LIBS", OCTAVE_CONF_LIBS }, | |
1278 { false, "LN_S", OCTAVE_CONF_LN_S }, | |
9575
55ecaefb7d0f
Use pkg-config to configure GraphicsMagick++.
David Grundberg <individ@acc.umu.se>
parents:
9572
diff
changeset
|
1279 { false, "MAGICK_CPPFLAGS", OCTAVE_CONF_MAGICK_CPPFLAGS }, |
55ecaefb7d0f
Use pkg-config to configure GraphicsMagick++.
David Grundberg <individ@acc.umu.se>
parents:
9572
diff
changeset
|
1280 { false, "MAGICK_LDFLAGS", OCTAVE_CONF_MAGICK_LDFLAGS }, |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7923
diff
changeset
|
1281 { false, "MAGICK_LIBS", OCTAVE_CONF_MAGICK_LIBS }, |
6274 | 1282 { false, "MKOCTFILE_DL_LDFLAGS", OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS }, |
9514 | 1283 { false, "OPENGL_LIBS", OCTAVE_CONF_OPENGL_LIBS }, |
1284 { false, "PTHREAD_CFLAGS", OCTAVE_CONF_PTHREAD_CFLAGS }, | |
1285 { false, "PTHREAD_LIBS", OCTAVE_CONF_PTHREAD_LIBS }, | |
9519
ee99f9f37505
improve configure checks for qhull and curl libs
John W. Eaton <jwe@octave.org>
parents:
9515
diff
changeset
|
1286 { false, "QHULL_CPPFLAGS", OCTAVE_CONF_QHULL_CPPFLAGS }, |
ee99f9f37505
improve configure checks for qhull and curl libs
John W. Eaton <jwe@octave.org>
parents:
9515
diff
changeset
|
1287 { false, "QHULL_LDFLAGS", OCTAVE_CONF_QHULL_LDFLAGS }, |
9514 | 1288 { false, "QHULL_LIBS", OCTAVE_CONF_QHULL_LIBS }, |
9570
1ab56c73ec7c
use OCTAVE_CHECK_LIBRARY to check for qrupdate library
John W. Eaton <jwe@octave.org>
parents:
9568
diff
changeset
|
1289 { false, "QRUPDATE_CPPFLAGS", OCTAVE_CONF_QRUPDATE_CPPFLAGS }, |
1ab56c73ec7c
use OCTAVE_CHECK_LIBRARY to check for qrupdate library
John W. Eaton <jwe@octave.org>
parents:
9568
diff
changeset
|
1290 { false, "QRUPDATE_LDFLAGS", OCTAVE_CONF_QRUPDATE_LDFLAGS }, |
9514 | 1291 { false, "QRUPDATE_LIBS", OCTAVE_CONF_QRUPDATE_LIBS }, |
6274 | 1292 { false, "RANLIB", OCTAVE_CONF_RANLIB }, |
1293 { false, "RDYNAMIC_FLAG", OCTAVE_CONF_RDYNAMIC_FLAG }, | |
9515 | 1294 { false, "READLINE_LIBS", OCTAVE_CONF_READLINE_LIBS }, |
9514 | 1295 { false, "REGEX_LIBS", OCTAVE_CONF_REGEX_LIBS }, |
6274 | 1296 { false, "RLD_FLAG", OCTAVE_CONF_RLD_FLAG }, |
1297 { false, "SED", OCTAVE_CONF_SED }, | |
1298 { false, "SHARED_LIBS", OCTAVE_CONF_SHARED_LIBS }, | |
1299 { false, "SHLEXT", OCTAVE_CONF_SHLEXT }, | |
1300 { false, "SHLEXT_VER", OCTAVE_CONF_SHLEXT_VER }, | |
1301 { false, "SH_LD", OCTAVE_CONF_SH_LD }, | |
1302 { false, "SH_LDFLAGS", OCTAVE_CONF_SH_LDFLAGS }, | |
1303 { false, "SONAME_FLAGS", OCTAVE_CONF_SONAME_FLAGS }, | |
1304 { false, "STATIC_LIBS", OCTAVE_CONF_STATIC_LIBS }, | |
9515 | 1305 { false, "TERM_LIBS", OCTAVE_CONF_TERM_LIBS }, |
6274 | 1306 { false, "UGLY_DEFS", OCTAVE_CONF_UGLY_DEFS }, |
9572
ab8a163f2052
use OCTAVE_CHECK_LIB to check for UMFPACK
John W. Eaton <jwe@octave.org>
parents:
9570
diff
changeset
|
1307 { false, "UMFPACK_CPPFLAGS", OCTAVE_CONF_UMFPACK_CPPFLAGS }, |
ab8a163f2052
use OCTAVE_CHECK_LIB to check for UMFPACK
John W. Eaton <jwe@octave.org>
parents:
9570
diff
changeset
|
1308 { false, "UMFPACK_LDFLAGS", OCTAVE_CONF_UMFPACK_LDFLAGS }, |
9514 | 1309 { false, "UMFPACK_LIBS", OCTAVE_CONF_UMFPACK_LIBS }, |
6274 | 1310 { false, "USE_64_BIT_IDX_T", OCTAVE_CONF_USE_64_BIT_IDX_T }, |
8772
aeedc045cfe3
toplev.cc (Foctave_config_info): add CARBON_LIBS, X11_INCFLAGS, and X11_LIBS to the struct
John W. Eaton <jwe@octave.org>
parents:
8735
diff
changeset
|
1311 { false, "X11_INCFLAGS", OCTAVE_CONF_X11_INCFLAGS }, |
aeedc045cfe3
toplev.cc (Foctave_config_info): add CARBON_LIBS, X11_INCFLAGS, and X11_LIBS to the struct
John W. Eaton <jwe@octave.org>
parents:
8735
diff
changeset
|
1312 { false, "X11_LIBS", OCTAVE_CONF_X11_LIBS }, |
6274 | 1313 { false, "XTRA_CFLAGS", OCTAVE_CONF_XTRA_CFLAGS }, |
1314 { false, "XTRA_CXXFLAGS", OCTAVE_CONF_XTRA_CXXFLAGS }, | |
1315 { false, "YACC", OCTAVE_CONF_YACC }, | |
1316 { false, "YFLAGS", OCTAVE_CONF_YFLAGS }, | |
9538
d0239bddf621
use OCTAVE_CHECK_LIB to check for zlib
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
1317 { false, "Z_CPPFLAGS", OCTAVE_CONF_Z_CPPFLAGS }, |
d0239bddf621
use OCTAVE_CHECK_LIB to check for zlib
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
1318 { false, "Z_LDFLAGS", OCTAVE_CONF_Z_LDFLAGS }, |
d0239bddf621
use OCTAVE_CHECK_LIB to check for zlib
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
1319 { false, "Z_LIBS", OCTAVE_CONF_Z_LIBS }, |
6274 | 1320 { false, "api_version", OCTAVE_API_VERSION }, |
1321 { true, "archlibdir", OCTAVE_ARCHLIBDIR }, | |
1322 { true, "bindir", OCTAVE_BINDIR }, | |
1323 { false, "canonical_host_type", OCTAVE_CANONICAL_HOST_TYPE }, | |
1324 { false, "config_opts", OCTAVE_CONF_config_opts }, | |
1325 { true, "datadir", OCTAVE_DATADIR }, | |
1326 { true, "datarootdir", OCTAVE_DATAROOTDIR }, | |
6276 | 1327 { true, "exec_prefix", OCTAVE_EXEC_PREFIX }, |
6274 | 1328 { true, "fcnfiledir", OCTAVE_FCNFILEDIR }, |
1329 { true, "imagedir", OCTAVE_IMAGEDIR }, | |
1330 { true, "includedir", OCTAVE_INCLUDEDIR }, | |
1331 { true, "infodir", OCTAVE_INFODIR }, | |
6276 | 1332 { true, "infofile", OCTAVE_INFOFILE }, |
6274 | 1333 { true, "libdir", OCTAVE_LIBDIR }, |
1334 { true, "libexecdir", OCTAVE_LIBEXECDIR }, | |
6311 | 1335 { true, "localapiarchlibdir", OCTAVE_LOCALAPIARCHLIBDIR }, |
6274 | 1336 { true, "localapifcnfiledir", OCTAVE_LOCALAPIFCNFILEDIR }, |
1337 { true, "localapioctfiledir", OCTAVE_LOCALAPIOCTFILEDIR }, | |
1338 { true, "localarchlibdir", OCTAVE_LOCALARCHLIBDIR }, | |
1339 { true, "localfcnfiledir", OCTAVE_LOCALFCNFILEDIR }, | |
1340 { true, "localoctfiledir", OCTAVE_LOCALOCTFILEDIR }, | |
1341 { true, "localstartupfiledir", OCTAVE_LOCALSTARTUPFILEDIR }, | |
1342 { true, "localverarchlibdir", OCTAVE_LOCALVERARCHLIBDIR }, | |
1343 { true, "localverfcnfiledir", OCTAVE_LOCALVERFCNFILEDIR }, | |
1344 { true, "localveroctfiledir", OCTAVE_LOCALVEROCTFILEDIR }, | |
1345 { true, "man1dir", OCTAVE_MAN1DIR }, | |
1346 { false, "man1ext", OCTAVE_MAN1EXT }, | |
1347 { true, "mandir", OCTAVE_MANDIR }, | |
1348 { true, "octfiledir", OCTAVE_OCTFILEDIR }, | |
8719
679c270b7584
install DOC and NEWS in $octetcdir
John W. Eaton <jwe@octave.org>
parents:
8704
diff
changeset
|
1349 { true, "octetcdir", OCTAVE_OCTETCDIR }, |
6274 | 1350 { true, "octincludedir", OCTAVE_OCTINCLUDEDIR }, |
1351 { true, "octlibdir", OCTAVE_OCTLIBDIR }, | |
6276 | 1352 { true, "prefix", OCTAVE_PREFIX }, |
6274 | 1353 { true, "startupfiledir", OCTAVE_STARTUPFILEDIR }, |
1354 { false, "version", OCTAVE_VERSION }, | |
1355 { false, 0, 0 } | |
4357 | 1356 }; |
1357 | |
1358 if (! initialized) | |
1359 { | |
4675 | 1360 m.assign ("dld", octave_value (octave_supports_dynamic_linking)); |
4357 | 1361 |
4697 | 1362 oct_mach_info::float_format ff = oct_mach_info::native_float_format (); |
1363 m.assign ("float_format", | |
1364 octave_value (oct_mach_info::float_format_as_string (ff))); | |
1365 | |
1366 m.assign ("words_big_endian", | |
1367 octave_value (oct_mach_info::words_big_endian ())); | |
1368 | |
1369 m.assign ("words_little_endian", | |
1370 octave_value (oct_mach_info::words_little_endian ())); | |
1371 | |
4357 | 1372 int i = 0; |
4440 | 1373 |
1374 while (true) | |
4357 | 1375 { |
6274 | 1376 const conf_info_struct& elt = conf_info[i++]; |
1377 | |
1378 const char *key = elt.key; | |
4357 | 1379 |
1380 if (key) | |
6274 | 1381 { |
1382 if (elt.subst_home) | |
1383 m.assign (key, octave_value (subst_octave_home (elt.val))); | |
1384 else | |
1385 m.assign (key, octave_value (elt.val)); | |
1386 } | |
4357 | 1387 else |
1388 break; | |
1389 } | |
1390 | |
4691 | 1391 bool unix_system = true; |
7013 | 1392 bool mac_system = false; |
4691 | 1393 bool windows_system = false; |
1394 | |
1395 #if defined (WIN32) | |
1396 windows_system = true; | |
1397 #if !defined (__CYGWIN__) | |
1398 unix_system = false; | |
1399 #endif | |
1400 #endif | |
1401 | |
8574
83b8c739d626
toplev.cc: check OCTAVE_USE_OS_X_API instead of __APPLE__ && __MACH__
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1402 #if defined (OCTAVE_USE_OS_X_API) |
7010 | 1403 mac_system = true; |
1404 #endif | |
1405 | |
4691 | 1406 m.assign ("unix", octave_value (unix_system)); |
7010 | 1407 m.assign ("mac", octave_value (mac_system)); |
4691 | 1408 m.assign ("windows", octave_value (windows_system)); |
1409 | |
4357 | 1410 initialized = true; |
1411 } | |
2162 | 1412 |
2689 | 1413 int nargin = args.length (); |
1414 | |
1415 if (nargin == 1) | |
1416 { | |
3523 | 1417 std::string arg = args(0).string_value (); |
2689 | 1418 |
1419 if (! error_state) | |
4675 | 1420 { |
1421 Cell c = m.contents (arg.c_str ()); | |
5199 | 1422 |
1423 if (c.is_empty ()) | |
1424 error ("octave_config_info: no info for `%s'", arg.c_str ()); | |
1425 else | |
1426 retval = c(0); | |
4675 | 1427 } |
2689 | 1428 } |
1429 else if (nargin == 0) | |
4233 | 1430 retval = m; |
2689 | 1431 else |
5823 | 1432 print_usage (); |
2689 | 1433 |
1434 return retval; | |
2162 | 1435 } |
1436 | |
1683 | 1437 #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE) |
2806 | 1438 |
1683 | 1439 int debug_new_delete = 0; |
1440 | |
1441 typedef void (*vfp)(void); | |
1442 extern vfp __new_handler; | |
1443 | |
1444 void * | |
1445 __builtin_new (size_t sz) | |
1446 { | |
1447 void *p; | |
1448 | |
1449 /* malloc (0) is unpredictable; avoid it. */ | |
1450 if (sz == 0) | |
1451 sz = 1; | |
2800 | 1452 p = malloc (sz); |
1683 | 1453 while (p == 0) |
1454 { | |
1455 (*__new_handler) (); | |
2800 | 1456 p = malloc (sz); |
1683 | 1457 } |
1458 | |
1459 if (debug_new_delete) | |
5629 | 1460 std::cerr << "__builtin_new: " << p << std::endl; |
1683 | 1461 |
1462 return p; | |
1463 } | |
1464 | |
1465 void | |
1466 __builtin_delete (void *ptr) | |
1467 { | |
1468 if (debug_new_delete) | |
5629 | 1469 std::cerr << "__builtin_delete: " << ptr << std::endl; |
1683 | 1470 |
1471 if (ptr) | |
1472 free (ptr); | |
1473 } | |
2806 | 1474 |
1683 | 1475 #endif |
1476 | |
1477 /* | |
1478 ;;; Local Variables: *** | |
1479 ;;; mode: C++ *** | |
1480 ;;; End: *** | |
1481 */ |