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